WIP donation test
This commit is contained in:
@@ -100,8 +100,81 @@ class ShieldCoinbaseDonationTest (BitcoinTestFramework):
|
|||||||
|
|
||||||
def run_test_custom_nondefault_fee(self):
|
def run_test_custom_nondefault_fee(self):
|
||||||
rpc = self.nodes[0]
|
rpc = self.nodes[0]
|
||||||
|
zaddr1 = rpc.z_getnewaddress()
|
||||||
|
|
||||||
|
donation = 5
|
||||||
|
|
||||||
# donation zaddr is already imported from previous test
|
# donation zaddr is already imported from previous test
|
||||||
|
# NOTE: goal here is to test a situation where
|
||||||
|
# sendAmount/donationAmount arithmetic leads to a situation where the
|
||||||
|
# exact amount in satoshis must deal with truncation/rounding
|
||||||
|
|
||||||
|
# generate some new coinbase funds
|
||||||
|
rpc.generate(1)
|
||||||
|
self.sync_all()
|
||||||
|
|
||||||
|
# shield funds to a new zaddr in this wallet with non-default fee
|
||||||
|
fee = 0.00000001 # 1 puposhi fee will lead to some kind of rounding/truncation arithmetic
|
||||||
|
response = rpc.z_shieldcoinbase('*', zaddr1, fee, 1, donation)
|
||||||
|
opid = response['opid']
|
||||||
|
print("opid=" + opid)
|
||||||
|
|
||||||
|
shieldingValue = response['shieldingValue']
|
||||||
|
# sanity check
|
||||||
|
assert_greater_than_or_equal( shieldingValue , 1.0 )
|
||||||
|
|
||||||
|
# TODO: this might not be enough time for slow machines, better
|
||||||
|
# solution would be to wait until the opid finishes
|
||||||
|
time.sleep(2) # give some time for the ztx to complete
|
||||||
|
|
||||||
|
# confirm tx from above
|
||||||
|
rpc.generate(1)
|
||||||
|
self.sync_all()
|
||||||
|
|
||||||
|
# get the txid
|
||||||
|
json = rpc.z_getoperationstatus()
|
||||||
|
# NOTE: this is index 1 because this test runs after the above test
|
||||||
|
# It would be better to specifically find the data for our opid
|
||||||
|
txid = json[1]['result']['txid']
|
||||||
|
print("txid=" + txid)
|
||||||
|
|
||||||
|
rpc.z_listunspent()
|
||||||
|
|
||||||
|
# (300000000 - 1)*.95
|
||||||
|
# 284999999.05
|
||||||
|
# (300000000 - 1)*.05
|
||||||
|
# 14999999.95
|
||||||
|
# The above value will be truncated (not rounded) by casting from
|
||||||
|
# double to CAmount/int64_t which means the donation will be 14999999
|
||||||
|
# and the sendAmount will be 300000000 - 14999999 = 285000001
|
||||||
|
|
||||||
|
expectedSendAmount = 285000001
|
||||||
|
expectedDonationAmount = 14999999
|
||||||
|
|
||||||
|
# actually seeing this: 2.84990500 + 0.14999500 = 2.99990000
|
||||||
|
# logging: donation=5, sendAmount=299999999, donationAmount=14999999
|
||||||
|
|
||||||
|
# lookup txid
|
||||||
|
rawtx1 = rpc.z_viewtransaction(txid)
|
||||||
|
|
||||||
|
# TODO: set this up once for all tests since they all use the same zaddr
|
||||||
|
donation_zaddr = "zregtestsapling1y30nwg0clsu6gcyrnvht8hdyfk3vwtszlh6kc4z5hv9hmpxzg2g0nx7c60xeecggm9x9gma96t4"
|
||||||
|
|
||||||
|
# there should be two outputs to different addresses, order is nondeterministic
|
||||||
|
if rawtx1['outputs'][0]['address'] == donation_zaddr:
|
||||||
|
donation_zout = 0
|
||||||
|
other_zout = 1
|
||||||
|
else:
|
||||||
|
donation_zout = 1
|
||||||
|
other_zout = 0
|
||||||
|
|
||||||
|
assert_equal( rawtx1['outputs'][donation_zout]['address'] , donation_zaddr, 'correct zaddr gets donation')
|
||||||
|
assert_equal( rawtx1['outputs'][donation_zout]['valueZat'] , expectedDonationAmount, '5% donation sends correct donationAmount')
|
||||||
|
|
||||||
|
assert_equal( rawtx1['outputs'][other_zout]['address'] , zaddr1, 'correct zaddr gets main amount')
|
||||||
|
assert_equal( rawtx1['outputs'][other_zout]['valueZat'] , expectedSendAmount, '5% donation sends correct sendAmount')
|
||||||
|
|
||||||
|
#TODO: assert sum = 3
|
||||||
|
|
||||||
def run_test_custom(self):
|
def run_test_custom(self):
|
||||||
rpc = self.nodes[0]
|
rpc = self.nodes[0]
|
||||||
@@ -149,7 +222,7 @@ class ShieldCoinbaseDonationTest (BitcoinTestFramework):
|
|||||||
# (3 - fee)*0.05
|
# (3 - fee)*0.05
|
||||||
expectedAmount1 = 14999500
|
expectedAmount1 = 14999500
|
||||||
|
|
||||||
# lookup txid on node1 which should have received donation
|
# lookup txid
|
||||||
rawtx1 = rpc.z_viewtransaction(txid)
|
rawtx1 = rpc.z_viewtransaction(txid)
|
||||||
# there should be two outputs to different addresses, order is nondeterministic
|
# there should be two outputs to different addresses, order is nondeterministic
|
||||||
if rawtx1['outputs'][0]['address'] == testing_zaddr:
|
if rawtx1['outputs'][0]['address'] == testing_zaddr:
|
||||||
|
|||||||
Reference in New Issue
Block a user