Skip to content
Bitcoin Roots

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. The two line-number columns refer to before and after.

test/functional/wallet_change_address.py CHANGED
@@ -59,15 +59,18 @@ class WalletChangeAddressTest(BitcoinTestFramework):
59
59
  addrs = addr1 + addr2
60
60
 
61
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]
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()
64
66
  self.generate(self.nodes[0], 1)
65
67
 
66
68
  for i in range(20):
67
69
  for n in [1, 2]:
68
70
  self.log.debug(f"Send transaction from node {n}: expected change index {i}")
69
71
  txid = self.nodes[n].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
70
- tx = self.nodes[n].getrawtransaction(txid, True)
72
+ self.nodes[n].syncwithvalidationinterfacequeue()
73
+ tx = self.nodes[n].decoderawtransaction(self.nodes[n].gettransaction(txid)["hex"])
71
74
  # find the change output and ensure that expected change index was used
72
75
  self.assert_change_index(self.nodes[n], tx, i)
73
76
 
@@ -78,10 +81,9 @@ class WalletChangeAddressTest(BitcoinTestFramework):
78
81
  w2 = self.nodes[2].get_wallet_rpc("w2")
79
82
  addr1 = w1.getnewaddress()
80
83
  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)
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()
85
87
  self.generate(self.nodes[0], 1)
86
88
 
87
89
  sendTo1 = self.nodes[0].getnewaddress()
@@ -91,7 +93,7 @@ class WalletChangeAddressTest(BitcoinTestFramework):
91
93
  # The avoid partial spends wallet will always create a change output
92
94
  node = self.nodes[2]
93
95
  res = w2.send({sendTo1: "1.0", sendTo2: "1.0", sendTo3: "0.9999"}, options={"change_position": 0})
94
- tx = node.getrawtransaction(res["txid"], True)
96
+ tx = node.decoderawtransaction(w2.gettransaction(res["txid"])["hex"])
95
97
  self.assert_change_pos(w2, tx, 0)
96
98
 
97
99
  # The default wallet will internally create a tx without change first,
@@ -99,7 +101,7 @@ class WalletChangeAddressTest(BitcoinTestFramework):
99
101
  # Ensure that the user-configured change position is kept
100
102
  node = self.nodes[1]
101
103
  res = w1.send({sendTo1: "1.0", sendTo2: "1.0", sendTo3: "0.9999"}, options={"change_position": 0})
102
- tx = node.getrawtransaction(res["txid"], True)
104
+ tx = node.decoderawtransaction(w1.gettransaction(res["txid"])["hex"])
103
105
  # If the wallet ignores the user's change_position there is still a 25%
104
106
  # that the random change position passes the test
105
107
  self.assert_change_pos(w1, tx, 0)