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

Method run_test

test/functional/rpc_generateblock.py:20–97  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

18 self.num_nodes = 1
19
20 def run_test(self):
21 node = self.nodes[0]
22 miniwallet = MiniWallet(node)
23 miniwallet.rescan_utxos()
24
25 self.log.info('Generate an empty block to address')
26 address = miniwallet.get_address()
27 hash = self.generateblock(node, output=address, transactions=[])['hash']
28 block = node.getblock(blockhash=hash, verbose=2)
29 assert_equal(len(block['tx']), 1)
30 assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], address)
31
32 self.log.info('Generate an empty block to a descriptor')
33 hash = self.generateblock(node, 'addr(' + address + ')', [])['hash']
34 block = node.getblock(blockhash=hash, verbosity=2)
35 assert_equal(len(block['tx']), 1)
36 assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], address)
37
38 self.log.info('Generate an empty block to a combo descriptor with compressed pubkey')
39 combo_key = '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'
40 combo_address = 'ert1qw508d6qejxtdg4y5r3zarvary0c5xw7kuu73e0'
41 hash = self.generateblock(node, 'combo(' + combo_key + ')', [])['hash']
42 block = node.getblock(hash, 2)
43 assert_equal(len(block['tx']), 1)
44 assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], combo_address)
45
46 self.log.info('Generate an empty block to a combo descriptor with uncompressed pubkey')
47 combo_key = '0408ef68c46d20596cc3f6ddf7c8794f71913add807f1dc55949fa805d764d191c0b7ce6894c126fce0babc6663042f3dde9b0cf76467ea315514e5a6731149c67'
48 combo_address = '2deWwXvaNqa5PDGXGg7vHDeTreKgKGPLNdF'
49 hash = self.generateblock(node, 'combo(' + combo_key + ')', [])['hash']
50 block = node.getblock(hash, 2)
51 assert_equal(len(block['tx']), 1)
52 assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], combo_address)
53
54 # Generate some extra mempool transactions to verify they don't get mined
55 for _ in range(10):
56 miniwallet.send_self_transfer(from_node=node)
57
58 self.log.info('Generate block with txid')
59 txid = miniwallet.send_self_transfer(from_node=node)['txid']
60 hash = self.generateblock(node, address, [txid])['hash']
61 block = node.getblock(hash, 1)
62 assert_equal(len(block['tx']), 2)
63 assert_equal(block['tx'][1], txid)
64
65 self.log.info('Generate block with raw tx')
66 rawtx = miniwallet.create_self_transfer()['hex']
67 hash = self.generateblock(node, address, [rawtx])['hash']
68
69 block = node.getblock(hash, 1)
70 assert_equal(len(block['tx']), 2)
71 txid = block['tx'][1]
72 assert_equal(node.getrawtransaction(txid=txid, verbose=False, blockhash=hash), rawtx)
73
74 self.log.info('Fail to generate block with out of order txs')
75 txid1 = miniwallet.send_self_transfer(from_node=node)['txid']
76 utxo1 = miniwallet.get_utxo(txid=txid1)
77 rawtx2 = miniwallet.create_self_transfer(utxo_to_spend=utxo1)['hex']

Callers

nothing calls this directly

Calls 10

rescan_utxosMethod · 0.95
get_addressMethod · 0.95
send_self_transferMethod · 0.95
create_self_transferMethod · 0.95
get_utxoMethod · 0.95
MiniWalletClass · 0.90
assert_equalFunction · 0.90
assert_raises_rpc_errorFunction · 0.90
infoMethod · 0.80
generateblockMethod · 0.45

Tested by

no test coverage detected