forked from qtumproject/qtum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqtum-state-root.py
More file actions
executable file
·60 lines (53 loc) · 2.35 KB
/
qtum-state-root.py
File metadata and controls
executable file
·60 lines (53 loc) · 2.35 KB
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
#!/usr/bin/env python3
# Copyright (c) 2015-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.script import *
from test_framework.mininode import *
import sys
class StateRootTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
# verify that the state hash is not 0 on genesis
def verify_not_null_test(self):
block_hash = self.node.getblockhash(0)
block = self.node.getblock(block_hash)
assert(int(block['hashStateRoot'], 16) != 0)
# verify that the state hash changes on contract creation
def verify_state_hash_changes(self):
amount = 20000*COIN
self.node.generate(COINBASE_MATURITY+50)
block_hash_a = self.node.getblockhash(COINBASE_MATURITY+50)
block_a = self.node.getblock(block_hash_a)
"""
pragma solidity ^0.4.10;
contract Example {
function () payable {}
}
"""
self.node.createcontract("60606040523415600b57fe5b5b60398060196000396000f30060606040525b600b5b5b565b0000a165627a7a7230582092926a9814888ff08700cbd86cf4ff8c50052f5fd894e794570d9551733591d60029")
self.node.generate(1)
block_hash_b = self.node.getblockhash(COINBASE_MATURITY+51)
block_b = self.node.getblock(block_hash_b)
assert(block_a['hashStateRoot'] != block_b['hashStateRoot'])
# verify that the state hash remains the same on restart
def verify_state_hash_remains_on_restart(self):
block_hash_a = self.node.getblockhash(COINBASE_MATURITY+51)
block_a = self.node.getblock(block_hash_a)
self.stop_nodes()
self.start_nodes()
self.node = self.nodes[0]
self.node.generate(1)
block_hash_b = self.node.getblockhash(COINBASE_MATURITY+52)
block_b = self.node.getblock(block_hash_b)
assert(block_a['hashStateRoot'] == block_b['hashStateRoot'])
def run_test(self):
self.node = self.nodes[0]
self.verify_not_null_test()
self.verify_state_hash_changes()
self.verify_state_hash_remains_on_restart()
if __name__ == '__main__':
StateRootTest().main()