From c2e4edb7ecca93e0b72975c8c6f90a2f3beeeebc Mon Sep 17 00:00:00 2001 From: Jianping Wu Date: Thu, 7 Feb 2019 13:50:53 -0800 Subject: [PATCH] Fixed wallet_account test. Only supported legacy address in regtest. Fixed wallet_backup test. Fixed wallet_basic. Fixed wallet_multiwallet and txn_clone. Fixed txn_doublespend test case. --- src/wallet/rpcwallet.cpp | 4 +- test/functional/test_framework/util.py | 4 +- test/functional/wallet_accounts.py | 26 ++++++------ test/functional/wallet_backup.py | 8 ++-- test/functional/wallet_basic.py | 24 +++++------ test/functional/wallet_multiwallet.py | 6 +-- test/functional/wallet_txn_clone.py | 16 ++++---- test/functional/wallet_txn_doublespend.py | 50 +++++++++++------------ 8 files changed, 70 insertions(+), 68 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3d9a3bc94..709bb9340 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -167,7 +167,9 @@ UniValue getnewaddress(const JSONRPCRequest& request) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[1].get_str())); } if (output_type == OUTPUT_TYPE_LEGACY) { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Legacy address type not supported")); + if (ChainNameFromCommandLine() != CBaseChainParams::REGTEST) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Legacy address type not supported")); + } } } diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 3046de52a..6a889d6cd 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -28,10 +28,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 LTC too low! (Should be %s LTC)" % (str(fee), str(target_fee))) + raise AssertionError("Fee of %s KVA too low! (Should be %s LTC)" % (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 LTC too high! (Should be %s LTC)" % (str(fee), str(target_fee))) + raise AssertionError("Fee of %s KVA too high! (Should be %s LTC)" % (str(fee), str(target_fee))) def assert_equal(thing1, thing2, *args): if thing1 != thing2 or any(thing1 != arg for arg in args): diff --git a/test/functional/wallet_accounts.py b/test/functional/wallet_accounts.py index ecd1cfc82..c98ff1f23 100755 --- a/test/functional/wallet_accounts.py +++ b/test/functional/wallet_accounts.py @@ -28,13 +28,13 @@ class WalletAccountsTest(BitcoinTestFramework): assert_equal(len(node.listunspent()), 0) # Note each time we call generate, all generated coins go into - # the same address, so we call twice to get two addresses w/50 each + # the same address, so we call twice to get two addresses w/500 each node.generate(1) node.generate(101) - assert_equal(node.getbalance(), 100) + assert_equal(node.getbalance(), 1000) # there should be 2 address groups - # each with 1 address with a balance of 50 Bitcoins + # each with 1 address with a balance of 500 Kevacoins address_groups = node.listaddressgroupings() assert_equal(len(address_groups), 2) # the addresses aren't linked now, but will be after we send to the @@ -43,16 +43,16 @@ class WalletAccountsTest(BitcoinTestFramework): for address_group in address_groups: assert_equal(len(address_group), 1) assert_equal(len(address_group[0]), 2) - assert_equal(address_group[0][1], 50) + assert_equal(address_group[0][1], 500) linked_addresses.add(address_group[0][0]) - # send 50 from each address to a third address not in this wallet + # send 500 from each address to a third address not in this wallet # There's some fee that will come back to us when the miner reward # matures. common_address = "msf4WtN1YQKXvNtvdFYt9JBnUD2FB41kjr" txid = node.sendmany( fromaccount="", - amounts={common_address: 100}, + amounts={common_address: 1000}, subtractfeefrom=[common_address], minconf=1, ) @@ -94,7 +94,7 @@ class WalletAccountsTest(BitcoinTestFramework): assert_equal( node.getreceivedbyaddress(account.addresses[0]), amount_to_send) assert_equal(node.getreceivedbyaccount(account.name), amount_to_send) - + # Check that sendfrom account reduces listaccounts balances. for i, account in enumerate(accounts): to_account = accounts[(i+1) % len(accounts)] @@ -107,12 +107,12 @@ class WalletAccountsTest(BitcoinTestFramework): node.move(account.name, "", node.getbalance(account.name)) account.verify(node) node.generate(101) - expected_account_balances = {"": 5200} + expected_account_balances = {"": 52000} for account in accounts: expected_account_balances[account.name] = 0 assert_equal(node.listaccounts(), expected_account_balances) - assert_equal(node.getbalance(""), 5200) - + assert_equal(node.getbalance(""), 52000) + # Check that setaccount can assign an account to a new unused address. for account in accounts: address = node.getaccountaddress("") @@ -120,7 +120,7 @@ class WalletAccountsTest(BitcoinTestFramework): account.add_address(address) account.verify(node) assert(address not in node.getaddressesbyaccount("")) - + # Check that addmultisigaddress can assign accounts. for account in accounts: addresses = [] @@ -129,10 +129,10 @@ class WalletAccountsTest(BitcoinTestFramework): multisig_address = node.addmultisigaddress(5, addresses, account.name)['address'] account.add_address(multisig_address) account.verify(node) - node.sendfrom("", multisig_address, 50) + node.sendfrom("", multisig_address, 500) node.generate(101) for account in accounts: - assert_equal(node.getbalance(account.name), 50) + assert_equal(node.getbalance(account.name), 500) # Check that setaccount can change the account of an address from a # different account. diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py index b4be7debb..66f408370 100755 --- a/test/functional/wallet_backup.py +++ b/test/functional/wallet_backup.py @@ -105,9 +105,9 @@ class WalletBackupTest(BitcoinTestFramework): self.nodes[3].generate(100) sync_blocks(self.nodes) - 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(), 500) + assert_equal(self.nodes[1].getbalance(), 500) + assert_equal(self.nodes[2].getbalance(), 500) assert_equal(self.nodes[3].getbalance(), 0) self.log.info("Creating transactions") @@ -140,7 +140,7 @@ class WalletBackupTest(BitcoinTestFramework): # 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) + assert_equal(total, 57000) ## # Test restoring spender wallets from backups diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index 050620f1d..a36dab3d9 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -41,15 +41,15 @@ class WalletTest(BitcoinTestFramework): self.nodes[0].generate(1) walletinfo = self.nodes[0].getwalletinfo() - assert_equal(walletinfo['immature_balance'], 50) + assert_equal(walletinfo['immature_balance'], 500) assert_equal(walletinfo['balance'], 0) self.sync_all([self.nodes[0:3]]) self.nodes[1].generate(101) self.sync_all([self.nodes[0:3]]) - assert_equal(self.nodes[0].getbalance(), 50) - assert_equal(self.nodes[1].getbalance(), 50) + assert_equal(self.nodes[0].getbalance(), 500) + assert_equal(self.nodes[1].getbalance(), 500) assert_equal(self.nodes[2].getbalance(), 0) # Check that only first and second nodes have UTXOs @@ -63,10 +63,10 @@ class WalletTest(BitcoinTestFramework): # First, outputs that are unspent both in the chain and in the # mempool should appear with or without include_mempool txout = self.nodes[0].gettxout(txid=confirmed_txid, n=confirmed_index, include_mempool=False) - assert_equal(txout['value'], 50) + assert_equal(txout['value'], 500) txout = self.nodes[0].gettxout(txid=confirmed_txid, n=confirmed_index, include_mempool=True) - assert_equal(txout['value'], 50) - + assert_equal(txout['value'], 500) + # Send 21 BTC from 0 to 2 using sendtoaddress call. # Locked memory should use at least 32 bytes to sign each transaction self.log.info("test getmemoryinfo") @@ -80,7 +80,7 @@ class WalletTest(BitcoinTestFramework): # utxo spent in mempool should be visible if you exclude mempool # but invisible if you include mempool txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, False) - assert_equal(txout['value'], 50) + assert_equal(txout['value'], 500) txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, True) assert txout is None # new utxo from mempool should be invisible if you exclude mempool @@ -123,7 +123,7 @@ class WalletTest(BitcoinTestFramework): # node0 should end up with 100 btc in block rewards plus fees, but # minus the 21 plus fees sent to node2 - assert_equal(self.nodes[0].getbalance(), 100-21) + assert_equal(self.nodes[0].getbalance(), 1000-21) assert_equal(self.nodes[2].getbalance(), 21) # Node0 should have two unspent outputs. @@ -151,8 +151,8 @@ class WalletTest(BitcoinTestFramework): self.sync_all([self.nodes[0:3]]) assert_equal(self.nodes[0].getbalance(), 0) - assert_equal(self.nodes[2].getbalance(), 94) - assert_equal(self.nodes[2].getbalance("from1"), 94-21) + assert_equal(self.nodes[2].getbalance(), 994) + assert_equal(self.nodes[2].getbalance("from1"), 994-21) # Verify that a spent output cannot be locked anymore spent_0 = {"txid": node0utxos[0]["txid"], "vout": node0utxos[0]["vout"]} @@ -165,7 +165,7 @@ class WalletTest(BitcoinTestFramework): txid = self.nodes[2].sendtoaddress(address, 10, "", "", False) self.nodes[2].generate(1) self.sync_all([self.nodes[0:3]]) - node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) + node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('984'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) assert_equal(self.nodes[0].getbalance(), Decimal('10')) # Send 10 BTC with subtract fee from amount @@ -221,7 +221,7 @@ class WalletTest(BitcoinTestFramework): #4. check if recipient (node0) can list the zero value tx usp = self.nodes[1].listunspent() inputs = [{"txid":usp[0]['txid'], "vout":usp[0]['vout']}] - outputs = {self.nodes[1].getnewaddress(): 49.998, self.nodes[0].getnewaddress(): 11.11} + outputs = {self.nodes[1].getnewaddress(): 499.998, self.nodes[0].getnewaddress(): 11.11} rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace("c0833842", "00000000") #replace 11.11 with 0.0 (int32) decRawTx = self.nodes[1].decoderawtransaction(rawTx) diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index 3a34c43b7..3e6334787 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -83,7 +83,7 @@ class MultiWalletTest(BitcoinTestFramework): assert_equal(set(node.listwallets()), {"w4", "w5"}) w5 = wallet("w5") w5_info = w5.getwalletinfo() - assert_equal(w5_info['immature_balance'], 50) + assert_equal(w5_info['immature_balance'], 500) competing_wallet_dir = os.path.join(self.options.tmpdir, 'competing_walletdir') os.mkdir(competing_wallet_dir) @@ -108,7 +108,7 @@ class MultiWalletTest(BitcoinTestFramework): # check w1 wallet balance w1_info = w1.getwalletinfo() - assert_equal(w1_info['immature_balance'], 50) + assert_equal(w1_info['immature_balance'], 500) w1_name = w1_info['walletname'] assert_equal(w1_name, "w1") @@ -125,7 +125,7 @@ class MultiWalletTest(BitcoinTestFramework): assert_equal(w4_name, "w") w1.generate(101) - assert_equal(w1.getbalance(), 100) + assert_equal(w1.getbalance(), 1000) assert_equal(w2.getbalance(), 0) assert_equal(w3.getbalance(), 0) assert_equal(w4.getbalance(), 0) diff --git a/test/functional/wallet_txn_clone.py b/test/functional/wallet_txn_clone.py index ce26d6e0e..82bf9541e 100755 --- a/test/functional/wallet_txn_clone.py +++ b/test/functional/wallet_txn_clone.py @@ -30,7 +30,7 @@ class TxnMallTest(BitcoinTestFramework): output_type="legacy" # All nodes should start with 1,250 BTC: - starting_balance = 1250 + starting_balance = 12500 for i in range(4): assert_equal(self.nodes[i].getbalance(), starting_balance) self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress! @@ -52,11 +52,11 @@ class TxnMallTest(BitcoinTestFramework): # Coins are sent to node1_address node1_address = self.nodes[1].getnewaddress("from0") - # Send tx1, and another transaction tx2 that won't be cloned + # Send tx1, and another transaction tx2 that won't be cloned txid1 = self.nodes[0].sendfrom("foo", node1_address, 40, 0) txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0) - # Construct a clone of tx1, to be malleated + # Construct a clone of tx1, to be malleated rawtx1 = self.nodes[0].getrawtransaction(txid1,1) clone_inputs = [{"txid":rawtx1["vin"][0]["txid"],"vout":rawtx1["vin"][0]["vout"]}] clone_outputs = {rawtx1["vout"][0]["scriptPubKey"]["addresses"][0]:rawtx1["vout"][0]["value"], @@ -131,7 +131,7 @@ class TxnMallTest(BitcoinTestFramework): tx1 = self.nodes[0].gettransaction(txid1) tx1_clone = self.nodes[0].gettransaction(txid1_clone) tx2 = self.nodes[0].gettransaction(txid2) - + # Verify expected confirmations assert_equal(tx1["confirmations"], -2) assert_equal(tx1_clone["confirmations"], 2) @@ -139,9 +139,9 @@ class TxnMallTest(BitcoinTestFramework): # Check node0's total balance; should be same as before the clone, + 100 BTC for 2 matured, # less possible orphaned matured subsidy - expected += 100 - if (self.options.mine_block): - expected -= 50 + expected += 1000 + if (self.options.mine_block): + expected -= 500 assert_equal(self.nodes[0].getbalance(), expected) assert_equal(self.nodes[0].getbalance("*", 0), expected) @@ -156,7 +156,7 @@ class TxnMallTest(BitcoinTestFramework): + fund_foo_tx["fee"] - 29 + fund_bar_tx["fee"] - + 100) + + 1000) # Node1's "from0" account balance assert_equal(self.nodes[1].getbalance("from0", 0), -(tx1["amount"] + tx2["amount"])) diff --git a/test/functional/wallet_txn_doublespend.py b/test/functional/wallet_txn_doublespend.py index 01129f381..49d4cc39c 100755 --- a/test/functional/wallet_txn_doublespend.py +++ b/test/functional/wallet_txn_doublespend.py @@ -23,22 +23,22 @@ class TxnMallTest(BitcoinTestFramework): def run_test(self): # All nodes should start with 1,250 BTC: - starting_balance = 1250 + starting_balance = 12500 for i in range(4): assert_equal(self.nodes[i].getbalance(), starting_balance) self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress! - + # Assign coins to foo and bar accounts: node0_address_foo = self.nodes[0].getnewaddress("foo") - fund_foo_txid = self.nodes[0].sendfrom("", node0_address_foo, 1219) + fund_foo_txid = self.nodes[0].sendfrom("", node0_address_foo, 12190) fund_foo_tx = self.nodes[0].gettransaction(fund_foo_txid) node0_address_bar = self.nodes[0].getnewaddress("bar") - fund_bar_txid = self.nodes[0].sendfrom("", node0_address_bar, 29) + fund_bar_txid = self.nodes[0].sendfrom("", node0_address_bar, 290) fund_bar_tx = self.nodes[0].gettransaction(fund_bar_txid) assert_equal(self.nodes[0].getbalance(""), - starting_balance - 1219 - 29 + fund_foo_tx["fee"] + fund_bar_tx["fee"]) + starting_balance - 12190 - 290 + fund_foo_tx["fee"] + fund_bar_tx["fee"]) # Coins are sent to node1_address node1_address = self.nodes[1].getnewaddress("from0") @@ -48,23 +48,23 @@ class TxnMallTest(BitcoinTestFramework): doublespend_fee = Decimal('-.02') rawtx_input_0 = {} rawtx_input_0["txid"] = fund_foo_txid - rawtx_input_0["vout"] = find_output(self.nodes[0], fund_foo_txid, 1219) + rawtx_input_0["vout"] = find_output(self.nodes[0], fund_foo_txid, 12190) rawtx_input_1 = {} rawtx_input_1["txid"] = fund_bar_txid - rawtx_input_1["vout"] = find_output(self.nodes[0], fund_bar_txid, 29) + rawtx_input_1["vout"] = find_output(self.nodes[0], fund_bar_txid, 290) inputs = [rawtx_input_0, rawtx_input_1] change_address = self.nodes[0].getnewaddress() outputs = {} - outputs[node1_address] = 1240 - outputs[change_address] = 1248 - 1240 + doublespend_fee + outputs[node1_address] = 12400 + outputs[change_address] = 12480 - 12400 + doublespend_fee rawtx = self.nodes[0].createrawtransaction(inputs, outputs) doublespend = self.nodes[0].signrawtransaction(rawtx) assert_equal(doublespend["complete"], True) # Create two spends using 1 50 BTC coin each - txid1 = self.nodes[0].sendfrom("foo", node1_address, 40, 0) - txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0) - + txid1 = self.nodes[0].sendfrom("foo", node1_address, 400, 0) + txid2 = self.nodes[0].sendfrom("bar", node1_address, 200, 0) + # Have node0 mine a block: if (self.options.mine_block): self.nodes[0].generate(1) @@ -76,14 +76,14 @@ class TxnMallTest(BitcoinTestFramework): # Node0's balance should be starting balance, plus 50BTC for another # matured block, minus 40, minus 20, and minus transaction fees: expected = starting_balance + fund_foo_tx["fee"] + fund_bar_tx["fee"] - if self.options.mine_block: expected += 50 + if self.options.mine_block: expected += 500 expected += tx1["amount"] + tx1["fee"] expected += tx2["amount"] + tx2["fee"] assert_equal(self.nodes[0].getbalance(), expected) # foo and bar accounts should be debited: - assert_equal(self.nodes[0].getbalance("foo", 0), 1219+tx1["amount"]+tx1["fee"]) - assert_equal(self.nodes[0].getbalance("bar", 0), 29+tx2["amount"]+tx2["fee"]) + assert_equal(self.nodes[0].getbalance("foo", 0), 12190+tx1["amount"]+tx1["fee"]) + assert_equal(self.nodes[0].getbalance("bar", 0), 290+tx2["amount"]+tx2["fee"]) if self.options.mine_block: assert_equal(tx1["confirmations"], 1) @@ -93,7 +93,7 @@ class TxnMallTest(BitcoinTestFramework): else: assert_equal(tx1["confirmations"], 0) assert_equal(tx2["confirmations"], 0) - + # Now give doublespend and its parents to miner: self.nodes[2].sendrawtransaction(fund_foo_tx["hex"]) self.nodes[2].sendrawtransaction(fund_bar_tx["hex"]) @@ -115,28 +115,28 @@ class TxnMallTest(BitcoinTestFramework): assert_equal(tx1["confirmations"], -2) assert_equal(tx2["confirmations"], -2) - # Node0's total balance should be starting balance, plus 100BTC for + # Node0's total balance should be starting balance, plus 100BTC for # two more matured blocks, minus 1240 for the double-spend, plus fees (which are # negative): - expected = starting_balance + 100 - 1240 + fund_foo_tx["fee"] + fund_bar_tx["fee"] + doublespend_fee + expected = starting_balance + 1000 - 12400 + fund_foo_tx["fee"] + fund_bar_tx["fee"] + doublespend_fee assert_equal(self.nodes[0].getbalance(), expected) assert_equal(self.nodes[0].getbalance("*"), expected) # Final "" balance is starting_balance - amount moved to accounts - doublespend + subsidies + # fees (which are negative) - assert_equal(self.nodes[0].getbalance("foo"), 1219) - assert_equal(self.nodes[0].getbalance("bar"), 29) + assert_equal(self.nodes[0].getbalance("foo"), 12190) + assert_equal(self.nodes[0].getbalance("bar"), 290) assert_equal(self.nodes[0].getbalance(""), starting_balance - -1219 - - 29 - -1240 - + 100 + -12190 + - 290 + -12400 + + 1000 + fund_foo_tx["fee"] + fund_bar_tx["fee"] + doublespend_fee) # Node1's "from0" account balance should be just the doublespend: - assert_equal(self.nodes[1].getbalance("from0"), 1240) + assert_equal(self.nodes[1].getbalance("from0"), 12400) if __name__ == '__main__': TxnMallTest().main()