Skip to content

Commit

Permalink
Fixes qa tests for increased block reward
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjaenson committed Apr 7, 2017
1 parent d7fd021 commit 87d57f1
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 35 deletions.
6 changes: 3 additions & 3 deletions qa/rpc-tests/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
start_nodes,
connect_nodes_bi,
)

from test_framework.mininode import INITIAL_BLOCK_REWARD

class BlockchainTest(BitcoinTestFramework):
"""
Expand Down Expand Up @@ -51,11 +51,11 @@ def _test_gettxoutsetinfo(self):
node = self.nodes[0]
res = node.gettxoutsetinfo()

assert_equal(res['total_amount'], Decimal('5750.00000000'))
assert_equal(res['total_amount'], Decimal(INITIAL_BLOCK_REWARD*115))
assert_equal(res['transactions'], 115)
assert_equal(res['height'], 115)
assert_equal(res['txouts'], 115)
assert_equal(res['bytes_serialized'], 7935),
assert_equal(res['bytes_serialized'], 8165),
assert_equal(len(res['bestblock']), 64)
assert_equal(len(res['hash_serialized']), 64)

Expand Down
3 changes: 2 additions & 1 deletion qa/rpc-tests/listsinceblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from test_framework.mininode import INITIAL_BLOCK_REWARD

class ListSinceBlockTest (BitcoinTestFramework):

Expand Down Expand Up @@ -48,7 +49,7 @@ def run_test (self):

assert_equal(self.nodes[0].getbalance(), 0)
assert_equal(self.nodes[1].getbalance(), 0)
assert_equal(self.nodes[2].getbalance(), 50)
assert_equal(self.nodes[2].getbalance(), INITIAL_BLOCK_REWARD)
assert_equal(self.nodes[3].getbalance(), 0)

# Split network into two
Expand Down
5 changes: 3 additions & 2 deletions qa/rpc-tests/mempool_resurrect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import INITIAL_BLOCK_REWARD

# Create one-input, one-output, no-fee transaction:
class MempoolCoinbaseTest(BitcoinTestFramework):
Expand Down Expand Up @@ -40,13 +41,13 @@ def run_test(self):

b = [ self.nodes[0].getblockhash(n) for n in range(1, 4) ]
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, (INITIAL_BLOCK_REWARD-0.01)) for txid in coinbase_txids ]
spends1_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw ]

blocks = []
blocks.extend(self.nodes[0].generate(1))

spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.98) for txid in spends1_id ]
spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, (INITIAL_BLOCK_REWARD-0.02)) for txid in spends1_id ]
spends2_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw ]

blocks.extend(self.nodes[0].generate(1))
Expand Down
3 changes: 2 additions & 1 deletion qa/rpc-tests/mempool_spendcoinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import INITIAL_BLOCK_REWARD

# Create one-input, one-output, no-fee transaction:
class MempoolSpendCoinbaseTest(BitcoinTestFramework):
Expand All @@ -41,7 +42,7 @@ def run_test(self):
# is too immature to spend.
b = [ self.nodes[0].getblockhash(n) for n in range(101, 103) ]
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
spends_raw = [ create_tx(self.nodes[0], txid, node0_address, (INITIAL_BLOCK_REWARD-0.01)) for txid in coinbase_txids ]

spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0])

Expand Down
7 changes: 4 additions & 3 deletions qa/rpc-tests/merkle_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import INITIAL_BLOCK_REWARD

class MerkleBlockTest(BitcoinTestFramework):

Expand Down Expand Up @@ -43,9 +44,9 @@ def run_test(self):
assert_equal(self.nodes[2].getbalance(), 0)

node0utxos = self.nodes[0].listunspent(1)
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99})
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): INITIAL_BLOCK_REWARD - 0.01})
txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"])
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99})
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): INITIAL_BLOCK_REWARD - 0.01})
txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2)["hex"])
assert_raises(JSONRPCException, self.nodes[0].gettxoutproof, [txid1])

Expand All @@ -63,7 +64,7 @@ def run_test(self):
assert_equal(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid1, txid2], blockhash)), txlist)

txin_spent = self.nodes[1].listunspent(1).pop()
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 49.98})
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): INITIAL_BLOCK_REWARD - 0.02})
self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"])
self.nodes[0].generate(1)
self.sync_all()
Expand Down
3 changes: 2 additions & 1 deletion qa/rpc-tests/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import INITIAL_BLOCK_REWARD
from struct import *
from io import BytesIO
from codecs import encode
Expand Down Expand Up @@ -69,7 +70,7 @@ def run_test(self):
self.nodes[2].generate(100)
self.sync_all()

assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[0].getbalance(), INITIAL_BLOCK_REWARD)

txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
self.sync_all()
Expand Down
14 changes: 12 additions & 2 deletions qa/rpc-tests/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@
MY_SUBVERSION = b"/python-mininode-tester:0.0.3/"
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)

COIN = 100000000 # 1 btc in satoshis

MAX_INV_SZ = 50000
MAX_BLOCK_BASE_SIZE = 2000000
POW_TARGET_SPACING = 600
INITIAL_HASH_STATE_ROOT = 0x21b463e3b52f6201c0ad6c991be0485b6ef8c092e64583ffa655cc1b171fe856
INITIAL_BLOCK_REWARD = 20000.0


COIN = 100000000 # 1 btc in satoshis

NODE_NETWORK = (1 << 0)
NODE_GETUTXO = (1 << 1)
Expand Down Expand Up @@ -426,18 +428,20 @@ def is_null(self):
class CTransaction(object):
def __init__(self, tx=None):
if tx is None:
self.nVersion = 1
self.nVersion = 2
self.vin = []
self.vout = []
self.wit = CTxWitness()
self.nLockTime = 0
self.nTime = 0
self.sha256 = None
self.hash = None
else:
self.nVersion = tx.nVersion
self.vin = copy.deepcopy(tx.vin)
self.vout = copy.deepcopy(tx.vout)
self.nLockTime = tx.nLockTime
self.nTime = tx.nTime
self.sha256 = tx.sha256
self.hash = tx.hash
self.wit = copy.deepcopy(tx.wit)
Expand All @@ -459,6 +463,8 @@ def deserialize(self, f):
self.wit.vtxinwit = [CTxInWitness() for i in range(len(self.vin))]
self.wit.deserialize(f)
self.nLockTime = struct.unpack("<I", f.read(4))[0]
if self.nVersion > 2 and self.nVersion < 3:
self.nTime = struct.unpack("<I", f.read(4))[0]
self.sha256 = None
self.hash = None

Expand All @@ -468,6 +474,8 @@ def serialize_without_witness(self):
r += ser_vector(self.vin)
r += ser_vector(self.vout)
r += struct.pack("<I", self.nLockTime)
if self.nVersion > 2 and self.nVersion < 3:
r += struct.pack("<I", self.nTime)
return r

# Only serialize with witness when explicitly called for
Expand All @@ -491,6 +499,8 @@ def serialize_with_witness(self):
self.wit.vtxinwit.append(CTxInWitness())
r += self.wit.serialize()
r += struct.pack("<I", self.nLockTime)
if self.nVersion > 2 and self.nVersion < 3:
r += struct.pack("<I", self.nTime)
return r

# Regular serialization is without witness -- must explicitly
Expand Down
9 changes: 5 additions & 4 deletions qa/rpc-tests/txn_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import INITIAL_BLOCK_REWARD

class TxnMallTest(BitcoinTestFramework):

Expand All @@ -27,7 +28,7 @@ def setup_network(self):

def run_test(self):
# All nodes should start with 1,250 BTC:
starting_balance = 1250
starting_balance = int(INITIAL_BLOCK_REWARD*25)
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!
Expand Down Expand Up @@ -132,9 +133,9 @@ def run_test(self):

# 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 += int(2*INITIAL_BLOCK_REWARD)
if (self.options.mine_block):
expected -= 50
expected -= int(INITIAL_BLOCK_REWARD)
assert_equal(self.nodes[0].getbalance(), expected)
assert_equal(self.nodes[0].getbalance("*", 0), expected)

Expand All @@ -149,7 +150,7 @@ def run_test(self):
+ fund_foo_tx["fee"]
- 29
+ fund_bar_tx["fee"]
+ 100)
+ int(2*INITIAL_BLOCK_REWARD))

# Node1's "from0" account balance
assert_equal(self.nodes[1].getbalance("from0", 0), -(tx1["amount"] + tx2["amount"]))
Expand Down
8 changes: 4 additions & 4 deletions qa/rpc-tests/wallet-accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
assert_equal,
connect_nodes_bi,
)

from test_framework.mininode import INITIAL_BLOCK_REWARD

class WalletAccountsTest(BitcoinTestFramework):

Expand All @@ -31,7 +31,7 @@ def run_test (self):

node.generate(101)

assert_equal(node.getbalance(), 4300)
assert_equal(node.getbalance(), INITIAL_BLOCK_REWARD*86)

accounts = ["a","b","c","d","e"]
amount_to_send = 1.0
Expand Down Expand Up @@ -64,13 +64,13 @@ def run_test (self):

node.generate(16)

expected_account_balances = {"": 5200}
expected_account_balances = {"": INITIAL_BLOCK_REWARD*104}
for account in accounts:
expected_account_balances[account] = 0

assert_equal(node.listaccounts(), expected_account_balances)

assert_equal(node.getbalance(""), 5200)
assert_equal(node.getbalance(""), INITIAL_BLOCK_REWARD*104)

for account in accounts:
address = node.getaccountaddress("")
Expand Down
18 changes: 10 additions & 8 deletions qa/rpc-tests/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import INITIAL_BLOCK_REWARD


class WalletTest (BitcoinTestFramework):

Expand Down Expand Up @@ -40,15 +42,15 @@ def run_test (self):
self.nodes[0].generate(1)

walletinfo = self.nodes[0].getwalletinfo()
assert_equal(walletinfo['immature_balance'], 50)
assert_equal(walletinfo['immature_balance'], INITIAL_BLOCK_REWARD)
assert_equal(walletinfo['balance'], 0)

self.sync_all()
self.nodes[1].generate(16)
self.sync_all()

assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[1].getbalance(), 50)
assert_equal(self.nodes[0].getbalance(), INITIAL_BLOCK_REWARD)
assert_equal(self.nodes[1].getbalance(), INITIAL_BLOCK_REWARD)
assert_equal(self.nodes[2].getbalance(), 0)

# Check that only first and second nodes have UTXOs
Expand Down Expand Up @@ -82,7 +84,7 @@ def run_test (self):

# 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(), 2*INITIAL_BLOCK_REWARD-21)
assert_equal(self.nodes[2].getbalance(), 21)

# Node0 should have two unspent outputs.
Expand Down Expand Up @@ -110,8 +112,8 @@ def run_test (self):
self.sync_all()

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(), 2*INITIAL_BLOCK_REWARD-6)
assert_equal(self.nodes[2].getbalance("from1"), 2*INITIAL_BLOCK_REWARD-27)

# Send 10 BTC normal
address = self.nodes[0].getnewaddress("test")
Expand All @@ -120,7 +122,7 @@ def run_test (self):
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('84'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal(2*INITIAL_BLOCK_REWARD-16), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
assert_equal(self.nodes[0].getbalance(), Decimal('10'))

# Send 10 BTC with subtract fee from amount
Expand Down Expand Up @@ -176,7 +178,7 @@ def run_test (self):
#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(): INITIAL_BLOCK_REWARD-0.002, 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)
Expand Down
12 changes: 7 additions & 5 deletions qa/rpc-tests/walletbackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from test_framework.util import *
from random import randint
import logging
from test_framework.mininode import INITIAL_BLOCK_REWARD

logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO, stream=sys.stdout)

class WalletBackupTest(BitcoinTestFramework):
Expand Down Expand Up @@ -112,10 +114,10 @@ def run_test(self):
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[3].getbalance(), 4250)
assert_equal(self.nodes[0].getbalance(), INITIAL_BLOCK_REWARD)
assert_equal(self.nodes[1].getbalance(), INITIAL_BLOCK_REWARD)
assert_equal(self.nodes[2].getbalance(), INITIAL_BLOCK_REWARD)
assert_equal(self.nodes[3].getbalance(), 85*INITIAL_BLOCK_REWARD)

logging.info("Creating transactions")
# Five rounds of sending each other transactions.
Expand Down Expand Up @@ -147,7 +149,7 @@ def run_test(self):

# 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, 114*INITIAL_BLOCK_REWARD)

##
# Test restoring spender wallets from backups
Expand Down
3 changes: 2 additions & 1 deletion qa/rpc-tests/zapwallettxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import INITIAL_BLOCK_REWARD


class ZapWalletTXesTest (BitcoinTestFramework):
Expand All @@ -29,7 +30,7 @@ def run_test (self):
self.nodes[1].generate(101)
self.sync_all()

assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[0].getbalance(), INITIAL_BLOCK_REWARD)

txid0 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
txid1 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
Expand Down

0 comments on commit 87d57f1

Please sign in to comment.