WIP donation test

This commit is contained in:
Duke
2025-10-13 18:21:51 -04:00
parent 1f50e635a0
commit 23ef00cfd7
3 changed files with 149 additions and 4 deletions

View File

@@ -0,0 +1,144 @@
#!/usr/bin/env python3
# Copyright (c) 2016-2025 The Hush developers
# Distributed under the GPLv3 software license, see the accompanying
# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \
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
import time
from decimal import Decimal
def assert_success(result):
assert_equal(result['result'], 'success')
def assert_error(result):
assert_equal(result['result'], 'error')
class LockZinsTest (BitcoinTestFramework):
def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir)
self.num_nodes = 2
self.options.nocleanup = 1 # do not delete datadir after test run
#self.options.nocleanup = 0
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.supply = 555
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=ZZZ',
#'-ac_algo=randomx',
#'-testnode=1', # why does this make the test node hang before run_test() ?
'-conf='+self.options.tmpdir+'/node0/regtest/ZZZ.conf',
'-port=63367',
'-rpcport=63368',
'-ac_supply=' + str(self.supply),
'-ac_reward=100000000',
'-ac_private=1',
'-allowlist=127.0.0.1',
'-regtest',
'--daemon',
#'-debug',
#'-zrpc',
#'-zdebug',
##'-zrpcunsafe'
],[
'-ac_name=ZZZ',
'-conf='+self.options.tmpdir+'/node1/regtest/ZZZ.conf',
'-port=63357',
'-rpcport=63358',
'-ac_supply=' + str(self.supply),
'-ac_reward=100000000',
'-ac_private=1',
'-allowlist=127.0.0.1',
'-regtest',
'--daemon',
#'-debug',
#'-zrpc',
#'-zdebug',
##'-zrpcunsafe'
]]
)
self.is_network_split = False
self.rpc = self.nodes[0]
self.sync_all()
print("Done setting up network")
def run_test (self):
print("Mining blocks...")
rpc0 = self.nodes[0]
rpc1 = self.nodes[1]
# mine initial ac_supply
rpc0.generate(1)
rpc1.generate(1)
self.sync_all()
zaddr1 = rpc0.z_getnewaddress()
#rpc0.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)
opid = response['opid']
shieldingValue = response['shieldingValue']
assert_true( shieldingValue >= self.supply )
print("opid=" + opid)
time.sleep(2) # give some time for the ztx to complete
# 555 supply plus magic utxo = 555.02070592
totalSupply = 55502070592 # in puposhis
expectedAmount = totalSupply
json = rpc0.z_getoperationstatus()
txid = json[0]['result']['txid']
wait_and_assert_operationid_status(rpc0, opid)
rawtx0 = rpc0.z_viewtransaction(txid)
assert_equal( rawtx0['outputs'][0]['valueZat'] , expectedAmount, '5% donation sends correct sendAmount')
# now we test giving a donation parameter
donation = 5
response = rpc1.z_shieldcoinbase('*', zaddr1, 0, 1, donation)
opid = response['opid']
shieldingValue = response['shieldingValue']
assert_true( shieldingValue >= self.supply )
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()
txid = json[0]['result']['txid']
wait_and_assert_operationid_status(rpc1, opid)
#TODO: sync with testing zaddr in src/wallet/asyncrpcoperation_shieldcoinbase.cpp
rpc1.z_importkey(testing_privkey)
rawtx1 = rpc1.z_viewtransaction(txid)
assert_equal( rawtx1['outputs'][0]['valueZat'] , totalSupply - expectedAmount, '5% donation sends correct donationAmount')
if __name__ == '__main__':
LockZinsTest ().main()