Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests - change mentions of satoshis to digibits #219

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/functional/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ don't have test cases for.
load a premined blockchain from cache with the default value of `False`. The
cached data directories contain a 200-block pre-mined blockchain with the
spendable mining rewards being split between four nodes. Each node has 25
mature block subsidies (25x50=1250 BTC) in its wallet. Using them is much more
mature block subsidies (25x50=1250 DGB) in its wallet. Using them is much more
efficient than mining blocks in your test.
- When calling RPCs with lots of arguments, consider using named keyword
arguments instead of positional arguments to make the intent of the call
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_bip68_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def run_test(self):
def test_disable_flag(self):
# Create some unconfirmed inputs
new_addr = self.nodes[0].getnewaddress()
self.nodes[0].sendtoaddress(new_addr, 2) # send 2 BTC
self.nodes[0].sendtoaddress(new_addr, 2) # send 2 DGB

utxos = self.nodes[0].listunspent(0, 0)
assert len(utxos) > 0
Expand Down
16 changes: 8 additions & 8 deletions test/functional/feature_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def run_test(self):
redeem_script = CScript([self.coinbase_pubkey] + [OP_2DUP, OP_CHECKSIGVERIFY] * 5 + [OP_CHECKSIG])
p2sh_script = script_to_p2sh_script(redeem_script)

# Create a transaction that spends one satoshi to the p2sh_script, the rest to OP_TRUE
# Create a transaction that spends one digibit to the p2sh_script, the rest to OP_TRUE
# This must be signed because it is spending a coinbase
spend = out[11]
tx = self.create_tx(spend, 0, 1, p2sh_script)
Expand All @@ -505,7 +505,7 @@ def run_test(self):
b39 = self.update_block(39, [tx])
b39_outputs += 1

# Until block is full, add tx's with 1 satoshi to p2sh_script, the rest to OP_TRUE
# Until block is full, add tx's with 1 digibit to p2sh_script, the rest to OP_TRUE
tx_new = None
tx_last = tx
total_weight = b39.get_weight()
Expand Down Expand Up @@ -1010,11 +1010,11 @@ def run_test(self):
# -> b64 (18) -> b65 (19) -> b69 (20)
# \-> b68 (20)
#
# b68 - coinbase with an extra 10 satoshis,
# creates a tx that has 9 satoshis from out[20] go to fees
# this fails because the coinbase is trying to claim 1 satoshi too much in fees
# b68 - coinbase with an extra 10 digibits,
# creates a tx that has 9 digibits from out[20] go to fees
# this fails because the coinbase is trying to claim 1 digibit too much in fees
#
# b69 - coinbase with extra 10 satoshis, and a tx that gives a 10 satoshi fee
# b69 - coinbase with extra 10 digibits, and a tx that gives a 10 digibit fee
# this succeeds
#
self.log.info("Reject a block trying to claim too much subsidy in the coinbase transaction")
Expand Down Expand Up @@ -1381,9 +1381,9 @@ def next_block(self, number, spend=None, additional_coinbase_value=0, script=CSc
if spend is None:
block = create_block(base_block_hash, coinbase, block_time, version=version)
else:
coinbase.vout[0].nValue += spend.vout[0].nValue - 1 # all but one satoshi to fees
coinbase.vout[0].nValue += spend.vout[0].nValue - 1 # all but one digibit to fees
coinbase.rehash()
tx = self.create_tx(spend, 0, 1, script) # spend 1 satoshi
tx = self.create_tx(spend, 0, 1, script) # spend 1 digibit
self.sign_tx(tx, spend)
tx.rehash()
block = create_block(base_block_hash, coinbase, block_time, version=version, txlist=[tx])
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_coinstatsindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _test_coin_stats_index(self):
signed_tx1 = self.nodes[0].signrawtransactionwithwallet(funded_tx1['hex'])
tx1_txid = self.nodes[0].sendrawtransaction(signed_tx1['hex'])

# Find the right position of the 21 BTC output
# Find the right position of the 21 DGB output
tx1_final = self.nodes[0].gettransaction(tx1_txid)
for output in tx1_final['details']:
if output['amount'] == Decimal('21.00000000') and output['category'] == 'receive':
Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_fee_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
assert_greater_than,
assert_greater_than_or_equal,
assert_raises_rpc_error,
satoshi_round,
digibit_round,
)

