From c446d0d63d46c740c7a21d573681f08ed19e0cda Mon Sep 17 00:00:00 2001 From: nadyka Date: Thu, 17 Jun 2021 00:57:57 +0400 Subject: [PATCH 1/2] change err msg --- src/wallet/wallettool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp index b2cb0bf479..e6ab3102cb 100644 --- a/src/wallet/wallettool.cpp +++ b/src/wallet/wallettool.cpp @@ -173,7 +173,7 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command) tfm::format(std::cerr, "%s\n", error.original); return ret; } - tfm::format(std::cout, "The dumpfile may contain private keys. To ensure the safety of your Bitcoin, do not share the dumpfile.\n"); + tfm::format(std::cout, "The dumpfile may contain private keys. To ensure the safety of your BGL, do not share the dumpfile.\n"); return ret; } else if (command == "createfromdump") { bilingual_str error; From c535ebd450647d9f166f42c40b304a94b1c36324 Mon Sep 17 00:00:00 2001 From: nadyka Date: Thu, 17 Jun 2021 01:12:26 +0400 Subject: [PATCH 2/2] functional tests actualization --- test/config.ini.in | 2 +- test/functional/README.md | 2 +- test/functional/data/rpc_bip67.json | 8 +- test/functional/feature_asmap.py | 29 +-- test/functional/feature_bip68_sequence.py | 2 +- .../feature_blockfilterindex_prune.py | 14 +- test/functional/feature_config_args.py | 1 + test/functional/feature_csv_activation.py | 213 +++++++++--------- test/functional/feature_rbf.py | 10 +- test/functional/feature_settings.py | 2 +- test/functional/feature_utxo_set_hash.py | 6 +- test/functional/interface_BGL_cli.py | 11 +- test/functional/interface_rest.py | 4 +- test/functional/mempool_accept.py | 2 +- test/functional/p2p_tx_download.py | 2 +- test/functional/rpc_blockchain.py | 2 +- test/functional/rpc_createmultisig.py | 4 +- test/functional/rpc_decodescript.py | 2 +- test/functional/rpc_deriveaddresses.py | 10 +- test/functional/rpc_dumptxoutset.py | 4 +- test/functional/rpc_fundrawtransaction.py | 23 +- test/functional/rpc_generateblock.py | 4 +- test/functional/rpc_net.py | 14 +- test/functional/rpc_rawtransaction.py | 14 +- test/functional/rpc_signrawtransaction.py | 5 +- test/functional/test_framework/address.py | 38 ++-- test/functional/test_framework/blocktools.py | 6 + test/functional/test_framework/messages.py | 2 +- test/functional/test_framework/muhash.py | 1 + test/functional/test_framework/p2p.py | 6 +- test/functional/test_framework/segwit_addr.py | 10 +- test/functional/test_framework/util.py | 49 ++-- test/functional/test_framework/wallet.py | 109 +++++++-- test/functional/test_runner.py | 2 +- test/functional/wallet_abandonconflict.py | 10 +- test/functional/wallet_avoidreuse.py | 64 +++--- test/functional/wallet_backup.py | 14 +- test/functional/wallet_balance.py | 64 +++--- test/functional/wallet_basic.py | 29 ++- test/functional/wallet_bumpfee.py | 10 +- test/functional/wallet_disable.py | 5 +- test/functional/wallet_dump.py | 7 +- test/functional/wallet_groups.py | 2 +- test/functional/wallet_hd.py | 2 +- test/functional/wallet_import_rescan.py | 4 +- test/functional/wallet_labels.py | 26 ++- test/functional/wallet_listsinceblock.py | 4 +- test/functional/wallet_multiwallet.py | 6 +- test/functional/wallet_watchonly.py | 4 +- 49 files changed, 488 insertions(+), 376 deletions(-) diff --git a/test/config.ini.in b/test/config.ini.in index 62c1ef1777..460faf6f4b 100644 --- a/test/config.ini.in +++ b/test/config.ini.in @@ -20,7 +20,7 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py @USE_BDB_TRUE@USE_BDB=true @BUILD_BGL_CLI_TRUE@ENABLE_CLI=true @BUILD_BGL_WALLET_TRUE@ENABLE_WALLET_TOOL=true -@BUILD_BGL_TRUE@ENABLE_BGL=true +@BUILD_BGLD_TRUE@ENABLE_BGLD=true @ENABLE_FUZZ_TRUE@ENABLE_FUZZ=true @ENABLE_ZMQ_TRUE@ENABLE_ZMQ=true @ENABLE_EXTERNAL_SIGNER_TRUE@ENABLE_EXTERNAL_SIGNER=true diff --git a/test/functional/README.md b/test/functional/README.md index dc7b92c56b..21bcaed22c 100644 --- a/test/functional/README.md +++ b/test/functional/README.md @@ -68,7 +68,7 @@ don't have test cases for. load a premined blockchain from cache with the default value of `False`. The cached data directories contain a 200-block pre-mined blockchain with the spendable mining rewards being split between four nodes. Each node has 25 - mature block subsidies (25x50=1250 BTC) in its wallet. Using them is much more + mature block subsidies (25x200=5000 BGL) in its wallet. Using them is much more efficient than mining blocks in your test. - When calling RPCs with lots of arguments, consider using named keyword arguments instead of positional arguments to make the intent of the call diff --git a/test/functional/data/rpc_bip67.json b/test/functional/data/rpc_bip67.json index 4d6f793d4a..6cb838c8c8 100644 --- a/test/functional/data/rpc_bip67.json +++ b/test/functional/data/rpc_bip67.json @@ -9,7 +9,7 @@ "02ff12471208c14bd580709cb2358d98975247d8765f92bc25eab3b2763ed605f8" ], "script": "522102fe6f0a5a297eb38c391581c4413e084773ea23954d93f7753db7dc0adc188b2f2102ff12471208c14bd580709cb2358d98975247d8765f92bc25eab3b2763ed605f852ae", - "address": "2N19tNw3Ss4L9QDERtCw7FhXb6jBsYmeXNu" + "address": "MFopd5XPCigDzvsnJxJaTPnjD5a9pBiXfP" }, { "keys": [ @@ -23,7 +23,7 @@ "02e2cc6bd5f45edd43bebe7cb9b675f0ce9ed3efe613b177588290ad188d11b404" ], "script": "522102632b12f4ac5b1d1b72b2a3b508c19172de44f6f46bcee50ba33f3f9291e47ed021027735a29bae7780a9755fae7a1c4374c656ac6a69ea9f3697fda61bb99a4f3e772102e2cc6bd5f45edd43bebe7cb9b675f0ce9ed3efe613b177588290ad188d11b40453ae", - "address": "2N3sVXU7MZefmYnZhrVX2bA7LyH6vygFZZ7" + "address": "MJXRmcbHuK1r9WD4HEtVnrNV5dVDBBp38s" }, { "keys": [ @@ -39,7 +39,7 @@ "030000000000000000000000000000000000004141414141414141414141414141" ], "script": "522102000000000000000000000000000000000000414141414141414141414141414021020000000000000000000000000000000000004141414141414141414141414141210300000000000000000000000000000000000041414141414141414141414141402103000000000000000000000000000000000000414141414141414141414141414154ae", - "address": "2Mt3L9TcDUAfLpSoyB3SNYtJGLiU49DKEWJ" + "address": "M8hGPc69oq1RRATKbnoqkaZQT4rLSDuuqT" }, { "keys": [ @@ -53,6 +53,6 @@ "03e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e9" ], "script": "5221021f2f6e1e50cb6a953935c3601284925decd3fd21bc445712576873fb8c6ebc1821022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da2103e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e953ae", - "address": "2NFd5JqpwmQNz3gevZJ3rz9ofuHvqaP9Cye" + "address": "MWH1YzJt74j4eQJGz3RLBr4p1eK7goXLMN" } ] diff --git a/test/functional/feature_asmap.py b/test/functional/feature_asmap.py index 17cfcc1477..6b5189f2d8 100755 --- a/test/functional/feature_asmap.py +++ b/test/functional/feature_asmap.py @@ -4,19 +4,19 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test asmap config argument for ASN-based IP bucketing. -Verify node behaviour and debug log when launching bitcoind in these cases: +Verify node behaviour and debug log when launching BGLd in these cases: -1. `bitcoind` with no -asmap arg, using /16 prefix for IP bucketing +1. `BGLd` with no -asmap arg, using /16 prefix for IP bucketing -2. `bitcoind -asmap=`, using the unit test skeleton asmap +2. `BGLd -asmap=`, using the unit test skeleton asmap -3. `bitcoind -asmap=`, using the unit test skeleton asmap +3. `BGLd -asmap=`, using the unit test skeleton asmap -4. `bitcoind -asmap/-asmap=` with no file specified, using the default asmap +4. `BGLd -asmap/-asmap=` with no file specified, using the default asmap -5. `bitcoind -asmap` with no file specified and a missing default asmap file +5. `BGLd -asmap` with no file specified and a missing default asmap file -6. `bitcoind -asmap` with an empty (unparsable) default asmap file +6. `BGLd -asmap` with an empty (unparsable) default asmap file The tests are order-independent. @@ -28,7 +28,7 @@ DEFAULT_ASMAP_FILENAME = 'ip_asn.map' # defined in src/init.cpp ASMAP = '../../src/test/data/asmap.raw' # path to unit test skeleton asmap -VERSION = 'fec61fa21a9f46f3b17bdcd660d7f4cd90b966aad3aec593c99b35f0aca15853' +VERSION = 'c88edc2215daef7b5ae0b71bd0bc100e1c4928cd59634e66938860a6b73a6b0e' def expected_messages(filename): return ['Opened asmap file "{}" (59 bytes) from disk'.format(filename), @@ -39,13 +39,13 @@ def set_test_params(self): self.num_nodes = 1 def test_without_asmap_arg(self): - self.log.info('Test bitcoind with no -asmap arg passed') + self.log.info('Test BGLd with no -asmap arg passed') self.stop_node(0) with self.node.assert_debug_log(['Using /16 prefix for IP bucketing']): self.start_node(0) def test_asmap_with_absolute_path(self): - self.log.info('Test bitcoind -asmap=') + self.log.info('Test BGLd -asmap=') self.stop_node(0) filename = os.path.join(self.datadir, 'my-map-file.map') shutil.copyfile(self.asmap_raw, filename) @@ -54,11 +54,12 @@ def test_asmap_with_absolute_path(self): os.remove(filename) def test_asmap_with_relative_path(self): - self.log.info('Test bitcoind -asmap=') + self.log.info('Test BGLd -asmap=') self.stop_node(0) name = 'ASN_map' filename = os.path.join(self.datadir, name) shutil.copyfile(self.asmap_raw, filename) + with self.node.assert_debug_log(expected_messages(filename)): self.start_node(0, ['-asmap={}'.format(name)]) os.remove(filename) @@ -66,20 +67,20 @@ def test_asmap_with_relative_path(self): def test_default_asmap(self): shutil.copyfile(self.asmap_raw, self.default_asmap) for arg in ['-asmap', '-asmap=']: - self.log.info('Test bitcoind {} (using default map file)'.format(arg)) + self.log.info('Test BGLd {} (using default map file)'.format(arg)) self.stop_node(0) with self.node.assert_debug_log(expected_messages(self.default_asmap)): self.start_node(0, [arg]) os.remove(self.default_asmap) def test_default_asmap_with_missing_file(self): - self.log.info('Test bitcoind -asmap with missing default map file') + self.log.info('Test BGLd -asmap with missing default map file') self.stop_node(0) msg = "Error: Could not find asmap file \"{}\"".format(self.default_asmap) self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg) def test_empty_asmap(self): - self.log.info('Test bitcoind -asmap with empty map file') + self.log.info('Test BGLd -asmap with empty map file') self.stop_node(0) with open(self.default_asmap, "w", encoding="utf-8") as f: f.write("") diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py index 2e3cff07f7..af22b7f429 100755 --- a/test/functional/feature_bip68_sequence.py +++ b/test/functional/feature_bip68_sequence.py @@ -72,7 +72,7 @@ def run_test(self): def test_disable_flag(self): # Create some unconfirmed inputs new_addr = self.nodes[0].getnewaddress() - self.nodes[0].sendtoaddress(new_addr, 2) # send 2 BTC + self.nodes[0].sendtoaddress(new_addr, 2) # send 2 BGL utxos = self.nodes[0].listunspent(0, 0) assert len(utxos) > 0 diff --git a/test/functional/feature_blockfilterindex_prune.py b/test/functional/feature_blockfilterindex_prune.py index e637f77053..d663ada483 100755 --- a/test/functional/feature_blockfilterindex_prune.py +++ b/test/functional/feature_blockfilterindex_prune.py @@ -25,15 +25,15 @@ def run_test(self): self.sync_index(height=200) assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) # Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection - self.nodes[0].generate(250) + self.nodes[0].generate(400) self.sync_all() - self.nodes[0].generate(250) + self.nodes[0].generate(400) self.sync_all() - self.sync_index(height=700) + self.sync_index(height=1000) self.log.info("prune some blocks") - pruneheight = self.nodes[0].pruneblockchain(400) - assert_equal(pruneheight, 250) + pruneheight = self.nodes[0].pruneblockchain(1000) + assert_equal(pruneheight, 506) self.log.info("check if we can access the tips blockfilter when we have pruned some blocks") assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) @@ -46,10 +46,10 @@ def run_test(self): self.log.info("make sure accessing the blockfilters throws an error") assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[0].getblockfilter, self.nodes[0].getblockhash(2)) - self.nodes[0].generate(1000) + self.nodes[0].generate(400) self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled") - pruneheight_new = self.nodes[0].pruneblockchain(1000) + pruneheight_new = self.nodes[0].pruneblockchain(1400) assert_greater_than(pruneheight_new, pruneheight) self.stop_node(0) diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py index a057367496..d32ebf1523 100755 --- a/test/functional/feature_config_args.py +++ b/test/functional/feature_config_args.py @@ -8,6 +8,7 @@ import time from test_framework.test_framework import BGLTestFramework +from test_framework import util class ConfArgsTest(BGLTestFramework): diff --git a/test/functional/feature_csv_activation.py b/test/functional/feature_csv_activation.py index 073ad0a7c0..5c24c8ab4f 100755 --- a/test/functional/feature_csv_activation.py +++ b/test/functional/feature_csv_activation.py @@ -37,13 +37,13 @@ bip112tx_special - test negative argument to OP_CSV bip112tx_emptystack - test empty stack (= no argument) OP_CSV """ -from decimal import Decimal from itertools import product -from io import BytesIO import time -from test_framework.blocktools import create_coinbase, create_block, create_transaction -from test_framework.messages import ToHex, CTransaction +from test_framework.blocktools import ( + create_block, + create_coinbase, +) from test_framework.p2p import P2PDataStore from test_framework.script import ( CScript, @@ -53,9 +53,12 @@ from test_framework.test_framework import BGLTestFramework from test_framework.util import ( assert_equal, - hex_str_to_bytes, softfork_active, ) +from test_framework.wallet import ( + MiniWallet, + MiniWalletMode, +) TESTING_TX_COUNT = 83 # Number of testing transactions: 1 BIP113 tx, 16 BIP68 txs, 66 BIP112 txs (see comments above) COINBASE_BLOCK_COUNT = TESTING_TX_COUNT # Number of coinbase blocks we need to generate as inputs for our txs @@ -83,66 +86,6 @@ def relative_locktime(sdf, srhb, stf, srlb): def all_rlt_txs(txs): return [tx['tx'] for tx in txs] -def sign_transaction(node, unsignedtx): - rawtx = ToHex(unsignedtx) - signresult = node.signrawtransactionwithwallet(rawtx) - tx = CTransaction() - f = BytesIO(hex_str_to_bytes(signresult['hex'])) - tx.deserialize(f) - return tx - -def create_bip112special(node, input, txversion, address): - tx = create_transaction(node, input, address, amount=Decimal("49.98")) - tx.nVersion = txversion - signtx = sign_transaction(node, tx) - signtx.vin[0].scriptSig = CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig))) - return signtx - -def create_bip112emptystack(node, input, txversion, address): - tx = create_transaction(node, input, address, amount=Decimal("49.98")) - tx.nVersion = txversion - signtx = sign_transaction(node, tx) - signtx.vin[0].scriptSig = CScript([OP_CHECKSEQUENCEVERIFY] + list(CScript(signtx.vin[0].scriptSig))) - return signtx - -def send_generic_input_tx(node, coinbases, address): - return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction(node, node.getblock(coinbases.pop())['tx'][0], address, amount=Decimal("49.99"))))) - -def create_bip68txs(node, bip68inputs, txversion, address, locktime_delta=0): - """Returns a list of bip68 transactions with different bits set.""" - txs = [] - assert len(bip68inputs) >= 16 - for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): - locktime = relative_locktime(sdf, srhb, stf, srlb) - tx = create_transaction(node, bip68inputs[i], address, amount=Decimal("49.98")) - tx.nVersion = txversion - tx.vin[0].nSequence = locktime + locktime_delta - tx = sign_transaction(node, tx) - tx.rehash() - txs.append({'tx': tx, 'sdf': sdf, 'stf': stf}) - - return txs - -def create_bip112txs(node, bip112inputs, varyOP_CSV, txversion, address, locktime_delta=0): - """Returns a list of bip68 transactions with different bits set.""" - txs = [] - assert len(bip112inputs) >= 16 - for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): - locktime = relative_locktime(sdf, srhb, stf, srlb) - tx = create_transaction(node, bip112inputs[i], address, amount=Decimal("49.98")) - if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed - tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta - else: # vary nSequence instead, OP_CSV is fixed - tx.vin[0].nSequence = locktime + locktime_delta - tx.nVersion = txversion - signtx = sign_transaction(node, tx) - if (varyOP_CSV): - signtx.vin[0].scriptSig = CScript([locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig))) - else: - signtx.vin[0].scriptSig = CScript([BASE_RELATIVE_LOCKTIME, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig))) - tx.rehash() - txs.append({'tx': signtx, 'sdf': sdf, 'stf': stf}) - return txs class BIP68_112_113Test(BGLTestFramework): def set_test_params(self): @@ -150,13 +93,69 @@ def set_test_params(self): self.setup_clean_chain = True self.extra_args = [[ '-whitelist=noban@127.0.0.1', - '-addresstype=legacy', '-par=1', # Use only one script thread to get the exact reject reason for testing ]] self.supports_cli = False - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() + def create_self_transfer_from_utxo(self, input_tx): + utxo = self.miniwallet.get_utxo(txid=input_tx.rehash(), mark_as_spent=False) + tx = self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo)['tx'] + return tx + + def create_bip112special(self, input, txversion): + tx = self.create_self_transfer_from_utxo(input) + tx.nVersion = txversion + self.miniwallet.sign_tx(tx) + tx.vin[0].scriptSig = CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(tx.vin[0].scriptSig))) + return tx + + def create_bip112emptystack(self, input, txversion): + tx = self.create_self_transfer_from_utxo(input) + tx.nVersion = txversion + self.miniwallet.sign_tx(tx) + tx.vin[0].scriptSig = CScript([OP_CHECKSEQUENCEVERIFY] + list(CScript(tx.vin[0].scriptSig))) + return tx + + def send_generic_input_tx(self, coinbases): + input_txid = self.nodes[0].getblock(coinbases.pop(), 2)['tx'][0]['txid'] + utxo_to_spend = self.miniwallet.get_utxo(txid=input_txid) + return self.miniwallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)['tx'] + + def create_bip68txs(self, bip68inputs, txversion, locktime_delta=0): + """Returns a list of bip68 transactions with different bits set.""" + txs = [] + assert len(bip68inputs) >= 16 + for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): + locktime = relative_locktime(sdf, srhb, stf, srlb) + tx = self.create_self_transfer_from_utxo(bip68inputs[i]) + tx.nVersion = txversion + tx.vin[0].nSequence = locktime + locktime_delta + self.miniwallet.sign_tx(tx) + tx.rehash() + txs.append({'tx': tx, 'sdf': sdf, 'stf': stf}) + + return txs + + def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta=0): + """Returns a list of bip68 transactions with different bits set.""" + txs = [] + assert len(bip112inputs) >= 16 + for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): + locktime = relative_locktime(sdf, srhb, stf, srlb) + tx = self.create_self_transfer_from_utxo(bip112inputs[i]) + if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed + tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta + else: # vary nSequence instead, OP_CSV is fixed + tx.vin[0].nSequence = locktime + locktime_delta + tx.nVersion = txversion + self.miniwallet.sign_tx(tx) + if (varyOP_CSV): + tx.vin[0].scriptSig = CScript([locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(tx.vin[0].scriptSig))) + else: + tx.vin[0].scriptSig = CScript([BASE_RELATIVE_LOCKTIME, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(tx.vin[0].scriptSig))) + tx.rehash() + txs.append({'tx': tx, 'sdf': sdf, 'stf': stf}) + return txs def generate_blocks(self, number): test_blocks = [] @@ -185,16 +184,16 @@ def send_blocks(self, blocks, success=True, reject_reason=None): def run_test(self): self.helper_peer = self.nodes[0].add_p2p_connection(P2PDataStore()) + self.miniwallet = MiniWallet(self.nodes[0], mode=MiniWalletMode.RAW_P2PK) self.log.info("Generate blocks in the past for coinbase outputs.") long_past_time = int(time.time()) - 600 * 1000 # enough to build up to 1000 blocks 10 minutes apart without worrying about getting into the future self.nodes[0].setmocktime(long_past_time - 100) # enough so that the generated blocks will still all be before long_past_time - self.coinbase_blocks = self.nodes[0].generate(COINBASE_BLOCK_COUNT) # blocks generated for inputs + self.coinbase_blocks = self.miniwallet.generate(COINBASE_BLOCK_COUNT) # blocks generated for inputs self.nodes[0].setmocktime(0) # set time back to present so yielded blocks aren't in the future as we advance last_block_time self.tipheight = COINBASE_BLOCK_COUNT # height of the next block to build self.last_block_time = long_past_time self.tip = int(self.nodes[0].getbestblockhash(), 16) - self.nodeaddress = self.nodes[0].getnewaddress() # Activation height is hardcoded # We advance to block height five below BIP112 activation for the following tests @@ -209,14 +208,14 @@ def run_test(self): # 16 normal inputs bip68inputs = [] for _ in range(16): - bip68inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress)) + bip68inputs.append(self.send_generic_input_tx(self.coinbase_blocks)) # 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig) bip112basicinputs = [] for _ in range(2): inputs = [] for _ in range(16): - inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress)) + inputs.append(self.send_generic_input_tx(self.coinbase_blocks)) bip112basicinputs.append(inputs) # 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP (actually will be prepended to spending scriptSig) @@ -224,16 +223,16 @@ def run_test(self): for _ in range(2): inputs = [] for _ in range(16): - inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress)) + inputs.append(self.send_generic_input_tx(self.coinbase_blocks)) bip112diverseinputs.append(inputs) # 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to spending scriptSig) - bip112specialinput = send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress) + bip112specialinput = self.send_generic_input_tx(self.coinbase_blocks) # 1 special input with (empty stack) OP_CSV (actually will be prepended to spending scriptSig) - bip112emptystackinput = send_generic_input_tx(self.nodes[0],self.coinbase_blocks, self.nodeaddress) + bip112emptystackinput = self.send_generic_input_tx(self.coinbase_blocks) # 1 normal input - bip113input = send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress) + bip113input = self.send_generic_input_tx(self.coinbase_blocks) self.nodes[0].setmocktime(self.last_block_time + 600) inputblockhash = self.nodes[0].generate(1)[0] # 1 block generated for inputs to be in chain at height 431 @@ -253,36 +252,36 @@ def run_test(self): # Test both version 1 and version 2 transactions for all tests # BIP113 test transaction will be modified before each use to put in appropriate block time - bip113tx_v1 = create_transaction(self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49.98")) + bip113tx_v1 = self.create_self_transfer_from_utxo(bip113input) bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE bip113tx_v1.nVersion = 1 - bip113tx_v2 = create_transaction(self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49.98")) + bip113tx_v2 = self.create_self_transfer_from_utxo(bip113input) bip113tx_v2.vin[0].nSequence = 0xFFFFFFFE bip113tx_v2.nVersion = 2 # For BIP68 test all 16 relative sequence locktimes - bip68txs_v1 = create_bip68txs(self.nodes[0], bip68inputs, 1, self.nodeaddress) - bip68txs_v2 = create_bip68txs(self.nodes[0], bip68inputs, 2, self.nodeaddress) + bip68txs_v1 = self.create_bip68txs(bip68inputs, 1) + bip68txs_v2 = self.create_bip68txs(bip68inputs, 2) # For BIP112 test: # 16 relative sequence locktimes of 10 against 10 OP_CSV OP_DROP inputs - bip112txs_vary_nSequence_v1 = create_bip112txs(self.nodes[0], bip112basicinputs[0], False, 1, self.nodeaddress) - bip112txs_vary_nSequence_v2 = create_bip112txs(self.nodes[0], bip112basicinputs[0], False, 2, self.nodeaddress) + bip112txs_vary_nSequence_v1 = self.create_bip112txs(bip112basicinputs[0], False, 1) + bip112txs_vary_nSequence_v2 = self.create_bip112txs(bip112basicinputs[0], False, 2) # 16 relative sequence locktimes of 9 against 10 OP_CSV OP_DROP inputs - bip112txs_vary_nSequence_9_v1 = create_bip112txs(self.nodes[0], bip112basicinputs[1], False, 1, self.nodeaddress, -1) - bip112txs_vary_nSequence_9_v2 = create_bip112txs(self.nodes[0], bip112basicinputs[1], False, 2, self.nodeaddress, -1) + bip112txs_vary_nSequence_9_v1 = self.create_bip112txs(bip112basicinputs[1], False, 1, -1) + bip112txs_vary_nSequence_9_v2 = self.create_bip112txs(bip112basicinputs[1], False, 2, -1) # sequence lock time of 10 against 16 (relative_lock_time) OP_CSV OP_DROP inputs - bip112txs_vary_OP_CSV_v1 = create_bip112txs(self.nodes[0], bip112diverseinputs[0], True, 1, self.nodeaddress) - bip112txs_vary_OP_CSV_v2 = create_bip112txs(self.nodes[0], bip112diverseinputs[0], True, 2, self.nodeaddress) + bip112txs_vary_OP_CSV_v1 = self.create_bip112txs(bip112diverseinputs[0], True, 1) + bip112txs_vary_OP_CSV_v2 = self.create_bip112txs(bip112diverseinputs[0], True, 2) # sequence lock time of 9 against 16 (relative_lock_time) OP_CSV OP_DROP inputs - bip112txs_vary_OP_CSV_9_v1 = create_bip112txs(self.nodes[0], bip112diverseinputs[1], True, 1, self.nodeaddress, -1) - bip112txs_vary_OP_CSV_9_v2 = create_bip112txs(self.nodes[0], bip112diverseinputs[1], True, 2, self.nodeaddress, -1) + bip112txs_vary_OP_CSV_9_v1 = self.create_bip112txs(bip112diverseinputs[1], True, 1, -1) + bip112txs_vary_OP_CSV_9_v2 = self.create_bip112txs(bip112diverseinputs[1], True, 2, -1) # -1 OP_CSV OP_DROP input - bip112tx_special_v1 = create_bip112special(self.nodes[0], bip112specialinput, 1, self.nodeaddress) - bip112tx_special_v2 = create_bip112special(self.nodes[0], bip112specialinput, 2, self.nodeaddress) + bip112tx_special_v1 = self.create_bip112special(bip112specialinput, 1) + bip112tx_special_v2 = self.create_bip112special(bip112specialinput, 2) # (empty stack) OP_CSV input - bip112tx_emptystack_v1 = create_bip112emptystack(self.nodes[0], bip112emptystackinput, 1, self.nodeaddress) - bip112tx_emptystack_v2 = create_bip112emptystack(self.nodes[0], bip112emptystackinput, 2, self.nodeaddress) + bip112tx_emptystack_v1 = self.create_bip112emptystack(bip112emptystackinput, 1) + bip112tx_emptystack_v2 = self.create_bip112emptystack(bip112emptystackinput, 2) self.log.info("TESTING") @@ -292,8 +291,8 @@ def run_test(self): success_txs = [] # BIP113 tx, -1 CSV tx and empty stack CSV tx should succeed bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block - bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1) - success_txs.append(bip113signed1) + self.miniwallet.sign_tx(bip113tx_v1) + success_txs.append(bip113tx_v1) success_txs.append(bip112tx_special_v1) success_txs.append(bip112tx_emptystack_v1) # add BIP 68 txs @@ -312,8 +311,8 @@ def run_test(self): success_txs = [] # BIP113 tx, -1 CSV tx and empty stack CSV tx should succeed bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block - bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) - success_txs.append(bip113signed2) + self.miniwallet.sign_tx(bip113tx_v2) + success_txs.append(bip113tx_v2) success_txs.append(bip112tx_special_v2) success_txs.append(bip112tx_emptystack_v2) # add BIP 68 txs @@ -338,17 +337,22 @@ def run_test(self): self.log.info("BIP 113 tests") # BIP 113 tests should now fail regardless of version number if nLockTime isn't satisfied by new rules bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block - bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1) + self.miniwallet.sign_tx(bip113tx_v1) + bip113tx_v1.rehash() bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block - bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) - for bip113tx in [bip113signed1, bip113signed2]: + self.miniwallet.sign_tx(bip113tx_v2) + bip113tx_v2.rehash() + for bip113tx in [bip113tx_v1, bip113tx_v2]: self.send_blocks([self.create_test_block([bip113tx])], success=False, reject_reason='bad-txns-nonfinal') + # BIP 113 tests should now pass if the locktime is < MTP bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block - bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1) + self.miniwallet.sign_tx(bip113tx_v1) + bip113tx_v1.rehash() bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block - bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) - for bip113tx in [bip113signed1, bip113signed2]: + self.miniwallet.sign_tx(bip113tx_v2) + bip113tx_v2.rehash() + for bip113tx in [bip113tx_v1, bip113tx_v2]: self.send_blocks([self.create_test_block([bip113tx])]) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) @@ -471,8 +475,9 @@ def run_test(self): time_txs = [] for tx in [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]: tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | SEQ_TYPE_FLAG - signtx = sign_transaction(self.nodes[0], tx) - time_txs.append(signtx) + self.miniwallet.sign_tx(tx) + tx.rehash() + time_txs.append(tx) self.send_blocks([self.create_test_block(time_txs)]) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) diff --git a/test/functional/feature_rbf.py b/test/functional/feature_rbf.py index 930940c4a9..0bb6199d1d 100755 --- a/test/functional/feature_rbf.py +++ b/test/functional/feature_rbf.py @@ -143,7 +143,7 @@ def test_simple_doublespend(self): # This will raise an exception due to insufficient fee assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, 0) - # Extra 0.1 BTC fee + # Extra 0.1 BGL fee tx1b = CTransaction() tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)] tx1b.vout = [CTxOut(int(0.9 * COIN), DUMMY_P2WPKH_SCRIPT)] @@ -178,7 +178,7 @@ def test_doublespend_chain(self): prevout = COutPoint(int(txid, 16), 0) # Whether the double-spend is allowed is evaluated by including all - # child fees - 40 BTC - so this attempt is rejected. + # child fees - 40 BGL - so this attempt is rejected. dbl_tx = CTransaction() dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)] dbl_tx.vout = [CTxOut(initial_nValue - 30 * COIN, DUMMY_P2WPKH_SCRIPT)] @@ -248,7 +248,7 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota # This will raise an exception due to insufficient fee assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, dbl_tx_hex, 0) - # 1 BTC fee is enough + # 1 BGL fee is enough dbl_tx = CTransaction() dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)] dbl_tx.vout = [CTxOut(initial_nValue - fee * n - 1 * COIN, DUMMY_P2WPKH_SCRIPT)] @@ -294,7 +294,7 @@ def test_replacement_feeperkb(self): # rejected. tx1b = CTransaction() tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)] - tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*999000]))] + tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*9990]))] tx1b_hex = txToHex(tx1b) # This will raise an exception due to insufficient fee @@ -502,7 +502,7 @@ def test_prioritised_transactions(self): # Higher fee, but the actual fee per KB is much lower. tx1b = CTransaction() tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)] - tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*740000]))] + tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*74000]))] tx1b_hex = txToHex(tx1b) # Verify tx1b cannot replace tx1a. diff --git a/test/functional/feature_settings.py b/test/functional/feature_settings.py index 145971f83c..367ba6289f 100755 --- a/test/functional/feature_settings.py +++ b/test/functional/feature_settings.py @@ -22,7 +22,7 @@ def set_test_params(self): def run_test(self): node, = self.nodes settings = Path(node.datadir, self.chain, "settings.json") - conf = Path(node.datadir, "bitcoin.conf") + conf = Path(node.datadir, "BGL.conf") # Assert empty settings file was created self.stop_node(0) diff --git a/test/functional/feature_utxo_set_hash.py b/test/functional/feature_utxo_set_hash.py index 31238d34ac..fdcc52153c 100755 --- a/test/functional/feature_utxo_set_hash.py +++ b/test/functional/feature_utxo_set_hash.py @@ -14,7 +14,7 @@ from test_framework.muhash import MuHash3072 from test_framework.test_framework import BGLTestFramework from test_framework.util import assert_equal -from test_framework.wallet import MiniWallet +from test_framework.wallet import MiniWallet,MiniWalletMode class UTXOSetHashTest(BGLTestFramework): def set_test_params(self): @@ -69,8 +69,8 @@ def test_muhash_implementation(self): assert_equal(finalized[::-1].hex(), node_muhash) self.log.info("Test deterministic UTXO set hash results") - assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "5b1b44097406226c0eb8e1362cd17a1f346522cf9390a8175a57a5262cb1963f") - assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "4b8803075d7151d06fad3e88b68ba726886794873fbfa841d12aefb2cc2b881b") + assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "1ec3e58b0be79fca5917c7c30b9761f12adb609d0233cf2b42fa17ec419f0056") + assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "faee25ca4765facb643b7a2d96531c568cb52ad84de5ae3d420a92967621ec17") def run_test(self): self.test_muhash_implementation() diff --git a/test/functional/interface_BGL_cli.py b/test/functional/interface_BGL_cli.py index 118076a38c..1ee9065e91 100755 --- a/test/functional/interface_BGL_cli.py +++ b/test/functional/interface_BGL_cli.py @@ -12,11 +12,11 @@ get_auth_cookie, ) -# The block reward of coinbaseoutput.nValue (50) BTC/block matures after +# The block reward of coinbaseoutput.nValue (200) BGL/block matures after # COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect -# node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 50 BTC/block. +# node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 200 BGL/block. BLOCKS = 101 -BALANCE = (BLOCKS - 100) * 50 +BALANCE = (BLOCKS - 100) * 200 JSON_PARSING_ERROR = 'error: Error parsing JSON: foo' BLOCKS_VALUE_OF_ZERO = 'error: the first argument (number of blocks to generate, default: 1) must be an integer value greater than zero' @@ -28,6 +28,7 @@ class TestBGLCli(BGLTestFramework): def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 1 + self.parse_args() if self.is_wallet_compiled(): self.requires_wallet = True @@ -108,7 +109,7 @@ def run_test(self): # Setup to test -getinfo, -generate, and -rpcwallet= with multiple wallets. wallets = [self.default_wallet_name, 'Encrypted', 'secret'] - amounts = [BALANCE + Decimal('9.999928'), Decimal(9), Decimal(31)] + amounts = [BALANCE + Decimal('9.99994360'), Decimal(9), Decimal(181)] self.nodes[0].createwallet(wallet_name=wallets[1]) self.nodes[0].createwallet(wallet_name=wallets[2]) w1 = self.nodes[0].get_wallet_rpc(wallets[0]) @@ -121,7 +122,7 @@ def run_test(self): w1.sendtoaddress(w2.getnewaddress(), amounts[1]) w1.sendtoaddress(w3.getnewaddress(), amounts[2]) - # Mine a block to confirm; adds a block reward (50 BTC) to the default wallet. + # Mine a block to confirm; adds a block reward (200 BGL) to the default wallet. self.nodes[0].generate(1) self.log.info("Test -getinfo with multiple wallets and -rpcwallet returns specified wallet balance") diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index 68fb436adf..6153a92b00 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -80,14 +80,14 @@ def run_test(self): self.log.info("Mine blocks and send BGL to node 1") # Random address so node1's balance doesn't increase - not_related_address = "2MxqoHEdNQTyYeX1mHcbrrpzgojbosTpCvJ" + not_related_address = "rbgl1qmevj8zfx0wdvp05cqwkmr6mxkfx60yezhdmczp" self.nodes[0].generate(1) self.sync_all() self.nodes[1].generatetoaddress(100, not_related_address) self.sync_all() - assert_equal(self.nodes[0].getbalance(), 50) + assert_equal(self.nodes[0].getbalance(), 200) txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1) self.sync_all() diff --git a/test/functional/mempool_accept.py b/test/functional/mempool_accept.py index cac1194098..3d51027e4f 100755 --- a/test/functional/mempool_accept.py +++ b/test/functional/mempool_accept.py @@ -284,7 +284,7 @@ def run_test(self): num_scripts = 100000 // len(output_p2sh_burn.serialize()) # Use enough outputs to make the tx too large for our policy tx.vout = [output_p2sh_burn] * num_scripts self.check_mempool_result( - result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'tx-size'}], + result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-oversize'}], rawtxs=[tx.serialize().hex()], ) tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference))) diff --git a/test/functional/p2p_tx_download.py b/test/functional/p2p_tx_download.py index 8d5de4e72b..442c2d430c 100755 --- a/test/functional/p2p_tx_download.py +++ b/test/functional/p2p_tx_download.py @@ -93,7 +93,7 @@ def test_inv_block(self): "txid": self.nodes[0].getblock(self.nodes[0].getblockhash(1))['tx'][0], "vout": 0 }], - outputs={ADDRESS_BCRT1_UNSPENDABLE: 50 - 0.00025}, + outputs={ADDRESS_BCRT1_UNSPENDABLE: 200 - 0.00025}, ) tx = self.nodes[0].signrawtransactionwithkey( hexstring=tx, diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 13413d25f4..37e2e7d581 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -221,7 +221,7 @@ def _test_gettxoutsetinfo(self): node = self.nodes[0] res = node.gettxoutsetinfo() - assert_equal(res['total_amount'], Decimal('8725.00000000')) + assert_equal(res['total_amount'], Decimal('34900.00000000')) assert_equal(res['transactions'], 200) assert_equal(res['height'], 200) assert_equal(res['txouts'], 200) diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py index 2fbfe905f7..6cf279e439 100755 --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -118,7 +118,7 @@ def checkbalances(self): height = node0.getblockchaininfo()["blocks"] assert 150 < height < 350 - total = 149 * 50 + (height - 149 - 100) * 25 + total = 149 * 200 + (height - 149 - 100) * 100 - decimal.Decimal("0.00038295") assert bal1 == 0 assert bal2 == self.moved assert bal0 + bal1 + bal2 == total @@ -151,7 +151,7 @@ def do_multisig(self): mredeem = msig["redeemScript"] assert_equal(desc, msig['descriptor']) if self.output_type == 'bech32': - assert madd[0:4] == "bcrt" # actually a bech32 address + assert madd[0:4] == "rbgl" # actually a bech32 address # compare against addmultisigaddress msigw = wmulti.addmultisigaddress(self.nsigs, self.pub, None, self.output_type) diff --git a/test/functional/rpc_decodescript.py b/test/functional/rpc_decodescript.py index a96d551119..c8ed8ed30c 100755 --- a/test/functional/rpc_decodescript.py +++ b/test/functional/rpc_decodescript.py @@ -175,7 +175,7 @@ def decoderawtransaction_asm_sighashtype(self): # verify that we have not altered scriptPubKey decoding. tx = '01000000018d1f5635abd06e2c7e2ddf58dc85b3de111e4ad6e0ab51bb0dcf5e84126d927300000000fdfe0000483045022100ae3b4e589dfc9d48cb82d41008dc5fa6a86f94d5c54f9935531924602730ab8002202f88cf464414c4ed9fa11b773c5ee944f66e9b05cc1e51d97abc22ce098937ea01483045022100b44883be035600e9328a01b66c7d8439b74db64187e76b99a68f7893b701d5380220225bf286493e4c4adcf928c40f785422572eb232f84a0b83b0dea823c3a19c75014c695221020743d44be989540d27b1b4bbbcfd17721c337cb6bc9af20eb8a32520b393532f2102c0120a1dda9e51a938d39ddd9fe0ebc45ea97e1d27a7cbd671d5431416d3dd87210213820eb3d5f509d7438c9eeecb4157b2f595105e7cd564b3cdbb9ead3da41eed53aeffffffff02611e0000000000001976a914dc863734a218bfe83ef770ee9d41a27f824a6e5688acee2a02000000000017a9142a5edea39971049a540474c6a99edf0aa4074c588700000000' rpc_result = self.nodes[0].decoderawtransaction(tx) - assert_equal('8e3730608c3b0bb5df54f09076e196bc292a8e39a78e73b44b6ba08c78f5cbb0', rpc_result['txid']) + assert_equal('57cf6dbb6faa83f78099c953777249b03d6e201023154f84d26b1bfaed59ac1f', rpc_result['txid']) assert_equal('0 3045022100ae3b4e589dfc9d48cb82d41008dc5fa6a86f94d5c54f9935531924602730ab8002202f88cf464414c4ed9fa11b773c5ee944f66e9b05cc1e51d97abc22ce098937ea[ALL] 3045022100b44883be035600e9328a01b66c7d8439b74db64187e76b99a68f7893b701d5380220225bf286493e4c4adcf928c40f785422572eb232f84a0b83b0dea823c3a19c75[ALL] 5221020743d44be989540d27b1b4bbbcfd17721c337cb6bc9af20eb8a32520b393532f2102c0120a1dda9e51a938d39ddd9fe0ebc45ea97e1d27a7cbd671d5431416d3dd87210213820eb3d5f509d7438c9eeecb4157b2f595105e7cd564b3cdbb9ead3da41eed53ae', rpc_result['vin'][0]['scriptSig']['asm']) assert_equal('OP_DUP OP_HASH160 dc863734a218bfe83ef770ee9d41a27f824a6e56 OP_EQUALVERIFY OP_CHECKSIG', rpc_result['vout'][0]['scriptPubKey']['asm']) assert_equal('OP_HASH160 2a5edea39971049a540474c6a99edf0aa4074c58 OP_EQUAL', rpc_result['vout'][1]['scriptPubKey']['asm']) diff --git a/test/functional/rpc_deriveaddresses.py b/test/functional/rpc_deriveaddresses.py index 374c4a0adc..285de242b3 100755 --- a/test/functional/rpc_deriveaddresses.py +++ b/test/functional/rpc_deriveaddresses.py @@ -15,19 +15,19 @@ def run_test(self): assert_raises_rpc_error(-5, "Missing checksum", self.nodes[0].deriveaddresses, "a") descriptor = "wpkh(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/0)#t6wfjs64" - address = "bcrt1qjqmxmkpmxt80xz4y3746zgt0q3u3ferr34acd5" + address = "rbgl1qjqmxmkpmxt80xz4y3746zgt0q3u3ferrg2ss57" assert_equal(self.nodes[0].deriveaddresses(descriptor), [address]) descriptor = descriptor[:-9] assert_raises_rpc_error(-5, "Missing checksum", self.nodes[0].deriveaddresses, descriptor) descriptor_pubkey = "wpkh(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/0)#s9ga3alw" - address = "bcrt1qjqmxmkpmxt80xz4y3746zgt0q3u3ferr34acd5" + address = "rbgl1qjqmxmkpmxt80xz4y3746zgt0q3u3ferrg2ss57" assert_equal(self.nodes[0].deriveaddresses(descriptor_pubkey), [address]) ranged_descriptor = "wpkh(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/*)#kft60nuy" - assert_equal(self.nodes[0].deriveaddresses(ranged_descriptor, [1, 2]), ["bcrt1qhku5rq7jz8ulufe2y6fkcpnlvpsta7rq4442dy", "bcrt1qpgptk2gvshyl0s9lqshsmx932l9ccsv265tvaq"]) - assert_equal(self.nodes[0].deriveaddresses(ranged_descriptor, 2), [address, "bcrt1qhku5rq7jz8ulufe2y6fkcpnlvpsta7rq4442dy", "bcrt1qpgptk2gvshyl0s9lqshsmx932l9ccsv265tvaq"]) + assert_equal(self.nodes[0].deriveaddresses(ranged_descriptor, [1, 2]), ["rbgl1qhku5rq7jz8ulufe2y6fkcpnlvpsta7rqv2cz5w", "rbgl1qpgptk2gvshyl0s9lqshsmx932l9ccsv2rtxyy2"]) + assert_equal(self.nodes[0].deriveaddresses(ranged_descriptor, 2), [address, "rbgl1qhku5rq7jz8ulufe2y6fkcpnlvpsta7rqv2cz5w", "rbgl1qpgptk2gvshyl0s9lqshsmx932l9ccsv2rtxyy2"]) assert_raises_rpc_error(-8, "Range should not be specified for an un-ranged descriptor", self.nodes[0].deriveaddresses, descsum_create("wpkh(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/0)"), [0, 2]) @@ -42,7 +42,7 @@ def run_test(self): assert_raises_rpc_error(-8, "Range should be greater or equal than 0", self.nodes[0].deriveaddresses, descsum_create("wpkh(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/*)"), [-1, 0]) combo_descriptor = descsum_create("combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/0)") - assert_equal(self.nodes[0].deriveaddresses(combo_descriptor), ["mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", "mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", address, "2NDvEwGfpEqJWfybzpKPHF2XH3jwoQV3D7x"]) + assert_equal(self.nodes[0].deriveaddresses(combo_descriptor), ["Eue2z7dmUSPS29RkwdNG7czwWxy48pNHSq", "Eue2z7dmUSPS29RkwdNG7czwWxy48pNHSq", address, "MUaBBR9kaVebGhFMF4kkSinRA6L5aRtPoC"]) hardened_without_privkey_descriptor = descsum_create("wpkh(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1'/1/0)") assert_raises_rpc_error(-5, "Cannot derive script without private keys", self.nodes[0].deriveaddresses, hardened_without_privkey_descriptor) diff --git a/test/functional/rpc_dumptxoutset.py b/test/functional/rpc_dumptxoutset.py index 6ac03e1c96..fa920f2b8f 100755 --- a/test/functional/rpc_dumptxoutset.py +++ b/test/functional/rpc_dumptxoutset.py @@ -35,13 +35,13 @@ def run_test(self): # Blockhash should be deterministic based on mocked time. assert_equal( out['base_hash'], - '6fd417acba2a8738b06fee43330c50d58e6a725046c3d843c8dd7e51d46d1ed6') + '57ccea06777257714f3cb5af00dd58f8e0a33865b98239ad120523685bad8712') with open(str(expected_path), 'rb') as f: digest = hashlib.sha256(f.read()).hexdigest() # UTXO snapshot hash should be deterministic based on mocked time. assert_equal( - digest, 'be032e5f248264ba08e11099ac09dbd001f6f87ffc68bf0f87043d8146d50664') + digest, 'f5ebe73124394aae25d4b6151caa6dbc51355233d1b7cde4a31780035c230f5c') # Specifying a path to an existing file will fail. assert_raises_rpc_error( diff --git a/test/functional/rpc_fundrawtransaction.py b/test/functional/rpc_fundrawtransaction.py index a512878841..be52785a32 100755 --- a/test/functional/rpc_fundrawtransaction.py +++ b/test/functional/rpc_fundrawtransaction.py @@ -9,6 +9,7 @@ from test_framework.test_framework import BGLTestFramework from test_framework.util import ( assert_equal, + assert_approx, assert_fee_amount, assert_greater_than, assert_greater_than_or_equal, @@ -99,7 +100,7 @@ def run_test(self): def test_change_position(self): """Ensure setting changePosition in fundraw with an exact match is handled properly.""" self.log.info("Test fundrawtxn changePosition option") - rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():50}) + rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():200}) rawmatch = self.nodes[2].fundrawtransaction(rawmatch, {"changePosition":1, "subtractFeeFromOutputs":[0]}) assert_equal(rawmatch["changepos"], -1) @@ -230,7 +231,7 @@ def test_invalid_change_address(self): dec_tx = self.nodes[2].decoderawtransaction(rawtx) assert_equal(utx['txid'], dec_tx['vin'][0]['txid']) - assert_raises_rpc_error(-5, "Change address must be a valid bitcoin address", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':'foobar'}) + assert_raises_rpc_error(-5, "Change address must be a valid BGL address", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':'foobar'}) def test_valid_change_address(self): self.log.info("Test fundrawtxn with a provided change address") @@ -571,7 +572,7 @@ def test_locked_wallet(self): self.sync_all() # Make sure funds are received at node1. - assert_equal(oldBalance+Decimal('51.10000000'), self.nodes[0].getbalance()) + assert_equal(oldBalance+Decimal('201.10000000'), self.nodes[0].getbalance()) def test_many_inputs_fee(self): """Multiple (~19) inputs tx test | Compare fee.""" @@ -626,7 +627,7 @@ def test_many_inputs_send(self): self.nodes[1].sendrawtransaction(fundedAndSignedTx['hex']) self.nodes[1].generate(1) self.sync_all() - assert_equal(oldBalance+Decimal('50.19000000'), self.nodes[0].getbalance()) #0.19+block reward + assert_equal(oldBalance+Decimal('200.19000000'), self.nodes[0].getbalance()) #0.19+block reward def test_op_return(self): self.log.info("Test fundrawtxn with OP_RETURN and no vin") @@ -909,23 +910,15 @@ def test_subtract_fee_with_presets(self): self.nodes[0].sendrawtransaction(signedtx['hex']) def test_transaction_too_large(self): - self.log.info("Test fundrawtx where BnB solution would result in a too large transaction, but Knapsack would not") + self.log.info("Test too large transaction") self.nodes[0].createwallet("large") wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name) recipient = self.nodes[0].get_wallet_rpc("large") outputs = {} - rawtx = recipient.createrawtransaction([], {wallet.getnewaddress(): 147.99899260}) - - # Make 1500 0.1 BTC outputs. The amount that we target for funding is in - # the BnB range when these outputs are used. However if these outputs - # are selected, the transaction will end up being too large, so it - # shouldn't use BnB and instead fall back to Knapsack but that behavior - # is not implemented yet. For now we just check that we get an error. - for _ in range(1500): + for _ in range(4000): outputs[recipient.getnewaddress()] = 0.1 - wallet.sendmany("", outputs) self.nodes[0].generate(10) - assert_raises_rpc_error(-4, "Transaction too large", recipient.fundrawtransaction, rawtx) + assert_raises_rpc_error(-6, "Transaction too large", wallet.sendmany,"", outputs) if __name__ == '__main__': diff --git a/test/functional/rpc_generateblock.py b/test/functional/rpc_generateblock.py index e751a848aa..ce4614ce2e 100755 --- a/test/functional/rpc_generateblock.py +++ b/test/functional/rpc_generateblock.py @@ -37,7 +37,7 @@ def run_test(self): self.log.info('Generate an empty block to a combo descriptor with compressed pubkey') combo_key = '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798' - combo_address = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080' + combo_address = 'rbgl1qw508d6qejxtdg4y5r3zarvary0c5xw7kahx879' hash = node.generateblock('combo(' + combo_key + ')', [])['hash'] block = node.getblock(hash, 2) assert_equal(len(block['tx']), 1) @@ -45,7 +45,7 @@ def run_test(self): self.log.info('Generate an empty block to a combo descriptor with uncompressed pubkey') combo_key = '0408ef68c46d20596cc3f6ddf7c8794f71913add807f1dc55949fa805d764d191c0b7ce6894c126fce0babc6663042f3dde9b0cf76467ea315514e5a6731149c67' - combo_address = 'mkc9STceoCcjoXEXe6cm66iJbmjM6zR9B2' + combo_address = 'Emahd6fU8JwGq9VrknyDkSkj8vtiNQSsoZ' hash = node.generateblock('combo(' + combo_key + ')', [])['hash'] block = node.getblock(hash, 2) assert_equal(len(block['tx']), 1) diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index f00da6a8a2..7163d70463 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -52,7 +52,7 @@ def run_test(self): self.wallet = MiniWallet(self.nodes[0]) self.wallet.generate(1) # Get out of IBD for the minfeefilter and getpeerinfo tests. - self.nodes[0].generate(101) + self.nodes[0].generate(100 + 1) # By default, the test framework sets up an addnode connection from # node 1 --> node0. By connecting node0 --> node 1, we're left with @@ -196,13 +196,7 @@ def test_getnodeaddresses(self): second_octet = i % 256 a = "{}.{}.1.1".format(first_octet, second_octet) # IPV4 imported_addrs.append(a) - addr = CAddress() - addr.time = 100000000 - addr.nServices = NODE_NETWORK | NODE_WITNESS - addr.ip = a - addr.port = 8333 - msg.addrs.append(addr) - self.nodes[0].p2p.send_and_ping(msg) + self.nodes[0].addpeeraddress(a, 8333) # Obtain addresses via rpc call and check they were ones sent in before. # @@ -211,8 +205,8 @@ def test_getnodeaddresses(self): # 64, although actual number will usually be slightly less due to # BucketPosition collisions. node_addresses = self.nodes[0].getnodeaddresses(0) - assert_greater_than(len(node_addresses), 50) - assert_greater_than(65, len(node_addresses)) + assert_greater_than(len(node_addresses), 5000) + assert_greater_than(10000, len(node_addresses)) for a in node_addresses: assert_greater_than(a["time"], 1527811200) # 1st June 2018 assert_equal(a["services"], NODE_NETWORK | NODE_WITNESS) diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py index 2d57c0f01a..71c49b2c18 100755 --- a/test/functional/rpc_rawtransaction.py +++ b/test/functional/rpc_rawtransaction.py @@ -266,7 +266,7 @@ def run_test(self): #use balance deltas instead of absolute values bal = self.nodes[2].getbalance() - # send 1.2 BTC to msig adr + # send 1.2 BGL to msig adr txId = self.nodes[0].sendtoaddress(mSigObj, 1.2) self.sync_all() self.nodes[0].generate(1) @@ -315,7 +315,7 @@ def run_test(self): self.sync_all() self.nodes[0].generate(1) self.sync_all() - assert_equal(self.nodes[0].getbalance(), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx + assert_equal(self.nodes[0].getbalance(), bal+Decimal('200.00000000')+Decimal('2.19000000')) #block reward + tx # 2of2 test for combining transactions bal = self.nodes[2].getbalance() @@ -360,7 +360,7 @@ def run_test(self): self.sync_all() self.nodes[0].generate(1) self.sync_all() - assert_equal(self.nodes[0].getbalance(), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx + assert_equal(self.nodes[0].getbalance(), bal+Decimal('200.00000000')+Decimal('2.19000000')) #block reward + tx # decoderawtransaction tests # witness transaction @@ -467,12 +467,12 @@ def run_test(self): self.sync_all() inputs = [{ "txid" : txId, "vout" : vout['n'] }] - # Fee 10,000 satoshis, (1 - (10000 sat * 0.00000001 BTC/sat)) = 0.9999 + # Fee 10,000 satoshis, (1 - (10000 sat * 0.00000001 BGL/sat)) = 0.9999 outputs = { self.nodes[0].getnewaddress() : Decimal("0.99990000") } rawTx = self.nodes[2].createrawtransaction(inputs, outputs) rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx) assert_equal(rawTxSigned['complete'], True) - # Fee 10,000 satoshis, ~100 b transaction, fee rate should land around 100 sat/byte = 0.00100000 BTC/kB + # Fee 10,000 satoshis, ~100 b transaction, fee rate should land around 100 sat/byte = 0.00100000 BGL/kB # Thus, testmempoolaccept should reject testres = self.nodes[2].testmempoolaccept([rawTxSigned['hex']], 0.00001000)[0] assert_equal(testres['allowed'], False) @@ -491,12 +491,12 @@ def run_test(self): self.sync_all() inputs = [{ "txid" : txId, "vout" : vout['n'] }] - # Fee 2,000,000 satoshis, (1 - (2000000 sat * 0.00000001 BTC/sat)) = 0.98 + # Fee 2,000,000 satoshis, (1 - (2000000 sat * 0.00000001 BGL/sat)) = 0.98 outputs = { self.nodes[0].getnewaddress() : Decimal("0.98000000") } rawTx = self.nodes[2].createrawtransaction(inputs, outputs) rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx) assert_equal(rawTxSigned['complete'], True) - # Fee 2,000,000 satoshis, ~100 b transaction, fee rate should land around 20,000 sat/byte = 0.20000000 BTC/kB + # Fee 2,000,000 satoshis, ~100 b transaction, fee rate should land around 20,000 sat/byte = 0.20000000 BGL/kB # Thus, testmempoolaccept should reject testres = self.nodes[2].testmempoolaccept([rawTxSigned['hex']])[0] assert_equal(testres['allowed'], False) diff --git a/test/functional/rpc_signrawtransaction.py b/test/functional/rpc_signrawtransaction.py index d20a2284e4..6fbdfb0fd1 100755 --- a/test/functional/rpc_signrawtransaction.py +++ b/test/functional/rpc_signrawtransaction.py @@ -41,7 +41,7 @@ def successful_signing_test(self): 'scriptPubKey': '76a914669b857c03a5ed269d5d85a1ffac9ed5d663072788ac'}, ] - outputs = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1} + outputs = {'rbgl1qmevj8zfx0wdvp05cqwkmr6mxkfx60yezhdmczp': 0.1} rawTx = self.nodes[0].createrawtransaction(inputs, outputs) rawTxSigned = self.nodes[0].signrawtransactionwithkey(rawTx, privKeys, inputs) @@ -90,7 +90,7 @@ def script_verification_error_test(self): 'scriptPubKey': 'badbadbadbad'} ] - outputs = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1} + outputs = {'rbgl1qmevj8zfx0wdvp05cqwkmr6mxkfx60yezhdmczp': 0.1} rawTx = self.nodes[0].createrawtransaction(inputs, outputs) @@ -192,6 +192,7 @@ def witness_script_test(self): # Now test with P2PKH and P2PK scripts as the witnessScript for tx_type in ['P2PKH', 'P2PK']: # these tests are order-independent + pass self.verify_txn_with_witness_script(tx_type) def verify_txn_with_witness_script(self, tx_type): diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py index e25629375e..31b29f3b83 100644 --- a/test/functional/test_framework/address.py +++ b/test/functional/test_framework/address.py @@ -9,15 +9,15 @@ import enum import unittest - +import sha3 from .script import hash256, hash160, sha256, CScript, OP_0 from .segwit_addr import encode_segwit_address from .util import assert_equal, hex_str_to_bytes -ADDRESS_BCRT1_UNSPENDABLE = 'rgbl1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj' -ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR = 'addr(bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj)#juyq9d97' +ADDRESS_BCRT1_UNSPENDABLE = 'rbgl1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv0fdzt' +ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR = 'addr(rbgl1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv0fdzt)#q3s9fnd2' # Coins sent to this address can be spent with a witness stack of just OP_TRUE -ADDRESS_BCRT1_P2WSH_OP_TRUE = 'rbgl1qft5p2uhsdcdc3l2ua4ap5qqfg4pjaqlp250x7us7a8qqhrxrxfsqseac85' +ADDRESS_BCRT1_P2WSH_OP_TRUE = 'rbgl1qft5p2uhsdcdc3l2ua4ap5qqfg4pjaqlp250x7us7a8qqhrxrxfsqdsgvpd' class AddressType(enum.Enum): @@ -77,12 +77,12 @@ def base58_to_byte(s): def keyhash_to_p2pkh(hash, main=False): assert len(hash) == 20 - version = 0 if main else 111 + version = 10 if main else 34 return byte_to_base58(hash, version) def scripthash_to_p2sh(hash, main=False): assert len(hash) == 20 - version = 5 if main else 196 + version = 25 if main else 50 return byte_to_base58(hash, version) def key_to_p2pkh(key, main=False): @@ -104,7 +104,7 @@ def program_to_witness(version, program, main=False): assert 0 <= version <= 16 assert 2 <= len(program) <= 40 assert version > 0 or len(program) in [20, 32] - return encode_segwit_address("bc" if main else "bcrt", version, program) + return encode_segwit_address("bgl" if main else "rbgl", version, program) def script_to_p2wsh(script, main=False): script = check_script(script) @@ -139,15 +139,15 @@ def test_base58encodedecode(self): def check_base58(data, version): self.assertEqual(base58_to_byte(byte_to_base58(data, version)), (data, version)) - check_base58(bytes.fromhex('1f8ea1702a7bd4941bca0941b852c4bbfedb2e05'), 111) - check_base58(bytes.fromhex('3a0b05f4d7f66c3ba7009f453530296c845cc9cf'), 111) - check_base58(bytes.fromhex('41c1eaf111802559bad61b60d62b1f897c63928a'), 111) - check_base58(bytes.fromhex('0041c1eaf111802559bad61b60d62b1f897c63928a'), 111) - check_base58(bytes.fromhex('000041c1eaf111802559bad61b60d62b1f897c63928a'), 111) - check_base58(bytes.fromhex('00000041c1eaf111802559bad61b60d62b1f897c63928a'), 111) - check_base58(bytes.fromhex('1f8ea1702a7bd4941bca0941b852c4bbfedb2e05'), 0) - check_base58(bytes.fromhex('3a0b05f4d7f66c3ba7009f453530296c845cc9cf'), 0) - check_base58(bytes.fromhex('41c1eaf111802559bad61b60d62b1f897c63928a'), 0) - check_base58(bytes.fromhex('0041c1eaf111802559bad61b60d62b1f897c63928a'), 0) - check_base58(bytes.fromhex('000041c1eaf111802559bad61b60d62b1f897c63928a'), 0) - check_base58(bytes.fromhex('00000041c1eaf111802559bad61b60d62b1f897c63928a'), 0) + check_base58(bytes.fromhex('1f8ea1702a7bd4941bca0941b852c4bbfedb2e05'), 34) + check_base58(bytes.fromhex('3a0b05f4d7f66c3ba7009f453530296c845cc9cf'), 34) + check_base58(bytes.fromhex('41c1eaf111802559bad61b60d62b1f897c63928a'), 34) + check_base58(bytes.fromhex('0041c1eaf111802559bad61b60d62b1f897c63928a'), 34) + check_base58(bytes.fromhex('000041c1eaf111802559bad61b60d62b1f897c63928a'), 34) + check_base58(bytes.fromhex('00000041c1eaf111802559bad61b60d62b1f897c63928a'), 34) + check_base58(bytes.fromhex('1f8ea1702a7bd4941bca0941b852c4bbfedb2e05'), 10) + check_base58(bytes.fromhex('3a0b05f4d7f66c3ba7009f453530296c845cc9cf'), 10) + check_base58(bytes.fromhex('41c1eaf111802559bad61b60d62b1f897c63928a'), 10) + check_base58(bytes.fromhex('0041c1eaf111802559bad61b60d62b1f897c63928a'), 10) + check_base58(bytes.fromhex('000041c1eaf111802559bad61b60d62b1f897c63928a'), 10) + check_base58(bytes.fromhex('00000041c1eaf111802559bad61b60d62b1f897c63928a'), 10) diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py index 53e317262b..26619fc8e9 100644 --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -29,6 +29,7 @@ hex_str_to_bytes, ser_uint256, sha256, + keccak256, uint256_from_str, ) from .script import ( @@ -178,6 +179,11 @@ def create_raw_transaction(node, txid, to_address, *, amount): signed_psbt = wrpc.walletprocesspsbt(psbt) psbt = signed_psbt['psbt'] final_psbt = node.finalizepsbt(psbt) + if not final_psbt["complete"]: + node.log.info(f'final_psbt={final_psbt}') + for w in node.listwallets(): + wrpc = node.get_wallet_rpc(w) + node.log.info(f'listunspent={wrpc.listunspent()}') assert_equal(final_psbt["complete"], True) return final_psbt['hex'] diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 5c7f346511..d32ef6be17 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -38,7 +38,7 @@ MAX_BLOOM_FILTER_SIZE = 36000 MAX_BLOOM_HASH_FUNCS = 50 -COIN = 100000000 # 1 btc in satoshis +COIN = 100000000 # 1 bgl in satoshis MAX_MONEY = 21000000 * COIN BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is BIP 125 opt-in and BIP 68-opt-out diff --git a/test/functional/test_framework/muhash.py b/test/functional/test_framework/muhash.py index ed8a12abea..183548f71f 100644 --- a/test/functional/test_framework/muhash.py +++ b/test/functional/test_framework/muhash.py @@ -4,6 +4,7 @@ """Native Python MuHash3072 implementation.""" import hashlib +import unittest from .util import modinv diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index d73f54a6f2..53fa5fbf5a 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -123,10 +123,10 @@ } MAGIC_BYTES = { - "mainnet": b"\xf9\xbe\xb4\xd9", # mainnet + "mainnet": b"\x8a\xb4\x91\xe8", # mainnet "testnet3": b"\x0b\x11\x09\x07", # testnet3 - "regtest": b"\xfa\xbf\xb5\xda", # regtest - "signet": b"\x0a\x03\xcf\x40", # signet + "regtest": b"\xd9\x8c\xbf\xba", # regtest + "signet": b"\x0a\x03\xcf\x40", # signet } diff --git a/test/functional/test_framework/segwit_addr.py b/test/functional/test_framework/segwit_addr.py index 861ca2b949..09fb505091 100644 --- a/test/functional/test_framework/segwit_addr.py +++ b/test/functional/test_framework/segwit_addr.py @@ -128,14 +128,14 @@ class TestFrameworkScript(unittest.TestCase): def test_segwit_encode_decode(self): def test_python_bech32(addr): hrp = addr[:4] - self.assertEqual(hrp, "bcrt") + self.assertEqual(hrp, "rbgl") (witver, witprog) = decode_segwit_address(hrp, addr) self.assertEqual(encode_segwit_address(hrp, witver, witprog), addr) # P2WPKH - test_python_bech32('bcrt1qthmht0k2qnh3wy7336z05lu2km7emzfpm3wg46') + test_python_bech32('rbgl1qqymf0uykeha35u2m9kaq384xmg53rfl3t46ccx') # P2WSH - test_python_bech32('bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj') - test_python_bech32('bcrt1qft5p2uhsdcdc3l2ua4ap5qqfg4pjaqlp250x7us7a8qqhrxrxfsqseac85') + test_python_bech32('rbgl1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv0fdzt') + test_python_bech32('rbgl1qffm0rgnk7pxfsxnflhvujfgxrwe5g227c6u3l43t7x7tal5z2snqdu6tz4') # P2TR - test_python_bech32('bcrt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqc8gma6') + #test_python_bech32('rbgl1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqc8gma6') diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index fa73de5776..3a26a2971e 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -20,6 +20,7 @@ from . import coverage from .authproxy import AuthServiceProxy, JSONRPCException from io import BytesIO +from typing import Callable, Optional logger = logging.getLogger("TestFramework.utils") @@ -39,10 +40,10 @@ def assert_fee_amount(fee, tx_size, fee_per_kB): """Assert the fee was in range""" target_fee = round(tx_size * fee_per_kB / 1000, 8) if fee < target_fee: - raise AssertionError("Fee of %s BTC too low! (Should be %s BTC)" % (str(fee), str(target_fee))) + raise AssertionError("Fee of %s BGL too low! (Should be %s BGL)" % (str(fee), str(target_fee))) # allow the wallet's estimation to be at most 2 bytes off if fee > (tx_size + 2) * fee_per_kB / 1000: - raise AssertionError("Fee of %s BTC too high! (Should be %s BTC)" % (str(fee), str(target_fee))) + raise AssertionError("Fee of %s BGL too high! (Should be %s BGL)" % (str(fee), str(target_fee))) def assert_equal(thing1, thing2, *args): @@ -80,7 +81,7 @@ def assert_raises_message(exc, message, fun, *args, **kwds): raise AssertionError("No exception raised") -def assert_raises_process_error(returncode, output, fun, *args, **kwds): +def assert_raises_process_error(returncode: int, output: str, fun: Callable, *args, **kwds): """Execute a process and asserts the process return code and output. Calls function `fun` with arguments `args` and `kwds`. Catches a CalledProcessError @@ -88,9 +89,9 @@ def assert_raises_process_error(returncode, output, fun, *args, **kwds): no CalledProcessError was raised or if the return code and output are not as expected. Args: - returncode (int): the process return code. - output (string): [a substring of] the process output. - fun (function): the function to call. This should execute a process. + returncode: the process return code. + output: [a substring of] the process output. + fun: the function to call. This should execute a process. args*: positional arguments for the function. kwds**: named arguments for the function. """ @@ -105,7 +106,7 @@ def assert_raises_process_error(returncode, output, fun, *args, **kwds): raise AssertionError("No exception raised") -def assert_raises_rpc_error(code, message, fun, *args, **kwds): +def assert_raises_rpc_error(code: Optional[int], message: Optional[str], fun: Callable, *args, **kwds): """Run an RPC and verify that a specific JSONRPC exception code and message is raised. Calls function `fun` with arguments `args` and `kwds`. Catches a JSONRPCException @@ -113,11 +114,11 @@ def assert_raises_rpc_error(code, message, fun, *args, **kwds): no JSONRPCException was raised or if the error code/message are not as expected. Args: - code (int), optional: the error code returned by the RPC call (defined - in src/rpc/protocol.h). Set to None if checking the error code is not required. - message (string), optional: [a substring of] the error string returned by the - RPC call. Set to None if checking the error string is not required. - fun (function): the function to call. This should be the name of an RPC. + code: the error code returned by the RPC call (defined in src/rpc/protocol.h). + Set to None if checking the error code is not required. + message: [a substring of] the error string returned by the RPC call. + Set to None if checking the error string is not required. + fun: the function to call. This should be the name of an RPC. args*: positional arguments for the function. kwds**: named arguments for the function. """ @@ -197,7 +198,7 @@ def assert_array_result(object_array, to_match, expected, should_not_find=False) def check_json_precision(): - """Make sure json library being used does not lose precision converting BTC values""" + """Make sure json library being used does not lose precision converting BGL values""" n = Decimal("20000000.00000003") satoshis = int(json.loads(json.dumps(float(n))) * 1.0e8) if satoshis != 2000000000000003: @@ -480,6 +481,28 @@ def create_confirmed_utxos(fee, node, count): return utxos +def chain_transaction(node, parent_txids, vouts, value, fee, num_outputs): + """Build and send a transaction that spends the given inputs (specified + by lists of parent_txid:vout each), with the desired total value and fee, + equally divided up to the desired number of outputs. + + Returns a tuple with the txid and the amount sent per output. + """ + send_value = satoshi_round((value - fee)/num_outputs) + inputs = [] + for (txid, vout) in zip(parent_txids, vouts): + inputs.append({'txid' : txid, 'vout' : vout}) + outputs = {} + for _ in range(num_outputs): + outputs[node.getnewaddress()] = send_value + rawtx = node.createrawtransaction(inputs, outputs, 0, True) + signedtx = node.signrawtransactionwithwallet(rawtx) + txid = node.sendrawtransaction(signedtx['hex']) + fulltx = node.getrawtransaction(txid, 1) + assert len(fulltx['vout']) == num_outputs # make sure we didn't generate a change output + return (txid, send_value) + + # Create large OP_RETURN txouts that can be appended to a transaction # to make it large (helper for constructing large transactions). def gen_return_txouts(): diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index a906a21dd0..b45c07a172 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -5,7 +5,9 @@ """A limited-functionality wallet, which may replace a real wallet in tests""" from decimal import Decimal +from typing import Optional from test_framework.address import ADDRESS_BCRT1_P2WSH_OP_TRUE +from test_framework.key import ECKey from test_framework.messages import ( COIN, COutPoint, @@ -16,48 +18,97 @@ ) from test_framework.script import ( CScript, + LegacySignatureHash, + OP_CHECKSIG, OP_TRUE, + OP_NOP, + SIGHASH_ALL, ) from test_framework.util import ( assert_equal, hex_str_to_bytes, satoshi_round, ) +from enum import Enum +class MiniWalletMode(Enum): + """Determines the transaction type the MiniWallet is creating and spending. + + For most purposes, the default mode ADDRESS_OP_TRUE should be sufficient; + it simply uses a fixed bech32 P2WSH address whose coins are spent with a + witness stack of OP_TRUE, i.e. following an anyone-can-spend policy. + However, if the transactions need to be modified by the user (e.g. prepending + scriptSig for testing opcodes that are activated by a soft-fork), or the txs + should contain an actual signature, the raw modes RAW_OP_TRUE and RAW_P2PK + can be useful. Summary of modes: + + | output | | tx is | can modify | needs + mode | description | address | standard | scriptSig | signing + ----------------+-------------------+-----------+----------+------------+---------- + ADDRESS_OP_TRUE | anyone-can-spend | bech32 | yes | no | no + RAW_OP_TRUE | anyone-can-spend | - (raw) | no | yes | no + RAW_P2PK | pay-to-public-key | - (raw) | yes | yes | yes + """ + ADDRESS_OP_TRUE = 1 + RAW_OP_TRUE = 2 + RAW_P2PK = 3 class MiniWallet: - def __init__(self, test_node): + def __init__(self, test_node,mode=MiniWalletMode.ADDRESS_OP_TRUE): self._test_node = test_node self._utxos = [] - self._address = ADDRESS_BCRT1_P2WSH_OP_TRUE - self._scriptPubKey = hex_str_to_bytes(self._test_node.validateaddress(self._address)['scriptPubKey']) + self._priv_key = None + self._address = None + assert isinstance(mode, MiniWalletMode) + if mode == MiniWalletMode.RAW_OP_TRUE: + self._scriptPubKey = bytes(CScript([OP_TRUE])) + elif mode == MiniWalletMode.RAW_P2PK: + # use simple deterministic private key (k=1) + self._priv_key = ECKey() + self._priv_key.set((1).to_bytes(32, 'big'), True) + pub_key = self._priv_key.get_pubkey() + self._scriptPubKey = bytes(CScript([pub_key.get_bytes(), OP_CHECKSIG])) + elif mode == MiniWalletMode.ADDRESS_OP_TRUE: + self._address = ADDRESS_BCRT1_P2WSH_OP_TRUE + self._scriptPubKey = hex_str_to_bytes(self._test_node.validateaddress(self._address)['scriptPubKey']) def scan_blocks(self, *, start=1, num): """Scan the blocks for self._address outputs and add them to self._utxos""" for i in range(start, start + num): block = self._test_node.getblock(blockhash=self._test_node.getblockhash(i), verbosity=2) for tx in block['tx']: - for out in tx['vout']: - if out['scriptPubKey']['hex'] == self._scriptPubKey.hex(): - self._utxos.append({'txid': tx['txid'], 'vout': out['n'], 'value': out['value']}) + self.scan_tx(tx) def generate(self, num_blocks): """Generate blocks with coinbase outputs to the internal address, and append the outputs to the internal list""" - blocks = self._test_node.generatetoaddress(num_blocks, self._address) + blocks = self._test_node.generatetodescriptor(num_blocks, f'raw({self._scriptPubKey.hex()})') for b in blocks: cb_tx = self._test_node.getblock(blockhash=b, verbosity=2)['tx'][0] self._utxos.append({'txid': cb_tx['txid'], 'vout': 0, 'value': cb_tx['vout'][0]['value']}) return blocks + def scan_tx(self, tx): + """Scan the tx for self._scriptPubKey outputs and add them to self._utxos""" + for out in tx['vout']: + if out['scriptPubKey']['hex'] == self._scriptPubKey.hex(): + self._utxos.append({'txid': tx['txid'], 'vout': out['n'], 'value': out['value']}) + + def sign_tx(self, tx): + """Sign tx that has been created by MiniWallet in P2PK mode""" + assert self._priv_key is not None + (sighash, err) = LegacySignatureHash(CScript(self._scriptPubKey), tx, 0, SIGHASH_ALL) + assert err is None + tx.vin[0].scriptSig = CScript([self._priv_key.sign_ecdsa(sighash) + bytes(bytearray([SIGHASH_ALL]))]) + def get_address(self): return self._address - def get_utxo(self, *, txid=''): + def get_utxo(self, *, txid: Optional[str]='', mark_as_spent=True): """ Returns a utxo and marks it as spent (pops it from the internal list) Args: - txid (string), optional: get the first utxo we find from a specific transaction + txid: get the first utxo we find from a specific transaction Note: Can be used to get the change output immediately after a send_self_transfer """ @@ -65,9 +116,18 @@ def get_utxo(self, *, txid=''): if txid: utxo = next(filter(lambda utxo: txid == utxo['txid'], self._utxos)) index = self._utxos.index(utxo) - return self._utxos.pop(index) + if mark_as_spent: + return self._utxos.pop(index) + else: + return self._utxos[index] def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None): + """Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed.""" + tx = self.create_self_transfer(fee_rate=fee_rate, from_node=from_node, utxo_to_spend=utxo_to_spend) + self.sendrawtransaction(from_node=from_node, tx_hex=tx['hex']) + return tx + + def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True, locktime=0): """Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed.""" self._utxos = sorted(self._utxos, key=lambda k: k['value']) utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee @@ -79,13 +139,30 @@ def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_sp tx = CTransaction() tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']))] tx.vout = [CTxOut(int(send_value * COIN), self._scriptPubKey)] - tx.wit.vtxinwit = [CTxInWitness()] - tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])] + tx.nLockTime = locktime + if not self._address: + # raw script + if self._priv_key is not None: + # P2PK, need to sign + self.sign_tx(tx) + else: + # anyone-can-spend + tx.vin[0].scriptSig = CScript([OP_NOP] * 35) # pad to identical size + else: + tx.wit.vtxinwit = [CTxInWitness()] + tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])] tx_hex = tx.serialize().hex() tx_info = from_node.testmempoolaccept([tx_hex])[0] - self._utxos.append({'txid': tx_info['txid'], 'vout': 0, 'value': send_value}) + assert_equal(mempool_valid, tx_info['allowed']) + if mempool_valid: + # TODO: for P2PK, vsize is not constant due to varying scriptSig length, + # so only check this for anyone-can-spend outputs right now + if self._priv_key is None: + assert_equal(tx_info['vsize'], vsize) + assert_equal(tx_info['fees']['base'], fee) + return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex,'tx': tx} + + def sendrawtransaction(self, *, from_node, tx_hex): from_node.sendrawtransaction(tx_hex) - assert_equal(tx_info['vsize'], vsize) - assert_equal(tx_info['fees']['base'], fee) - return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex} + self.scan_tx(from_node.decoderawtransaction(tx_hex)) diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 67014c7d73..c4b759fd86 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -352,7 +352,7 @@ def main(): logging.basicConfig(format='%(message)s', level=logging_level) # Create base test directory - tmpdir = "%s/test_runner_₿_🏃_%s" % (args.tmpdirprefix, datetime.datetime.now().strftime("%Y%m%d_%H%M%S")) + tmpdir = "%s/test_runner_%s" % (args.tmpdirprefix, datetime.datetime.now().strftime("%Y%m%d_%H%M%S")) os.makedirs(tmpdir) diff --git a/test/functional/wallet_abandonconflict.py b/test/functional/wallet_abandonconflict.py index 54d4cab7f4..88ac2950d5 100755 --- a/test/functional/wallet_abandonconflict.py +++ b/test/functional/wallet_abandonconflict.py @@ -50,13 +50,13 @@ def run_test(self): # Disconnect nodes so node0's transactions don't get into node1's mempool self.disconnect_nodes(0, 1) - # Identify the 10btc outputs + # Identify the BGL outputs nA = next(tx_out["vout"] for tx_out in self.nodes[0].gettransaction(txA)["details"] if tx_out["amount"] == Decimal("10")) nB = next(tx_out["vout"] for tx_out in self.nodes[0].gettransaction(txB)["details"] if tx_out["amount"] == Decimal("10")) nC = next(tx_out["vout"] for tx_out in self.nodes[0].gettransaction(txC)["details"] if tx_out["amount"] == Decimal("10")) inputs = [] - # spend 10btc outputs from txA and txB + # spend BGL outputs from txA and txB inputs.append({"txid": txA, "vout": nA}) inputs.append({"txid": txB, "vout": nB}) outputs = {} @@ -66,7 +66,7 @@ def run_test(self): signed = self.nodes[0].signrawtransactionwithwallet(self.nodes[0].createrawtransaction(inputs, outputs)) txAB1 = self.nodes[0].sendrawtransaction(signed["hex"]) - # Identify the 14.99998btc output + # Identify the 14.99998BGL output nAB = next(tx_out["vout"] for tx_out in self.nodes[0].gettransaction(txAB1)["details"] if tx_out["amount"] == Decimal("14.99998")) #Create a child tx spending AB1 and C @@ -162,13 +162,13 @@ def run_test(self): self.connect_nodes(0, 1) self.sync_blocks() - # Verify that B and C's 10 BTC outputs are available for spending again because AB1 is now conflicted + # Verify that B and C's 10 BGL outputs are available for spending again because AB1 is now conflicted newbalance = self.nodes[0].getbalance() assert_equal(newbalance, balance + Decimal("20")) balance = newbalance # There is currently a minor bug around this and so this test doesn't work. See Issue #7315 - # Invalidate the block with the double spend and B's 10 BTC output should no longer be available + # Invalidate the block with the double spend and B's 10 BGL output should no longer be available # Don't think C's should either self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) newbalance = self.nodes[0].getbalance() diff --git a/test/functional/wallet_avoidreuse.py b/test/functional/wallet_avoidreuse.py index 29b17955da..817314d1a9 100755 --- a/test/functional/wallet_avoidreuse.py +++ b/test/functional/wallet_avoidreuse.py @@ -164,8 +164,8 @@ def test_change_remains_change(self, node): def test_sending_from_reused_address_without_avoid_reuse(self): ''' - Test the same as test_sending_from_reused_address_fails, except send the 10 BTC with - the avoid_reuse flag set to false. This means the 10 BTC send should succeed, + Test the same as test_sending_from_reused_address_fails, except send the 10 BGL with + the avoid_reuse flag set to false. This means the 10 BGL send should succeed, where it fails in test_sending_from_reused_address_fails. ''' self.log.info("Test sending from reused address with avoid_reuse=false") @@ -177,9 +177,9 @@ def test_sending_from_reused_address_without_avoid_reuse(self): self.nodes[0].generate(1) self.sync_all() - # listunspent should show 1 single, unused 10 btc output + # listunspent should show 1 single, unused 10 BGL output assert_unspent(self.nodes[1], total_count=1, total_sum=10, reused_supported=True, reused_count=0) - # getbalances should show no used, 10 btc trusted + # getbalances should show no used, 10 BGL trusted assert_balances(self.nodes[1], mine={"used": 0, "trusted": 10}) # node 0 should not show a used entry, as it does not enable avoid_reuse assert("used" not in self.nodes[0].getbalances()["mine"]) @@ -188,39 +188,39 @@ def test_sending_from_reused_address_without_avoid_reuse(self): self.nodes[0].generate(1) self.sync_all() - # listunspent should show 1 single, unused 5 btc output + # listunspent should show 1 single, unused 5 BGL output assert_unspent(self.nodes[1], total_count=1, total_sum=5, reused_supported=True, reused_count=0) - # getbalances should show no used, 5 btc trusted + # getbalances should show no used, 5 BGL trusted assert_balances(self.nodes[1], mine={"used": 0, "trusted": 5}) self.nodes[0].sendtoaddress(fundaddr, 10) self.nodes[0].generate(1) self.sync_all() - # listunspent should show 2 total outputs (5, 10 btc), one unused (5), one reused (10) + # listunspent should show 2 total outputs (5, 10 BGL), one unused (5), one reused (10) assert_unspent(self.nodes[1], total_count=2, total_sum=15, reused_count=1, reused_sum=10) - # getbalances should show 10 used, 5 btc trusted + # getbalances should show 10 used, 5 BGL trusted assert_balances(self.nodes[1], mine={"used": 10, "trusted": 5}) self.nodes[1].sendtoaddress(address=retaddr, amount=10, avoid_reuse=False) - # listunspent should show 1 total outputs (5 btc), unused + # listunspent should show 1 total outputs (5 BGL), unused assert_unspent(self.nodes[1], total_count=1, total_sum=5, reused_count=0) - # getbalances should show no used, 5 btc trusted + # getbalances should show no used, 5 BGL trusted assert_balances(self.nodes[1], mine={"used": 0, "trusted": 5}) - # node 1 should now have about 5 btc left (for both cases) + # node 1 should now have about 5 BGL left (for both cases) assert_approx(self.nodes[1].getbalance(), 5, 0.001) assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 5, 0.001) def test_sending_from_reused_address_fails(self, second_addr_type): ''' Test the simple case where [1] generates a new address A, then - [0] sends 10 BTC to A. - [1] spends 5 BTC from A. (leaving roughly 5 BTC useable) - [0] sends 10 BTC to A again. - [1] tries to spend 10 BTC (fails; dirty). - [1] tries to spend 4 BTC (succeeds; change address sufficient) + [0] sends 10 BGL to A. + [1] spends 5 BGL from A. (leaving roughly 5 BGL useable) + [0] sends 10 BGL to A again. + [1] tries to spend 10 BGL (fails; dirty). + [1] tries to spend 4 BGL (succeeds; change address sufficient) ''' self.log.info("Test sending from reused {} address fails".format(second_addr_type)) @@ -231,18 +231,18 @@ def test_sending_from_reused_address_fails(self, second_addr_type): self.nodes[0].generate(1) self.sync_all() - # listunspent should show 1 single, unused 10 btc output + # listunspent should show 1 single, unused 10 BGL output assert_unspent(self.nodes[1], total_count=1, total_sum=10, reused_supported=True, reused_count=0) - # getbalances should show no used, 10 btc trusted + # getbalances should show no used, 10 BGL trusted assert_balances(self.nodes[1], mine={"used": 0, "trusted": 10}) self.nodes[1].sendtoaddress(retaddr, 5) self.nodes[0].generate(1) self.sync_all() - # listunspent should show 1 single, unused 5 btc output + # listunspent should show 1 single, unused 5 BGL output assert_unspent(self.nodes[1], total_count=1, total_sum=5, reused_supported=True, reused_count=0) - # getbalances should show no used, 5 btc trusted + # getbalances should show no used, 5 BGL trusted assert_balances(self.nodes[1], mine={"used": 0, "trusted": 5}) if not self.options.descriptors: @@ -262,9 +262,9 @@ def test_sending_from_reused_address_fails(self, second_addr_type): self.nodes[0].generate(1) self.sync_all() - # listunspent should show 2 total outputs (5, 10 btc), one unused (5), one reused (10) + # listunspent should show 2 total outputs (5, 10 BGL), one unused (5), one reused (10) assert_unspent(self.nodes[1], total_count=2, total_sum=15, reused_count=1, reused_sum=10) - # getbalances should show 10 used, 5 btc trusted + # getbalances should show 10 used, 5 BGL trusted assert_balances(self.nodes[1], mine={"used": 10, "trusted": 5}) # node 1 should now have a balance of 5 (no dirty) or 15 (including dirty) @@ -275,12 +275,12 @@ def test_sending_from_reused_address_fails(self, second_addr_type): self.nodes[1].sendtoaddress(retaddr, 4) - # listunspent should show 2 total outputs (1, 10 btc), one unused (1), one reused (10) + # listunspent should show 2 total outputs (1, 10 BGL), one unused (1), one reused (10) assert_unspent(self.nodes[1], total_count=2, total_sum=11, reused_count=1, reused_sum=10) - # getbalances should show 10 used, 1 btc trusted + # getbalances should show 10 used, 1 BGL trusted assert_balances(self.nodes[1], mine={"used": 10, "trusted": 1}) - # node 1 should now have about 1 btc left (no dirty) and 11 (including dirty) + # node 1 should now have about 1 BGL left (no dirty) and 11 (including dirty) assert_approx(self.nodes[1].getbalance(), 1, 0.001) assert_approx(self.nodes[1].getbalance(avoid_reuse=False), 11, 0.001) @@ -316,10 +316,10 @@ def test_getbalances_used(self): def test_full_destination_group_is_preferred(self): ''' - Test the case where [1] only has 11 outputs of 1 BTC in the same reused - address and tries to send a small payment of 0.5 BTC. The wallet + Test the case where [1] only has 11 outputs of 1 BGL in the same reused + address and tries to send a small payment of 0.5 BGL. The wallet should use 10 outputs from the reused address as inputs and not a - single 1 BTC input, in order to join several outputs from the reused + single 1 BGL input, in order to join several outputs from the reused address. ''' self.log.info("Test that full destination groups are preferred in coin selection") @@ -330,7 +330,7 @@ def test_full_destination_group_is_preferred(self): new_addr = self.nodes[1].getnewaddress() ret_addr = self.nodes[0].getnewaddress() - # Send 11 outputs of 1 BTC to the same, reused address in the wallet + # Send 11 outputs of 1 BGL to the same, reused address in the wallet for _ in range(11): self.nodes[0].sendtoaddress(new_addr, 1) @@ -347,8 +347,8 @@ def test_full_destination_group_is_preferred(self): def test_all_destination_groups_are_used(self): ''' - Test the case where [1] only has 22 outputs of 1 BTC in the same reused - address and tries to send a payment of 20.5 BTC. The wallet + Test the case where [1] only has 22 outputs of 1 BGL in the same reused + address and tries to send a payment of 20.5 BGL. The wallet should use all 22 outputs from the reused address as inputs. ''' self.log.info("Test that all destination groups are used") @@ -359,7 +359,7 @@ def test_all_destination_groups_are_used(self): new_addr = self.nodes[1].getnewaddress() ret_addr = self.nodes[0].getnewaddress() - # Send 22 outputs of 1 BTC to the same, reused address in the wallet + # Send 22 outputs of 1 BGL to the same, reused address in the wallet for _ in range(22): self.nodes[0].sendtoaddress(new_addr, 1) diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py index ee7af2a881..e19da88787 100755 --- a/test/functional/wallet_backup.py +++ b/test/functional/wallet_backup.py @@ -8,7 +8,7 @@ 4 nodes. 1 2 and 3 send transactions between each other, fourth node is a miner. 1 2 3 each mine a block to start, then -Miner creates 100 blocks so 1 2 3 each have 50 mature +Miner creates 100 blocks so 1 2 3 each have 200 mature coins to spend. Then 5 iterations of 1/2/3 sending coins amongst themselves to get transactions in the wallets, @@ -21,7 +21,7 @@ transaction fees paid mature. Sanity check: - Sum(1,2,3,4 balances) == 114*50 + Sum(1,2,3,4 balances) == 114*200 1/2/3 are shutdown, and their wallets erased. Then restore using wallet.dat backup. And @@ -126,9 +126,9 @@ def run_test(self): self.nodes[3].generate(100) self.sync_blocks() - assert_equal(self.nodes[0].getbalance(), 50) - assert_equal(self.nodes[1].getbalance(), 50) - assert_equal(self.nodes[2].getbalance(), 50) + assert_equal(self.nodes[0].getbalance(), 200) + assert_equal(self.nodes[1].getbalance(), 200) + assert_equal(self.nodes[2].getbalance(), 200) assert_equal(self.nodes[3].getbalance(), 0) self.log.info("Creating transactions") @@ -162,8 +162,8 @@ def run_test(self): total = balance0 + balance1 + balance2 + balance3 # At this point, there are 214 blocks (103 for setup, then 10 rounds, then 101.) - # 114 are mature, so the sum of all wallets should be 114 * 50 = 5700. - assert_equal(total, 5700) + # 114 are mature, so the sum of all wallets should be 114 * 200 = 22800. + assert_equal(round(total), 22800) ## # Test restoring spender wallets from backups diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py index a533a93beb..51e7053b11 100755 --- a/test/functional/wallet_balance.py +++ b/test/functional/wallet_balance.py @@ -77,35 +77,35 @@ def run_test(self): if not self.options.descriptors: # Tests legacy watchonly behavior which is not present (and does not need to be tested) in descriptor wallets - assert_equal(self.nodes[0].getbalances()['mine']['trusted'], 50) - assert_equal(self.nodes[0].getwalletinfo()['balance'], 50) - assert_equal(self.nodes[1].getbalances()['mine']['trusted'], 50) + assert_equal(self.nodes[0].getbalances()['mine']['trusted'], 200) + assert_equal(self.nodes[0].getwalletinfo()['balance'], 200) + assert_equal(self.nodes[1].getbalances()['mine']['trusted'], 200) - assert_equal(self.nodes[0].getbalances()['watchonly']['immature'], 5000) + assert_equal(self.nodes[0].getbalances()['watchonly']['immature'], 20000) assert 'watchonly' not in self.nodes[1].getbalances() - assert_equal(self.nodes[0].getbalance(), 50) - assert_equal(self.nodes[1].getbalance(), 50) + assert_equal(self.nodes[0].getbalance(), 200) + assert_equal(self.nodes[1].getbalance(), 200) self.log.info("Test getbalance with different arguments") - assert_equal(self.nodes[0].getbalance("*"), 50) - assert_equal(self.nodes[0].getbalance("*", 1), 50) - assert_equal(self.nodes[0].getbalance(minconf=1), 50) + assert_equal(self.nodes[0].getbalance("*"), 200) + assert_equal(self.nodes[0].getbalance("*", 1), 200) + assert_equal(self.nodes[0].getbalance(minconf=1), 200) if not self.options.descriptors: - assert_equal(self.nodes[0].getbalance(minconf=0, include_watchonly=True), 100) - assert_equal(self.nodes[0].getbalance("*", 1, True), 100) + assert_equal(self.nodes[0].getbalance(minconf=0, include_watchonly=True), 400) + assert_equal(self.nodes[0].getbalance("*", 1, True), 400) else: - assert_equal(self.nodes[0].getbalance(minconf=0, include_watchonly=True), 50) - assert_equal(self.nodes[0].getbalance("*", 1, True), 50) - assert_equal(self.nodes[1].getbalance(minconf=0, include_watchonly=True), 50) + assert_equal(self.nodes[0].getbalance(minconf=0, include_watchonly=True), 200) + assert_equal(self.nodes[0].getbalance("*", 1, True), 200) + assert_equal(self.nodes[1].getbalance(minconf=0, include_watchonly=True), 200) - # Send 40 BTC from 0 to 1 and 60 BTC from 1 to 0. + # Send 40 BGL from 0 to 1 and 210 BGL from 1 to 0. txs = create_transactions(self.nodes[0], self.nodes[1].getnewaddress(), 40, [Decimal('0.01')]) self.nodes[0].sendrawtransaction(txs[0]['hex']) self.nodes[1].sendrawtransaction(txs[0]['hex']) # sending on both nodes is faster than waiting for propagation self.sync_all() - txs = create_transactions(self.nodes[1], self.nodes[0].getnewaddress(), 60, [Decimal('0.01'), Decimal('0.02')]) + txs = create_transactions(self.nodes[1], self.nodes[0].getnewaddress(), 210, [Decimal('0.01'), Decimal('0.02')]) self.nodes[1].sendrawtransaction(txs[0]['hex']) self.nodes[0].sendrawtransaction(txs[0]['hex']) # sending on both nodes is faster than waiting for propagation self.sync_all() @@ -115,11 +115,11 @@ def run_test(self): self.log.info("Test balances with unconfirmed inputs") - # Before `test_balance()`, we have had two nodes with a balance of 50 + # Before `test_balance()`, we have had two nodes with a balance of 200 # each and then we: # # 1) Sent 40 from node A to node B with fee 0.01 - # 2) Sent 60 from node B to node A with fee 0.01 + # 2) Sent 210 from node B to node A with fee 0.01 # # Then we check the balances: # @@ -148,18 +148,18 @@ def run_test(self): # 1) Sent 40 from node A to node B with fee 0.01 # 2) Sent 10 from node B to node A with fee 0.01 # - # Then our node would report a confirmed balance of 40 + 50 - 10 = 80 - # BTC, which is more than would be available if transaction 1 were + # Then our node would report a confirmed balance of 40 + 200 - 10 = 230 + # BGL, which is more than would be available if transaction 1 were # replaced. def test_balances(*, fee_node_1=0): # getbalances expected_balances_0 = {'mine': {'immature': Decimal('0E-8'), - 'trusted': Decimal('9.99'), # change from node 0's send - 'untrusted_pending': Decimal('60.0')}, - 'watchonly': {'immature': Decimal('5000'), - 'trusted': Decimal('50.0'), + 'trusted': Decimal('159.99'), # change from node 0's send + 'untrusted_pending': Decimal('210.0')}, + 'watchonly': {'immature': Decimal('20000'), + 'trusted': Decimal('200.0'), 'untrusted_pending': Decimal('0E-8')}} expected_balances_1 = {'mine': {'immature': Decimal('0E-8'), 'trusted': Decimal('0E-8'), # node 1's send had an unsafe input @@ -169,20 +169,20 @@ def test_balances(*, fee_node_1=0): assert_equal(self.nodes[0].getbalances(), expected_balances_0) assert_equal(self.nodes[1].getbalances(), expected_balances_1) # getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions - assert_equal(self.nodes[0].getbalance(), Decimal('9.99')) # change from node 0's send + assert_equal(self.nodes[0].getbalance(), Decimal('159.99')) # change from node 0's send assert_equal(self.nodes[1].getbalance(), Decimal('0')) # node 1's send had an unsafe input # Same with minconf=0 - assert_equal(self.nodes[0].getbalance(minconf=0), Decimal('9.99')) + assert_equal(self.nodes[0].getbalance(minconf=0), Decimal('159.99')) assert_equal(self.nodes[1].getbalance(minconf=0), Decimal('0')) # getbalance with a minconf incorrectly excludes coins that have been spent more recently than the minconf blocks ago # TODO: fix getbalance tracking of coin spentness depth assert_equal(self.nodes[0].getbalance(minconf=1), Decimal('0')) assert_equal(self.nodes[1].getbalance(minconf=1), Decimal('0')) # getunconfirmedbalance - assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) # output of node 1's spend + assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('210')) # output of node 1's spend assert_equal(self.nodes[1].getunconfirmedbalance(), Decimal('30') - fee_node_1) # Doesn't include output of node 0's send since it was spent # getwalletinfo.unconfirmed_balance - assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], Decimal('60')) + assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], Decimal('210')) assert_equal(self.nodes[1].getwalletinfo()["unconfirmed_balance"], Decimal('30') - fee_node_1) test_balances(fee_node_1=Decimal('0.01')) @@ -199,7 +199,7 @@ def test_balances(*, fee_node_1=0): self.sync_all() # balances are correct after the transactions are confirmed - balance_node0 = Decimal('69.99') # node 1's send plus change from node 0's send + balance_node0 = Decimal('369.99') # node 1's send plus change from node 0's send balance_node1 = Decimal('29.98') # change from node 0's send assert_equal(self.nodes[0].getbalances()['mine']['trusted'], balance_node0) assert_equal(self.nodes[1].getbalances()['mine']['trusted'], balance_node1) @@ -235,7 +235,7 @@ def test_balances(*, fee_node_1=0): # mempool because it is the third descendant of the tx above for _ in range(3): # Set amount high enough such that all coins are spent by each tx - txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 99) + txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 99*4) self.log.info('Check that wallet txs not in the mempool are untrusted') assert txid not in self.nodes[0].getrawmempool() @@ -246,8 +246,8 @@ def test_balances(*, fee_node_1=0): tx_orig = self.nodes[0].gettransaction(txid)['hex'] # Increase fee by 1 coin tx_replace = tx_orig.replace( - struct.pack("