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

Method run_test

test/functional/mining_basic.py:75–286  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

73 self.connect_nodes(0, 1)
74
75 def run_test(self):
76 node = self.nodes[0]
77 self.wallet = MiniWallet(node)
78 self.mine_chain()
79
80 def assert_submitblock(block, result_str_1, result_str_2=None):
81 block.solve()
82 result_str_2 = result_str_2 or 'duplicate-invalid'
83 assert_equal(result_str_1, node.submitblock(hexdata=block.serialize().hex()))
84 assert_equal(result_str_2, node.submitblock(hexdata=block.serialize().hex()))
85
86 self.log.info('getmininginfo')
87 mining_info = node.getmininginfo()
88 assert_equal(mining_info['blocks'], 200)
89 assert_equal(mining_info['chain'], self.chain)
90 assert 'currentblocktx' not in mining_info
91 assert 'currentblockweight' not in mining_info
92 assert_equal(mining_info['pooledtx'], 0)
93
94 self.log.info("getblocktemplate: Test default witness commitment")
95 txid = int(self.wallet.send_self_transfer(from_node=node)['wtxid'], 16)
96 tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
97
98 # Check that default_witness_commitment is present.
99 assert 'default_witness_commitment' in tmpl
100 # witness_commitment = tmpl['default_witness_commitment']
101
102 # Check that default_witness_commitment is correct.
103 witness_root = CBlock.get_merkle_root([ser_uint256(0),
104 ser_uint256(txid)])
105 script = get_witness_script(witness_root, 0)
106 assert_equal(script.hex(), "6a24aa21a9ed3160175963f85aa4d48b96b0b1c16eb02693d2ee908f73391e78a73747722e72") # ELEMENTS: use `script` to placate linter
107
108 # ELEMENTS: The following assertion fails because
109 # (1) Elements appears to use a different merkle tree computation than Bitcoin here
110 # (ComputeFastMerkleRoot vs ComputeMerkleRoot)
111 # (2) Elements does some slightly different thing than Bitcoin with what goes into the merkle tree
112 # (see the "ELEMENTS:" comment in validation.cpp:3399.)
113 # assert_equal(witness_commitment, script.hex())
114
115 # Mine a block to leave initial block download and clear the mempool
116 self.generatetoaddress(node, 1, node.get_deterministic_priv_key().address)
117 tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
118 self.log.info("getblocktemplate: Test capability advertised")
119 assert 'proposal' in tmpl['capabilities']
120 assert 'coinbasetxn' not in tmpl
121
122 next_height = int(tmpl["height"])
123 coinbase_tx = create_coinbase(height=next_height)
124 # sequence numbers must not be max for nLockTime to have effect
125 coinbase_tx.vin[0].nSequence = 2**32 - 2
126 coinbase_tx.rehash()
127
128 block = CBlock()
129 block.nVersion = tmpl["version"]
130 block.hashPrevBlock = int(tmpl["previousblockhash"], 16)
131 block.nTime = tmpl["curtime"]
132 block.block_height = node.getblockcount()+1

Callers

nothing calls this directly

Calls 15

mine_chainMethod · 0.95
serializeMethod · 0.95
solveMethod · 0.95
MiniWalletClass · 0.90
assert_equalFunction · 0.90
ser_uint256Function · 0.90
get_witness_scriptFunction · 0.90
create_coinbaseFunction · 0.90
CBlockClass · 0.90
assert_raises_rpc_errorFunction · 0.90
CBlockHeaderClass · 0.90
P2PDataStoreClass · 0.90

Tested by

no test coverage detected