|
|
@@ -24,17 +24,6 @@ |
|
|
|
|
|
class WalletTest (BitcoinTestFramework):
|
|
|
|
|
|
- def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size):
|
|
|
- """Return curr_balance after asserting the fee was in range"""
|
|
|
- fee = balance_with_fee - curr_balance
|
|
|
- target_fee = fee_per_byte * tx_size
|
|
|
- if fee < target_fee:
|
|
|
- raise AssertionError("Fee of %s BTC too low! (Should be %s BTC)"%(str(fee), str(target_fee)))
|
|
|
- # allow the node's estimation to be at most 2 bytes off
|
|
|
- if fee > fee_per_byte * (tx_size + 2):
|
|
|
- raise AssertionError("Fee of %s BTC too high! (Should be %s BTC)"%(str(fee), str(target_fee)))
|
|
|
- return curr_balance
|
|
|
-
|
|
|
def setup_chain(self):
|
|
|
print("Initializing test directory "+self.options.tmpdir)
|
|
|
initialize_chain_clean(self.options.tmpdir, 4)
|
|
|
@@ -115,37 +104,33 @@ def run_test (self): |
|
|
|
|
|
# Send 10 BTC normal
|
|
|
address = self.nodes[0].getnewaddress("test")
|
|
|
- fee_per_byte = Decimal('0.001') / 1000
|
|
|
- self.nodes[2].settxfee(fee_per_byte * 1000)
|
|
|
+ self.nodes[2].settxfee(Decimal('0.001'))
|
|
|
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False)
|
|
|
self.nodes[2].generate(1)
|
|
|
self.sync_all()
|
|
|
- node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('90'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
|
|
|
- assert_equal(self.nodes[0].getbalance(), Decimal('10'))
|
|
|
+ assert_equal(self.nodes[2].getbalance(), Decimal('89.99900000'))
|
|
|
+ assert_equal(self.nodes[0].getbalance(), Decimal('10.00000000'))
|
|
|
|
|
|
# Send 10 BTC with subtract fee from amount
|
|
|
txid = self.nodes[2].sendtoaddress(address, 10, "", "", True)
|
|
|
self.nodes[2].generate(1)
|
|
|
self.sync_all()
|
|
|
- node_2_bal -= Decimal('10')
|
|
|
- assert_equal(self.nodes[2].getbalance(), node_2_bal)
|
|
|
- node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
|
|
|
+ assert_equal(self.nodes[2].getbalance(), Decimal('79.99900000'))
|
|
|
+ assert_equal(self.nodes[0].getbalance(), Decimal('19.99900000'))
|
|
|
|
|
|
# Sendmany 10 BTC
|
|
|
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", [])
|
|
|
self.nodes[2].generate(1)
|
|
|
self.sync_all()
|
|
|
- node_0_bal += Decimal('10')
|
|
|
- node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
|
|
|
- assert_equal(self.nodes[0].getbalance(), node_0_bal)
|
|
|
+ assert_equal(self.nodes[2].getbalance(), Decimal('69.99800000'))
|
|
|
+ assert_equal(self.nodes[0].getbalance(), Decimal('29.99900000'))
|
|
|
|
|
|
# Sendmany 10 BTC with subtract fee from amount
|
|
|
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", [address])
|
|
|
self.nodes[2].generate(1)
|
|
|
self.sync_all()
|
|
|
- node_2_bal -= Decimal('10')
|
|
|
- assert_equal(self.nodes[2].getbalance(), node_2_bal)
|
|
|
- node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
|
|
|
+ assert_equal(self.nodes[2].getbalance(), Decimal('59.99800000'))
|
|
|
+ assert_equal(self.nodes[0].getbalance(), Decimal('39.99800000'))
|
|
|
|
|
|
# Test ResendWalletTransactions:
|
|
|
# Create a couple of transactions, then start up a fourth
|
|
|
@@ -206,15 +191,15 @@ def run_test (self): |
|
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
|
|
self.nodes[1].generate(1) #mine a block, tx should not be in there
|
|
|
self.sync_all()
|
|
|
- assert_equal(self.nodes[2].getbalance(), node_2_bal); #should not be changed because tx was not broadcasted
|
|
|
-
|
|
|
+ assert_equal(self.nodes[2].getbalance(), Decimal('59.99800000')); #should not be changed because tx was not broadcasted
|
|
|
+
|
|
|
#now broadcast from another node, mine a block, sync, and check the balance
|
|
|
self.nodes[1].sendrawtransaction(txObjNotBroadcasted['hex'])
|
|
|
self.nodes[1].generate(1)
|
|
|
self.sync_all()
|
|
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
|
|
- assert_equal(self.nodes[2].getbalance(), node_2_bal + Decimal('2')); #should not be
|
|
|
-
|
|
|
+ assert_equal(self.nodes[2].getbalance(), Decimal('61.99800000')); #should not be
|
|
|
+
|
|
|
#create another tx
|
|
|
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2);
|
|
|
|
|
|
@@ -231,7 +216,7 @@ def run_test (self): |
|
|
sync_blocks(self.nodes)
|
|
|
|
|
|
#tx should be added to balance because after restarting the nodes tx should be broadcastet
|
|
|
- assert_equal(self.nodes[2].getbalance(), node_2_bal + Decimal('4')); #should not be
|
|
|
-
|
|
|
+ assert_equal(self.nodes[2].getbalance(), Decimal('63.99800000')); #should not be
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
WalletTest ().main ()
|
0 comments on commit
d49f724