Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_basic.py
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Have node0 mine a block, thus it will collect its own fee. | # Have node0 mine a block, thus it will collect its own fee. | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
# Exercise locking of unspent outputs | # Exercise locking of unspent outputs | ||||
unspent_0 = self.nodes[2].listunspent()[0] | unspent_0 = self.nodes[2].listunspent()[0] | ||||
unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]} | unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]} | ||||
assert_raises_rpc_error(-8, "Invalid parameter, expected locked output", | |||||
self.nodes[2].lockunspent, True, [unspent_0]) | |||||
self.nodes[2].lockunspent(False, [unspent_0]) | self.nodes[2].lockunspent(False, [unspent_0]) | ||||
assert_raises_rpc_error(-8, "Invalid parameter, output already locked", | |||||
self.nodes[2].lockunspent, False, [unspent_0]) | |||||
assert_raises_rpc_error(-4, "Insufficient funds", | assert_raises_rpc_error(-4, "Insufficient funds", | ||||
self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 20) | self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 20) | ||||
assert_equal([unspent_0], self.nodes[2].listlockunspent()) | assert_equal([unspent_0], self.nodes[2].listlockunspent()) | ||||
self.nodes[2].lockunspent(True, [unspent_0]) | self.nodes[2].lockunspent(True, [unspent_0]) | ||||
assert_equal(len(self.nodes[2].listlockunspent()), 0) | assert_equal(len(self.nodes[2].listlockunspent()), 0) | ||||
assert_raises_rpc_error(-8, "Invalid parameter, unknown transaction", self.nodes[2].lockunspent, False, [ | |||||
{"txid": "0000000000000000000000000000000000", "vout": 0}]) | |||||
assert_raises_rpc_error(-8, "Invalid parameter, vout index out of bounds", | |||||
self.nodes[2].lockunspent, False, [{"txid": unspent_0["txid"], "vout": 999}]) | |||||
# Have node1 generate 100 blocks (so node0 can recover the fee) | # Have node1 generate 100 blocks (so node0 can recover the fee) | ||||
self.nodes[1].generate(100) | self.nodes[1].generate(100) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
# node0 should end up with 100 btc in block rewards plus fees, but | # node0 should end up with 100 btc in block rewards plus fees, but | ||||
# minus the 21 plus fees sent to node2 | # minus the 21 plus fees sent to node2 | ||||
assert_equal(self.nodes[0].getbalance(), 100 - 21) | assert_equal(self.nodes[0].getbalance(), 100 - 21) | ||||
Show All 23 Lines | def run_test(self): | ||||
# Have node1 mine a block to confirm transactions: | # Have node1 mine a block to confirm transactions: | ||||
self.nodes[1].generate(1) | self.nodes[1].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
assert_equal(self.nodes[0].getbalance(), 0) | assert_equal(self.nodes[0].getbalance(), 0) | ||||
assert_equal(self.nodes[2].getbalance(), 94) | assert_equal(self.nodes[2].getbalance(), 94) | ||||
assert_equal(self.nodes[2].getbalance("from1"), 94 - 21) | assert_equal(self.nodes[2].getbalance("from1"), 94 - 21) | ||||
# Verify that a spent output cannot be locked anymore | |||||
spent_0 = {"txid": node0utxos[0]["txid"], | |||||
"vout": node0utxos[0]["vout"]} | |||||
assert_raises_rpc_error(-8, "Invalid parameter, expected unspent output", | |||||
self.nodes[0].lockunspent, False, [spent_0]) | |||||
# Send 10 BTC normal | # Send 10 BTC normal | ||||
old_balance = self.nodes[2].getbalance() | old_balance = self.nodes[2].getbalance() | ||||
address = self.nodes[0].getnewaddress("test") | address = self.nodes[0].getnewaddress("test") | ||||
fee_per_byte = Decimal('0.001') / 1000 | fee_per_byte = Decimal('0.001') / 1000 | ||||
self.nodes[2].settxfee(fee_per_byte * 1000) | self.nodes[2].settxfee(fee_per_byte * 1000) | ||||
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False) | txid = self.nodes[2].sendtoaddress(address, 10, "", "", False) | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
▲ Show 20 Lines • Show All 321 Lines • Show Last 20 Lines |