Test that submitblock adds the nonce automatically when possible.
(self)
| 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): |
no test coverage detected