(self)
| 32 | self.skip_if_no_wallet() |
| 33 | |
| 34 | def run_test(self): |
| 35 | self.log.info("Setting up") |
| 36 | # Mine some coins |
| 37 | self.generate(self.nodes[0], COINBASE_MATURITY + 1) |
| 38 | |
| 39 | # Get some addresses from the two nodes |
| 40 | addr1 = [self.nodes[1].getnewaddress() for _ in range(3)] |
| 41 | addr2 = [self.nodes[2].getnewaddress() for _ in range(3)] |
| 42 | addrs = addr1 + addr2 |
| 43 | |
| 44 | # Send 1 + 0.5 coin to each address |
| 45 | [self.nodes[0].sendtoaddress(addr, 1.0) for addr in addrs] |
| 46 | [self.nodes[0].sendtoaddress(addr, 0.5) for addr in addrs] |
| 47 | |
| 48 | self.generate(self.nodes[0], 1) |
| 49 | |
| 50 | # For each node, send 0.2 coins back to 0; |
| 51 | # - node[1] should pick one 0.5 UTXO and leave the rest |
| 52 | # ELEMENTS: since SRD was added, node[1] sometimes picks a 1.0 UTXO |
| 53 | # - node[2] should pick one (1.0 + 0.5) UTXO group corresponding to a |
| 54 | # given address, and leave the rest |
| 55 | self.log.info("Test sending transactions picks one UTXO group and leaves the rest") |
| 56 | txid1 = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 0.2) |
| 57 | tx1 = self.nodes[1].getrawtransaction(txid1, True) |
| 58 | # txid1 should have 1 input and 2 outputs |
| 59 | assert_equal(1, len(tx1["vin"])) |
| 60 | assert_equal(2+1, len(tx1["vout"])) |
| 61 | # one output should be 0.2, the other should be ~0.3 |
| 62 | v = [vout["value"] for vout in tx1["vout"] if vout["scriptPubKey"]["type"] != "fee"] |
| 63 | v.sort() |
| 64 | assert_approx(v[0], vexp=0.2, vspan=0.0001) |
| 65 | # ELEMENTS |
| 66 | try: |
| 67 | assert_approx(v[1], vexp=0.3, vspan=0.0001) |
| 68 | except AssertionError: |
| 69 | assert_approx(v[1], vexp=0.8, vspan=0.0001) |
| 70 | |
| 71 | |
| 72 | txid2 = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 0.2) |
| 73 | tx2 = self.nodes[2].getrawtransaction(txid2, True) |
| 74 | # txid2 should have 2 inputs and 2 outputs |
| 75 | assert_equal(2, len(tx2["vin"])) |
| 76 | assert_equal(2+1, len(tx2["vout"])) |
| 77 | # one output should be 0.2, the other should be ~1.3 |
| 78 | v = [vout["value"] for vout in tx2["vout"] if vout["scriptPubKey"]["type"] != "fee"] |
| 79 | v.sort() |
| 80 | assert_approx(v[0], vexp=0.2, vspan=0.0001) |
| 81 | assert_approx(v[1], vexp=1.3, vspan=0.0001) |
| 82 | |
| 83 | self.log.info("Test avoiding partial spends if warranted, even if avoidpartialspends is disabled") |
| 84 | self.sync_all() |
| 85 | self.generate(self.nodes[0], 1) |
| 86 | # Nodes 1-2 now have confirmed UTXOs (letters denote destinations): |
| 87 | # Node #1: Node #2: |
| 88 | # - A 1.0 - D0 1.0 |
| 89 | # - B0 1.0 - D1 0.5 |
| 90 | # - B1 0.5 - E0 1.0 |
| 91 | # - C0 1.0 - E1 0.5 |
nothing calls this directly
no test coverage detected