MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / run_test

Method run_test

test/functional/wallet_groups.py:29–93  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

27 self.skip_if_no_wallet()
28
29 def run_test(self):
30 # Mine some coins
31 self.nodes[0].generate(110)
32
33 # Get some addresses from the two nodes
34 addr1 = [self.nodes[1].getnewaddress() for i in range(3)]
35 addr2 = [self.nodes[2].getnewaddress() for i in range(3)]
36 addrs = addr1 + addr2
37
38 # Send 1 + 0.5 coin to each address
39 [self.nodes[0].sendtoaddress(addr, 1.0) for addr in addrs]
40 [self.nodes[0].sendtoaddress(addr, 0.5) for addr in addrs]
41
42 self.nodes[0].generate(1)
43 self.sync_all()
44
45 # For each node, send 0.2 coins back to 0;
46 # - node[1] should pick one 0.5 UTXO and leave the rest
47 # - node[2] should pick one (1.0 + 0.5) UTXO group corresponding to a
48 # given address, and leave the rest
49 txid1 = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
50 tx1 = self.nodes[1].getrawtransaction(txid1, True)
51 # txid1 should have 1 input and 2 outputs
52 assert_equal(1, len(tx1["vin"]))
53 assert_equal(2, len(tx1["vout"]))
54 # one output should be 0.2, the other should be ~0.3
55 v = [vout["value"] for vout in tx1["vout"]]
56 v.sort()
57 assert_approx(v[0], 0.2)
58 assert_approx(v[1], 0.3, 0.0001)
59
60 txid2 = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
61 tx2 = self.nodes[2].getrawtransaction(txid2, True)
62 # txid2 should have 2 inputs and 2 outputs
63 assert_equal(2, len(tx2["vin"]))
64 assert_equal(2, len(tx2["vout"]))
65 # one output should be 0.2, the other should be ~1.3
66 v = [vout["value"] for vout in tx2["vout"]]
67 v.sort()
68 assert_approx(v[0], 0.2)
69 assert_approx(v[1], 1.3, 0.0001)
70
71 # Empty out node2's wallet
72 self.nodes[2].sendtoaddress(address=self.nodes[0].getnewaddress(), amount=self.nodes[2].getbalance(), subtractfeefromamount=True)
73 self.sync_all()
74 self.nodes[0].generate(1)
75
76 # Fill node2's wallet with 10000 outputs corresponding to the same
77 # scriptPubKey
78 for i in range(5):
79 raw_tx = self.nodes[0].createrawtransaction([{"txid":"0"*64, "vout":0}], [{addr2[0]: 0.05}])
80 tx = FromHex(CTransaction(), raw_tx)
81 tx.vin = []
82 tx.vout = [tx.vout[0]] * 2000
83 funded_tx = self.nodes[0].fundrawtransaction(ToHex(tx))
84 signed_tx = self.nodes[0].signrawtransactionwithwallet(funded_tx['hex'])
85 self.nodes[0].sendrawtransaction(signed_tx['hex'])
86 self.nodes[0].generate(1)

Callers

nothing calls this directly

Calls 7

assert_equalFunction · 0.90
FromHexFunction · 0.90
CTransactionClass · 0.90
ToHexFunction · 0.90
assert_approxFunction · 0.85
sync_allMethod · 0.80
sortMethod · 0.45

Tested by

no test coverage detected