|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Test the wallet accounts properly when there are cloned transactions with malleated scriptsigs."""
|
6 | 6 |
|
| 7 | +import io |
7 | 8 | from test_framework.test_framework import BitcoinTestFramework
|
8 | 9 | from test_framework.util import (
|
9 | 10 | assert_equal,
|
10 | 11 | connect_nodes,
|
11 | 12 | disconnect_nodes,
|
12 | 13 | sync_blocks,
|
13 | 14 | )
|
| 15 | +from test_framework.messages import CTransaction, COIN |
14 | 16 |
|
15 | 17 | class TxnMallTest(BitcoinTestFramework):
|
16 | 18 | def set_test_params(self):
|
@@ -72,19 +74,14 @@ def run_test(self):
|
72 | 74 | clone_raw = self.nodes[0].createrawtransaction(clone_inputs, clone_outputs, clone_locktime)
|
73 | 75 |
|
74 | 76 | # createrawtransaction randomizes the order of its outputs, so swap them if necessary.
|
75 |
| - # output 0 is at version+#inputs+input+sigstub+sequence+#outputs |
76 |
| - # 40 BTC serialized is 00286bee00000000 |
77 |
| - pos0 = 2 * (4 + 1 + 36 + 1 + 4 + 1) |
78 |
| - hex40 = "00286bee00000000" |
79 |
| - output_len = 16 + 2 + 2 * int("0x" + clone_raw[pos0 + 16:pos0 + 16 + 2], 0) |
80 |
| - if (rawtx1["vout"][0]["value"] == 40 and clone_raw[pos0:pos0 + 16] != hex40 or rawtx1["vout"][0]["value"] != 40 and clone_raw[pos0:pos0 + 16] == hex40): |
81 |
| - output0 = clone_raw[pos0:pos0 + output_len] |
82 |
| - output1 = clone_raw[pos0 + output_len:pos0 + 2 * output_len] |
83 |
| - clone_raw = clone_raw[:pos0] + output1 + output0 + clone_raw[pos0 + 2 * output_len:] |
| 77 | + clone_tx = CTransaction() |
| 78 | + clone_tx.deserialize(io.BytesIO(bytes.fromhex(clone_raw))) |
| 79 | + if (rawtx1["vout"][0]["value"] == 40 and clone_tx.vout[0].nValue != 40*COIN or rawtx1["vout"][0]["value"] != 40 and clone_tx.vout[0].nValue == 40*COIN): |
| 80 | + (clone_tx.vout[0], clone_tx.vout[1]) = (clone_tx.vout[1], clone_tx.vout[0]) |
84 | 81 |
|
85 | 82 | # Use a different signature hash type to sign. This creates an equivalent but malleated clone.
|
86 | 83 | # Don't send the clone anywhere yet
|
87 |
| - tx1_clone = self.nodes[0].signrawtransactionwithwallet(clone_raw, None, "ALL|ANYONECANPAY") |
| 84 | + tx1_clone = self.nodes[0].signrawtransactionwithwallet(clone_tx.serialize().hex(), None, "ALL|ANYONECANPAY") |
88 | 85 | assert_equal(tx1_clone["complete"], True)
|
89 | 86 |
|
90 | 87 | # Have node0 mine a block, if requested:
|
|
0 commit comments