v29.4-roots.3 · Commit 10: [PATCH 10/30] fix: harden final Roots assurance
test/functional/wallet_change_address.py
Before: test/functional/wallet_change_address.py · After: test/functional/wallet_change_address.py
File metadata
index 07bab82697ecbaf6a88645e63fafde884ea3c407..9441ed4471527f6250065df7db30a3dce535d37c 100755
Download original patch · Release notes
Diff rows 1–50 of 50. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
test/functional/wallet_change_address.py
CHANGED
|
@@ -59,15 +59,18 @@ class WalletChangeAddressTest(BitcoinTestFramework):
|
|
| 59 |
addrs = addr1 + addr2
|
| 60 |
|
| 61 |
# Send 1 + 0.5 coin to each address
|
| 62 |
-
[self.nodes[0].sendtoaddress(addr, 1.0) for addr in addrs]
|
| 63 |
-
[self.nodes[0].sendtoaddress(addr, 0.5) for addr in addrs]
|
|
|
|
|
|
|
| 64 |
self.generate(self.nodes[0], 1)
|
| 65 |
|
| 66 |
for i in range(20):
|
| 67 |
for n in [1, 2]:
|
| 68 |
self.log.debug(f"Send transaction from node {n}: expected change index {i}")
|
| 69 |
txid = self.nodes[n].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
|
| 70 |
-
tx = self.nodes[n].getrawtransaction(txid, True)
|
|
|
|
| 71 |
# find the change output and ensure that expected change index was used
|
| 72 |
self.assert_change_index(self.nodes[n], tx, i)
|
| 73 |
|
|
@@ -78,10 +81,9 @@ class WalletChangeAddressTest(BitcoinTestFramework):
|
|
| 78 |
w2 = self.nodes[2].get_wallet_rpc("w2")
|
| 79 |
addr1 = w1.getnewaddress()
|
| 80 |
addr2 = w2.getnewaddress()
|
| 81 |
-
self.nodes[0].sendtoaddress(addr1, 3.0)
|
| 82 |
-
self.nodes[0].sendtoaddress(addr1, 0.1)
|
| 83 |
-
self.nodes[0].sendtoaddress(addr2, 3.0)
|
| 84 |
-
self.nodes[0].sendtoaddress(addr2, 0.1)
|
| 85 |
self.generate(self.nodes[0], 1)
|
| 86 |
|
| 87 |
sendTo1 = self.nodes[0].getnewaddress()
|
|
@@ -91,7 +93,7 @@ class WalletChangeAddressTest(BitcoinTestFramework):
|
|
| 91 |
# The avoid partial spends wallet will always create a change output
|
| 92 |
node = self.nodes[2]
|
| 93 |
res = w2.send({sendTo1: "1.0", sendTo2: "1.0", sendTo3: "0.9999"}, options={"change_position": 0})
|
| 94 |
-
tx = node.getrawtransaction(res["txid"], True)
|
| 95 |
self.assert_change_pos(w2, tx, 0)
|
| 96 |
|
| 97 |
# The default wallet will internally create a tx without change first,
|
|
@@ -99,7 +101,7 @@ class WalletChangeAddressTest(BitcoinTestFramework):
|
|
| 99 |
# Ensure that the user-configured change position is kept
|
| 100 |
node = self.nodes[1]
|
| 101 |
res = w1.send({sendTo1: "1.0", sendTo2: "1.0", sendTo3: "0.9999"}, options={"change_position": 0})
|
| 102 |
-
tx = node.getrawtransaction(res["txid"], True)
|
| 103 |
# If the wallet ignores the user's change_position there is still a 25%
|
| 104 |
# that the random change position passes the test
|
| 105 |
self.assert_change_pos(w1, tx, 0)
|
|
|
|
| 59 |
addrs = addr1 + addr2
|
| 60 |
|
| 61 |
# Send 1 + 0.5 coin to each address
|
| 62 |
+
for amount in (1.0, 0.5):
|
| 63 |
+
for addr in addrs:
|
| 64 |
+
self.nodes[0].sendtoaddress(addr, amount)
|
| 65 |
+
self.nodes[0].syncwithvalidationinterfacequeue()
|
| 66 |
self.generate(self.nodes[0], 1)
|
| 67 |
|
| 68 |
for i in range(20):
|
| 69 |
for n in [1, 2]:
|
| 70 |
self.log.debug(f"Send transaction from node {n}: expected change index {i}")
|
| 71 |
txid = self.nodes[n].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
|
| 72 |
+
self.nodes[n].syncwithvalidationinterfacequeue()
|
| 73 |
+
tx = self.nodes[n].decoderawtransaction(self.nodes[n].gettransaction(txid)["hex"])
|
| 74 |
# find the change output and ensure that expected change index was used
|
| 75 |
self.assert_change_index(self.nodes[n], tx, i)
|
| 76 |
|
|
|
|
| 81 |
w2 = self.nodes[2].get_wallet_rpc("w2")
|
| 82 |
addr1 = w1.getnewaddress()
|
| 83 |
addr2 = w2.getnewaddress()
|
| 84 |
+
for addr, amount in ((addr1, 3.0), (addr1, 0.1), (addr2, 3.0), (addr2, 0.1)):
|
| 85 |
+
self.nodes[0].sendtoaddress(addr, amount)
|
| 86 |
+
self.nodes[0].syncwithvalidationinterfacequeue()
|
|
|
|
| 87 |
self.generate(self.nodes[0], 1)
|
| 88 |
|
| 89 |
sendTo1 = self.nodes[0].getnewaddress()
|
|
|
|
| 93 |
# The avoid partial spends wallet will always create a change output
|
| 94 |
node = self.nodes[2]
|
| 95 |
res = w2.send({sendTo1: "1.0", sendTo2: "1.0", sendTo3: "0.9999"}, options={"change_position": 0})
|
| 96 |
+
tx = node.decoderawtransaction(w2.gettransaction(res["txid"])["hex"])
|
| 97 |
self.assert_change_pos(w2, tx, 0)
|
| 98 |
|
| 99 |
# The default wallet will internally create a tx without change first,
|
|
|
|
| 101 |
# Ensure that the user-configured change position is kept
|
| 102 |
node = self.nodes[1]
|
| 103 |
res = w1.send({sendTo1: "1.0", sendTo2: "1.0", sendTo3: "0.9999"}, options={"change_position": 0})
|
| 104 |
+
tx = node.decoderawtransaction(w1.gettransaction(res["txid"])["hex"])
|
| 105 |
# If the wallet ignores the user's change_position there is still a 25%
|
| 106 |
# that the random change position passes the test
|
| 107 |
self.assert_change_pos(w1, tx, 0)
|