# Construct 2 trivial P2SH's and the ScriptSigs that spend them
Expand Down Expand Up @@ -60,7 +60,7 @@ def small_txpuzzle_randfee(from_node, conflist, unconflist, amount, min_fee, fee
# Exponentially distributed from 1-128 * fee_increment
rand_fee = float(fee_increment) * (1.1892 ** random.randint(0, 28))
# Total fee ranges from min_fee to min_fee + 127*fee_increment
fee = min_fee - fee_increment + satoshi_round(rand_fee)
fee = min_fee - fee_increment + digibit_round(rand_fee)
tx = CTransaction()
total_in = Decimal("0.00000000")
while total_in <= (amount + fee) and len(conflist) > 0:
Expand Down Expand Up @@ -99,7 +99,7 @@ def split_inputs(from_node, txins, txouts, initial_split=False):
tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(int(prevtxout["txid"], 16), prevtxout["vout"]), b""))

half_change = satoshi_round(prevtxout["amount"] / 2)
half_change = digibit_round(prevtxout["amount"] / 2)
rem_change = prevtxout["amount"] - half_change - Decimal("0.00100000")
tx.vout.append(CTxOut(int(half_change * COIN), P2SH_1))
tx.vout.append(CTxOut(int(rem_change * COIN), P2SH_2))
Expand Down
14 changes: 7 additions & 7 deletions test/functional/feature_rbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from test_framework.script import CScript, OP_DROP
from test_framework.test_framework import DigiByteTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, satoshi_round
from test_framework.util import assert_equal, assert_raises_rpc_error, digibit_round
from test_framework.script_util import DUMMY_P2WPKH_SCRIPT, DUMMY_2_P2WPKH_SCRIPT
from test_framework.wallet import MiniWallet

