-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_transaction.py
74 lines (52 loc) · 1.56 KB
/
test_transaction.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
from sktest_helpers import *
import pytest
@pytest.fixture
def schain1():
ch = create_default_chain(num_nodes=1)
ch.start()
yield ch
ch.stop()
@pytest.fixture
def schain2():
ch = create_default_chain(num_nodes=2)
ch.start()
yield ch
ch.stop()
@pytest.fixture(params=[2, 3])
def schain_n(request):
ch = create_default_chain(num_nodes=request.param)
ch.start()
yield ch
ch.stop()
def test_one_node(schain1):
ch = schain1
assert (ch.eth.blockNumber == 0)
assert (ch.nonce(0) == 0)
balance = ch.balance(0)
ch.transaction()
assert (ch.eth.blockNumber == 1)
assert (ch.nonce(0) == 1)
assert (balance > ch.balance(0))
def test_two_nodes(schain2):
ch = schain2
eth2 = ch.nodes[1].eth
acc1 = ch.accounts[0]
acc2 = ch.accounts[1]
balance1 = eth2.getBalance(acc1)
balance2 = eth2.getBalance(acc2)
assert (eth2.blockNumber == 0)
assert (eth2.getTransactionCount(acc1) == 0)
ch.transaction()
assert (eth2.blockNumber == 1)
assert (eth2.getTransactionCount(acc1) == 1)
assert (balance1 > eth2.getBalance(acc1))
assert (balance2 < eth2.getBalance(acc2))
# gas cost goes to 0 address
assert (balance1 + balance2 == eth2.getBalance(acc1) + eth2.getBalance(acc2) + eth2.getBalance("0x0000000000000000000000000000000000000000"))
assert (ch.compare_all_states() is None)
def test_n_nodes(schain_n):
ch = schain_n
assert (ch.eth.blockNumber == 0)
assert (ch.nonce(0) == 0)
ch.transaction()
assert (ch.compare_all_states() is None)