Skip to content

Commit

Permalink
Merge branch 'development' into AddressIndexing_development
Browse files Browse the repository at this point in the history
  • Loading branch information
cronicc committed Mar 17, 2022
2 parents d59a595 + 5e9d8b4 commit 10270bb
Show file tree
Hide file tree
Showing 102 changed files with 3,535 additions and 734 deletions.
3 changes: 3 additions & 0 deletions qa/pull-tester/rpc-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ testScripts=(
'sc_bwt_request.py'
'sc_cert_quality_wallet.py'
'ws_messages.py'
'ws_getsidechainversions.py'
'sc_cert_ceasing_split.py'
'sc_async_proof_verifier.py'
'sc_quality_blockchain.py'
Expand Down Expand Up @@ -131,6 +132,8 @@ testScripts=(
'txindex.py'
'getblockexpanded.py'
'sc_rpc_cmds_json_output.py'
'sc_getscgenesisinfo.py'
'fundaddresses.py'
);
testScriptsExt=(
'getblocktemplate_longpoll.py'
Expand Down
81 changes: 81 additions & 0 deletions qa/rpc-tests/fundaddresses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
# Copyright (c) 2018 The Zencash 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 SC_VERSION_FORK_HEIGHT, BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, start_nodes, mark_logs

NUMB_OF_NODES = 1
DEBUG_MODE = 1

class FundAddressesTest(BitcoinTestFramework):

def setup_chain(self, split=False):
print("Initializing test directory " + self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, NUMB_OF_NODES)

def setup_network(self, split=False):
self.nodes = []

self.nodes = start_nodes(NUMB_OF_NODES, self.options.tmpdir)

self.is_network_split = split
self.sync_all()

def check_block_fund_addresses(self, block_hash, expected_addresses):
block_data = self.nodes[0].getblock(block_hash, 1)
tx_data = block_data["tx"]
for tx in tx_data:
vout_data = self.nodes[0].getrawtransaction(tx, 1)["vout"]

# We expect the coinbase transaction to have one output for each fund address
# (foundation one is always mandatory, secure node and super node ones only starting from fork 3)
# and one output for the miner reward.
assert_equal(len(vout_data), len(expected_addresses) + 1)

for i in range(1, len(vout_data)):
vout = vout_data[i]
assert_equal(vout["scriptPubKey"]["addresses"][0], expected_addresses[i - 1])

def run_test(self):

'''
This test checks that the right addresses are used for community, securenode and supernode funds
when mining blocks.
'''

# network topology: (0)

mark_logs("Node 0 generates 500 blocks", self.nodes, DEBUG_MODE)
blocks = self.nodes[0].generate(500)
self.sync_all()

# Consider that blocks[0] is not the genesis block but the block at height 1 (second block)
# For this reason, all fork heights must be decreased by 1

current_fork_height = 1 - 1 # chainsplit fork
mark_logs("Check chainsplit fork address [height = {}]".format(current_fork_height + 1), self.nodes, DEBUG_MODE)
self.check_block_fund_addresses(blocks[current_fork_height], ["zrQWJd1fhtkQtrjbYPXfHFF1c61DUtiXcCD"])
self.check_block_fund_addresses(blocks[current_fork_height + 1], ["zrQWJd1fhtkQtrjbYPXfHFF1c61DUtiXcCD"])

current_fork_height = 101 - 1 # community fund fork
mark_logs("Check community fund fork address [height = {}]".format(current_fork_height + 1), self.nodes, DEBUG_MODE)
self.check_block_fund_addresses(blocks[current_fork_height - 1], ["zrQWJd1fhtkQtrjbYPXfHFF1c61DUtiXcCD"])
self.check_block_fund_addresses(blocks[current_fork_height], ["zrQWJd1fhtkQtrjbYPXfHFF1c61DUtiXcCD"])
self.check_block_fund_addresses(blocks[current_fork_height + 1], ["zrQWJd1fhtkQtrjbYPXfHFF1c61DUtiXcCD"])

current_fork_height = 105 - 1 # null transaction fork
mark_logs("Check null transaction fork addresses [height = {}]".format(current_fork_height + 1), self.nodes, DEBUG_MODE)
self.check_block_fund_addresses(blocks[current_fork_height - 1], ["zrQWJd1fhtkQtrjbYPXfHFF1c61DUtiXcCD"])
self.check_block_fund_addresses(blocks[current_fork_height], ["zrQWJd1fhtkQtrjbYPXfHFF1c61DUtiXcCD", "zrQG6x9j33DLbCfzAqu3qKMe7z1VDL1z2L7", "zrMasbhB1yyfQ5RBUm7NPcEjGWZdRneWCEx"])
self.check_block_fund_addresses(blocks[current_fork_height + 1], ["zrQWJd1fhtkQtrjbYPXfHFF1c61DUtiXcCD", "zrQG6x9j33DLbCfzAqu3qKMe7z1VDL1z2L7", "zrMasbhB1yyfQ5RBUm7NPcEjGWZdRneWCEx"])

current_fork_height = SC_VERSION_FORK_HEIGHT - 1 # sidechain version fork
mark_logs("Check sidechain version fork addresses [height = {}]".format(current_fork_height + 1), self.nodes, DEBUG_MODE)
self.check_block_fund_addresses(blocks[current_fork_height - 1], ["zrQWJd1fhtkQtrjbYPXfHFF1c61DUtiXcCD", "zrQG6x9j33DLbCfzAqu3qKMe7z1VDL1z2L7", "zrMasbhB1yyfQ5RBUm7NPcEjGWZdRneWCEx"])
self.check_block_fund_addresses(blocks[current_fork_height], ["zrLaR63UYCHVvo5BJHoMUTuZFPmcUu866wB", "zrPaU1KWpNrg5fcLsSk17z7cc71FvnVnXxi", "zrMna8FbuTyrvFikAsmQMyAfufF3WoGksFu"])
self.check_block_fund_addresses(blocks[current_fork_height + 1], ["zrLaR63UYCHVvo5BJHoMUTuZFPmcUu866wB", "zrPaU1KWpNrg5fcLsSk17z7cc71FvnVnXxi", "zrMna8FbuTyrvFikAsmQMyAfufF3WoGksFu"])

if __name__ == '__main__':
FundAddressesTest().main()
10 changes: 8 additions & 2 deletions qa/rpc-tests/getblockexpanded.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ def run_test(self):
vk = mcTest.generate_params("sc1")
constant = generate_random_field_element_hex()

cmdInput = {'withdrawalEpochLength': EPOCH_LENGTH, 'toaddress': "dada", 'amount': creation_amount, 'wCertVk': vk,
'constant': constant}
cmdInput = {
"version": 0,
'withdrawalEpochLength': EPOCH_LENGTH,
'toaddress': "dada",
'amount': creation_amount,
'wCertVk': vk,
'constant': constant
}

ret = self.nodes[0].sc_create(cmdInput)
creating_tx = ret['txid']
Expand Down
11 changes: 9 additions & 2 deletions qa/rpc-tests/getblockmerkleroots.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ def run_test(self):
vk = mcTest.generate_params("sc1")
constant = generate_random_field_element_hex()

cmdInput = {'withdrawalEpochLength': 123, 'toaddress': "dada", 'amount': 3.0, 'wCertVk': vk,
'customData': "bb" * 1024, 'constant': constant}
cmdInput = {
'version': 0,
'withdrawalEpochLength': 123,
'toaddress': "dada",
'amount': 3.0,
'wCertVk': vk,
'customData': "bb" * 1024,
'constant': constant
}
ret = self.nodes[0].sc_create(cmdInput)
scid = ret['scid']
self.sync_all()
Expand Down
11 changes: 9 additions & 2 deletions qa/rpc-tests/getblocktemplate_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,15 @@ def run_test(self):
vk = mcTest.generate_params("sc1")
constant = generate_random_field_element_hex()

cmdInput = {'withdrawalEpochLength': SC_EPOCH_LENGTH, 'toaddress': "dada", 'amount': SC_CREATION_AMOUNT, 'wCertVk': vk,
'customData': "bb" * 1024, 'constant': constant}
cmdInput = {
'version': 0,
'withdrawalEpochLength': SC_EPOCH_LENGTH,
'toaddress': "dada",
'amount': SC_CREATION_AMOUNT,
'wCertVk': vk,
'customData': "bb" * 1024,
'constant': constant
}
ret = self.nodes[1].sc_create(cmdInput)
creating_tx = ret['txid']
scid = ret['scid']
Expand Down
10 changes: 9 additions & 1 deletion qa/rpc-tests/listtransactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,15 @@ def run_test(self):
vk = mcTest.generate_params("sc1")
constant = generate_random_field_element_hex()

cmdInput = {'fromaddress': fromaddr, 'toaddress': sidechain_address, 'amount': sc_creation_amount, 'fee': fee, 'wCertVk': vk, "constant": constant}
cmdInput = {
'version': 0,
'fromaddress': fromaddr,
'toaddress': sidechain_address,
'amount': sc_creation_amount,
'fee': fee,
'wCertVk': vk,
'constant': constant
}
try:
res = self.nodes[1].sc_create(cmdInput)
tx = res['txid']
Expand Down
1 change: 1 addition & 0 deletions qa/rpc-tests/merkle_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def run_test(self):

sc_cr = []
sc_cr.append({
"version": 0,
"epoch_length": sc_epoch_len,
"amount": sc_cr_amount,
"address": sc_address,
Expand Down
23 changes: 23 additions & 0 deletions qa/rpc-tests/rawtransactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def run_test(self):

sc_cr = []
sc_cr.append({
"version": 0,
"epoch_length": sc_epoch_len,
"amount": sc_cr_amount,
"address": sc_address,
Expand All @@ -230,6 +231,7 @@ def run_test(self):
})

sc_cr.append({
"version": 0,
"epoch_length": sc_epoch2_len,
"amount": sc_cr_amount2,
"address": sc_address,
Expand All @@ -238,8 +240,19 @@ def run_test(self):
"constant": constant
})

# missing sc version
sc_cr_without_version = [ {
"epoch_length": sc_epoch_len,
"amount": sc_cr_amount,
"address": sc_address,
"wCertVk": vk,
"wCeasedVk": cswVk,
"constant": constant
}]

# too big an epoch (max is 4032)
sc_cr_bad = [ {
"version": 0,
"epoch_length": 4033,
"amount": sc_cr_amount2,
"address": sc_address,
Expand All @@ -248,6 +261,15 @@ def run_test(self):
"constant": constant
} ]

#Try create a SC without providing the version
print("Try creating a SC without version")

try:
rawtx=self.nodes[0].createrawtransaction([], {}, [], sc_cr_without_version)
except JSONRPCException as e:
errorString = e.error['message']
assert_equal("version" in errorString, True)

#Try create a SC with too big an epoch len
print("Try creating a SC with an epoch too big")

Expand Down Expand Up @@ -408,6 +430,7 @@ def run_test(self):
cswVk2 = self.cswMcTest.generate_params("csw2")
constant2 = generate_random_field_element_hex()
sc_cr2 = [{
"version": 0,
"epoch_length": sc_epoch_len,
"amount": Decimal("4.0"),
"address": "ccc",
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/run_sc_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o pipefail

rm /tmp/result.log

for i in sbh_rpc_cmds.py rawtransactions.py getblocktemplate_proposals.py listtransactions.py ws_messages.py sc_*py
for i in sbh_rpc_cmds.py rawtransactions.py getblocktemplate_proposals.py listtransactions.py ws_messages.py ws_getsidechainversions.py sc_*py
do
echo "$i ---------------------------" | tee -a /tmp/result.log
time stdbuf --output=L python2 ./$i 2>&1 | tee -a /tmp/result.log
Expand Down
1 change: 1 addition & 0 deletions qa/rpc-tests/sbh_rpc_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def run_test(self):
minconf = 1
fee = Decimal("0.000025")
cmdInput = {
"version": 0,
"withdrawalEpochLength": EPOCH_LENGTH,
"fromaddress": taddr_1,
"toaddress": sc_toaddress,
Expand Down
1 change: 1 addition & 0 deletions qa/rpc-tests/sc_async_proof_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def run_test(self):

sc_cr = []
sc_cr.append({
"version": 0,
"epoch_length": sc_epoch_len,
"amount": sc_cr_amount,
"address": sc_address,
Expand Down
19 changes: 14 additions & 5 deletions qa/rpc-tests/sc_big_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from test_framework.test_framework import MINIMAL_SC_HEIGHT
from test_framework.util import assert_true, assert_equal, initialize_chain_clean, \
start_nodes, stop_nodes, wait_bitcoinds, sync_blocks, sync_mempools, connect_nodes_bi, mark_logs, \
dump_sc_info, dump_sc_info_record, get_epoch_data, get_spendable, swap_bytes, advance_epoch
dump_sc_info, dump_sc_info_record, get_epoch_data, get_spendable, swap_bytes, advance_epoch, \
get_field_element_with_padding
from test_framework.mc_test.mc_test import *
import os
import pprint
Expand Down Expand Up @@ -160,9 +161,17 @@ def advance_sidechains_epoch(num_of_scs):
cmtCfg.append([[254*4, 151]])

cmdInput = {
'withdrawalEpochLength': EPOCH_LENGTH, 'amount': amount, 'fee': fee,
'constant':constant , 'wCertVk': certVk, 'wCeasedVk': cswVk, 'toaddress':"cdcd",
'vFieldElementCertificateFieldConfig':feCfg[0], 'vBitVectorCertificateFieldConfig':cmtCfg[0] }
'version': 0,
'withdrawalEpochLength': EPOCH_LENGTH,
'amount': amount,
'fee': fee,
'constant':constant ,
'wCertVk': certVk,
'wCeasedVk': cswVk,
'toaddress':"cdcd",
'vFieldElementCertificateFieldConfig':feCfg[0],
'vBitVectorCertificateFieldConfig':cmtCfg[0]
}

scids = []
scc_txs = []
Expand All @@ -177,7 +186,7 @@ def advance_sidechains_epoch(num_of_scs):
vCfe = ["ab000100"]
vCmt = [BIT_VECTOR_BUF]

fe1 = "00000000000000000000000000000000000000000000000000000000" + "ab000100"
fe1 = get_field_element_with_padding("ab000100", 0)
fe2 = BIT_VECTOR_FE

proofCfeArray = [fe1, fe2]
Expand Down
9 changes: 7 additions & 2 deletions qa/rpc-tests/sc_block_partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ def create_sc(cmdInput, node):

#-------------------------------------------------------
cmdInput = {
'withdrawalEpochLength': EPOCH_LENGTH, 'amount': amount, 'fee': 0.0001,
'constant':constant , 'wCertVk': certVk, 'toaddress':"cdcd",
'version': 0,
'withdrawalEpochLength': EPOCH_LENGTH,
'amount': amount,
'fee': 0.0001,
'constant':constant ,
'wCertVk': certVk,
'toaddress':"cdcd",
}

tx, scid = create_sc(cmdInput, self.nodes[0])
Expand Down
4 changes: 3 additions & 1 deletion qa/rpc-tests/sc_bwt_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def run_test(self):

fee_cr1 = Decimal("0.0002")
cmdInput = {
"version": 0,
"withdrawalEpochLength":EPOCH_LENGTH,
"toaddress":"dada",
"amount":creation_amount1,
Expand Down Expand Up @@ -306,6 +307,7 @@ def run_test(self):
prev_epoch_hash_2 = self.nodes[0].getbestblockhash()
epoch_len_2 = 10
cmdInput = {
"version": 0,
"withdrawalEpochLength":epoch_len_2,
"toaddress":"dada",
"amount":creation_amount2,
Expand Down Expand Up @@ -350,7 +352,7 @@ def run_test(self):
mark_logs("Node0 creates a tx with a few bwt request and mixed outputs using raw version of cmd", self.nodes, DEBUG_MODE)
outputs = { self.nodes[0].getnewaddress() :4.998 }
sc_cr_amount = 1.0
sc_cr = [ {"epoch_length":10, "amount":sc_cr_amount, "address":"effe", "wCertVk":vk3, "constant":c3} ]
sc_cr = [ {"version": 0, "epoch_length":10, "amount":sc_cr_amount, "address":"effe", "wCertVk":vk3, "constant":c3} ]
ft_amount_1 = 1.0
ft_amount_2 = 2.0
mc_return_address = self.nodes[0].getnewaddress()
Expand Down
13 changes: 8 additions & 5 deletions qa/rpc-tests/sc_cert_addressindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ def run_test(self):
vk = mcTest.generate_params("sc1")
constant = generate_random_field_element_hex()

cmdInput = {'withdrawalEpochLength': EPOCH_LENGTH,
'toaddress': "dada",
'amount': creation_amount,
'wCertVk': vk,
'constant': constant}
cmdInput = {
'version': 0,
'withdrawalEpochLength': EPOCH_LENGTH,
'toaddress': "dada",
'amount': creation_amount,
'wCertVk': vk,
'constant': constant
}

ret = self.nodes[0].sc_create(cmdInput)
creating_tx = ret['txid']
Expand Down
13 changes: 8 additions & 5 deletions qa/rpc-tests/sc_cert_addrmempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ def run_test(self):
constant = generate_random_field_element_hex()

# Create a SC
cmdInput = {'withdrawalEpochLength': EPOCH_LENGTH,
'toaddress': "dada",
'amount': creation_amount,
'wCertVk': vk,
'constant': constant}
cmdInput = {
'version': 0,
'withdrawalEpochLength': EPOCH_LENGTH,
'toaddress': "dada",
'amount': creation_amount,
'wCertVk': vk,
'constant': constant
}

ret = self.nodes[0].sc_create(cmdInput)
scid = ret['scid']
Expand Down
2 changes: 2 additions & 0 deletions qa/rpc-tests/sc_cert_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def run_test(self):
vk = mcTest.generate_params("sc1")
constant = generate_random_field_element_hex()
cmdInput = {
"version": 0,
"withdrawalEpochLength":EPOCH_LENGTH,
"toaddress":"dada",
"amount":creation_amount,
Expand Down Expand Up @@ -693,6 +694,7 @@ def run_test(self):
mark_logs("Node0 creates new sidechain", self.nodes, DEBUG_MODE)
vk2 = mcTest.generate_params("sc2", "cert_no_const")
cmdInput = {
"version": 0,
"withdrawalEpochLength":EPOCH_LENGTH,
"toaddress":"dada",
"amount":creation_amount,
Expand Down
Loading

0 comments on commit 10270bb

Please sign in to comment.