@@ -55,78 +55,78 @@ def setup_network(self, split=False):
55
55
connect_nodes_bi (self .nodes ,0 ,2 )
56
56
self .is_network_split = False
57
57
self .sync_all ()
58
-
58
+
59
59
def run_test (self ):
60
60
url = urlparse .urlparse (self .nodes [0 ].url )
61
61
print "Mining blocks..."
62
-
62
+
63
63
self .nodes [0 ].generate (1 )
64
64
self .sync_all ()
65
65
self .nodes [2 ].generate (100 )
66
66
self .sync_all ()
67
-
67
+
68
68
assert_equal (self .nodes [0 ].getbalance (), 50 )
69
-
69
+
70
70
txid = self .nodes [0 ].sendtoaddress (self .nodes [1 ].getnewaddress (), 0.1 )
71
71
self .sync_all ()
72
72
self .nodes [2 ].generate (1 )
73
73
self .sync_all ()
74
74
bb_hash = self .nodes [0 ].getbestblockhash ()
75
-
75
+
76
76
assert_equal (self .nodes [1 ].getbalance (), Decimal ("0.1" )) #balance now should be 0.1 on node 1
77
-
77
+
78
78
# load the latest 0.1 tx over the REST API
79
79
json_string = http_get_call (url .hostname , url .port , '/rest/tx/' + txid + self .FORMAT_SEPARATOR + "json" )
80
80
json_obj = json .loads (json_string )
81
81
vintx = json_obj ['vin' ][0 ]['txid' ] # get the vin to later check for utxo (should be spent by then)
82
- # get n of 0.1 outpoint
82
+ # get n of 0.1 outpoint
83
83
n = 0
84
84
for vout in json_obj ['vout' ]:
85
85
if vout ['value' ] == 0.1 :
86
86
n = vout ['n' ]
87
-
88
-
87
+
88
+
89
89
######################################
90
90
# GETUTXOS: query a unspent outpoint #
91
91
######################################
92
- json_request = '{" checkmempool":true,"outpoints":[{"txid":" ' + txid + '","n": ' + str (n )+ '}]}'
93
- json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'json' , json_request )
92
+ json_request = '/ checkmempool/ ' + txid + '- ' + str (n )
93
+ json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
94
94
json_obj = json .loads (json_string )
95
-
95
+
96
96
#check chainTip response
97
97
assert_equal (json_obj ['chaintipHash' ], bb_hash )
98
-
98
+
99
99
#make sure there is one utxo
100
100
assert_equal (len (json_obj ['utxos' ]), 1 )
101
101
assert_equal (json_obj ['utxos' ][0 ]['value' ], 0.1 )
102
-
103
-
102
+
103
+
104
104
################################################
105
105
# GETUTXOS: now query a already spent outpoint #
106
106
################################################
107
- json_request = '{" checkmempool":true,"outpoints":[{"txid":" ' + vintx + '","n":0}]} '
108
- json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'json' , json_request )
107
+ json_request = '/ checkmempool/ ' + vintx + '-0 '
108
+ json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
109
109
json_obj = json .loads (json_string )
110
-
110
+
111
111
#check chainTip response
112
112
assert_equal (json_obj ['chaintipHash' ], bb_hash )
113
113
114
114
#make sure there is no utox in the response because this oupoint has been spent
115
115
assert_equal (len (json_obj ['utxos' ]), 0 )
116
-
116
+
117
117
#check bitmap
118
118
assert_equal (json_obj ['bitmap' ], "0" )
119
-
120
-
119
+
120
+
121
121
##################################################
122
122
# GETUTXOS: now check both with the same request #
123
123
##################################################
124
- json_request = '{" checkmempool":true,"outpoints":[{"txid":" ' + txid + '","n": ' + str (n )+ '},{"txid":" ' + vintx + '","n":0}]} '
125
- json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'json' , json_request )
124
+ json_request = '/ checkmempool/ ' + txid + '- ' + str (n )+ '/ ' + vintx + '-0 '
125
+ json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
126
126
json_obj = json .loads (json_string )
127
127
assert_equal (len (json_obj ['utxos' ]), 1 )
128
128
assert_equal (json_obj ['bitmap' ], "10" )
129
-
129
+
130
130
#test binary response
131
131
bb_hash = self .nodes [0 ].getbestblockhash ()
132
132
@@ -135,19 +135,18 @@ def run_test(self):
135
135
binaryRequest += pack ("i" , n );
136
136
binaryRequest += binascii .unhexlify (vintx );
137
137
binaryRequest += pack ("i" , 0 );
138
-
138
+
139
139
bin_response = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'bin' , binaryRequest )
140
-
141
140
output = StringIO .StringIO ()
142
141
output .write (bin_response )
143
142
output .seek (0 )
144
143
chainHeight = unpack ("i" , output .read (4 ))[0 ]
145
144
hashFromBinResponse = hex (deser_uint256 (output ))[2 :].zfill (65 ).rstrip ("L" )
146
-
145
+
147
146
assert_equal (bb_hash , hashFromBinResponse ) #check if getutxo's chaintip during calculation was fine
148
147
assert_equal (chainHeight , 102 ) #chain height must be 102
149
-
150
-
148
+
149
+
151
150
############################
152
151
# GETUTXOS: mempool checks #
153
152
############################
@@ -157,55 +156,56 @@ def run_test(self):
157
156
json_string = http_get_call (url .hostname , url .port , '/rest/tx/' + txid + self .FORMAT_SEPARATOR + "json" )
158
157
json_obj = json .loads (json_string )
159
158
vintx = json_obj ['vin' ][0 ]['txid' ] # get the vin to later check for utxo (should be spent by then)
160
- # get n of 0.1 outpoint
159
+ # get n of 0.1 outpoint
161
160
n = 0
162
161
for vout in json_obj ['vout' ]:
163
162
if vout ['value' ] == 0.1 :
164
163
n = vout ['n' ]
165
-
166
- json_request = '{"checkmempool":false,"outpoints":[{"txid":" ' + txid + '","n": ' + str (n )+ '}]}'
167
- json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'json' , json_request )
164
+
165
+ json_request = '/ ' + txid + '- ' + str (n )
166
+ json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
168
167
json_obj = json .loads (json_string )
169
168
assert_equal (len (json_obj ['utxos' ]), 0 ) #there should be a outpoint because it has just added to the mempool
170
-
171
- json_request = '{" checkmempool":true,"outpoints":[{"txid":" ' + txid + '","n": ' + str (n )+ '}]}'
172
- json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'json' , json_request )
169
+
170
+ json_request = '/ checkmempool/ ' + txid + '- ' + str (n )
171
+ json_string = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' )
173
172
json_obj = json .loads (json_string )
174
173
assert_equal (len (json_obj ['utxos' ]), 1 ) #there should be a outpoint because it has just added to the mempool
175
-
174
+
176
175
#do some invalid requests
177
176
json_request = '{"checkmempool'
178
177
response = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'json' , json_request , True )
179
178
assert_equal (response .status , 500 ) #must be a 500 because we send a invalid json request
180
-
179
+
181
180
json_request = '{"checkmempool'
182
181
response = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'bin' , json_request , True )
183
182
assert_equal (response .status , 500 ) #must be a 500 because we send a invalid bin request
184
-
183
+
184
+ response = http_get_call (url .hostname , url .port , '/rest/getutxos/checkmempool' + self .FORMAT_SEPARATOR + 'bin' , '' , True )
185
+ assert_equal (response .status , 500 ) #must be a 500 because we send a invalid bin request
186
+
185
187
#test limits
186
- json_request = '{"checkmempool":true,"outpoints":['
187
- for x in range (0 , 200 ):
188
- json_request += '{"txid":"' + txid + '","n":' + str (n )+ '},'
189
- json_request = json_request .rstrip ("," )
190
- json_request += "]}" ;
191
- response = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'json' , json_request , True )
188
+ json_request = '/checkmempool/'
189
+ for x in range (0 , 20 ):
190
+ json_request += txid + '-' + str (n )+ '/'
191
+ json_request = json_request .rstrip ("/" )
192
+ response = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' , '' , True )
192
193
assert_equal (response .status , 500 ) #must be a 500 because we exceeding the limits
193
-
194
- json_request = '{"checkmempool":true,"outpoints":['
195
- for x in range (0 , 90 ):
196
- json_request += '{"txid":"' + txid + '","n":' + str (n )+ '},'
197
- json_request = json_request .rstrip ("," )
198
- json_request += "]}" ;
199
- response = http_get_call (url .hostname , url .port , '/rest/getutxos' + self .FORMAT_SEPARATOR + 'json' , json_request , True )
194
+
195
+ json_request = '/checkmempool/'
196
+ for x in range (0 , 15 ):
197
+ json_request += txid + '-' + str (n )+ '/'
198
+ json_request = json_request .rstrip ("/" );
199
+ response = http_get_call (url .hostname , url .port , '/rest/getutxos' + json_request + self .FORMAT_SEPARATOR + 'json' , '' , True )
200
200
assert_equal (response .status , 200 ) #must be a 500 because we exceeding the limits
201
201
202
202
self .nodes [0 ].generate (1 ) #generate block to not affect upcomming tests
203
203
self .sync_all ()
204
-
204
+
205
205
################
206
206
# /rest/block/ #
207
207
################
208
-
208
+
209
209
# check binary format
210
210
response = http_get_call (url .hostname , url .port , '/rest/block/' + bb_hash + self .FORMAT_SEPARATOR + "bin" , "" , True )
211
211
assert_equal (response .status , 200 )
@@ -249,7 +249,7 @@ def run_test(self):
249
249
hex_string = http_get_call (url .hostname , url .port , '/rest/tx/' + tx_hash + self .FORMAT_SEPARATOR + "hex" , "" , True )
250
250
assert_equal (hex_string .status , 200 )
251
251
assert_greater_than (int (response .getheader ('content-length' )), 10 )
252
-
252
+
253
253
254
254
255
255
# check block tx details
@@ -279,7 +279,7 @@ def run_test(self):
279
279
280
280
#test rest bestblock
281
281
bb_hash = self .nodes [0 ].getbestblockhash ()
282
-
282
+
283
283
json_string = http_get_call (url .hostname , url .port , '/rest/chaininfo.json' )
284
284
json_obj = json .loads (json_string )
285
285
assert_equal (json_obj ['bestblockhash' ], bb_hash )
0 commit comments