Files
dragonx/qa/rpc-tests/ac_private.py

87 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2016-2024 The Hush developers
# Copyright (c) 2018 SuperNET 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
import time
from decimal import Decimal
from random import choice
from string import ascii_uppercase
def assert_success(result):
assert_equal(result['result'], 'success')
def assert_error(result):
assert_equal(result['result'], 'error')
class PrivateTest (BitcoinTestFramework):
def setup_chain(self):
print("Initializing ac_private test directory "+self.options.tmpdir)
self.num_nodes = 1
self.options.nocleanup = 1 # do not delete datadir after test run
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
# These nodes simulate z2z asset chain parameters
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',
'-conf='+self.options.tmpdir+'/node0/regtest/ZZZ.conf',
'-port=64367',
'-rpcport=64368',
'-ac_supply=10',
'-ac_reward=25600000000',
'-ac_private=1',
'-allowlist=127.0.0.1',
#'-debug',
'-regtest',
'--daemon',
'-rpcuser=hush',
'-rpcpassword=puppy'
]]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_test (self):
print("Mining blocks...")
rpc = self.nodes[0]
rpc.generate(1)
self.sync_all()
rpc.getinfo()
rpc.getwalletinfo()
taddr = rpc.getnewaddress()
# sending to arbitrary non-notary transparent address is not allowed
print("Sending to " + taddr)
try:
rpc.sendtoaddress(taddr, 1)
except:
assert_true(1)
# this should work but don't
#assert_raises(JSONRPCException, rpc.sendtoaddress, taddr,1)
if __name__ == '__main__':
PrivateTest ().main()