diff --git a/qa/rpc-tests/shieldcoinbase_donation.py b/qa/rpc-tests/shieldcoinbase_donation.py index 34686058a..c755c14ee 100755 --- a/qa/rpc-tests/shieldcoinbase_donation.py +++ b/qa/rpc-tests/shieldcoinbase_donation.py @@ -5,7 +5,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException -from test_framework.util import assert_equal, assert_greater_than, \ +from test_framework.util import assert_equal, assert_greater_than, assert_greater_than_or_equal, \ initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises, assert_true, \ wait_and_assert_operationid_status @@ -19,7 +19,7 @@ def assert_success(result): def assert_error(result): assert_equal(result['result'], 'error') -class LockZinsTest (BitcoinTestFramework): +class ShieldCoinbaseDonationTest (BitcoinTestFramework): def setup_chain(self): print("Initializing test directory "+self.options.tmpdir) self.num_nodes = 2 @@ -72,7 +72,10 @@ class LockZinsTest (BitcoinTestFramework): print("Done setting up network") def run_test (self): - print("Mining blocks...") + self.run_test_default() + self.run_test_custom() + + def run_test_default(self): rpc0 = self.nodes[0] rpc1 = self.nodes[1] @@ -108,37 +111,59 @@ class LockZinsTest (BitcoinTestFramework): rawtx0 = rpc0.z_viewtransaction(txid) assert_equal( rawtx0['outputs'][0]['valueZat'] , expectedAmount, '5% donation sends correct sendAmount') + def run_test_custom(self): + rpc0 = self.nodes[0] + rpc1 = self.nodes[1] + zaddr1 = rpc0.z_getnewaddress() + + # generate some new coinbase funds + rpc0.generate(1) + rpc1.generate(1) + self.sync_all() + + # zregtestsapling1y30nwg0clsu6gcyrnvht8hdyfk3vwtszlh6kc4z5hv9hmpxzg2g0nx7c60xeecggm9x9gma96t4 + testing_privkey = "secret-extended-key-regtest1q0hgrms7qqqqpqrsz6myrtnh3ccp8uzp0kgxj6029wr6vq5hqvyccdlz7a745pgm5eeaamxqp9rxll2xctfrlw2l8xhxsc7zsut2tyz0374rrlk8srjswx7rhm6hcf2d7fuwajazvjesafduzxyka4w02tqjxdehzvghyrsd2zll90k3g2ckdvc5kqd6r7r7nglrtj0ej5a40d6lh8zxrvdlxrpuc59y5m8n9tekdxh4wpqn3smv5nxu4vvu58f8dgwn92qfqrvxqlscchtyh" + + # import zaddr that receives donation to node1, no rescan + rpc1.z_importkey(testing_privkey, "no") + + rpc1.z_listaddresses() + # now we test giving a donation parameter donation = 5 - response = rpc1.z_shieldcoinbase('*', zaddr1, 0, 1, donation) + + # shield funds to a new zaddr in this node0 wallet, donation goes to + # node1 wallet + response = rpc0.z_shieldcoinbase('*', zaddr1, 0, 1, donation) opid = response['opid'] + print("opid=" + opid) + #wait_and_assert_operationid_status(rpc0, opid) shieldingValue = response['shieldingValue'] - assert_true( shieldingValue >= self.supply ) + assert_greater_than_or_equal( shieldingValue , 1.0 ) + + time.sleep(2) # give some time for the ztx to complete + + rpc0.getinfo() + rpc1.getinfo() rpc0.generate(1) rpc1.generate(1) self.sync_all() - print("opid=" + opid) - - time.sleep(2) # give some time for the ztx to complete - - # 555 supply plus magic utxo = 555.02070592 - totalSupply = 55502070592 - expectedAmount = 52726967062 # 95% of above supply, rounded to closest satoshi - - json = rpc1.z_getoperationstatus() + # get the txid from node0 that created it + json = rpc0.z_getoperationstatus() txid = json[0]['result']['txid'] + print("txid=" + txid) - wait_and_assert_operationid_status(rpc1, opid) + rpc1.z_listunspent() - #TODO: sync with testing zaddr in src/wallet/asyncrpcoperation_shieldcoinbase.cpp - rpc1.z_importkey(testing_privkey) + expectedAmount = 5000000 + # lookup txid on node1 which should have received donation rawtx1 = rpc1.z_viewtransaction(txid) - assert_equal( rawtx1['outputs'][0]['valueZat'] , totalSupply - expectedAmount, '5% donation sends correct donationAmount') + assert_equal( rawtx1['outputs'][0]['valueZat'] , expectedAmount, '5% donation sends correct donationAmount') if __name__ == '__main__': - LockZinsTest ().main() + ShieldCoinbaseDonationTest().main()