Expand Down Expand Up @@ -52,11 +52,11 @@ def make_utxo(self, node, amount, confirmed=True, scriptPubKey=DUMMY_P2WPKH_SCRI
unconfirmed otherwise.
"""
fee = 1 * COIN
while node.getbalance() < satoshi_round((amount + fee) / COIN):
while node.getbalance() < digibit_round((amount + fee) / COIN):
self.generate(node, COINBASE_MATURITY)

new_addr = node.getnewaddress()
txid = node.sendtoaddress(new_addr, satoshi_round((amount + fee) / COIN))
txid = node.sendtoaddress(new_addr, digibit_round((amount + fee) / COIN))
tx1 = node.getrawtransaction(txid, 1)
txid = int(txid, 16)
i, _ = next(filter(lambda vout: new_addr == vout[1]['scriptPubKey']['address'], enumerate(tx1['vout'])))
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_simple_doublespend(self):
# This will raise an exception due to insufficient fee
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, 0)

# Extra 0.1 BTC fee
# Extra 0.1 DGB fee
tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1b.vout = [CTxOut(int(0.9 * COIN), DUMMY_P2WPKH_SCRIPT)]
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_doublespend_chain(self):
prevout = COutPoint(int(txid, 16), 0)

# Whether the double-spend is allowed is evaluated by including all
# child fees - 40 BTC - so this attempt is rejected.
# child fees - 40 DGB - so this attempt is rejected.
dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - 30 * COIN, DUMMY_P2WPKH_SCRIPT)]
Expand Down Expand Up @@ -259,7 +259,7 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.001 * COIN, _tot
# This will raise an exception due to insufficient fee
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, dbl_tx_hex, 0)

# 1 BTC fee is enough
# 1 DGB fee is enough
dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - fee * n - 1 * COIN, DUMMY_P2WPKH_SCRIPT)]
Expand Down Expand Up @@ -638,7 +638,7 @@ def test_replacement_relay_fee(self):
tx = wallet.send_self_transfer(from_node=self.nodes[0])['tx']

# Higher fee, higher feerate, different txid, but the replacement does not provide a relay
# fee conforming to node's `incrementalrelayfee` policy of 1000 sat per KB.
# fee conforming to node's `incrementalrelayfee` policy of 1000 dbit per KB.
tx.vout[0].nValue -= 1
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx.serialize().hex())

Expand Down
2 changes: 1 addition & 1 deletion test/functional/mempool_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def run_test(self):
tx_to_be_evicted_id = miniwallet.send_self_transfer(from_node=node, fee_rate=relayfee)["txid"]

# Increase the tx fee rate to give the subsequent transactions a higher priority in the mempool
# The tx has an approx. vsize of 65k, i.e. multiplying the previous fee rate (in sats/kvB)
# The tx has an approx. vsize of 65k, i.e. multiplying the previous fee rate (in dbit/kvB)
# by 130 should result in a fee that corresponds to 2x of that fee rate
base_fee = relayfee * 130

Expand Down
10 changes: 5 additions & 5 deletions test/functional/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
assert_equal,
assert_raises_rpc_error,
chain_transaction,
satoshi_round,
digibit_round,
)

# default limits
Expand Down Expand Up @@ -197,10 +197,10 @@ def run_test(self):
for x in reversed(chain):
descendant_fees += mempool[x]['fee']
if (x == chain[-1]):
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee']+satoshi_round(0.00002))
assert_equal(mempool[x]['fees']['modified'], mempool[x]['fee']+satoshi_round(0.00002))
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee']+digibit_round(0.00002))
assert_equal(mempool[x]['fees']['modified'], mempool[x]['fee']+digibit_round(0.00002))
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 2000)
assert_equal(mempool[x]['fees']['descendant'], descendant_fees+satoshi_round(0.00002))
assert_equal(mempool[x]['fees']['descendant'], descendant_fees+digibit_round(0.00002))

# Check that node1's mempool is as expected (-> custom ancestor limit)
mempool0 = self.nodes[0].getrawmempool(False)
Expand Down Expand Up @@ -296,7 +296,7 @@ def run_test(self):
value = utxo[0]['amount']
vout = utxo[0]['vout']

send_value = satoshi_round((value - fee)/2)
send_value = digibit_round((value - fee)/2)
inputs = [ {'txid' : txid, 'vout' : vout} ]
outputs = {}
for _ in range(2):
Expand Down
2 changes: 1 addition & 1 deletion test/functional/p2p_dandelion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
1. Resistance to active probing:
Stem: 0 --> 1 --> 2 --> 0 where each node has argument "-dandelion=1"
Probe: TestNode --> 0
Node 0 generates a Dandelion transaction "tx": 1.0 BTC from Node 0 to Node 2
Node 0 generates a Dandelion transaction "tx": 1.0 DGB from Node 0 to Node 2
TestNode immediately sends getdata for tx to Node 0
Assert that Node 0 does not reply with tx

Expand Down
8 changes: 4 additions & 4 deletions test/functional/p2p_feefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ def test_feefilter(self):

conn = self.nodes[0].add_p2p_connection(TestP2PConn())

self.log.info("Test txs paying 20 sat/byte are received by test connection")
self.log.info("Test txs paying 20 dbit/byte are received by test connection")
TX_KEY = 'wtxid' if P2P_VERSION >= WTXID_RELAY_VERSION else 'txid'
txids = [miniwallet.send_self_transfer(fee_rate=Decimal('0.000200'), from_node=node1)[TX_KEY] for _ in range(3)]
conn.wait_for_invs_to_match(txids)
conn.clear_invs()

# Set a fee filter of 0.15 sat/byte on test connection
# Set a fee filter of 0.15 dbit/byte on test connection
conn.send_and_ping(msg_feefilter(150))

self.log.info("Test txs paying 0.15 sat/byte are received by test connection")
self.log.info("Test txs paying 0.15 dbit/byte are received by test connection")
txids = [miniwallet.send_self_transfer(fee_rate=Decimal('0.00000150'), from_node=node1)[TX_KEY] for _ in range(3)]
conn.wait_for_invs_to_match(txids)
conn.clear_invs()

self.log.info("Test txs paying 0.1 sat/byte are no longer received by test connection")
self.log.info("Test txs paying 0.1 dbit/byte are no longer received by test connection")
txids = [miniwallet.send_self_transfer(fee_rate=Decimal('0.00000100'), from_node=node1)[TX_KEY] for _ in range(3)]
self.sync_mempools() # must be sure node 0 has received all txs

Expand Down
32 changes: 16 additions & 16 deletions test/functional/rpc_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def test_all_watched_funds(self):
wwatch.unloadwallet()

def test_option_feerate(self):
self.log.info("Test fundrawtxn with explicit fee rates (fee_rate sat/vB and feeRate DGB/kvB)")
self.log.info("Test fundrawtxn with explicit fee rates (fee_rate dbit/vB and feeRate DGB/kvB)")
node = self.nodes[3]
# Make sure there is exactly one input so coin selection can't skew the result.
assert_equal(len(self.nodes[3].listunspent(1)), 1)
Expand All @@ -726,10 +726,10 @@ def test_option_feerate(self):
rawtx = node.createrawtransaction(inputs, outputs)

result = node.fundrawtransaction(rawtx) # uses self.min_relay_tx_fee (set by settxfee)
btc_kvb_to_sat_vb = 100000 # (1e5)
result1 = node.fundrawtransaction(rawtx, {"fee_rate": str(2 * btc_kvb_to_sat_vb * self.min_relay_tx_fee)})
dgb_kvb_to_dbit_vb = 100000 # (1e5)
result1 = node.fundrawtransaction(rawtx, {"fee_rate": str(2 * dgb_kvb_to_dbit_vb * self.min_relay_tx_fee)})
result2 = node.fundrawtransaction(rawtx, {"feeRate": 2 * self.min_relay_tx_fee})
result3 = node.fundrawtransaction(rawtx, {"fee_rate": 10 * btc_kvb_to_sat_vb * self.min_relay_tx_fee})
result3 = node.fundrawtransaction(rawtx, {"fee_rate": 10 * dgb_kvb_to_dbit_vb * self.min_relay_tx_fee})
result4 = node.fundrawtransaction(rawtx, {"feeRate": str(10 * self.min_relay_tx_fee)})

result_fee_rate = result['fee'] * 10 / count_bytes(result['hex'])
Expand All @@ -742,7 +742,7 @@ def test_option_feerate(self):
for param, zero_value in product(["fee_rate", "feeRate"], [0, 0.000, 0.00000000, "0", "0.000", "0.00000000"]):
assert_equal(self.nodes[3].fundrawtransaction(rawtx, {param: zero_value})["fee"], 0)

# With no arguments passed, expect fee of 14100 satoshis.
# With no arguments passed, expect fee of 14100 digibits.
# Expect fee to be 100x higher when an explicit fee rate 100x greater is specified.
result = node.fundrawtransaction(rawtx, {"fee_rate": 10000})
assert_approx(result["fee"], vexp=0.0141, vspan=0.0001)
Expand Down Expand Up @@ -780,17 +780,17 @@ def test_option_feerate(self):
# Test fee rate values that don't pass fixed-point parsing checks.
for invalid_value in ["", 0.000000001, 1e-09, 1.111111111, 1111111111111111, "31.999999999999999999999"]:
assert_raises_rpc_error(-3, "Invalid amount", node.fundrawtransaction, rawtx, {param: invalid_value, "add_inputs": True})
# Test fee_rate values that cannot be represented in sat/vB.
# Test fee_rate values that cannot be represented in dbit/vB.
for invalid_value in [0.0001, 0.00000001, 0.00099999, 31.99999999, "0.0001", "0.00000001", "0.00099999", "31.99999999"]:
assert_raises_rpc_error(-3, "Invalid amount",
node.fundrawtransaction, rawtx, {"fee_rate": invalid_value, "add_inputs": True})

self.log.info("Test min fee rate checks are bypassed with fundrawtxn, e.g. a fee_rate under 1 sat/vB is allowed")
self.log.info("Test min fee rate checks are bypassed with fundrawtxn, e.g. a fee_rate under 1 dbit/vB is allowed")
node.fundrawtransaction(rawtx, {"fee_rate": 0.999, "add_inputs": True})
node.fundrawtransaction(rawtx, {"feeRate": 0.00000999, "add_inputs": True})

self.log.info("- raises RPC error if both feeRate and fee_rate are passed")
assert_raises_rpc_error(-8, "Cannot specify both fee_rate (sat/vB) and feeRate (DGB/kvB)",
assert_raises_rpc_error(-8, "Cannot specify both fee_rate (dbit/vB) and feeRate (DGB/kvB)",
node.fundrawtransaction, rawtx, {"fee_rate": 0.1, "feeRate": 0.1, "add_inputs": True})

self.log.info("- raises RPC error if both feeRate and estimate_mode passed")
Expand Down Expand Up @@ -852,13 +852,13 @@ def test_option_subtract_fee_from_outputs(self):
assert_equal(output[3], output[4] + result[4]['fee'])
assert_equal(change[3] + result[3]['fee'], change[4])

# Test subtract fee from outputs with fee_rate (sat/vB)
btc_kvb_to_sat_vb = 100000 # (1e5)
# Test subtract fee from outputs with fee_rate (dbit/vB)
dgb_kvb_to_dbit_vb = 100000 # (1e5)
result = [self.nodes[3].fundrawtransaction(rawtx), # uses self.min_relay_tx_fee (set by settxfee)
self.nodes[3].fundrawtransaction(rawtx, {"subtractFeeFromOutputs": []}), # empty subtraction list
self.nodes[3].fundrawtransaction(rawtx, {"subtractFeeFromOutputs": [0]}), # uses self.min_relay_tx_fee (set by settxfee)
self.nodes[3].fundrawtransaction(rawtx, {"fee_rate": 2 * btc_kvb_to_sat_vb * self.min_relay_tx_fee}),
self.nodes[3].fundrawtransaction(rawtx, {"fee_rate": 2 * btc_kvb_to_sat_vb * self.min_relay_tx_fee, "subtractFeeFromOutputs": [0]}),]
self.nodes[3].fundrawtransaction(rawtx, {"fee_rate": 2 * dgb_kvb_to_dbit_vb * self.min_relay_tx_fee}),
self.nodes[3].fundrawtransaction(rawtx, {"fee_rate": 2 * dgb_kvb_to_dbit_vb * self.min_relay_tx_fee, "subtractFeeFromOutputs": [0]}),]
dec_tx = [self.nodes[3].decoderawtransaction(tx_['hex']) for tx_ in result]
output = [d['vout'][1 - r['changepos']]['value'] for d, r in zip(dec_tx, result)]
change = [d['vout'][r['changepos']]['value'] for d, r in zip(dec_tx, result)]
Expand Down Expand Up @@ -902,7 +902,7 @@ def test_option_subtract_fee_from_outputs(self):
assert_equal(share[2], share[3])

# Output 0 takes at least as much share of the fee, and no more than 2
# satoshis more, than outputs 2 and 3.
# digibits more, than outputs 2 and 3.
assert_greater_than_or_equal(share[0], share[2])
assert_greater_than_or_equal(share[2] + Decimal(2e-8), share[0])

Expand Down Expand Up @@ -1049,13 +1049,13 @@ def test_feerate_rounding(self):
self.sync_all()

# A P2WPKH input costs 68 vbytes; With a single P2WPKH output, the rest of the tx is 42 vbytes for a total of 110 vbytes.
# At a feerate of 1.85 sat/vb, the input will need a fee of 125.8 sats and the rest 77.7 sats
# The entire tx fee should be 203.5 sats.
# At a feerate of 1.85 dbit/vb, the input will need a fee of 125.8 dbits and the rest 77.7 dbits
# The entire tx fee should be 203.5 dbits.
# Coin selection rounds the fee individually instead of at the end (due to how CFeeRate::GetFee works).
# If rounding down (which is the incorrect behavior), then the calculated fee will be 125 + 77 = 202.
# If rounding up, then the calculated fee will be 126 + 78 = 204.
# In the former case, the calculated needed fee is higher than the actual fee being paid, so an assertion is reached
# To test this does not happen, we subtract 202 sats from the input value. If working correctly, this should
# To test this does not happen, we subtract 202 dbits from the input value. If working correctly, this should
# fail with insufficient funds rather than digibyted asserting.
rawtx = w.createrawtransaction(inputs=[], outputs=[{self.nodes[0].getnewaddress(address_type="bech32"): 1 - 0.00000202}])
assert_raises_rpc_error(-4, "Insufficient funds", w.fundrawtransaction, rawtx, {"fee_rate": 1.85})
Expand Down
Loading