Refactor donation test now that we are using just one node
This commit is contained in:
@@ -57,22 +57,24 @@ class ShieldCoinbaseDonationTest (BitcoinTestFramework):
|
||||
print("Done setting up network")
|
||||
|
||||
def run_test (self):
|
||||
# NOTE: order of these tests is important
|
||||
self.run_test_default()
|
||||
self.run_test_custom()
|
||||
self.run_test_custom_nondefault_fee()
|
||||
|
||||
def run_test_default(self):
|
||||
rpc0 = self.nodes[0]
|
||||
rpc = self.nodes[0]
|
||||
|
||||
# mine initial ac_supply
|
||||
rpc0.generate(1)
|
||||
rpc.generate(1)
|
||||
self.sync_all()
|
||||
|
||||
zaddr1 = rpc0.z_getnewaddress()
|
||||
#rpc0.z_exportkey(zaddr1)
|
||||
zaddr1 = rpc.z_getnewaddress()
|
||||
#rpc.z_exportkey(zaddr1)
|
||||
|
||||
# first we test the default situation where no donation is given and
|
||||
# it defaults to 0
|
||||
response = rpc0.z_shieldcoinbase('*', zaddr1, 0, 1)
|
||||
response = rpc.z_shieldcoinbase('*', zaddr1, 0, 1)
|
||||
opid = response['opid']
|
||||
shieldingValue = response['shieldingValue']
|
||||
|
||||
@@ -88,62 +90,67 @@ class ShieldCoinbaseDonationTest (BitcoinTestFramework):
|
||||
totalSupply = 55505537304 # in puposhis
|
||||
expectedAmount = totalSupply
|
||||
|
||||
json = rpc0.z_getoperationstatus()
|
||||
json = rpc.z_getoperationstatus()
|
||||
txid = json[0]['result']['txid']
|
||||
|
||||
wait_and_assert_operationid_status(rpc0, opid)
|
||||
wait_and_assert_operationid_status(rpc, opid)
|
||||
|
||||
rawtx0 = rpc0.z_viewtransaction(txid)
|
||||
rawtx0 = rpc.z_viewtransaction(txid)
|
||||
assert_equal( rawtx0['outputs'][0]['valueZat'] , expectedAmount, '5% donation sends correct sendAmount')
|
||||
|
||||
def run_test_custom_nondefault_fee(self):
|
||||
rpc = self.nodes[0]
|
||||
|
||||
# donation zaddr is already imported from previous test
|
||||
|
||||
def run_test_custom(self):
|
||||
rpc0 = self.nodes[0]
|
||||
zaddr1 = rpc0.z_getnewaddress()
|
||||
rpc = self.nodes[0]
|
||||
zaddr1 = rpc.z_getnewaddress()
|
||||
|
||||
# generate some new coinbase funds
|
||||
rpc0.generate(1)
|
||||
rpc.generate(1)
|
||||
self.sync_all()
|
||||
|
||||
testing_zaddr = "zregtestsapling1y30nwg0clsu6gcyrnvht8hdyfk3vwtszlh6kc4z5hv9hmpxzg2g0nx7c60xeecggm9x9gma96t4"
|
||||
testing_privkey = "secret-extended-key-regtest1q0hgrms7qqqqpqrsz6myrtnh3ccp8uzp0kgxj6029wr6vq5hqvyccdlz7a745pgm5eeaamxqp9rxll2xctfrlw2l8xhxsc7zsut2tyz0374rrlk8srjswx7rhm6hcf2d7fuwajazvjesafduzxyka4w02tqjxdehzvghyrsd2zll90k3g2ckdvc5kqd6r7r7nglrtj0ej5a40d6lh8zxrvdlxrpuc59y5m8n9tekdxh4wpqn3smv5nxu4vvu58f8dgwn92qfqrvxqlscchtyh"
|
||||
|
||||
# import zaddr that receives donation , no rescan
|
||||
rpc0.z_importkey(testing_privkey, "no")
|
||||
rpc.z_importkey(testing_privkey, "no")
|
||||
|
||||
rpc0.z_listaddresses()
|
||||
rpc.z_listaddresses()
|
||||
|
||||
# now we test giving a donation parameter
|
||||
donation = 5
|
||||
|
||||
# shield funds to a new zaddr in this wallet with default fee
|
||||
fee = 0.0001
|
||||
response = rpc0.z_shieldcoinbase('*', zaddr1, fee, 1, donation)
|
||||
response = rpc.z_shieldcoinbase('*', zaddr1, fee, 1, donation)
|
||||
opid = response['opid']
|
||||
print("opid=" + opid)
|
||||
#wait_and_assert_operationid_status(rpc0, opid)
|
||||
#wait_and_assert_operationid_status(rpc, opid)
|
||||
shieldingValue = response['shieldingValue']
|
||||
|
||||
assert_greater_than_or_equal( shieldingValue , 1.0 )
|
||||
|
||||
time.sleep(2) # give some time for the ztx to complete
|
||||
|
||||
rpc0.getinfo()
|
||||
rpc.getinfo()
|
||||
|
||||
rpc0.generate(1)
|
||||
rpc.generate(1)
|
||||
self.sync_all()
|
||||
|
||||
# get the txid
|
||||
json = rpc0.z_getoperationstatus()
|
||||
json = rpc.z_getoperationstatus()
|
||||
txid = json[0]['result']['txid']
|
||||
print("txid=" + txid)
|
||||
|
||||
rpc0.z_listunspent()
|
||||
rpc.z_listunspent()
|
||||
|
||||
# (3 - fee)*0.05
|
||||
expectedAmount1 = 14999500
|
||||
|
||||
# lookup txid on node1 which should have received donation
|
||||
rawtx1 = rpc0.z_viewtransaction(txid)
|
||||
rawtx1 = rpc.z_viewtransaction(txid)
|
||||
# there should be two outputs to different addresses, order is nondeterministic
|
||||
if rawtx1['outputs'][0]['address'] == testing_zaddr:
|
||||
donation_zout = 0
|
||||
|
||||
Reference in New Issue
Block a user