MCPcopy Create free account
hub / github.com/ElementsProject/elements / run_test

Method run_test

test/functional/interface_rest.py:86–355  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

84 return json.loads(resp.read().decode('utf-8'), parse_float=Decimal)
85
86 def run_test(self):
87 self.url = urllib.parse.urlparse(self.nodes[0].url)
88 self.wallet = MiniWallet(self.nodes[0])
89 self.wallet.rescan_utxos()
90
91 self.log.info("Broadcast test transaction and sync nodes")
92 txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))
93 self.sync_all()
94
95 self.log.info("Test the /tx URI")
96
97 json_obj = self.test_rest_request(f"/tx/{txid}")
98 assert_equal(json_obj['txid'], txid)
99
100 # Check hex format response
101 hex_response = self.test_rest_request(f"/tx/{txid}", req_type=ReqType.HEX, ret_type=RetType.OBJ)
102 assert_greater_than_or_equal(int(hex_response.getheader('content-length')),
103 json_obj['size']*2)
104
105 spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) # get the vin to later check for utxo (should be spent by then)
106 # get n of 0.1 outpoint
107 n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1'))
108 spending = (txid, n)
109
110 # Test /tx with an invalid and an unknown txid
111 resp = self.test_rest_request(uri=f"/tx/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400)
112 assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid hash: {INVALID_PARAM}")
113 resp = self.test_rest_request(uri=f"/tx/{UNKNOWN_PARAM}", ret_type=RetType.OBJ, status=404)
114 assert_equal(resp.read().decode('utf-8').rstrip(), f"{UNKNOWN_PARAM} not found")
115
116 self.log.info("Query an unspent TXO using the /getutxos URI")
117
118 self.generate(self.wallet, 1)
119 bb_hash = self.nodes[0].getbestblockhash()
120
121 # Check chainTip response
122 json_obj = self.test_rest_request(f"/getutxos/{spending[0]}-{spending[1]}")
123 assert_equal(json_obj['chaintipHash'], bb_hash)
124
125 # Make sure there is one utxo
126 assert_equal(len(json_obj['utxos']), 1)
127 assert_equal(json_obj['utxos'][0]['value'], Decimal('0.1'))
128
129 self.log.info("Query a spent TXO using the /getutxos URI")
130
131 json_obj = self.test_rest_request(f"/getutxos/{spent[0]}-{spent[1]}")
132
133 # Check chainTip response
134 assert_equal(json_obj['chaintipHash'], bb_hash)
135
136 # Make sure there is no utxo in the response because this outpoint has been spent
137 assert_equal(len(json_obj['utxos']), 0)
138
139 # Check bitmap
140 assert_equal(json_obj['bitmap'], "0")
141
142 self.log.info("Query two TXOs using the /getutxos URI")
143

Callers

nothing calls this directly

Calls 15

test_rest_requestMethod · 0.95
MiniWalletClass · 0.90
getnewdestinationFunction · 0.90
assert_equalFunction · 0.90
assert_greater_thanFunction · 0.90
rescan_utxosMethod · 0.80
infoMethod · 0.80
send_toMethod · 0.80
hexMethod · 0.80
send_self_transferMethod · 0.80

Tested by

no test coverage detected