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

Method run_test

test/functional/feature_nulldummy.py:61–121  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

59 self.skip_if_no_wallet()
60
61 def run_test(self):
62 util.node_fastmerkle = self.nodes[0]
63 self.nodes[0].createwallet(wallet_name='wmulti', disable_private_keys=True)
64 wmulti = self.nodes[0].get_wallet_rpc('wmulti')
65 w0 = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
66 self.address = w0.getnewaddress()
67 self.pubkey = w0.getaddressinfo(self.address)['pubkey']
68 self.ms_address = wmulti.addmultisigaddress(1, [self.pubkey])['address']
69 self.wit_address = w0.getnewaddress(address_type='p2sh-segwit')
70 self.wit_ms_address = wmulti.addmultisigaddress(1, [self.pubkey], '', 'p2sh-segwit')['address']
71 if not self.options.descriptors:
72 # Legacy wallets need to import these so that they are watched by the wallet. This is unnecessary (and does not need to be tested) for descriptor wallets
73 wmulti.importaddress(self.ms_address)
74 wmulti.importaddress(self.wit_ms_address)
75
76 self.coinbase_blocks = self.generate(self.nodes[0], 2) # block height = 2
77 coinbase_txid = []
78 for i in self.coinbase_blocks:
79 coinbase_txid.append(self.nodes[0].getblock(i)['tx'][0])
80 self.generate(self.nodes[0], COINBASE_MATURITY) # block height = COINBASE_MATURITY + 2
81 self.lastblockhash = self.nodes[0].getbestblockhash()
82 self.lastblockheight = COINBASE_MATURITY + 2
83 self.lastblocktime = int(time.time()) + self.lastblockheight
84
85 self.log.info(f"Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [{COINBASE_MATURITY + 3}]")
86 coinbase_value = self.nodes[0].gettxout(coinbase_txid[0], 0)["value"]
87 test1txs = [create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, amount=49, fee=coinbase_value-49)]
88 txid1 = self.nodes[0].sendrawtransaction(test1txs[0].serialize_with_witness().hex(), 0)
89 test1txs.append(create_transaction(self.nodes[0], txid1, self.ms_address, amount=48, fee=49-48))
90 txid2 = self.nodes[0].sendrawtransaction(test1txs[1].serialize_with_witness().hex(), 0)
91 coinbase_value = self.nodes[0].gettxout(coinbase_txid[1], 0)["value"]
92 test1txs.append(create_transaction(self.nodes[0], coinbase_txid[1], self.wit_ms_address, amount=49, fee=coinbase_value-49))
93 txid3 = self.nodes[0].sendrawtransaction(test1txs[2].serialize_with_witness().hex(), 0)
94 self.block_submit(self.nodes[0], test1txs, accept=True)
95
96 self.log.info("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation")
97 test2tx = create_transaction(self.nodes[0], txid2, self.ms_address, amount=47, fee=48-47)
98 invalidate_nulldummy_tx(test2tx)
99 assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test2tx.serialize_with_witness().hex(), 0)
100
101 self.log.info(f"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [{COINBASE_MATURITY + 4}]")
102 self.block_submit(self.nodes[0], [test2tx], accept=True)
103
104 self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
105 test4tx = create_transaction(self.nodes[0], test2tx.hash, self.address, amount=46, fee=47-46)
106 test6txs = [CTransaction(test4tx)]
107 invalidate_nulldummy_tx(test4tx)
108 assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test4tx.serialize_with_witness().hex(), 0)
109 self.block_submit(self.nodes[0], [test4tx], accept=False)
110
111 self.log.info("Test 5: Non-NULLDUMMY P2WSH multisig transaction invalid after activation")
112 test5tx = create_transaction(self.nodes[0], txid3, self.wit_address, amount=48, fee=49-48)
113 test6txs.append(CTransaction(test5tx))
114 test5tx.wit.vtxinwit[0].scriptWitness.stack[0] = b'\x01'
115 assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test5tx.serialize_with_witness().hex(), 0)
116 self.block_submit(self.nodes[0], [test5tx], with_witness=True, accept=False)
117
118 self.log.info(f"Test 6: NULLDUMMY compliant base/witness transactions should be accepted to mempool and in block after activation [{COINBASE_MATURITY + 5}]")

Callers

nothing calls this directly

Calls 14

block_submitMethod · 0.95
create_transactionFunction · 0.90
assert_raises_rpc_errorFunction · 0.90
CTransactionClass · 0.90
invalidate_nulldummy_txFunction · 0.85
createwalletMethod · 0.80
addmultisigaddressMethod · 0.80
importaddressMethod · 0.80
infoMethod · 0.80
sendrawtransactionMethod · 0.80
hexMethod · 0.80
get_wallet_rpcMethod · 0.45

Tested by

no test coverage detected