Skip to content

Commit

Permalink
test: Set some Blackcoin values in test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
lateminer committed Jan 24, 2024
1 parent 475373b commit 8ad196f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
4 changes: 2 additions & 2 deletions test/functional/test_framework/blocktools.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
MAX_BLOCK_SIGOPS_WEIGHT = MAX_BLOCK_SIGOPS * WITNESS_SCALE_FACTOR

# Genesis block time (regtest)
TIME_GENESIS_BLOCK = 1296688602
TIME_GENESIS_BLOCK = 1393221600

MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60

# Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
COINBASE_MATURITY = 100
COINBASE_MATURITY = 10

# From BIP141
WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed"
Expand Down
9 changes: 5 additions & 4 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import random
import socket
import struct
import sys
import time

from test_framework.siphash import siphash256
Expand All @@ -36,8 +37,8 @@
MAX_BLOOM_FILTER_SIZE = 36000
MAX_BLOOM_HASH_FUNCS = 50

COIN = 100000000 # 1 btc in satoshis
MAX_MONEY = 21000000 * COIN
COIN = 100000000 # 1 BLK in satoshis
MAX_MONEY = sys.maxsize

MAX_BIP125_RBF_SEQUENCE = 0xfffffffd # Sequence number that is rbf-opt-in (BIP 125) and csv-opt-out (BIP 68)
SEQUENCE_FINAL = 0xffffffff # Sequence number that disables nLockTime if set for every input of a tx
Expand Down Expand Up @@ -68,8 +69,8 @@
DEFAULT_ANCESTOR_LIMIT = 25 # default max number of in-mempool ancestors
DEFAULT_DESCENDANT_LIMIT = 25 # default max number of in-mempool descendants

# Default setting for -datacarriersize. 80 bytes of data, +1 for OP_RETURN, +2 for the pushdata opcodes.
MAX_OP_RETURN_RELAY = 83
# Default setting for -datacarriersize. 220 bytes of data, +1 for OP_RETURN, +2 for the pushdata opcodes.
MAX_OP_RETURN_RELAY = 223

DEFAULT_MEMPOOL_EXPIRY_HOURS = 336 # hours

Expand Down
12 changes: 8 additions & 4 deletions test/functional/test_framework/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@
# Version 70016 supports wtxid relay
P2P_VERSION = 70016
# The services that this test framework offers in its `version` message
P2P_SERVICES = NODE_NETWORK | NODE_WITNESS
'''
# Blackcoin
# NODE_NETWORK | NODE_WITNESS
'''
P2P_SERVICES = NODE_NETWORK
# The P2P user agent string that this test framework sends in its `version` message
P2P_SUBVERSION = "/python-p2p-tester:0.0.3/"
# Value for relay that this test framework sends in its `version` message
Expand Down Expand Up @@ -135,9 +139,9 @@
}

MAGIC_BYTES = {
"mainnet": b"\xf9\xbe\xb4\xd9", # mainnet
"testnet3": b"\x0b\x11\x09\x07", # testnet3
"regtest": b"\xfa\xbf\xb5\xda", # regtest
"mainnet": b"\x70\x32\x22\x05", # mainnet
"testnet": b"\xcd\xf2\xc0\xef", # testnet
"regtest": b"\x70\x35\x22\x06", # regtest
"signet": b"\x0a\x03\xcf\x40", # signet
}

Expand Down
31 changes: 16 additions & 15 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ def run_test(self):
self.generate(self.nodes[0], 1, sync_fun=self.no_op)

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

self.sync_all(self.nodes[0:3])
self.generate(self.nodes[1], COINBASE_MATURITY + 1, sync_fun=lambda: 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(), 10000)
assert_equal(self.nodes[1].getbalance(), 10000)
assert_equal(self.nodes[2].getbalance(), 0)

# Check that only first and second nodes have UTXOs
Expand All @@ -88,19 +88,19 @@ def run_test(self):
# 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'], 10000)
txout = self.nodes[0].gettxout(txid=confirmed_txid, n=confirmed_index, include_mempool=True)
assert_equal(txout['value'], 50)
assert_equal(txout['value'], 10000)

# Send 21 BTC from 0 to 2 using sendtoaddress call.
# Send 21 BLK from 0 to 2 using sendtoaddress call.
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
mempool_txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)

self.log.info("Test gettxout (second part)")
# 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'], 10000)
txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index) # by default include_mempool=True
assert txout is None
txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, True)
Expand Down Expand Up @@ -200,9 +200,9 @@ def run_test(self):
# Have node1 generate 100 blocks (so node0 can recover the fee)
self.generate(self.nodes[1], COINBASE_MATURITY, sync_fun=lambda: 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 20000 BLK 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(), 20000 - 21)
assert_equal(self.nodes[2].getbalance(), 21)

# Node0 should have two unspent outputs.
Expand All @@ -229,22 +229,23 @@ def run_test(self):
self.generate(self.nodes[1], 1, sync_fun=lambda: 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(), 19994)

# 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 BLK normal
address = self.nodes[0].getnewaddress("test")
fee_per_byte = Decimal('0.001') / 1000
self.nodes[2].settxfee(fee_per_byte * 1000)
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False)
self.generate(self.nodes[2], 1, sync_fun=lambda: 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].gettransaction(txid)['hex']))

node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('19984'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(self.nodes[0].getbalance(), Decimal('10'))

# Send 10 BTC with subtract fee from amount
# Send 10 BLK with subtract fee from amount
txid = self.nodes[2].sendtoaddress(address, 10, "", "", True)
self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
node_2_bal -= Decimal('10')
Expand All @@ -253,14 +254,14 @@ def run_test(self):

self.log.info("Test sendmany")

# Sendmany 10 BTC
# Sendmany 10 BLK
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [])
self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
node_0_bal += Decimal('10')
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(self.nodes[0].getbalance(), node_0_bal)

# Sendmany 10 BTC with subtract fee from amount
# Sendmany 10 BLK with subtract fee from amount
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address])
self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
node_2_bal -= Decimal('10')
Expand Down
4 changes: 2 additions & 2 deletions test/functional/wallet_create_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_tx_size_too_large(self):
outputs = {self.nodes[0].getnewaddress(address_type='bech32'): 0.000025 for _ in range(400)}
raw_tx = self.nodes[0].createrawtransaction(inputs=[], outputs=outputs)

for fee_setting in ['-minrelaytxfee=0.01', '-paytxfee=0.01']:
for fee_setting in ['-minrelaytxfee=0.1', '-paytxfee=0.1']:
self.log.info('Check maxtxfee in combination with {}'.format(fee_setting))
self.restart_node(0, extra_args=[fee_setting])
assert_raises_rpc_error(
Expand All @@ -68,7 +68,7 @@ def test_tx_size_too_large(self):

self.log.info('Check maxtxfee in combination with settxfee')
self.restart_node(0)
self.nodes[0].settxfee(0.01)
self.nodes[0].settxfee(0.1)
assert_raises_rpc_error(
-6,
"Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",
Expand Down

0 comments on commit 8ad196f

Please sign in to comment.