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

Code before:
    def check_fee_estimates_btw_modes(self, node, expected_conservative, expected_economical):
        fee_est_conservative = node.estimatesmartfee(1, estimate_mode="conservative")['feerate']
        fee_est_economical = node.estimatesmartfee(1)['feerate']
        assert_equal(fee_est_conservative, expected_conservative)
        assert_equal(fee_est_economical, expected_economical)

    def test_estimation_modes(self):
        low_feerate = Decimal("0.001")
        high_feerate = Decimal("0.005")
        weight = 1000
        tx_count = 24
        # Broadcast and mine high fee (1k weight) transactions for the first 5 blocks.
        for _ in range(5):
            self.broadcast_and_mine(self.nodes[1], self.nodes[2], high_feerate, weight, tx_count)
        self.check_fee_estimates_btw_modes(self.nodes[0], high_feerate, high_feerate)

        # Broadcast and mine high fee (1k weight) transactions for the next 7 blocks.
        for _ in range(7):
            self.broadcast_and_mine(self.nodes[1], self.nodes[2], high_feerate, weight, tx_count)
        self.check_fee_estimates_btw_modes(self.nodes[0], high_feerate, high_feerate)

        # We now track 12 blocks; short horizon stats will start decaying.
        # Broadcast and mine low fee (1k weight) transactions for the next 4 blocks.
        for _ in range(4):
            self.broadcast_and_mine(self.nodes[1], self.nodes[2], low_feerate, weight, tx_count)
        # conservative mode will consider longer time horizons while economical mode do not
        # Check the fee estimates for both modes after mining low fee transactions.
        self.check_fee_estimates_btw_modes(self.nodes[0], high_feerate, low_feerate)


    def run_test(self):
        self.log.info("This test is time consuming, please be patient")
        self.log.info("Splitting inputs so we can generate tx's")

        # Split two coinbases into many small utxos
        self.start_node(0)
        self.wallet = MiniWallet(self.nodes[0])
        self.initial_split(self.nodes[0])
        self.log.info("Finished splitting")

        # Now we can connect the other nodes, didn't want to connect them earlier
        # so the estimates would not be affected by the splitting transactions
        self.start_node(1)
        self.start_node(2)
        self.connect_nodes(1, 0)
        self.connect_nodes(0, 2)
        self.connect_nodes(2, 1)
        self.sync_all()

        self.log.info("Testing estimates with single transactions.")
        self.sanity_check_estimates_range()

Review comment (suggestion):
```Suggestion
        # conservative mode will consider longer time horizons while economical mode does not
```

Code after:
        """Broadcast and mine some number of transactions with a specified fee rate."""
        for _ in range(count):
            self.wallet.send_self_transfer(from_node=broadcaster, fee_rate=feerate)
        self.sync_mempools()
        self.generate(miner, 1)

    def test_estimation_modes(self):
        low_feerate = Decimal("0.001")
        high_feerate = Decimal("0.005")
        tx_count = 24
        # Broadcast and mine high fee transactions for the first 12 blocks.
        for _ in range(12):
            self.broadcast_and_mine(self.nodes[1], self.nodes[2], high_feerate, tx_count)
        check_fee_estimates_btw_modes(self.nodes[0], high_feerate, high_feerate)

        # We now track 12 blocks; short horizon stats will start decaying.
        # Broadcast and mine low fee transactions for the next 4 blocks.
        for _ in range(4):
            self.broadcast_and_mine(self.nodes[1], self.nodes[2], low_feerate, tx_count)
        # conservative mode will consider longer time horizons while economical mode does not
        # Check the fee estimates for both modes after mining low fee transactions.
        check_fee_estimates_btw_modes(self.nodes[0], high_feerate, low_feerate)


    def run_test(self):
        self.log.info("This test is time consuming, please be patient")
        self.log.info("Splitting inputs so we can generate tx's")

        # Split two coinbases into many small utxos
        self.start_node(0)
        self.wallet = MiniWallet(self.nodes[0])
        self.initial_split(self.nodes[0])
        self.log.info("Finished splitting")

        # Now we can connect the other nodes, didn't want to connect them earlier
        # so the estimates would not be affected by the splitting transactions
        self.start_node(1)
        self.start_node(2)
        self.connect_nodes(1, 0)
        self.connect_nodes(0, 2)
        self.connect_nodes(2, 1)
        self.sync_all()

        self.log.info("Testing estimates with single transactions.")
        self.sanity_check_estimates_range()

        self.log.info("Test fee_estimates.dat is flushed periodically")
        self.test_estimate_dat_is_flushed_periodically()

        # check that the effective feerate is greater than or equal to the mempoolminfee even for high mempoolminfee
        self.log.info(