forked from qtumproject/qtum-bitcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtum-searchlog-restart-node.py
executable file
·148 lines (116 loc) · 8.26 KB
/
qtum-searchlog-restart-node.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/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
RPC_INVALID_PARAMETER = -8
class QtumRPCSearchlogsTestModified(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self, split=False):
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,extra_args=[["-logevents"]])
self.is_network_split = False
def create_contracts_with_logs(self):
contract_addresses = []
send_result = []
block_hashes = []
self.nodes[0].generate(600)
contract_address = self.nodes[0].createcontract("6060604052600d600055341561001457600080fd5b61017e806100236000396000f30060606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063027c1aaf1461004e5780635b9af12b14610058575b005b61005661008f565b005b341561006357600080fd5b61007960048080359060200190919050506100a1565b6040518082815260200191505060405180910390f35b60026000808282540292505081905550565b60007fc5c442325655248f6bccf5c6181738f8755524172cea2a8bd1e38e43f833e7f282600054016000548460405180848152602001838152602001828152602001935050505060405180910390a17fc5c442325655248f6bccf5c6181738f8755524172cea2a8bd1e38e43f833e7f282600054016000548460405180848152602001838152602001828152602001935050505060405180910390a1816000540160008190555060005490509190505600a165627a7a7230582015732bfa66bdede47ecc05446bf4c1e8ed047efac25478cb13b795887df70f290029")['address']
self.nodes[0].generate(1)
contract_addresses.append(contract_address)
send_result.append(self.nodes[0].sendtocontract(contract_address,"5b9af12b"))
block_hashes.append(self.nodes[0].generate(1))
contract_address = self.nodes[0].createcontract("6060604052341561000f57600080fd5b61029b8061001e6000396000f300606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806394e8767d14610067578063b717cfe6146100a6578063d3b57be9146100bb578063f7e52d58146100d0575b600080fd5b341561007257600080fd5b61008860048080359060200190919050506100e5565b60405180826000191660001916815260200191505060405180910390f35b34156100b157600080fd5b6100b961018e565b005b34156100c657600080fd5b6100ce6101a9565b005b34156100db57600080fd5b6100e36101b3565b005b600080821415610117577f30000000000000000000000000000000000000000000000000000000000000009050610186565b5b600082111561018557610100816001900481151561013257fe5b0460010290507f01000000000000000000000000000000000000000000000000000000000000006030600a8481151561016757fe5b06010260010281179050600a8281151561017d57fe5b049150610118565b5b809050919050565b60008081548092919060010191905055506101a76101b3565b565b6101b161018e565b565b7f746f7069632034000000000000000000000000000000000000000000000000007f746f7069632033000000000000000000000000000000000000000000000000007f746f7069632032000000000000000000000000000000000000000000000000007f746f70696320310000000000000000000000000000000000000000000000000060405180807f3700000000000000000000000000000000000000000000000000000000000000815250600101905060405180910390a45600a165627a7a72305820262764914338437fc49c9f752503904820534b24092308961bc10cd851985ae50029")['address']
self.nodes[0].generate(1)
contract_addresses.append(contract_address)
send_result.append(self.nodes[0].sendtocontract(contract_address,"d3b57be9"))
block_hashes.append(self.nodes[0].generate(1))
return contract_addresses, send_result, block_hashes
def check_logs(self, contract_addresses,first_output,first_call=True):
addresses = {}
address = []
address.append(contract_addresses[0])
addresses["addresses"] = address
topics = {}
topic = []
topic.append("c5c442325655248f6bccf5c6181738f8755524172cea2a8bd1e38e43f833e7f2")
topics["topics"] = topic
error_topics = {}
error_topic = []
error_topic.append("35c442325655248f6bccf5c6181738f8755524172cea2a8bd1e38e43f833e7f2")
error_topics["topics"] = error_topic
if first_call:
first_output.append(self.nodes[0].searchlogs(602,602,addresses))
else:
assert_equal(self.nodes[0].searchlogs(602,602,addresses),first_output[0])
assert_equal(self.nodes[0].searchlogs(602,602,addresses),self.nodes[0].searchlogs(602,602,addresses,topics))
assert_equal(self.nodes[0].searchlogs(602,602,addresses,error_topics),[])
address.clear()
address.append(contract_addresses[1])
topic.clear()
topic.append("746f706963203100000000000000000000000000000000000000000000000000")
topic.append("746f706963203200000000000000000000000000000000000000000000000000")
if first_call:
first_output.append(self.nodes[0].searchlogs(604,604,addresses))
else:
assert_equal(self.nodes[0].searchlogs(604,604,addresses),first_output[1])
assert_equal(self.nodes[0].searchlogs(604,604,addresses),self.nodes[0].searchlogs(604,604,addresses,topics))
topic.reverse()
assert_equal(self.nodes[0].searchlogs(604,604,addresses,topics),[])
topic.remove("746f706963203200000000000000000000000000000000000000000000000000")
topic.append("746f706963203300000000000000000000000000000000000000000000000000")
assert_equal(self.nodes[0].searchlogs(604,604,addresses),self.nodes[0].searchlogs(604,604,addresses,topics))
topic.remove("746f706963203100000000000000000000000000000000000000000000000000")
topic.insert(0,"746f706963103100000000000000000000000000000000000000000000000000")
assert_equal(self.nodes[0].searchlogs(604,604,addresses,topics),[])
topic.remove("746f706963203300000000000000000000000000000000000000000000000000")
topic.insert(1,"746f706963203200000000000000000000000000000000000000000000000000")
assert_equal(self.nodes[0].searchlogs(604,604,addresses),self.nodes[0].searchlogs(604,604,addresses,topics))
topic.reverse()
assert_equal(self.nodes[0].searchlogs(604,604,addresses,topics),[])
def check_searchlogs(self, contract_addresses, send_result, block_hashes):
try:
self.nodes[0].searchlogs(0,0)
except JSONRPCException as exp:
assert_equal(exp.error["code"], RPC_INVALID_PARAMETER)
try:
self.nodes[0].searchlogs(1,0)
except JSONRPCException as exp:
assert_equal(exp.error["code"], RPC_INVALID_PARAMETER)
try:
self.nodes[0].searchlogs(604,0)
except JSONRPCException as exp:
assert_equal(exp.error["code"], RPC_INVALID_PARAMETER)
ret = self.nodes[0].searchlogs(0,604)
assert_equal(ret[0]['blockHash'], block_hashes[0][0])
assert_equal(ret[0]['blockNumber'], 602)
assert_equal(ret[0]['transactionHash'], send_result[0]['txid'])
assert_equal(ret[0]['transactionIndex'], 1)
assert_equal(ret[0]['from'], send_result[0]['hash160'])
assert_equal(ret[0]['to'], contract_addresses[0])
assert_equal(ret[0]['gasUsed'], 30991)
assert_equal(ret[0]['contractAddress'], contract_addresses[0])
assert_equal(ret[1]['blockHash'], block_hashes[1][0])
assert_equal(ret[1]['blockNumber'], 604)
assert_equal(ret[1]['transactionHash'], send_result[1]['txid'])
assert_equal(ret[1]['transactionIndex'], 1)
assert_equal(ret[1]['from'], send_result[1]['hash160'])
assert_equal(ret[1]['to'], contract_addresses[1])
assert_equal(ret[1]['gasUsed'], 43679)
assert_equal(ret[1]['contractAddress'], contract_addresses[1])
def run_test(self):
contract_addresses, send_result, block_hashes = self.create_contracts_with_logs()
first_output = []
self.check_searchlogs(contract_addresses, send_result, block_hashes)
self.check_logs(contract_addresses,first_output)
stop_nodes(self.nodes) #turn off node
self.setup_network() #start node again
self.check_logs(contract_addresses, first_output, False)
if __name__ == '__main__':
QtumRPCSearchlogsTestModified().main()