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

Method test_submit_block

test/functional/p2p_segwit.py:971–1004  ·  view source on GitHub ↗

Test that submitblock adds the nonce automatically when possible.

(self)

Source from the content-addressed store, hash-verified

969
970 @subtest
971 def test_submit_block(self):
972 """Test that submitblock adds the nonce automatically when possible."""
973 block = self.build_next_block()
974
975 # Try using a custom nonce and then don't supply it.
976 # This shouldn't possibly work.
977 add_witness_commitment(block, nonce=1)
978 block.vtx[0].wit = CTxWitness() # drop the nonce
979 block.solve()
980 assert_equal('bad-witness-merkle-match', self.nodes[0].submitblock(block.serialize().hex()))
981 assert self.nodes[0].getbestblockhash() != block.hash
982
983 # Now redo commitment with the standard nonce, but let bitcoind fill it in.
984 add_witness_commitment(block, nonce=0)
985 block.vtx[0].wit = CTxWitness()
986 block.solve()
987 assert_equal(None, self.nodes[0].submitblock(block.serialize().hex()))
988 assert_equal(self.nodes[0].getbestblockhash(), block.hash)
989
990 # This time, add a tx with non-empty witness, but don't supply
991 # the commitment.
992 block_2 = self.build_next_block()
993
994 add_witness_commitment(block_2)
995
996 block_2.solve()
997
998 # Drop commitment and nonce -- submitblock should not fill in.
999 block_2.vtx[0].vout.pop()
1000 block_2.vtx[0].wit = CTxWitness()
1001
1002 assert_equal('bad-txnmrklroot', self.nodes[0].submitblock(block_2.serialize().hex()))
1003 # Tip should not advance!
1004 assert self.nodes[0].getbestblockhash() != block_2.hash
1005
1006 @subtest
1007 def test_extra_witness_data(self):

Callers 1

run_testMethod · 0.95

Calls 7

build_next_blockMethod · 0.95
add_witness_commitmentFunction · 0.90
CTxWitnessClass · 0.90
assert_equalFunction · 0.90
hexMethod · 0.80
solveMethod · 0.45
serializeMethod · 0.45

Tested by

no test coverage detected