(self)
| 33 | self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=destination, amount=int(COIN * amount)) |
| 34 | |
| 35 | def run_test(self): |
| 36 | # ELEMENTS hacks |
| 37 | self.wallet = MiniWallet(self.nodes[0], hrp="bcrt") |
| 38 | self.nodes[0].set_deterministic_priv_key('2Mysp7FKKe52eoC2JmU46irt1dt58TpCvhQ', 'cTNbtVJmhx75RXomhYWSZAafuNNNKPd1cr2ZiUcAeukLNGrHWjvJ') |
| 39 | self.wallet.generate(200, invalid_call=False) |
| 40 | self.wallet.rescan_utxos() |
| 41 | |
| 42 | self.log.info("Create UTXOs...") |
| 43 | pubk1, spk_P2SH_SEGWIT, addr_P2SH_SEGWIT = getnewdestination("p2sh-segwit", prefix=196) |
| 44 | pubk2, spk_LEGACY, addr_LEGACY = getnewdestination("legacy", version=111) |
| 45 | pubk3, spk_BECH32, addr_BECH32 = getnewdestination("bech32", hrp="bcrt") |
| 46 | self.sendtodestination(spk_P2SH_SEGWIT, 0.001) |
| 47 | self.sendtodestination(spk_LEGACY, 0.002) |
| 48 | self.sendtodestination(spk_BECH32, 0.004) |
| 49 | |
| 50 | #send to child keys of tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK |
| 51 | self.sendtodestination("mkHV1C6JLheLoUSSZYk7x3FH5tnx9bu7yc", 0.008) # (m/0'/0'/0') |
| 52 | self.sendtodestination("mipUSRmJAj2KrjSvsPQtnP8ynUon7FhpCR", 0.016) # (m/0'/0'/1') |
| 53 | self.sendtodestination("n37dAGe6Mq1HGM9t4b6rFEEsDGq7Fcgfqg", 0.032) # (m/0'/0'/1500') |
| 54 | self.sendtodestination("mqS9Rpg8nNLAzxFExsgFLCnzHBsoQ3PRM6", 0.064) # (m/0'/0'/0) |
| 55 | self.sendtodestination("mnTg5gVWr3rbhHaKjJv7EEEc76ZqHgSj4S", 0.128) # (m/0'/0'/1) |
| 56 | self.sendtodestination("mketCd6B9U9Uee1iCsppDJJBHfvi6U6ukC", 0.256) # (m/0'/0'/1500) |
| 57 | self.sendtodestination("mj8zFzrbBcdaWXowCQ1oPZ4qioBVzLzAp7", 0.512) # (m/1/1/0') |
| 58 | self.sendtodestination("mfnKpKQEftniaoE1iXuMMePQU3PUpcNisA", 1.024) # (m/1/1/1') |
| 59 | self.sendtodestination("mou6cB1kaP1nNJM1sryW6YRwnd4shTbXYQ", 2.048) # (m/1/1/1500') |
| 60 | self.sendtodestination("mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", 4.096) # (m/1/1/0) |
| 61 | self.sendtodestination("mxp7w7j8S1Aq6L8StS2PqVvtt4HGxXEvdy", 8.192) # (m/1/1/1) |
| 62 | self.sendtodestination("mpQ8rokAhp1TAtJQR6F6TaUmjAWkAWYYBq", 16.384) # (m/1/1/1500) |
| 63 | |
| 64 | self.generate(self.nodes[0], 1) |
| 65 | |
| 66 | scan = self.nodes[0].scantxoutset("start", []) |
| 67 | info = self.nodes[0].gettxoutsetinfo() |
| 68 | assert_equal(scan['success'], True) |
| 69 | assert_equal(scan['height'], info['height']) |
| 70 | assert_equal(scan['txouts'], info['txouts']) |
| 71 | assert_equal(scan['bestblock'], info['bestblock']) |
| 72 | |
| 73 | self.log.info("Test if we have found the non HD unspent outputs.") |
| 74 | assert_equal(self.nodes[0].scantxoutset("start", ["pkh(" + pubk1.hex() + ")", "pkh(" + pubk2.hex() + ")", "pkh(" + pubk3.hex() + ")"])['total_unblinded_bitcoin_amount'], Decimal("0.002")) |
| 75 | assert_equal(self.nodes[0].scantxoutset("start", ["wpkh(" + pubk1.hex() + ")", "wpkh(" + pubk2.hex() + ")", "wpkh(" + pubk3.hex() + ")"])['total_unblinded_bitcoin_amount'], Decimal("0.004")) |
| 76 | assert_equal(self.nodes[0].scantxoutset("start", ["sh(wpkh(" + pubk1.hex() + "))", "sh(wpkh(" + pubk2.hex() + "))", "sh(wpkh(" + pubk3.hex() + "))"])['total_unblinded_bitcoin_amount'], Decimal("0.001")) |
| 77 | assert_equal(self.nodes[0].scantxoutset("start", ["combo(" + pubk1.hex() + ")", "combo(" + pubk2.hex() + ")", "combo(" + pubk3.hex() + ")"])['total_unblinded_bitcoin_amount'], Decimal("0.007")) |
| 78 | assert_equal(self.nodes[0].scantxoutset("start", ["addr(" + addr_P2SH_SEGWIT + ")", "addr(" + addr_LEGACY + ")", "addr(" + addr_BECH32 + ")"])['total_unblinded_bitcoin_amount'], Decimal("0.007")) |
| 79 | assert_equal(self.nodes[0].scantxoutset("start", ["addr(" + addr_P2SH_SEGWIT + ")", "addr(" + addr_LEGACY + ")", "combo(" + pubk3.hex() + ")"])['total_unblinded_bitcoin_amount'], Decimal("0.007")) |
| 80 | |
| 81 | self.log.info("Test range validation.") |
| 82 | assert_raises_rpc_error(-8, "End of range is too high", self.nodes[0].scantxoutset, "start", [{"desc": "desc", "range": -1}]) |
| 83 | assert_raises_rpc_error(-8, "Range should be greater or equal than 0", self.nodes[0].scantxoutset, "start", [{"desc": "desc", "range": [-1, 10]}]) |
| 84 | assert_raises_rpc_error(-8, "End of range is too high", self.nodes[0].scantxoutset, "start", [{"desc": "desc", "range": [(2 << 31 + 1) - 1000000, (2 << 31 + 1)]}]) |
| 85 | assert_raises_rpc_error(-8, "Range specified as [begin,end] must not have begin after end", self.nodes[0].scantxoutset, "start", [{"desc": "desc", "range": [2, 1]}]) |
| 86 | assert_raises_rpc_error(-8, "Range is too large", self.nodes[0].scantxoutset, "start", [{"desc": "desc", "range": [0, 1000001]}]) |
| 87 | |
| 88 | self.log.info("Test extended key derivation.") |
| 89 | # Run various scans, and verify that the sum of the amounts of the matches corresponds to the expected subset. |
| 90 | # Note that all amounts in the UTXO set are powers of 2 multiplied by 0.001 BTC, so each amounts uniquely identifies a subset. |
| 91 | assert_equal(self.nodes[0].scantxoutset("start", ["combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0h/0h)"])['total_unblinded_bitcoin_amount'], Decimal("0.008")) |
| 92 | assert_equal(self.nodes[0].scantxoutset("start", ["combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0'/1h)"])['total_unblinded_bitcoin_amount'], Decimal("0.016")) |
nothing calls this directly
no test coverage detected