From 563329ab204ab8d56842f025c0f1450b4eef8aee Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 5 Aug 2018 22:04:24 -0700 Subject: [PATCH 01/40] Add new test file --- qa/pull-tester/rpc-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 50de39f64..fb4ff99a7 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -11,6 +11,7 @@ export BITCOIND=${REAL_BITCOIND} #Run the tests testScripts=( + 'cryptoconditions.py' 'paymentdisclosure.py' 'prioritisetransaction.py' 'wallet_treestate.py' From 107fe4500ac87aa4809046e5fff2381fcb078976 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 5 Aug 2018 23:52:51 -0700 Subject: [PATCH 02/40] Fix location of kmd binary used in tests --- qa/pull-tester/tests-config.sh.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qa/pull-tester/tests-config.sh.in b/qa/pull-tester/tests-config.sh.in index cc76e8ad8..8d9467f3f 100755 --- a/qa/pull-tester/tests-config.sh.in +++ b/qa/pull-tester/tests-config.sh.in @@ -13,6 +13,6 @@ EXEEXT="@EXEEXT@" @ENABLE_ZMQ_TRUE@ENABLE_ZMQ=1 @ENABLE_PROTON_TRUE@ENABLE_PROTON=1 -REAL_BITCOIND="$BUILDDIR/src/zcashd${EXEEXT}" -REAL_BITCOINCLI="$BUILDDIR/src/zcash-cli${EXEEXT}" +REAL_BITCOIND="$BUILDDIR/src/komodod${EXEEXT}" +REAL_BITCOINCLI="$BUILDDIR/src/komodo-cli${EXEEXT}" From 8e5de27a674bfcf27c05ee87488b8e20129055aa Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 5 Aug 2018 23:53:07 -0700 Subject: [PATCH 03/40] Fix some compile issues on os x --- configure.ac | 4 ++-- src/txdb.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 7de40ff26..33bcf519f 100644 --- a/configure.ac +++ b/configure.ac @@ -507,8 +507,8 @@ if test x$use_hardening != xno; then if test x$TARGET_OS != xwindows; then # All windows code is PIC, forcing it on just adds useless compile warnings - AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)]) - AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)]) + # AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)]) + # AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)]) AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"],[AC_MSG_ERROR(Cannot enable -fPIE)]) AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],[AC_MSG_ERROR(Cannot enable -pie)]) else diff --git a/src/txdb.cpp b/src/txdb.cpp index edebd4d7c..13d87e2c9 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -430,7 +430,7 @@ extern UniValue CBlockTreeDB::Snapshot(int top) }; int64_t startingHeight = chainActive.Height(); - fprintf(stderr, "Starting snapshot at height %li\n", startingHeight); + fprintf(stderr, "Starting snapshot at height %lli\n", startingHeight); for (iter->SeekToLast(); iter->Valid(); iter->Prev()) { boost::this_thread::interruption_point(); @@ -487,7 +487,7 @@ extern UniValue CBlockTreeDB::Snapshot(int top) } UniValue addresses(UniValue::VARR); - fprintf(stderr, "total=%f, totalAddresses=%li, utxos=%li, ignored=%li\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); + fprintf(stderr, "total=%f, totalAddresses=%lli, utxos=%lli, ignored=%lli\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); for (std::pair element : addressAmounts) { vaddr.push_back( make_pair(element.second, element.first) ); From 752791ae3dc1c0b1c9f6d6c5179acda189d4d5cb Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 00:36:10 -0700 Subject: [PATCH 04/40] Add stub test file for cc tests --- qa/rpc-tests/cryptoconditions.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 qa/rpc-tests/cryptoconditions.py diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py new file mode 100755 index 000000000..80f411303 --- /dev/null +++ b/qa/rpc-tests/cryptoconditions.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python2 +# Copyright (c) 2018 SuperNET developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +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, start_nodes, start_node, connect_nodes_bi, \ + stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds + +import time +from decimal import Decimal + +class WalletTest (BitcoinTestFramework): + + def setup_chain(self): + print("Initializing CC test directory "+self.options.tmpdir) + initialize_chain_clean(self.options.tmpdir, 4) + + def run_test (self): + print "Mining blocks..." + + self.nodes[0].generate(4) + self.sync_all() + + address = self.nodes[0].getnewaddress() + assert_equal(0,42) + +if __name__ == '__main__': + WalletTest ().main () From 3ccd5a79e5060b02985e970732e7228565c85908 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 00:43:31 -0700 Subject: [PATCH 05/40] Look for the correct config file in our tests --- qa/rpc-tests/test_framework/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index f3ea481ee..d368aa879 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -75,7 +75,7 @@ def initialize_datadir(dirname, n): datadir = os.path.join(dirname, "node"+str(n)) if not os.path.isdir(datadir): os.makedirs(datadir) - with open(os.path.join(datadir, "zcash.conf"), 'w') as f: + with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); f.write("showmetrics=0\n"); f.write("rpcuser=rt\n"); @@ -144,7 +144,7 @@ def initialize_chain(test_dir): from_dir = os.path.join("cache", "node"+str(i)) to_dir = os.path.join(test_dir, "node"+str(i)) shutil.copytree(from_dir, to_dir) - initialize_datadir(test_dir, i) # Overwrite port/rpcport in zcash.conf + initialize_datadir(test_dir, i) # Overwrite port/rpcport in komodo.conf def initialize_chain_clean(test_dir, num_nodes): """ From 45a4cba477433583dca2a515020e8fd8ea624df4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 00:44:49 -0700 Subject: [PATCH 06/40] fix test docs --- qa/rpc-tests/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qa/rpc-tests/README.md b/qa/rpc-tests/README.md index a0229b56d..17aee1967 100644 --- a/qa/rpc-tests/README.md +++ b/qa/rpc-tests/README.md @@ -18,9 +18,9 @@ Possible options: ``` -h, --help show this help message and exit - --nocleanup Leave bitcoinds and test.* datadir on exit or error - --noshutdown Don't stop bitcoinds after the test execution - --srcdir=SRCDIR Source directory containing bitcoind/bitcoin-cli (default: + --nocleanup Leave komodods and test.* datadir on exit or error + --noshutdown Don't stop komodods after the test execution + --srcdir=SRCDIR Source directory containing komodod/komodo-cli (default: ../../src) --tmpdir=TMPDIR Root directory for datadirs --tracerpc Print out all RPC calls as they are made @@ -31,7 +31,7 @@ If you set the environment variable `PYTHON_DEBUG=1` you will get some debug out A 200-block -regtest blockchain and wallets for four nodes is created the first time a regression test is run and is stored in the cache/ directory. Each node has the miner -subsidy from 25 mature blocks (25*10=250 ZEC) in its wallet. +subsidy from 25 mature blocks (25*10=250 KMD) in its wallet. After the first run, the cache/ blockchain and wallets are copied into a temporary directory and used as the initial @@ -42,5 +42,5 @@ to recover with: ```bash rm -rf cache -killall zcashd +killall komodod ``` From f4cdde0e85683eada52704d0f292dad4ae90fd50 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 08:09:15 -0700 Subject: [PATCH 07/40] Enable txindex in regtest komodo.confs and update binary in initialize_chain --- qa/rpc-tests/test_framework/util.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index d368aa879..8619ea44c 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -77,36 +77,41 @@ def initialize_datadir(dirname, n): os.makedirs(datadir) with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); + f.write("txindex=1\n"); f.write("showmetrics=0\n"); f.write("rpcuser=rt\n"); f.write("rpcpassword=rt\n"); f.write("port="+str(p2p_port(n))+"\n"); f.write("rpcport="+str(rpc_port(n))+"\n"); f.write("listenonion=0\n"); + # TODO: maybe make these optional, defaulted to on for now + f.write("addressindex=1\n"); + f.write("spentindex=1\n"); + f.write("timestampindex=1\n"); return datadir def initialize_chain(test_dir): """ Create (or copy from cache) a 200-block-long chain and 4 wallets. - bitcoind and bitcoin-cli must be in search path. + komodod and komodo-cli must be in search path. """ if not os.path.isdir(os.path.join("cache", "node0")): devnull = open("/dev/null", "w+") - # Create cache directories, run bitcoinds: + # Create cache directories, run komodods: for i in range(4): datadir=initialize_datadir("cache", i) - args = [ os.getenv("BITCOIND", "bitcoind"), "-keypool=1", "-datadir="+datadir, "-discover=0" ] + args = [ os.getenv("BITCOIND", "komodod"), "-keypool=1", "-datadir="+datadir, "-discover=0" ] if i > 0: args.append("-connect=127.0.0.1:"+str(p2p_port(0))) bitcoind_processes[i] = subprocess.Popen(args) if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: bitcoind started, calling bitcoin-cli -rpcwait getblockcount" - subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir, + print "initialize_chain: komodod started, calling komodo-cli -rpcwait getblockcount" + subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir, "-rpcwait", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: bitcoin-cli -rpcwait getblockcount completed" + print "initialize_chain: komodo-cli -rpcwait getblockcount completed" devnull.close() rpcs = [] for i in range(4): From 6358342934b443f47d9bd8fffcbfc7beaaa9a1e1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 10:59:33 -0700 Subject: [PATCH 08/40] debug valid pubkey error --- src/wallet/rpcwallet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 295460618..5dbd374d6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4836,7 +4836,7 @@ int32_t ensure_CCrequirements() if ( NOTARY_PUBKEY33[0] == 0 ) return(-1); else if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) == 0 ) - return(-1); + return(-2); else return(0); } @@ -4923,11 +4923,13 @@ UniValue diceaddress(const UniValue& params, bool fHelp) UniValue faucetaddress(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; std::vector pubkey; + int errno; cp = CCinit(&C,EVAL_FAUCET); if ( fHelp || params.size() > 1 ) throw runtime_error("faucetaddress [pubkey]\n"); - if ( ensure_CCrequirements() < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + errno = ensure_CCrequirements(); + if ( errno < 0 ) + throw runtime_error(strprintf("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet. ERR=%d\n", errno)); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Faucet",pubkey)); From 25709e30789b62b55dc8a8f13dd10d7db61abafd Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 22:50:38 +0200 Subject: [PATCH 09/40] These %lli/%li formats are platform-dependent --- src/txdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 13d87e2c9..af5927043 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -430,7 +430,7 @@ extern UniValue CBlockTreeDB::Snapshot(int top) }; int64_t startingHeight = chainActive.Height(); - fprintf(stderr, "Starting snapshot at height %lli\n", startingHeight); + //fprintf(stderr, "Starting snapshot at height %lli\n", startingHeight); for (iter->SeekToLast(); iter->Valid(); iter->Prev()) { boost::this_thread::interruption_point(); @@ -487,7 +487,7 @@ extern UniValue CBlockTreeDB::Snapshot(int top) } UniValue addresses(UniValue::VARR); - fprintf(stderr, "total=%f, totalAddresses=%lli, utxos=%lli, ignored=%lli\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); + //fprintf(stderr, "total=%f, totalAddresses=%li, utxos=%li, ignored=%li\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); for (std::pair element : addressAmounts) { vaddr.push_back( make_pair(element.second, element.first) ); From 467e1047aaf558370b165bd8848cca1f02fc378b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 23:00:47 +0200 Subject: [PATCH 10/40] Optimize our cc python test; only start 1 node for now --- qa/rpc-tests/cryptoconditions.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 80f411303..a0f4fe0a8 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -12,20 +12,30 @@ from test_framework.util import assert_equal, assert_greater_than, \ import time from decimal import Decimal -class WalletTest (BitcoinTestFramework): +class CryptoConditionsTest (BitcoinTestFramework): def setup_chain(self): print("Initializing CC test directory "+self.options.tmpdir) initialize_chain_clean(self.options.tmpdir, 4) + def setup_nodes(self): + return start_nodes(1, self.options.tmpdir) + + def setup_network(self, split=False): + self.nodes = start_nodes(1, self.options.tmpdir) + self.is_network_split=False + self.sync_all() + def run_test (self): print "Mining blocks..." - self.nodes[0].generate(4) + rpc = self.nodes[0] + rpc.generate(4) self.sync_all() - address = self.nodes[0].getnewaddress() - assert_equal(0,42) + faucet = rpc.faucetaddress() + assert_equal(faucet['result'], 'success') + assert_equal(faucet['myaddress'][0], 'R') if __name__ == '__main__': - WalletTest ().main () + CryptoConditionsTest ().main () From 32829f6d6fc8d559ebff5493278381295416d894 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 08:13:18 +0200 Subject: [PATCH 11/40] Fix various test suite bugs and create CC AC in our tests --- qa/rpc-tests/cryptoconditions.py | 33 +++++++++++++++++++++-------- qa/rpc-tests/test_framework/util.py | 14 ++++++------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index a0f4fe0a8..0fc162c75 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -16,23 +16,38 @@ class CryptoConditionsTest (BitcoinTestFramework): def setup_chain(self): print("Initializing CC test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + self.num_nodes = 1 + initialize_chain_clean(self.options.tmpdir, self.num_nodes) - def setup_nodes(self): - return start_nodes(1, self.options.tmpdir) - - def setup_network(self, split=False): - self.nodes = start_nodes(1, self.options.tmpdir) - self.is_network_split=False + def setup_network(self, split = False): + print("Setting up network...") + self.pubkey = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" + self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, + extra_args=[[ + '-ac_name=REGTEST', + '-addressindex=1', + '-spentindex=1', + '-ac_supply=5555555', + '-ac_reward=10000000', + '-pubkey=02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf', + '-ac_cc=1' + ]] * self.num_nodes + ) + self.is_network_split = split self.sync_all() def run_test (self): - print "Mining blocks..." - + print("Mining blocks...") rpc = self.nodes[0] rpc.generate(4) self.sync_all() + # this corresponds to -pubkey above + print("Importking pubkey") + rpc.importprivkey(privkey) + validate = rpc.validateaddress(self.pubkey) + # Begin actual CC tests faucet = rpc.faucetaddress() assert_equal(faucet['result'], 'success') assert_equal(faucet['myaddress'][0], 'R') diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 8619ea44c..fc0a04bf2 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -1,4 +1,5 @@ # Copyright (c) 2014 The Bitcoin Core developers +# Copyright (c) 2018 The SuperNET developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -78,6 +79,7 @@ def initialize_datadir(dirname, n): with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); f.write("txindex=1\n"); + f.write("server=1\n"); f.write("showmetrics=0\n"); f.write("rpcuser=rt\n"); f.write("rpcpassword=rt\n"); @@ -182,22 +184,22 @@ def _rpchost_to_args(rpchost): def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None): """ - Start a bitcoind and return RPC connection to it + Start a komodod and return RPC connection to it """ datadir = os.path.join(dirname, "node"+str(i)) if binary is None: - binary = os.getenv("BITCOIND", "bitcoind") + binary = os.getenv("BITCOIND", "komodod") args = [ binary, "-datadir="+datadir, "-keypool=1", "-discover=0", "-rest" ] if extra_args is not None: args.extend(extra_args) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") if os.getenv("PYTHON_DEBUG", ""): - print "start_node: bitcoind started, calling bitcoin-cli -rpcwait getblockcount" - subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir] + + print "start_node: komodod started, calling komodo-cli -rpcwait getblockcount" + subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + _rpchost_to_args(rpchost) + ["-rpcwait", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): - print "start_node: calling bitcoin-cli -rpcwait getblockcount returned" + print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) if timewait is not None: @@ -209,7 +211,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None): """ - Start multiple bitcoinds, return RPC connections to them + Start multiple komodods, return RPC connections to them """ if extra_args is None: extra_args = [ None for i in range(num_nodes) ] if binary is None: binary = [ None for i in range(num_nodes) ] From 5ec4373ca4e54b98435a9ee329e047a46239769d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 09:22:40 +0200 Subject: [PATCH 12/40] More debugging trying to make getblockcount work and not have komodod hang the test --- qa/rpc-tests/cryptoconditions.py | 8 ++++++-- qa/rpc-tests/test_framework/util.py | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 0fc162c75..7e1810085 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -7,7 +7,7 @@ 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, start_nodes, start_node, connect_nodes_bi, \ - stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds + stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port import time from decimal import Decimal @@ -24,7 +24,11 @@ class CryptoConditionsTest (BitcoinTestFramework): self.pubkey = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, - extra_args=[[ + extra_args=[[ + '-regtest', + '-server=1', + '-rpcport=64368', + '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', '-ac_name=REGTEST', '-addressindex=1', '-spentindex=1', diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index fc0a04bf2..146499d08 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -76,6 +76,7 @@ def initialize_datadir(dirname, n): datadir = os.path.join(dirname, "node"+str(n)) if not os.path.isdir(datadir): os.makedirs(datadir) + print("Writing to " + os.path.join(datadir,"komodo.conf")) with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); f.write("txindex=1\n"); @@ -84,7 +85,9 @@ def initialize_datadir(dirname, n): f.write("rpcuser=rt\n"); f.write("rpcpassword=rt\n"); f.write("port="+str(p2p_port(n))+"\n"); - f.write("rpcport="+str(rpc_port(n))+"\n"); + rpcport = str(rpc_port(n)) + f.write("rpcport="+rpcport+"\n"); + print "RPC port=" + rpcport f.write("listenonion=0\n"); # TODO: maybe make these optional, defaulted to on for now f.write("addressindex=1\n"); @@ -108,10 +111,12 @@ def initialize_chain(test_dir): if i > 0: args.append("-connect=127.0.0.1:"+str(p2p_port(0))) bitcoind_processes[i] = subprocess.Popen(args) + cmd = os.getenv("BITCOINCLI", "komodo-cli") + cmd_args = cmd + " -datadir="+datadir + " -rpcwait getblockcount" if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: komodod started, calling komodo-cli -rpcwait getblockcount" - subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir, - "-rpcwait", "getblockcount"], stdout=devnull) + print "initialize_chain: komodod started, calling: " + cmd_args + subprocess.check_call([ cmd, "-datadir="+datadir, + "-rpcwait", "getblockcount"]) #, stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): print "initialize_chain: komodo-cli -rpcwait getblockcount completed" devnull.close() @@ -193,8 +198,10 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= if extra_args is not None: args.extend(extra_args) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") + cmd = os.getenv("BITCOINCLI", "komodo-cli") + cmd_args = cmd + "-datadir="+datadir + " -rpcwait getblockcount" if os.getenv("PYTHON_DEBUG", ""): - print "start_node: komodod started, calling komodo-cli -rpcwait getblockcount" + print "start_node: komodod started, calling : " + cmd_args subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + _rpchost_to_args(rpchost) + ["-rpcwait", "getblockcount"], stdout=devnull) From 626af0e73e29b97a246b11880df39628e529ff3c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 20:13:32 +0200 Subject: [PATCH 13/40] Getting closer, invalid rpc user/pass instead of wrong port --- qa/rpc-tests/cryptoconditions.py | 10 ++++++--- qa/rpc-tests/test_framework/util.py | 32 +++++++++++++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 7e1810085..c9778fd3e 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -26,20 +26,24 @@ class CryptoConditionsTest (BitcoinTestFramework): self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ '-regtest', - '-server=1', - '-rpcport=64368', + # TODO: AC.conf instead of komodo.conf + #'-conf='+self.options.tmpdir+'/node0/komodo.conf', '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', + '-port=64367', + '-rpcport=64368', '-ac_name=REGTEST', '-addressindex=1', '-spentindex=1', '-ac_supply=5555555', '-ac_reward=10000000', '-pubkey=02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf', - '-ac_cc=1' + '-ac_cc=1', + '-daemon', ]] * self.num_nodes ) self.is_network_split = split self.sync_all() + print("Done setting up network") def run_test (self): print("Mining blocks...") diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 146499d08..16f9e813f 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -84,10 +84,10 @@ def initialize_datadir(dirname, n): f.write("showmetrics=0\n"); f.write("rpcuser=rt\n"); f.write("rpcpassword=rt\n"); - f.write("port="+str(p2p_port(n))+"\n"); - rpcport = str(rpc_port(n)) - f.write("rpcport="+rpcport+"\n"); - print "RPC port=" + rpcport + #f.write("port="+str(p2p_port(n))+"\n"); + #rpcport = str(rpc_port(n)) + #f.write("rpcport="+rpcport+"\n"); + #print "RPC port=" + rpcport f.write("listenonion=0\n"); # TODO: maybe make these optional, defaulted to on for now f.write("addressindex=1\n"); @@ -115,8 +115,11 @@ def initialize_chain(test_dir): cmd_args = cmd + " -datadir="+datadir + " -rpcwait getblockcount" if os.getenv("PYTHON_DEBUG", ""): print "initialize_chain: komodod started, calling: " + cmd_args - subprocess.check_call([ cmd, "-datadir="+datadir, - "-rpcwait", "getblockcount"]) #, stdout=devnull) + strcmd = cmd + " " + "-datadir="+datadir + " -rpcwait getblockcount" + + print("Running " + strcmd) + subprocess.check_call(strcmd, shell=True); + #subprocess.check_call([ cmd, "-rpcwait", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): print "initialize_chain: komodo-cli -rpcwait getblockcount completed" devnull.close() @@ -198,13 +201,20 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= if extra_args is not None: args.extend(extra_args) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") + cmd = os.getenv("BITCOINCLI", "komodo-cli") - cmd_args = cmd + "-datadir="+datadir + " -rpcwait getblockcount" + print("cmd=" + cmd) + #TODO: + cmd_args = " -datadir="+datadir + " -rpcport=64368 -rpcwait -conf=" +datadir+"/komodo.conf getblockcount " if os.getenv("PYTHON_DEBUG", ""): - print "start_node: komodod started, calling : " + cmd_args - subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + - _rpchost_to_args(rpchost) + - ["-rpcwait", "getblockcount"], stdout=devnull) + print "start_node: komodod started, calling : " + cmd + " " + cmd_args + strcmd = cmd + " " + cmd_args + + print("Running " + strcmd) + subprocess.check_call(strcmd, shell=True); + #subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + + # _rpchost_to_args(rpchost) + + # ["-rpcwait", "-rpcport=6438", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() From 3528faa71183c1002031e26cc4037f8ebbab071d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 20:51:12 +0200 Subject: [PATCH 14/40] Use correct rpc user/pass; this only works the second time its run, some kind of timing/caching issue --- qa/rpc-tests/cryptoconditions.py | 14 +++++++++----- qa/rpc-tests/test_framework/util.py | 13 ++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index c9778fd3e..7dc8c2d07 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -25,10 +25,10 @@ class CryptoConditionsTest (BitcoinTestFramework): self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ - '-regtest', + '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', # TODO: AC.conf instead of komodo.conf #'-conf='+self.options.tmpdir+'/node0/komodo.conf', - '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', + '-regtest', '-port=64367', '-rpcport=64368', '-ac_name=REGTEST', @@ -38,8 +38,12 @@ class CryptoConditionsTest (BitcoinTestFramework): '-ac_reward=10000000', '-pubkey=02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf', '-ac_cc=1', + '-whitelist=127.0.0.1', + '-debug', '-daemon', - ]] * self.num_nodes + '-rpcuser=rt', + '-rpcpassword=rt' + ]] ) self.is_network_split = split self.sync_all() @@ -51,8 +55,8 @@ class CryptoConditionsTest (BitcoinTestFramework): rpc.generate(4) self.sync_all() # this corresponds to -pubkey above - print("Importking pubkey") - rpc.importprivkey(privkey) + print("Importing privkey") + rpc.importprivkey(self.privkey) validate = rpc.validateaddress(self.pubkey) # Begin actual CC tests diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 16f9e813f..81a9b4633 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -76,6 +76,8 @@ def initialize_datadir(dirname, n): datadir = os.path.join(dirname, "node"+str(n)) if not os.path.isdir(datadir): os.makedirs(datadir) + # kmd AC's don't use this, they use the conf auto-created when the AC is created + # plus CLI arguments. This is for komodod tests print("Writing to " + os.path.join(datadir,"komodo.conf")) with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); @@ -102,6 +104,7 @@ def initialize_chain(test_dir): komodod and komodo-cli must be in search path. """ + print("initialize_chain") if not os.path.isdir(os.path.join("cache", "node0")): devnull = open("/dev/null", "w+") # Create cache directories, run komodods: @@ -199,13 +202,14 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= binary = os.getenv("BITCOIND", "komodod") args = [ binary, "-datadir="+datadir, "-keypool=1", "-discover=0", "-rest" ] if extra_args is not None: args.extend(extra_args) + print("args=" + ' '.join(args)) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") cmd = os.getenv("BITCOINCLI", "komodo-cli") print("cmd=" + cmd) - #TODO: - cmd_args = " -datadir="+datadir + " -rpcport=64368 -rpcwait -conf=" +datadir+"/komodo.conf getblockcount " + #TODO: this will only work on the regtest AC, and probably breaks non-CC tests + cmd_args = " -datadir="+datadir + " -rpcwait -conf=" +datadir+"/REGTEST.conf getblockcount " if os.getenv("PYTHON_DEBUG", ""): print "start_node: komodod started, calling : " + cmd + " " + cmd_args strcmd = cmd + " " + cmd_args @@ -218,11 +222,14 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= if os.getenv("PYTHON_DEBUG", ""): print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() - url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) + #url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) + url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', 64368) + print("connecting to " + url) if timewait is not None: proxy = AuthServiceProxy(url, timeout=timewait) else: proxy = AuthServiceProxy(url) + print("created proxy") proxy.url = url # store URL on proxy for info return proxy From 38a2d0c825077c815d4c92775ce4d7552ed1076d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 20:57:42 +0200 Subject: [PATCH 15/40] Pass along extra_args correctly to get correct rpc user/pass --- qa/rpc-tests/test_framework/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 81a9b4633..249d2d0ba 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -209,7 +209,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= cmd = os.getenv("BITCOINCLI", "komodo-cli") print("cmd=" + cmd) #TODO: this will only work on the regtest AC, and probably breaks non-CC tests - cmd_args = " -datadir="+datadir + " -rpcwait -conf=" +datadir+"/REGTEST.conf getblockcount " + cmd_args = ' '.join(extra_args) + " -rpcwait -conf=" +datadir+"/REGTEST.conf getblockcount " if os.getenv("PYTHON_DEBUG", ""): print "start_node: komodod started, calling : " + cmd + " " + cmd_args strcmd = cmd + " " + cmd_args From eb8f0960e1a9ea02ca2d373438d0851497882bd7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:23:05 +0200 Subject: [PATCH 16/40] Fix some docs and references to bitcoind --- qa/rpc-tests/test_framework/test_framework.py | 12 ++++++------ qa/rpc-tests/test_framework/util.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 56151bb3e..0d5fe5244 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -90,11 +90,11 @@ class BitcoinTestFramework(object): parser = optparse.OptionParser(usage="%prog [options]") parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true", - help="Leave bitcoinds and test.* datadir on exit or error") + help="Leave komodods and test.* datadir on exit or error") parser.add_option("--noshutdown", dest="noshutdown", default=False, action="store_true", - help="Don't stop bitcoinds after the test execution") + help="Don't stop komodods after the test execution") parser.add_option("--srcdir", dest="srcdir", default="../../src", - help="Source directory containing bitcoind/bitcoin-cli (default: %default)") + help="Source directory containing komodod/komodo-cli (default: %default)") parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"), help="Root directory for datadirs") parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true", @@ -137,7 +137,7 @@ class BitcoinTestFramework(object): stop_nodes(self.nodes) wait_bitcoinds() else: - print("Note: bitcoinds were not stopped and may still be running") + print("Note: komodods were not stopped and may still be running") if not self.options.nocleanup and not self.options.noshutdown: print("Cleaning up") @@ -165,10 +165,10 @@ class ComparisonTestFramework(BitcoinTestFramework): def add_options(self, parser): parser.add_option("--testbinary", dest="testbinary", - default=os.getenv("BITCOIND", "bitcoind"), + default=os.getenv("BITCOIND", "komodod"), help="bitcoind binary to test") parser.add_option("--refbinary", dest="refbinary", - default=os.getenv("BITCOIND", "bitcoind"), + default=os.getenv("BITCOIND", "komodod"), help="bitcoind binary to use for reference nodes (if any)") def setup_chain(self): diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 249d2d0ba..2e349794b 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -202,7 +202,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= binary = os.getenv("BITCOIND", "komodod") args = [ binary, "-datadir="+datadir, "-keypool=1", "-discover=0", "-rest" ] if extra_args is not None: args.extend(extra_args) - print("args=" + ' '.join(args)) + #print("args=" + ' '.join(args)) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") From dcc6cdb0830f71bbb7feef98fbc1a24f9efbccf1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:24:33 +0200 Subject: [PATCH 17/40] Remove reference to REGTEST.conf in start_node which all tests use, not just CC tests. it is passed via extra_args --- qa/rpc-tests/test_framework/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 2e349794b..1080f32f1 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -209,7 +209,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= cmd = os.getenv("BITCOINCLI", "komodo-cli") print("cmd=" + cmd) #TODO: this will only work on the regtest AC, and probably breaks non-CC tests - cmd_args = ' '.join(extra_args) + " -rpcwait -conf=" +datadir+"/REGTEST.conf getblockcount " + cmd_args = ' '.join(extra_args) + " -rpcwait getblockcount " if os.getenv("PYTHON_DEBUG", ""): print "start_node: komodod started, calling : " + cmd + " " + cmd_args strcmd = cmd + " " + cmd_args From 8d454fb58e459b28f296ab46c8b0e4e7ea07a096 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:32:56 +0200 Subject: [PATCH 18/40] Sleep a bit to give time for regtest komodod to start --- qa/rpc-tests/test_framework/util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 1080f32f1..2c63a9b23 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -215,6 +215,8 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= strcmd = cmd + " " + cmd_args print("Running " + strcmd) + import time + time.sleep(2) subprocess.check_call(strcmd, shell=True); #subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + # _rpchost_to_args(rpchost) + From d48c67574f00cbb6b79bcdc02d392eabd052d7f0 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:45:32 +0200 Subject: [PATCH 19/40] Improve faucetaddress tests --- qa/rpc-tests/cryptoconditions.py | 5 ++++- qa/rpc-tests/test_framework/util.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 7dc8c2d07..24bd2925b 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -62,7 +62,10 @@ class CryptoConditionsTest (BitcoinTestFramework): # Begin actual CC tests faucet = rpc.faucetaddress() assert_equal(faucet['result'], 'success') - assert_equal(faucet['myaddress'][0], 'R') + # verify all keys look like valid AC addrs, could be better + for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: + assert_equal(faucet[x][0], 'R') + if __name__ == '__main__': CryptoConditionsTest ().main () diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 2c63a9b23..856ae5a05 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -208,7 +208,6 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= cmd = os.getenv("BITCOINCLI", "komodo-cli") print("cmd=" + cmd) - #TODO: this will only work on the regtest AC, and probably breaks non-CC tests cmd_args = ' '.join(extra_args) + " -rpcwait getblockcount " if os.getenv("PYTHON_DEBUG", ""): print "start_node: komodod started, calling : " + cmd + " " + cmd_args @@ -225,6 +224,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() #url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) + #TODO: this breaks non CC tests url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', 64368) print("connecting to " + url) if timewait is not None: From 380bcb10ba6ac2436238175fe83da281d75227f3 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:50:54 +0200 Subject: [PATCH 20/40] Add some dice tests --- qa/rpc-tests/cryptoconditions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 24bd2925b..7fb4eb47e 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -60,12 +60,20 @@ class CryptoConditionsTest (BitcoinTestFramework): validate = rpc.validateaddress(self.pubkey) # Begin actual CC tests + + # Faucet tests faucet = rpc.faucetaddress() assert_equal(faucet['result'], 'success') # verify all keys look like valid AC addrs, could be better for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: assert_equal(faucet[x][0], 'R') + # Dice tests + dice = rpc.diceaddress() + assert_equal(dice['result'], 'success') + for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: + assert_equal(dice[x][0], 'R') + if __name__ == '__main__': CryptoConditionsTest ().main () From 7b6e9bf0695f5cf6d39bd113c54aac051b69eab2 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 23:34:50 +0200 Subject: [PATCH 21/40] More faucet and token tests --- qa/rpc-tests/cryptoconditions.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 7fb4eb47e..a9c54d09b 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -21,7 +21,8 @@ class CryptoConditionsTest (BitcoinTestFramework): def setup_network(self, split = False): print("Setting up network...") - self.pubkey = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" + self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" + self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf" self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ @@ -36,7 +37,7 @@ class CryptoConditionsTest (BitcoinTestFramework): '-spentindex=1', '-ac_supply=5555555', '-ac_reward=10000000', - '-pubkey=02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf', + '-pubkey=' + self.pubkey, '-ac_cc=1', '-whitelist=127.0.0.1', '-debug', @@ -52,12 +53,11 @@ class CryptoConditionsTest (BitcoinTestFramework): def run_test (self): print("Mining blocks...") rpc = self.nodes[0] - rpc.generate(4) + rpc.generate(1) self.sync_all() # this corresponds to -pubkey above print("Importing privkey") rpc.importprivkey(self.privkey) - validate = rpc.validateaddress(self.pubkey) # Begin actual CC tests @@ -68,12 +68,29 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: assert_equal(faucet[x][0], 'R') + result = rpc.faucetinfo() + assert_equal(result['result'], 'success') + + # fails + #result = rpc.faucetfund(1) + # Dice tests dice = rpc.diceaddress() assert_equal(dice['result'], 'success') for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: assert_equal(dice[x][0], 'R') + # Token tests + result = rpc.tokenaddress() + assert_equal(result['result'], 'success') + for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.tokenaddress(self.pubkey) + assert_equal(result['result'], 'success') + for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + if __name__ == '__main__': CryptoConditionsTest ().main () From 8567b4386b8fa73818f7538b601f536672034aee Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 8 Aug 2018 07:25:52 +0200 Subject: [PATCH 22/40] Add a test for tokenlist --- qa/rpc-tests/cryptoconditions.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index a9c54d09b..e19bb6b23 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -91,6 +91,13 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: assert_equal(result[x][0], 'R') + # fails if no funds? + # result = rpc.tokencreate("DUKE", 0.10, "duke") + # assert_equal(result['result'], 'success') + + result = rpc.tokenlist() + assert_equal(result, []) + if __name__ == '__main__': CryptoConditionsTest ().main () From 776fb6cd6249dc07de77f1d55e7525448a2b8bfa Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 8 Aug 2018 09:11:33 +0200 Subject: [PATCH 23/40] Add tests for tokenorders and tokenbalance --- qa/rpc-tests/cryptoconditions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index e19bb6b23..347f6ae2f 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -95,9 +95,20 @@ class CryptoConditionsTest (BitcoinTestFramework): # result = rpc.tokencreate("DUKE", 0.10, "duke") # assert_equal(result['result'], 'success') + # there are no tokens created yet result = rpc.tokenlist() assert_equal(result, []) + # there are no token orders yet + result = rpc.tokenorders() + assert_equal(result, []) + + result = rpc.tokenbalance(self.pubkey) + assert_equal(result['balance'], 0) + assert_equal(result['result'], 'success') + assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') + assert_equal(result['tokenid'], self.pubkey) + if __name__ == '__main__': CryptoConditionsTest ().main () From 77373514f575e8592b9af24fbc87da35b46f09c8 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 8 Aug 2018 09:25:47 +0200 Subject: [PATCH 24/40] Add dicelist test; dicefund/tokeninfo tests need to be funded to work correctly --- qa/rpc-tests/cryptoconditions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 347f6ae2f..8be0a69bf 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -80,6 +80,13 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: assert_equal(dice[x][0], 'R') + # no dice created yet + result = rpc.dicelist() + assert_equal(result, []) + + #result = rpc.dicefund("LUCKY",10000,1,10000,10,5) + #assert_equal(result, []) + # Token tests result = rpc.tokenaddress() assert_equal(result['result'], 'success') @@ -109,6 +116,8 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') assert_equal(result['tokenid'], self.pubkey) + #result = rpc.tokeninfo(self.pubkey) + if __name__ == '__main__': CryptoConditionsTest ().main () From 1399f859e0dab9bcd55b64c3d0a7b69dcc534bf2 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Aug 2018 08:53:24 +0200 Subject: [PATCH 25/40] Mine more blocks to ensure a mature balance --- qa/rpc-tests/cryptoconditions.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 8be0a69bf..2784a5823 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -53,12 +53,20 @@ class CryptoConditionsTest (BitcoinTestFramework): def run_test (self): print("Mining blocks...") rpc = self.nodes[0] - rpc.generate(1) + + # utxos from block 1 become mature in block 101 + rpc.generate(101) self.sync_all() + # this corresponds to -pubkey above print("Importing privkey") rpc.importprivkey(self.privkey) + result = rpc.getwalletinfo() + # basic sanity tests + assert_equal(result['txcount'], 101) + assert_greater_than(result['balance'], 0.0) + # Begin actual CC tests # Faucet tests @@ -72,7 +80,7 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['result'], 'success') # fails - #result = rpc.faucetfund(1) + #result = rpc.faucetfund(-1.0) # Dice tests dice = rpc.diceaddress() From de3a68db84af05bbf755c5015789bf8f5ac1587d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Aug 2018 22:52:29 +0200 Subject: [PATCH 26/40] add more tests for faucetfund edge cases --- qa/rpc-tests/cryptoconditions.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 2784a5823..06f965340 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -79,8 +79,15 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetinfo() assert_equal(result['result'], 'success') - # fails - #result = rpc.faucetfund(-1.0) + result = rpc.faucetfund("1") + assert_equal(result['result'], 'success') + assert_true(result['hex']) + + result = rpc.faucetfund("0") + assert_equal(result['result'], 'error') + + result = rpc.faucetfund("-1") + assert_equal(result['result'], 'error') # Dice tests dice = rpc.diceaddress() From 700c1fcfc3dffbe2654776e90e808c9a2974cd98 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Aug 2018 22:54:23 +0200 Subject: [PATCH 27/40] Improve error checking on funds argument to faucetfund --- qa/rpc-tests/test_framework/test_framework.py | 2 +- src/wallet/rpcwallet.cpp | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 0d5fe5244..f545b4246 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -151,7 +151,7 @@ class BitcoinTestFramework(object): sys.exit(1) -# Test framework for doing p2p comparison testing, which sets up some bitcoind +# Test framework for doing p2p comparison testing, which sets up some komodod # binaries: # 1 binary: test binary # 2 binaries: 1 test binary, 1 ref binary diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5dbd374d6..386997b3f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5146,12 +5146,20 @@ UniValue faucetfund(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); funds = atof(params[0].get_str().c_str()) * COIN; - hex = FaucetFund(0,funds); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create faucet funding transaction")); + if (funds > 0) { + hex = FaucetFund(0,funds); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create faucet funding transaction")); + } + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "funding amount must be positive")); + } return(result); } From 2098a4c9bbfd60de2294fcebcd99cfe22f75cfe9 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Aug 2018 23:37:38 +0200 Subject: [PATCH 28/40] Disallow negative funding in faucetfund --- qa/rpc-tests/cryptoconditions.py | 1 - src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 06f965340..97b41fd12 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -81,7 +81,6 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetfund("1") assert_equal(result['result'], 'success') - assert_true(result['hex']) result = rpc.faucetfund("0") assert_equal(result['result'], 'error') diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 386997b3f..744b95b57 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5138,7 +5138,7 @@ UniValue faucetinfo(const UniValue& params, bool fHelp) UniValue faucetfund(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t funds; std::string hex; + UniValue result(UniValue::VOBJ); int64_t funds; std::string hex; if ( fHelp || params.size() > 1 ) throw runtime_error("faucetfund amount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5147,7 +5147,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); funds = atof(params[0].get_str().c_str()) * COIN; if (funds > 0) { - hex = FaucetFund(0,funds); + hex = FaucetFund(0,(uint64_t) funds); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From fe6882f14ccc7d936cad6a3f1ecceb8bfc4f5414 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 10 Aug 2018 08:04:34 +0200 Subject: [PATCH 29/40] More faucet tests, currently sendrawtransaction failing with bad-txns-inputs-duplicate --- qa/rpc-tests/cryptoconditions.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 97b41fd12..36126cfc5 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -66,6 +66,7 @@ class CryptoConditionsTest (BitcoinTestFramework): # basic sanity tests assert_equal(result['txcount'], 101) assert_greater_than(result['balance'], 0.0) + balance = result['balance'] # Begin actual CC tests @@ -79,15 +80,34 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetinfo() assert_equal(result['result'], 'success') - result = rpc.faucetfund("1") - assert_equal(result['result'], 'success') - result = rpc.faucetfund("0") assert_equal(result['result'], 'error') result = rpc.faucetfund("-1") assert_equal(result['result'], 'error') + result = rpc.faucetfund("1") + assert_equal(result['result'], 'success') + assert result['hex'], "hex key found" + + result = rpc.sendrawtransaction(result['hex']) + txid = result[0] + assert txid, "found txid" + + # we need the tx above to be confirmed in the next block + rpc.generate(1) + + # clear the rawmempool + rpc.getrawmempool() + result = rpc.getwalletinfo() + + # make sure our balance is less now + assert_greater_than(balance, result['balance']) + + result = rpc.faucetinfo() + assert_equal(result['result'], 'success') + assert_greater_than( result['funding'], 0 ) + # Dice tests dice = rpc.diceaddress() assert_equal(dice['result'], 'success') From 7b9e2b3c608dbb7469e042e6a88f76f68d7e3569 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 10 Aug 2018 08:40:28 +0200 Subject: [PATCH 30/40] faucetget tests --- qa/rpc-tests/cryptoconditions.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 36126cfc5..f3022c036 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -86,10 +86,13 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetfund("-1") assert_equal(result['result'], 'error') - result = rpc.faucetfund("1") + # why does this fail? + #result = rpc.faucetfund("1987") + result = rpc.faucetfund("2") assert_equal(result['result'], 'success') assert result['hex'], "hex key found" + # broadcast the xtn result = rpc.sendrawtransaction(result['hex']) txid = result[0] assert txid, "found txid" @@ -108,6 +111,15 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['result'], 'success') assert_greater_than( result['funding'], 0 ) + result = rpc.faucetget() + assert_equal(result['result'], 'success') + assert result['hex'], "hex key found" + + # broadcast the xtn + result = rpc.sendrawtransaction(result['hex']) + txid = result[0] + assert txid, "found txid" + # Dice tests dice = rpc.diceaddress() assert_equal(dice['result'], 'success') From a6a826c625527a21f2953d7642a68a6f8da0f3d1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 10 Aug 2018 09:23:04 +0200 Subject: [PATCH 31/40] Add more tests, fails sometimes still due to bad-txns-inputs-duplicate --- qa/rpc-tests/cryptoconditions.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index f3022c036..17a887bd5 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -29,10 +29,10 @@ class CryptoConditionsTest (BitcoinTestFramework): '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', # TODO: AC.conf instead of komodo.conf #'-conf='+self.options.tmpdir+'/node0/komodo.conf', - '-regtest', '-port=64367', '-rpcport=64368', '-ac_name=REGTEST', + '-regtest', '-addressindex=1', '-spentindex=1', '-ac_supply=5555555', @@ -88,6 +88,8 @@ class CryptoConditionsTest (BitcoinTestFramework): # why does this fail? #result = rpc.faucetfund("1987") + + # we need at least 1 + txfee to get result = rpc.faucetfund("2") assert_equal(result['result'], 'success') assert result['hex'], "hex key found" @@ -101,11 +103,12 @@ class CryptoConditionsTest (BitcoinTestFramework): rpc.generate(1) # clear the rawmempool - rpc.getrawmempool() - result = rpc.getwalletinfo() + result = rpc.getrawmempool() + result = rpc.getwalletinfo() + balance2 = result['balance'] # make sure our balance is less now - assert_greater_than(balance, result['balance']) + assert_greater_than(balance, balance2) result = rpc.faucetinfo() assert_equal(result['result'], 'success') @@ -120,6 +123,13 @@ class CryptoConditionsTest (BitcoinTestFramework): txid = result[0] assert txid, "found txid" + # confirm above tx + rpc.generate(1) + result = rpc.getwalletinfo() + + # we should have slightly more funds from the faucet now + assert_greater_than(result['balance'], balance2) + # Dice tests dice = rpc.diceaddress() assert_equal(dice['result'], 'success') From ba0f55ac2f80cca6d8453ee772ca29b39f074d0f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 10 Aug 2018 10:46:07 +0200 Subject: [PATCH 32/40] Add tests for tokencreate and rewardsaddress --- qa/rpc-tests/cryptoconditions.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 17a887bd5..23c6479fe 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -151,12 +151,11 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenaddress(self.pubkey) assert_equal(result['result'], 'success') - for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']: assert_equal(result[x][0], 'R') - # fails if no funds? - # result = rpc.tokencreate("DUKE", 0.10, "duke") - # assert_equal(result['result'], 'success') + result = rpc.tokencreate("DUKE", "1987.420", "duke") + assert_equal(result['result'], 'success') # there are no tokens created yet result = rpc.tokenlist() @@ -174,6 +173,16 @@ class CryptoConditionsTest (BitcoinTestFramework): #result = rpc.tokeninfo(self.pubkey) + # Rewards Tests + + result = rpc.rewardsaddress() + for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.rewardsaddress(self.pubkey) + for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress', 'CCaddress']: + assert_equal(result[x][0], 'R') + if __name__ == '__main__': CryptoConditionsTest ().main () From 9b30af9799b6406c87c42a14768cac9561ed47cb Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 10 Aug 2018 18:10:21 +0200 Subject: [PATCH 33/40] Fix bug in FaucetGet where it returns an int instead of a string --- qa/rpc-tests/cryptoconditions.py | 9 +++++---- src/cc/faucet.cpp | 2 +- src/wallet/rpcwallet.cpp | 5 ++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 23c6479fe..b99d31216 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -68,7 +68,7 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_greater_than(result['balance'], 0.0) balance = result['balance'] - # Begin actual CC tests + ###### Begin actual CC tests ###### # Faucet tests faucet = rpc.faucetaddress() @@ -77,6 +77,10 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: assert_equal(faucet[x][0], 'R') + # no funds in the faucet yet + result = rpc.faucetget() + assert_equal(result['result'], 'error') + result = rpc.faucetinfo() assert_equal(result['result'], 'success') @@ -86,9 +90,6 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetfund("-1") assert_equal(result['result'], 'error') - # why does this fail? - #result = rpc.faucetfund("1987") - # we need at least 1 + txfee to get result = rpc.faucetfund("2") assert_equal(result['result'], 'success') diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 403b56c3e..6cfa9c941 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -169,7 +169,7 @@ std::string FaucetGet(uint64_t txfee) mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); } else fprintf(stderr,"cant find faucet inputs\n"); - return(0); + return(""); } std::string FaucetFund(uint64_t txfee,int64_t funds) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 142b7696c..10b1f1676 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5179,7 +5179,10 @@ UniValue faucetget(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create faucet get transaction")); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create faucet get transaction")); + } return(result); } From f1084b8898c547e9d595c9cc045fee69b18bb5c1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 00:34:38 +0200 Subject: [PATCH 34/40] Refactor faucet/rewards/dice/token tests into their own functions --- qa/rpc-tests/cryptoconditions.py | 51 +++++++++++++++++++------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index b99d31216..420cddf31 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -27,8 +27,6 @@ class CryptoConditionsTest (BitcoinTestFramework): self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', - # TODO: AC.conf instead of komodo.conf - #'-conf='+self.options.tmpdir+'/node0/komodo.conf', '-port=64367', '-rpcport=64368', '-ac_name=REGTEST', @@ -50,27 +48,15 @@ class CryptoConditionsTest (BitcoinTestFramework): self.sync_all() print("Done setting up network") - def run_test (self): - print("Mining blocks...") + def run_faucet_tests(self): rpc = self.nodes[0] - # utxos from block 1 become mature in block 101 - rpc.generate(101) - self.sync_all() - - # this corresponds to -pubkey above - print("Importing privkey") - rpc.importprivkey(self.privkey) - - result = rpc.getwalletinfo() # basic sanity tests + result = rpc.getwalletinfo() assert_equal(result['txcount'], 101) assert_greater_than(result['balance'], 0.0) balance = result['balance'] - ###### Begin actual CC tests ###### - - # Faucet tests faucet = rpc.faucetaddress() assert_equal(faucet['result'], 'success') # verify all keys look like valid AC addrs, could be better @@ -131,7 +117,9 @@ class CryptoConditionsTest (BitcoinTestFramework): # we should have slightly more funds from the faucet now assert_greater_than(result['balance'], balance2) - # Dice tests + def run_dice_tests(self): + rpc = self.nodes[0] + dice = rpc.diceaddress() assert_equal(dice['result'], 'success') for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: @@ -144,7 +132,8 @@ class CryptoConditionsTest (BitcoinTestFramework): #result = rpc.dicefund("LUCKY",10000,1,10000,10,5) #assert_equal(result, []) - # Token tests + def run_token_tests(self): + rpc = self.nodes[0] result = rpc.tokenaddress() assert_equal(result['result'], 'success') for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: @@ -172,10 +161,11 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') assert_equal(result['tokenid'], self.pubkey) - #result = rpc.tokeninfo(self.pubkey) - - # Rewards Tests + result = rpc.tokeninfo(self.pubkey) + assert_equal(result['result'], 'success') + def run_rewards_tests(self): + rpc = self.nodes[0] result = rpc.rewardsaddress() for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress']: assert_equal(result[x][0], 'R') @@ -185,5 +175,24 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result[x][0], 'R') + def run_test (self): + print("Mining blocks...") + rpc = self.nodes[0] + + # utxos from block 1 become mature in block 101 + rpc.generate(101) + self.sync_all() + + # this corresponds to -pubkey above + print("Importing privkey") + rpc.importprivkey(self.privkey) + + + self.run_faucet_tests() + self.run_rewards_tests() + self.run_dice_tests() + self.run_token_tests() + + if __name__ == '__main__': CryptoConditionsTest ().main () From 03fb3946a109df5b9d5dd57e717bf4127a9da299 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 07:18:31 +0200 Subject: [PATCH 35/40] Fix various return values which should be std::string --- src/cc/CCassetstx.cpp | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 7d55b85ff..bfd51f4b7 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -60,12 +60,14 @@ UniValue AssetInfo(uint256 assetid) if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find assetid\n"); + result.push_back(Pair("result","error")); result.push_back(Pair("error","cant find assetid")); - return(0); + return(result); } if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) { fprintf(stderr,"assetid isnt assetcreation txid\n"); + result.push_back(Pair("result","error")); result.push_back(Pair("error","assetid isnt assetcreation txid")); } result.push_back(Pair("result","success")); @@ -182,13 +184,13 @@ std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std:: if ( assetsupply < 0 ) { fprintf(stderr,"negative assetsupply %lld\n",(long long)assetsupply); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( name.size() > 32 || description.size() > 4096 ) { fprintf(stderr,"name.%d or description.%d is too big\n",(int32_t)name.size(),(int32_t)description.size()); - return(0); + return(""); } if ( txfee == 0 ) txfee = 10000; @@ -199,7 +201,7 @@ std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std:: mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(cp->CChexstr) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetCreateOpRet('c',Mypubkey(),name,description))); } - return(0); + return(""); } std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) @@ -208,7 +210,7 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector des if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -234,7 +236,7 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector des } else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN); //} else fprintf(stderr,"numoutputs.%d != numamounts.%d\n",n,(int32_t)amounts.size()); } - return(0); + return(""); } std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal) @@ -243,17 +245,17 @@ std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64 if ( bidamount < 0 || pricetotal < 0 ) { fprintf(stderr,"negative bidamount %lld, pricetotal %lld\n",(long long)bidamount,(long long)pricetotal); - return(0); + return(""); } if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find assetid\n"); - return(0); + return(""); } if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) { fprintf(stderr,"assetid isnt assetcreation txid\n"); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -264,7 +266,7 @@ std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64 mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount,GetUnspendable(cp,0))); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('b',assetid,zeroid,pricetotal,Mypubkey()))); } - return(0); + return(""); } std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t pricetotal) @@ -273,7 +275,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p if ( askamount < 0 || pricetotal < 0 ) { fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -296,18 +298,18 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p } else fprintf(stderr,"need some assets to place ask\n"); } fprintf(stderr,"need some native coins to place ask\n"); - return(0); + return(""); } std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) { CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; fprintf(stderr,"asset swaps disabled\n"); - return(0); + return(""); if ( askamount < 0 || pricetotal < 0 ) { fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -335,7 +337,7 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a } else fprintf(stderr,"need some assets to place ask\n"); } fprintf(stderr,"need some native coins to place ask\n"); - return(0); + return(""); } std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) @@ -356,7 +358,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('o',assetid,zeroid,0,Mypubkey()))); } } - return(0); + return(""); } std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) @@ -377,7 +379,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('x',assetid,zeroid,0,Mypubkey()))); } } - return(0); + return(""); } std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount) @@ -386,7 +388,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f if ( fillamount < 0 ) { fprintf(stderr,"negative fillamount %lld\n",(long long)fillamount); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -426,12 +428,12 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt if ( fillunits < 0 ) { fprintf(stderr,"negative fillunits %lld\n",(long long)fillunits); - return(0); + return(""); } if ( assetid2 != zeroid ) { fprintf(stderr,"asset swaps disabled\n"); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); @@ -475,5 +477,5 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt } else fprintf(stderr,"filltx not enough utxos\n"); } } - return(0); + return(""); } From efa644f28ebff71c000b5742fd1c89537c9b4a68 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 08:21:32 +0200 Subject: [PATCH 36/40] Add some rewards tests --- qa/rpc-tests/cryptoconditions.py | 10 +++++++++- src/cc/rewards.cpp | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 420cddf31..57befe997 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -161,8 +161,9 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') assert_equal(result['tokenid'], self.pubkey) + # this is not a valid assetid result = rpc.tokeninfo(self.pubkey) - assert_equal(result['result'], 'success') + assert_equal(result['result'], 'error') def run_rewards_tests(self): rpc = self.nodes[0] @@ -174,6 +175,13 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress', 'CCaddress']: assert_equal(result[x][0], 'R') + # no rewards yet + result = rpc.rewardslist() + assert_equal(result, []) + + # looking up non-existent reward should return error + result = rpc.rewardsinfo("none") + assert_equal(result['result'], 'error') def run_test (self): print("Mining blocks...") diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 896284245..083133eca 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -371,12 +371,14 @@ UniValue RewardsInfo(uint256 rewardsid) if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); + result.push_back(Pair("result","error")); result.push_back(Pair("error","cant find fundingtxid")); return(result); } if ( vintx.vout.size() > 0 && DecodeRewardsFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,sbits,APR,minseconds,maxseconds,mindeposit) == 0 ) { fprintf(stderr,"fundingtxid isnt rewards creation txid\n"); + result.push_back(Pair("result","error")); result.push_back(Pair("error","fundingtxid isnt rewards creation txid")); return(result); } From 15b76bd76a871429eab3f71e1388db13c1990c20 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 08:58:56 +0200 Subject: [PATCH 37/40] More rewards tests --- qa/rpc-tests/cryptoconditions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 57befe997..53c733ab0 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -183,6 +183,16 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsinfo("none") assert_equal(result['result'], 'error') + result = rpc.rewardscreatefunding("STUFF", "1000", "5", "1", "10", "10") + assert result['hex'], 'got raw xtn' + txid = rpc.sendrawtransaction(result['hex']) + assert txid, 'got txid' + + # confirm the above xtn + rpc.generate(1) + result = rpc.rewardsinfo(txid) + assert_equal(result['result'], 'success') + def run_test (self): print("Mining blocks...") rpc = self.nodes[0] From 88e714577b1ce5740431e39f23fd20538125f87b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 16:47:24 +0200 Subject: [PATCH 38/40] More rewards tests --- qa/rpc-tests/cryptoconditions.py | 14 ++++++++++++++ src/wallet/rpcwallet.cpp | 20 ++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 53c733ab0..9367055d7 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -192,6 +192,20 @@ class CryptoConditionsTest (BitcoinTestFramework): rpc.generate(1) result = rpc.rewardsinfo(txid) assert_equal(result['result'], 'success') + assert_equal(result['name'], 'STUFF') + assert_equal(result['APR'], "5.00000000") + assert_equal(result['minseconds'], 86400) + assert_equal(result['maxseconds'], 864000) + assert_equal(result['funding'], "1000.00000000") + assert_equal(result['mindeposit'], "10.00000000") + assert_equal(result['fundingtxid'], txid) + + # funding amount must be positive + result = rpc.rewardsaddfunding("STUFF", txid, "0") + assert_equal(result['result'], 'error') + + result = rpc.rewardsaddfunding("STUFF", txid, "100") + assert_equal(result['result'], 'success') def run_test (self): print("Mining blocks...") diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 10b1f1676..6329d4a52 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5024,7 +5024,7 @@ UniValue rewardslock(const UniValue& params, bool fHelp) UniValue rewardsaddfunding(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; uint64_t amount; std::string hex; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; int64_t amount; std::string hex; if ( fHelp || params.size() != 3 ) throw runtime_error("rewardsaddfunding name fundingtxid amount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5035,11 +5035,19 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsAddfunding(0,name,fundingtxid,amount); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create rewards addfunding transaction")); + if (amount > 0) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create rewards addfunding transaction")); + } + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "funding amount must be positive")); + } return(result); } From 941619eb461ab11b6d5490f2233c6f5aeee7ba31 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 19:14:51 +0200 Subject: [PATCH 39/40] Make the REGTEST AC special in our test suite, so we get a predictable rpc port number --- qa/rpc-tests/cryptoconditions.py | 3 ++- qa/rpc-tests/test_framework/util.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 9367055d7..849d7daea 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -26,10 +26,11 @@ class CryptoConditionsTest (BitcoinTestFramework): self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ + # always give -ac_name as first extra_arg + '-ac_name=REGTEST', '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', '-port=64367', '-rpcport=64368', - '-ac_name=REGTEST', '-regtest', '-addressindex=1', '-spentindex=1', diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 856ae5a05..5cb0d1b10 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -223,9 +223,10 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= if os.getenv("PYTHON_DEBUG", ""): print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() - #url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) - #TODO: this breaks non CC tests - url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', 64368) + if extra_args[0] == '-ac_name=REGTEST': + url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', 64368) + else: + url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) print("connecting to " + url) if timewait is not None: proxy = AuthServiceProxy(url, timeout=timewait) From 012613d7ac289b53ecc5d277321f7dc3f9507bdc Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 19:24:19 +0200 Subject: [PATCH 40/40] Undo this, it should be on a diff branch --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 33bcf519f..7de40ff26 100644 --- a/configure.ac +++ b/configure.ac @@ -507,8 +507,8 @@ if test x$use_hardening != xno; then if test x$TARGET_OS != xwindows; then # All windows code is PIC, forcing it on just adds useless compile warnings - # AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)]) - # AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)]) + AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)]) + AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)]) AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"],[AC_MSG_ERROR(Cannot enable -fPIE)]) AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],[AC_MSG_ERROR(Cannot enable -pie)]) else