From 994a0151f781687c349a839d9c58c2545229ccf7 Mon Sep 17 00:00:00 2001 From: webworker01 Date: Wed, 12 Dec 2018 18:01:05 -0500 Subject: [PATCH 1/3] Set sapling for zilla in far future, fix oot sapling param --- src/assetchains.json | 6 +++++- src/assetchains.old | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/assetchains.json b/src/assetchains.json index 7bc6b7147..1a0ae25e2 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -124,7 +124,11 @@ }, { "ac_name": "ZILLA", - "ac_supply": "11000000" + "ac_supply": "11000000", + "ac_sapling": "5000000", + "addnode": [ + "51.68.215.104" + ] }, { "ac_name": "RFOX", diff --git a/src/assetchains.old b/src/assetchains.old index 5389e54bd..c1419e7f5 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -27,14 +27,14 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=BEER -ac_supply=100000000 -addnode=78.47.196.146 & ./komodod -pubkey=$pubkey -ac_name=PIZZA -ac_supply=100000000 -addnode=78.47.196.146 & ./komodod -pubkey=$pubkey -ac_name=NINJA -ac_supply=100000000 -addnode=78.47.196.146 & -./komodod -pubkey=$pubkey -ac_name=OOT -ac_supply=216000000 -ac_saplinig=5000000 -addnode=174.138.107.226 & +./komodod -pubkey=$pubkey -ac_name=OOT -ac_supply=216000000 -ac_sapling=5000000 -addnode=174.138.107.226 & ./komodod -pubkey=$pubkey -ac_name=BNTN -ac_supply=500000000 -addnode=94.130.169.205 & ./komodod -pubkey=$pubkey -ac_name=CHAIN -ac_supply=999999 -addnode=78.47.146.222 & ./komodod -pubkey=$pubkey -ac_name=PRLPAY -ac_supply=500000000 -addnode=13.250.226.125 & ./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 & ./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=10000000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -ac_ccactivate=205000 -addnode=46.101.124.153 & -./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 & +./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -ac_sapling=5000000 -addnode=51.68.215.104 & ./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & ~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & ./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & From 6e15b6fbd67c6a96879cabc3839f58d22d081c5e Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Thu, 13 Dec 2018 19:04:52 +0600 Subject: [PATCH 2/3] initial tests for ChannelsCC --- qa/pull-tester/rpc-tests.sh | 1 + qa/rpc-tests/cryptoconditions_channels.py | 174 ++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100755 qa/rpc-tests/cryptoconditions_channels.py diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 0d7d5509c..d95bf612c 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -14,6 +14,7 @@ testScripts=( 'ac_private.py' 'verushash.py' 'cryptoconditions.py' + 'cryptoconditions_channels.py' 'cryptoconditions_dice.py' 'cryptoconditions_faucet.py' 'cryptoconditions_oracles.py' diff --git a/qa/rpc-tests/cryptoconditions_channels.py b/qa/rpc-tests/cryptoconditions_channels.py new file mode 100755 index 000000000..0010f825b --- /dev/null +++ b/qa/rpc-tests/cryptoconditions_channels.py @@ -0,0 +1,174 @@ +#!/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, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ + stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises +from cryptoconditions import assert_success, assert_error, generate_random_string + + +class CryptoconditionsChannelsTest(BitcoinTestFramework): + + def setup_chain(self): + print("Initializing CC test directory "+self.options.tmpdir) + self.num_nodes = 2 + initialize_chain_clean(self.options.tmpdir, self.num_nodes) + + def setup_network(self, split = False): + print("Setting up network...") + self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" + self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf" + self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" + self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp" + self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0" + self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi" + 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=REGTEST', + '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', + '-port=64367', + '-rpcport=64368', + '-regtest', + '-addressindex=1', + '-spentindex=1', + '-ac_supply=5555555', + '-ac_reward=10000000000000', + '-pubkey=' + self.pubkey, + '-ac_cc=2', + '-whitelist=127.0.0.1', + '-debug', + '--daemon', + '-rpcuser=rt', + '-rpcpassword=rt' + ], + ['-ac_name=REGTEST', + '-conf='+self.options.tmpdir+'/node1/REGTEST.conf', + '-port=64365', + '-rpcport=64366', + '-regtest', + '-addressindex=1', + '-spentindex=1', + '-ac_supply=5555555', + '-ac_reward=10000000000000', + '-pubkey=' + self.pubkey1, + '-ac_cc=2', + '-whitelist=127.0.0.1', + '-debug', + '-addnode=127.0.0.1:64367', + '--daemon', + '-rpcuser=rt', + '-rpcpassword=rt']] + ) + self.is_network_split = split + self.rpc = self.nodes[0] + self.rpc1 = self.nodes[1] + 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_channels_tests(self): + + + """!!! for testing needed test daemon which built with custom flag + export CONFIGURE_FLAGS='CPPFLAGS=-DTESTMODE' + since in usual mode 101 confirmations are needed for payment/refund + """ + + rpc = self.nodes[0] + rpc1 = self.nodes[1] + + # getting empty channels list + result = rpc.channelsinfo() + assert_equal(len(result), 2) + assert_equal(result["result"], "success") + assert_equal(result["name"], "Channels Info") + + # 10 payments, 100000 sat denomination channel opening with second node pubkey + new_channel_hex = rpc.channelsopen(self.pubkey1, "10", "100000") + assert_success(new_channel_hex) + channel_txid = self.send_and_mine(new_channel_hex["hex"], rpc) + assert channel_txid, "got channel txid" + + # checking if our new channel in common channels list + result = rpc.channelsinfo() + assert_equal(len(result), 3) + + # checking info about channel directly + result = rpc.channelsinfo(channel_txid) + assert_success(result) + assert_equal(result["Open"], "10 payments of 100000 satoshi") + + # open transaction should be confirmed + rpc.generate(1) + + # trying to make wrong denomination channel payment + result = rpc.channelspayment(channel_txid, "199000") + assert_error(result) + + # trying to make 0 channel payment + result = rpc.channelspayment(channel_txid, "0") + assert_error(result) + + # trying to make negative channel payment + result = rpc.channelspayment(channel_txid, "-1") + assert_error(result) + + # valid channel payment + result = rpc.channelspayment(channel_txid, "100000") + assert_success(result) + payment_tx_id = self.send_and_mine(result["hex"], rpc) + assert payment_tx_id, "got txid" + + # now in channelinfo payment information should appear + result = rpc.channelsinfo(channel_txid) + assert_equal(result["Payment"], "100000 satoshi to {}, 9 payments left".format(self.addr1)) + + # executing channel close + result = rpc.channelsclose(channel_txid) + assert_success(result) + channel_close_txid = self.send_and_mine(result["hex"], rpc) + assert channel_close_txid, "got txid" + + rpc.generate(2) + self.sync_all() + + # now in channelinfo closed flag should appear + result = rpc.channelsinfo(channel_txid) + assert_equal(result["Close"], "channel") + + # executing channel refund + result = rpc.channelsrefund(channel_txid, channel_close_txid) + assert_success(result) + refund_txid = self.send_and_mine(result["hex"], rpc) + assert refund_txid, "got txid" + + def run_test(self): + print("Mining blocks...") + rpc = self.nodes[0] + rpc1 = self.nodes[1] + # utxos from block 1 become mature in block 101 + rpc.generate(101) + self.sync_all() + rpc.getinfo() + rpc1.getinfo() + # this corresponds to -pubkey above + print("Importing privkeys") + rpc.importprivkey(self.privkey) + rpc1.importprivkey(self.privkey1) + self.run_channels_tests() + + +if __name__ == '__main__': + CryptoconditionsChannelsTest().main() From fb168165bf47a0d282d151dff4ed9ba77e92a611 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 13 Dec 2018 02:34:25 -1100 Subject: [PATCH 3/3] Prevent divide by 0 in -ac_options --- src/komodo_globals.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 401a874e3..2590a4a21 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -155,6 +155,8 @@ int64_t komodo_current_supply(uint32_t nHeight) uint64_t lastEnd = j == 0 ? 0 : ASSETCHAINS_ENDSUBSIDY[j - 1]; uint64_t curEnd = ASSETCHAINS_ENDSUBSIDY[j] == 0 ? nHeight : nHeight > ASSETCHAINS_ENDSUBSIDY[j] ? ASSETCHAINS_ENDSUBSIDY[j] : nHeight; uint64_t period = ASSETCHAINS_HALVING[j]; + if ( period == 0 ) + period = 210000; uint32_t nSteps = (curEnd - lastEnd) / period; uint32_t modulo = (curEnd - lastEnd) % period; uint64_t decay = ASSETCHAINS_DECAY[j]; @@ -208,7 +210,8 @@ int64_t komodo_current_supply(uint32_t nHeight) // calculate amount in one step's triangular protrusion over minor triangle's hypotenuse denominator = nSteps * period; - + if ( denominator == 0 ) + denominator = 1; // difference of one step vs. total stepDifference = (period * subsidyDifference) / denominator;