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