Repository: bitcoin/bitcoin
File: test/functional/mining_prioritisetransaction.py (Python)

Code before:
    assert_raises_rpc_error,
    create_lots_of_big_transactions,
    gen_return_txouts,
)
from test_framework.wallet import MiniWallet


class PrioritiseTransactionTest(BitcoinTestFramework):
    def set_test_params(self):
        self.num_nodes = 1
        self.extra_args = [[
            "-printpriority=1",
        ]] * self.num_nodes
        self.supports_cli = False

    def clear_prioritisation(self, node):
        for txid, info in node.getprioritisedtransactions().items():
            delta = info["fee_delta"]
            node.prioritisetransaction(txid, 0, -delta)
        assert_equal(node.getprioritisedtransactions(), {})

    def test_large_fee_bump(self):
        self.log.info("Test that a large fee delta is honoured")
        tx = self.wallet.create_self_transfer()
        txid = tx["txid"]
        fee_delta = int(41 * COIN)
        self.nodes[0].prioritisetransaction(txid=txid, fee_delta=fee_delta)
        assert_equal(
            self.nodes[0].getprioritisedtransactions(),
            {
                txid: {
                    "fee_delta": fee_delta,
                    "in_mempool": False,
                },
            },
        )
        self.nodes[0].sendrawtransaction(tx["hex"])
        expected_modified_fee = tx["fee"] + Decimal(fee_delta) / COIN
        assert_equal(
            self.nodes[0].getprioritisedtransactions(),
            {
                txid: {
                    "fee_delta": fee_delta,
                    "in_mempool": True,
                    "modified_fee": int(expected_modified_fee * COIN),
                },
            },
        )
        # This transaction forms its own chunk.
        mempool_entry = self.nodes[0].getrawmempool(verbose=True)[txid]
        assert_equal(mempool_entry["fees"]["base"], tx["fee"])

Review comment (bug):
Curious why 41 was chosen? I also tested with values much closer to the typical max value of a signed int in cpp.

With the above patch that I mentioned in the overall review comment, the test behaviour is like the following - 

Fails:
```diff
-        fee_delta = int(41 * COIN)
+        fee_delta = int(22 * COIN)
```

Passes:
```diff
-        fee_delta = int(41 * COIN)
+        fee_delta = int(21 * COIN)
```

Code after:
    assert_raises_rpc_error,
    create_lots_of_big_transactions,
    gen_return_txouts,
)
from test_framework.wallet import MiniWallet


class PrioritiseTransactionTest(BitcoinTestFramework):
    def set_test_params(self):
        self.num_nodes = 1
        self.extra_args = [[
            "-printpriority=1",
        ]] * self.num_nodes
        self.supports_cli = False

    def clear_prioritisation(self, node):
        for txid, info in node.getprioritisedtransactions().items():
            delta = info["fee_delta"]
            node.prioritisetransaction(txid, 0, -delta)
        assert_equal(node.getprioritisedtransactions(), {})

    def test_large_fee_bump(self):
        self.log.info("Test that a large fee delta is honoured")
        tx = self.wallet.create_self_transfer()
        txid = tx["txid"]
        fee_delta = int(86 * COIN)  # large enough to not fit into (u)int32_t
        self.nodes[0].prioritisetransaction(txid=txid, fee_delta=fee_delta)
        assert_equal(
            self.nodes[0].getprioritisedtransactions(),
            {
                txid: {
                    "fee_delta": fee_delta,
                    "in_mempool": False,
                },
            },
        )
        self.nodes[0].sendrawtransaction(tx["hex"])
        expected_modified_fee = tx["fee"] + Decimal(fee_delta) / COIN
        assert_equal(
            self.nodes[0].getprioritisedtransactions(),
            {
                txid: {
                    "fee_delta": fee_delta,
                    "in_mempool": True,
                    "modified_fee": int(expected_modified_fee * COIN),
                },
            },
        )
        # This transaction forms its own chunk.
        mempool_entry = self.nodes[0].getrawmempool(verbose=True)[txid]
        assert_equal(mempool_entry["fees"]["base"], tx["fee"])