-
-
Save Bicaru20/e86b46a81b89527ed0c8b4ce377e827d to your computer and use it in GitHub Desktop.
Test to reproduce a transaction with a time based locktime that is replaced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # Copyright (c) 2014-present The Bitcoin Core developers | |
| # Distributed under the MIT software license, see the accompanying | |
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | |
| """Test to reproduce a transaction with a time based locktime that is replaced. | |
| It shouldn't do anti fee sniping in this case, as it can be easily identified that | |
| anti fee sniping is being applied and also the locktime type shoulnd't change | |
| without the user consent.""" | |
| # To run it: python3 test/functional/rbf_time_based.py --configfile build/test/config.ini | |
| from test_framework.test_framework import BitcoinTestFramework | |
| def get_change_address(tx, node): | |
| tx_details = node.getrawtransaction(tx, 1) | |
| txout_addresses = [txout['scriptPubKey']['address'] for txout in tx_details["vout"]] | |
| return [address for address in txout_addresses if node.getaddressinfo(address)["ischange"]] | |
| class ReplaceByFeeTimeBasedLocktime(BitcoinTestFramework): | |
| def set_test_params(self): | |
| self.num_nodes = 2 | |
| self.uses_wallet = None | |
| self.extra_args = [["-deprecatedrpc=fullrbf", "-deprecatedrpc=bip125"], []] | |
| def run_test(self): | |
| self.nodes[0].createwallet("rbf") | |
| wallet = self.nodes[0].get_wallet_rpc("rbf") | |
| self.generatetoaddress(self.nodes[0], 101, wallet.getnewaddress()) | |
| tip_height = self.nodes[0].getblockchaininfo()["blocks"] | |
| self.log.info(f"Creating a transation with time based lockitme: 500000000") | |
| tx = wallet.send(outputs={wallet.getnewaddress(): 9}, fee_rate=1, locktime=500000000) | |
| hex_tx = self.nodes[0].getrawtransaction(tx["txid"]) | |
| # Replacement with higher fee_rate | |
| change_addr = get_change_address(tx["txid"], wallet)[0] | |
| bumped = wallet.bumpfee(txid=tx["txid"], options={"fee_rate":5, "outputs": [{change_addr: 10}]}) | |
| locktime = self.nodes[0].getrawtransaction(bumped["txid"],True)["locktime"] | |
| self.log.info(f"The replacement should have the same locktime and shouldn't do anti fee sniping") | |
| self.log.info(f"However the new locktime is: {locktime}") | |
| self.log.info(f"Hexadecimals of the transations") | |
| self.log.info(f"Original: {hex_tx}") | |
| self.log.info(f"Replacement: {self.nodes[0].getrawtransaction(bumped["txid"])}") | |
| if __name__ == '__main__': | |
| ReplaceByFeeTimeBasedLocktime(__file__).main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment