-
Notifications
You must be signed in to change notification settings - Fork 387
/
test_transfer.py
80 lines (47 loc) · 2.1 KB
/
test_transfer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python3
import brownie
def test_sender_balance_decreases(alice, bob, token):
sender_balance = token.balanceOf(alice)
amount = sender_balance // 4
token.transfer(bob, amount, {"from": alice})
assert token.balanceOf(alice) == sender_balance - amount
def test_receiver_balance_increases(alice, bob, token):
receiver_balance = token.balanceOf(bob)
amount = token.balanceOf(alice) // 4
token.transfer(bob, amount, {"from": alice})
assert token.balanceOf(bob) == receiver_balance + amount
def test_total_supply_not_affected(alice, bob, token):
total_supply = token.totalSupply()
amount = token.balanceOf(alice)
token.transfer(bob, amount, {"from": alice})
assert token.totalSupply() == total_supply
def test_returns_true(alice, bob, token):
amount = token.balanceOf(alice)
tx = token.transfer(bob, amount, {"from": alice})
assert tx.return_value is True
def test_transfer_full_balance(alice, bob, token):
amount = token.balanceOf(alice)
receiver_balance = token.balanceOf(bob)
token.transfer(bob, amount, {"from": alice})
assert token.balanceOf(alice) == 0
assert token.balanceOf(bob) == receiver_balance + amount
def test_transfer_zero_tokens(alice, bob, token):
sender_balance = token.balanceOf(alice)
receiver_balance = token.balanceOf(bob)
token.transfer(bob, 0, {"from": alice})
assert token.balanceOf(alice) == sender_balance
assert token.balanceOf(bob) == receiver_balance
def test_transfer_to_self(alice, bob, token):
sender_balance = token.balanceOf(alice)
amount = sender_balance // 4
token.transfer(alice, amount, {"from": alice})
assert token.balanceOf(alice) == sender_balance
def test_insufficient_balance(alice, bob, token):
balance = token.balanceOf(alice)
with brownie.reverts():
token.transfer(bob, balance + 1, {"from": alice})
def test_transfer_event_fires(alice, bob, token):
amount = token.balanceOf(alice)
tx = token.transfer(bob, amount, {"from": alice})
assert len(tx.events) == 1
assert tx.events["Transfer"].values() == [alice, bob, amount]