|
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
|
| 9 | +from test_framework.messages import CTransaction |
8 | 10 | from test_framework.util import (
|
9 | 11 | assert_equal,
|
10 | 12 | connect_nodes,
|
11 | 13 | disconnect_nodes,
|
12 | 14 | sync_blocks,
|
| 15 | + hex_str_to_bytes, |
13 | 16 | )
|
14 | 17 |
|
15 | 18 | class TxnMallTest(BitcoinTestFramework):
|
@@ -69,15 +72,10 @@ def run_test(self):
|
69 | 72 | clone_raw = self.nodes[0].createrawtransaction(clone_inputs, clone_outputs, clone_locktime)
|
70 | 73 |
|
71 | 74 | # createrawtransaction randomizes the order of its outputs, so swap them if necessary.
|
72 |
| - # output 0 is at version+#inputs+input+sigstub+sequence+#outputs |
73 |
| - # 40 BTC serialized is 00286bee00000000 |
74 |
| - pos0 = 2 * (4 + 1 + 36 + 1 + 4 + 1) |
75 |
| - hex40 = "00286bee00000000" |
76 |
| - output_len = 16 + 2 + 2 * int("0x" + clone_raw[pos0 + 16:pos0 + 16 + 2], 0) |
77 |
| - 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): |
78 |
| - output0 = clone_raw[pos0:pos0 + output_len] |
79 |
| - output1 = clone_raw[pos0 + output_len:pos0 + 2 * output_len] |
80 |
| - clone_raw = clone_raw[:pos0] + output1 + output0 + clone_raw[pos0 + 2 * output_len:] |
| 75 | + clone_tx = CTransaction() |
| 76 | + clone_tx.deserialize(io.BytesIO(hex_str_to_bytes(clone_raw))) |
| 77 | + if (rawtx1["vout"][0]["value"] == 40 and clone_tx.vout[0].nValue != 40 or rawtx1["vout"][0]["value"] != 40 and clone_tx.vout[0].nValue == 40): |
| 78 | + (clone_tx.vout[0], clone_tx.vout[1]) = (clone_tx.vout[1], clone_tx.vout[0]) |
81 | 79 |
|
82 | 80 | # Use a different signature hash type to sign. This creates an equivalent but malleated clone.
|
83 | 81 | # Don't send the clone anywhere yet
|
|
0 commit comments