A test for lockzins branch which currently fails on dev branch
This commit is contained in:
@@ -7,7 +7,8 @@ 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
|
||||
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
|
||||
@@ -38,11 +39,11 @@ class LockZinsTest (BitcoinTestFramework):
|
||||
'-conf='+self.options.tmpdir+'/node0/regtest/ZZZ.conf',
|
||||
'-port=64367',
|
||||
'-rpcport=64368',
|
||||
'-ac_supply=10',
|
||||
'-ac_reward=25600000000',
|
||||
'-ac_supply=1',
|
||||
'-ac_reward=100000000',
|
||||
'-ac_private=1',
|
||||
'-allowlist=127.0.0.1',
|
||||
'-debug',
|
||||
#'-debug',
|
||||
'-regtest',
|
||||
'--daemon',
|
||||
#'-rpcuser=hush',
|
||||
@@ -57,22 +58,47 @@ class LockZinsTest (BitcoinTestFramework):
|
||||
def run_test (self):
|
||||
print("Mining blocks...")
|
||||
rpc = self.nodes[0]
|
||||
# mine the initial ac_supply
|
||||
rpc.generate(5)
|
||||
self.sync_all()
|
||||
|
||||
zaddr = rpc.z_getnewaddress()
|
||||
print("Created zaddr %s" % zaddr)
|
||||
|
||||
rpc.getinfo()
|
||||
time.sleep(1)
|
||||
rpc.getinfo()
|
||||
|
||||
rpc.z_shieldcoinbase('*', zaddr)
|
||||
# mine initial ac_supply
|
||||
rpc.generate(1)
|
||||
|
||||
self.sync_all()
|
||||
print(rpc.z_getbalances())
|
||||
|
||||
zaddr1 = rpc.z_getnewaddress()
|
||||
zaddr2 = rpc.z_getnewaddress()
|
||||
|
||||
x = 0
|
||||
while x < 15:
|
||||
rpc.generate(1)
|
||||
self.sync_all()
|
||||
time.sleep(1)
|
||||
rpc.z_shieldcoinbase('*', zaddr1, 0, 1)
|
||||
x = x+1
|
||||
|
||||
rpc.generate(11)
|
||||
self.sync_all()
|
||||
rpc.z_listunspent()
|
||||
rpc.z_getbalances()
|
||||
|
||||
recipients = []
|
||||
recipients.append({"address": zaddr2, "amount": Decimal('3')})
|
||||
|
||||
# queue 4 ztxs, which will try to spend the same funds multiple times
|
||||
# without correct locking of zins
|
||||
opid1 = rpc.z_sendmany(zaddr1,recipients,1,0)
|
||||
opid2 = rpc.z_sendmany(zaddr1,recipients,1,0)
|
||||
opid3 = rpc.z_sendmany(zaddr1,recipients,1,0)
|
||||
opid4 = rpc.z_sendmany(zaddr1,recipients,1,0)
|
||||
|
||||
rpc.generate(1)
|
||||
self.sync_all()
|
||||
wait_and_assert_operationid_status(self.nodes[0], opid1)
|
||||
wait_and_assert_operationid_status(self.nodes[0], opid2)
|
||||
wait_and_assert_operationid_status(self.nodes[0], opid3)
|
||||
wait_and_assert_operationid_status(self.nodes[0], opid4)
|
||||
|
||||
# give time for all z_sendmany's to run
|
||||
#time.sleep(10)
|
||||
|
||||
rpc.z_getoperationstatus()
|
||||
|
||||
if __name__ == '__main__':
|
||||
LockZinsTest ().main()
|
||||
|
||||
@@ -103,6 +103,7 @@ def initialize_datadir(dirname, n):
|
||||
with open(os.path.join(datadir, "ZZZ.conf"), 'w') as f:
|
||||
f.write("regtest=1\n");
|
||||
f.write("txindex=1\n");
|
||||
#f.write("testnode=1\n");
|
||||
f.write("server=1\n");
|
||||
f.write("showmetrics=0\n");
|
||||
f.write("rpcuser=hush\n");
|
||||
@@ -481,7 +482,7 @@ def assert_raises(exc, fun, *args, **kwds):
|
||||
def wait_and_assert_operationid_status(node, myopid, in_status='success', in_errormsg=None, timeout=300):
|
||||
print('waiting for async operation {}'.format(myopid))
|
||||
result = None
|
||||
for _ in xrange(1, timeout):
|
||||
for _ in range(1, timeout):
|
||||
results = node.z_getoperationresult([myopid])
|
||||
if len(results) > 0:
|
||||
result = results[0]
|
||||
|
||||
Reference in New Issue
Block a user