Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 10: [PATCH 10/68] fix: harden Roots priority and wallet policy boundaries

test/functional/wallet_change_address.py

Before: test/functional/wallet_change_address.py · After: test/functional/wallet_change_address.py

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