Browse Source

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.
cn
Jianping Wu 6 years ago
parent
commit
c2e4edb7ec
  1. 4
      src/wallet/rpcwallet.cpp
  2. 4
      test/functional/test_framework/util.py
  3. 20
      test/functional/wallet_accounts.py
  4. 8
      test/functional/wallet_backup.py
  5. 22
      test/functional/wallet_basic.py
  6. 6
      test/functional/wallet_multiwallet.py
  7. 8
      test/functional/wallet_txn_clone.py
  8. 42
      test/functional/wallet_txn_doublespend.py

4
src/wallet/rpcwallet.cpp

@ -167,7 +167,9 @@ UniValue getnewaddress(const JSONRPCRequest& request) @@ -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"));
}
}
}

4
test/functional/test_framework/util.py

@ -28,10 +28,10 @@ def assert_fee_amount(fee, tx_size, fee_per_kB): @@ -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):

20
test/functional/wallet_accounts.py

@ -28,13 +28,13 @@ class WalletAccountsTest(BitcoinTestFramework): @@ -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): @@ -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,
)
@ -107,11 +107,11 @@ class WalletAccountsTest(BitcoinTestFramework): @@ -107,11 +107,11 @@ 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:
@ -129,10 +129,10 @@ class WalletAccountsTest(BitcoinTestFramework): @@ -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.

8
test/functional/wallet_backup.py

@ -105,9 +105,9 @@ class WalletBackupTest(BitcoinTestFramework): @@ -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): @@ -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

22
test/functional/wallet_basic.py

@ -41,15 +41,15 @@ class WalletTest(BitcoinTestFramework): @@ -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,9 +63,9 @@ class WalletTest(BitcoinTestFramework): @@ -63,9 +63,9 @@ 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
@ -80,7 +80,7 @@ class WalletTest(BitcoinTestFramework): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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)

6
test/functional/wallet_multiwallet.py

@ -83,7 +83,7 @@ class MultiWalletTest(BitcoinTestFramework): @@ -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): @@ -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): @@ -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)

8
test/functional/wallet_txn_clone.py

@ -30,7 +30,7 @@ class TxnMallTest(BitcoinTestFramework): @@ -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!
@ -139,9 +139,9 @@ class TxnMallTest(BitcoinTestFramework): @@ -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
expected += 1000
if (self.options.mine_block):
expected -= 50
expected -= 500
assert_equal(self.nodes[0].getbalance(), expected)
assert_equal(self.nodes[0].getbalance("*", 0), expected)
@ -156,7 +156,7 @@ class TxnMallTest(BitcoinTestFramework): @@ -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"]))

42
test/functional/wallet_txn_doublespend.py

@ -23,22 +23,22 @@ class TxnMallTest(BitcoinTestFramework): @@ -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,22 +48,22 @@ class TxnMallTest(BitcoinTestFramework): @@ -48,22 +48,22 @@ 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):
@ -76,14 +76,14 @@ class TxnMallTest(BitcoinTestFramework): @@ -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)
@ -118,25 +118,25 @@ class TxnMallTest(BitcoinTestFramework): @@ -118,25 +118,25 @@ class TxnMallTest(BitcoinTestFramework):
# 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()

Loading…
Cancel
Save