Changeset View
Changeset View
Standalone View
Standalone View
test/functional/merkle_blocks.py
Show All 10 Lines | |||||
from test_framework.util import * | from test_framework.util import * | ||||
class MerkleBlockTest(BitcoinTestFramework): | class MerkleBlockTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 4 | self.num_nodes = 4 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
# Nodes 0/1 are "wallet" nodes, Nodes 2/3 are used for testing | # Nodes 0/1 are "wallet" nodes, Nodes 2/3 are used for testing | ||||
self.extra_args = [["-deprecatedrpc=signrawtransaction"], | self.extra_args = [[], [], [], ["-txindex"]] | ||||
["-deprecatedrpc=signrawtransaction"], [], ["-txindex"]] | |||||
def setup_network(self): | def setup_network(self): | ||||
self.setup_nodes() | self.setup_nodes() | ||||
connect_nodes(self.nodes[0], 1) | connect_nodes(self.nodes[0], 1) | ||||
connect_nodes(self.nodes[0], 2) | connect_nodes(self.nodes[0], 2) | ||||
connect_nodes(self.nodes[0], 3) | connect_nodes(self.nodes[0], 3) | ||||
self.sync_all() | self.sync_all() | ||||
def run_test(self): | def run_test(self): | ||||
self.log.info("Mining blocks...") | self.log.info("Mining blocks...") | ||||
self.nodes[0].generate(105) | self.nodes[0].generate(105) | ||||
self.sync_all() | self.sync_all() | ||||
chain_height = self.nodes[1].getblockcount() | chain_height = self.nodes[1].getblockcount() | ||||
assert_equal(chain_height, 105) | assert_equal(chain_height, 105) | ||||
assert_equal(self.nodes[1].getbalance(), 0) | assert_equal(self.nodes[1].getbalance(), 0) | ||||
assert_equal(self.nodes[2].getbalance(), 0) | assert_equal(self.nodes[2].getbalance(), 0) | ||||
node0utxos = self.nodes[0].listunspent(1) | node0utxos = self.nodes[0].listunspent(1) | ||||
tx1 = self.nodes[0].createrawtransaction( | tx1 = self.nodes[0].createrawtransaction( | ||||
[node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99}) | [node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99}) | ||||
txid1 = self.nodes[0].sendrawtransaction( | txid1 = self.nodes[0].sendrawtransaction( | ||||
self.nodes[0].signrawtransaction(tx1)["hex"]) | self.nodes[0].signrawtransactionwithwallet(tx1)["hex"]) | ||||
tx2 = self.nodes[0].createrawtransaction( | tx2 = self.nodes[0].createrawtransaction( | ||||
[node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99}) | [node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99}) | ||||
txid2 = self.nodes[0].sendrawtransaction( | txid2 = self.nodes[0].sendrawtransaction( | ||||
self.nodes[0].signrawtransaction(tx2)["hex"]) | self.nodes[0].signrawtransactionwithwallet(tx2)["hex"]) | ||||
# This will raise an exception because the transaction is not yet in a block | # This will raise an exception because the transaction is not yet in a block | ||||
assert_raises_rpc_error(-5, "Transaction not yet in block", | assert_raises_rpc_error(-5, "Transaction not yet in block", | ||||
self.nodes[0].gettxoutproof, [txid1]) | self.nodes[0].gettxoutproof, [txid1]) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
blockhash = self.nodes[0].getblockhash(chain_height + 1) | blockhash = self.nodes[0].getblockhash(chain_height + 1) | ||||
self.sync_all() | self.sync_all() | ||||
txlist = [] | txlist = [] | ||||
blocktxn = self.nodes[0].getblock(blockhash, True)["tx"] | blocktxn = self.nodes[0].getblock(blockhash, True)["tx"] | ||||
txlist.append(blocktxn[1]) | txlist.append(blocktxn[1]) | ||||
txlist.append(blocktxn[2]) | txlist.append(blocktxn[2]) | ||||
assert_equal(self.nodes[2].verifytxoutproof( | assert_equal(self.nodes[2].verifytxoutproof( | ||||
self.nodes[2].gettxoutproof([txid1])), [txid1]) | self.nodes[2].gettxoutproof([txid1])), [txid1]) | ||||
assert_equal(self.nodes[2].verifytxoutproof( | assert_equal(self.nodes[2].verifytxoutproof( | ||||
self.nodes[2].gettxoutproof([txid1, txid2])), txlist) | self.nodes[2].gettxoutproof([txid1, txid2])), txlist) | ||||
assert_equal(self.nodes[2].verifytxoutproof( | assert_equal(self.nodes[2].verifytxoutproof( | ||||
self.nodes[2].gettxoutproof([txid1, txid2], blockhash)), txlist) | self.nodes[2].gettxoutproof([txid1, txid2], blockhash)), txlist) | ||||
txin_spent = self.nodes[1].listunspent(1).pop() | txin_spent = self.nodes[1].listunspent(1).pop() | ||||
tx3 = self.nodes[1].createrawtransaction( | tx3 = self.nodes[1].createrawtransaction( | ||||
[txin_spent], {self.nodes[0].getnewaddress(): 49.98}) | [txin_spent], {self.nodes[0].getnewaddress(): 49.98}) | ||||
txid3 = self.nodes[0].sendrawtransaction( | txid3 = self.nodes[0].sendrawtransaction( | ||||
self.nodes[1].signrawtransaction(tx3)["hex"]) | self.nodes[1].signrawtransactionwithwallet(tx3)["hex"]) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
self.sync_all() | self.sync_all() | ||||
txid_spent = txin_spent["txid"] | txid_spent = txin_spent["txid"] | ||||
txid_unspent = txid1 if txin_spent["txid"] != txid1 else txid2 | txid_unspent = txid1 if txin_spent["txid"] != txid1 else txid2 | ||||
# We can't find the block from a fully-spent tx | # We can't find the block from a fully-spent tx | ||||
assert_raises_rpc_error(-5, "Transaction not yet in block", | assert_raises_rpc_error(-5, "Transaction not yet in block", | ||||
Show All 25 Lines |