From 713673a6ed75ce434198d89aee179fd3dcc0453b Mon Sep 17 00:00:00 2001 From: Niven Date: Mon, 16 Oct 2023 12:14:28 +0800 Subject: [PATCH 1/6] Add max transferdomain miner test --- test/functional/feature_evm_miner.py | 77 ++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/test/functional/feature_evm_miner.py b/test/functional/feature_evm_miner.py index 2610a489cc5..66774b0dc83 100755 --- a/test/functional/feature_evm_miner.py +++ b/test/functional/feature_evm_miner.py @@ -293,6 +293,48 @@ def varying_block_base_fee(self): tx_info = block_info["tx"][1] assert_equal(tx_info["vm"]["msg"]["hash"], hash[2:]) + def block_with_multiple_transfer_domain_txs(self): + self.rollback_to(self.start_height) + + # Send transferdomain txs to be included in the first block + total_unspent = len(self.nodes[0].listunspent()) + total_transferdomain_txs = 52 + transferdomaintx_hashes = [] + start_nonce_erc55 = self.nodes[0].w3.eth.get_transaction_count( + self.address_erc55 + ) + for i in range(total_transferdomain_txs): + hash = self.nodes[0].transferdomain( + [ + { + "src": { + "address": self.address, + "amount": "1@DFI", + "domain": 2, + }, + "dst": { + "address": self.ethAddress, + "amount": "1@DFI", + "domain": 3, + }, + "nonce": start_nonce_erc55 + i, + } + ] + ) + transferdomaintx_hashes.append(hash) + + self.nodes[0].generate(1) + block_info = self.nodes[0].getblock(self.nodes[0].getbestblockhash(), 4) + assert_equal(len(block_info["tx"][1:]), total_transferdomain_txs * 2 - total_unspent) + + idx = 0 + for tx_info in block_info["tx"][1:]: + if tx_info["vm"]["txtype"] == "TransferDomain": + assert_equal(tx_info["txid"], transferdomaintx_hashes[idx]) + idx += 1 + else: + assert_equal(tx_info["vm"]["txtype"], "AutoAuth") + def blocks_size_gas_limit_with_transferdomain_txs(self): self.rollback_to(self.start_height) abi, bytecode, _ = EVMContract.from_file("Loop.sol", "Loop").compile() @@ -903,29 +945,32 @@ def multiple_transferdomain_txs(self): def run_test(self): self.setup() - # Test mining multiple full blocks - self.multiple_blocks_size_gas_limit() + # # Test mining multiple full blocks + # self.multiple_blocks_size_gas_limit() + + # # Test mining txs into blocks with varying block fees + # self.varying_block_base_fee() - # Test mining txs into blocks with varying block fees - self.varying_block_base_fee() + # Test mining multiple transferdomain txs in the same block + self.block_with_multiple_transfer_domain_txs() - # Test mining full block with transferdomain txs - self.blocks_size_gas_limit_with_transferdomain_txs() + # # Test mining full block with transferdomain txs + # self.blocks_size_gas_limit_with_transferdomain_txs() - # Test mining multiple full blocks with max evm txs per sender and RBF - self.multiple_blocks_size_gas_limit_max_txs_with_rbf() + # # Test mining multiple full blocks with max evm txs per sender and RBF + # self.multiple_blocks_size_gas_limit_max_txs_with_rbf() - # Test invalid tx in block creation - self.invalid_evm_tx_in_block_creation() + # # Test invalid tx in block creation + # self.invalid_evm_tx_in_block_creation() - # Test for block size overflow from fee mismatch between tx queue and block - self.state_dependent_txs_in_block_and_queue() + # # Test for block size overflow from fee mismatch between tx queue and block + # self.state_dependent_txs_in_block_and_queue() - # Test for multiple expensive evm txs and transferdomain txs in the same block - self.multiple_evm_and_transferdomain_txs() + # # Test for multiple expensive evm txs and transferdomain txs in the same block + # self.multiple_evm_and_transferdomain_txs() - # Test for multiple transferdomain txs in the same block - self.multiple_transferdomain_txs() + # # Test for multiple transferdomain txs in the same block + # self.multiple_transferdomain_txs() if __name__ == "__main__": From 266835fadd95c541cf893c4fd25467dbe0cbc70f Mon Sep 17 00:00:00 2001 From: Niven Date: Mon, 16 Oct 2023 12:15:25 +0800 Subject: [PATCH 2/6] Fmt py --- test/functional/feature_evm_miner.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/functional/feature_evm_miner.py b/test/functional/feature_evm_miner.py index 66774b0dc83..a09767f8615 100755 --- a/test/functional/feature_evm_miner.py +++ b/test/functional/feature_evm_miner.py @@ -325,7 +325,9 @@ def block_with_multiple_transfer_domain_txs(self): self.nodes[0].generate(1) block_info = self.nodes[0].getblock(self.nodes[0].getbestblockhash(), 4) - assert_equal(len(block_info["tx"][1:]), total_transferdomain_txs * 2 - total_unspent) + assert_equal( + len(block_info["tx"][1:]), total_transferdomain_txs * 2 - total_unspent + ) idx = 0 for tx_info in block_info["tx"][1:]: From c5b2b7b10f5ea0889e0e34d596cc15b6365e3507 Mon Sep 17 00:00:00 2001 From: Niven Date: Mon, 16 Oct 2023 12:15:57 +0800 Subject: [PATCH 3/6] Remove comment --- test/functional/feature_evm_miner.py | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/functional/feature_evm_miner.py b/test/functional/feature_evm_miner.py index a09767f8615..74bf6b23de3 100755 --- a/test/functional/feature_evm_miner.py +++ b/test/functional/feature_evm_miner.py @@ -947,32 +947,32 @@ def multiple_transferdomain_txs(self): def run_test(self): self.setup() - # # Test mining multiple full blocks - # self.multiple_blocks_size_gas_limit() + # Test mining multiple full blocks + self.multiple_blocks_size_gas_limit() - # # Test mining txs into blocks with varying block fees - # self.varying_block_base_fee() + # Test mining txs into blocks with varying block fees + self.varying_block_base_fee() # Test mining multiple transferdomain txs in the same block self.block_with_multiple_transfer_domain_txs() - # # Test mining full block with transferdomain txs - # self.blocks_size_gas_limit_with_transferdomain_txs() + # Test mining full block with transferdomain txs + self.blocks_size_gas_limit_with_transferdomain_txs() - # # Test mining multiple full blocks with max evm txs per sender and RBF - # self.multiple_blocks_size_gas_limit_max_txs_with_rbf() + # Test mining multiple full blocks with max evm txs per sender and RBF + self.multiple_blocks_size_gas_limit_max_txs_with_rbf() - # # Test invalid tx in block creation - # self.invalid_evm_tx_in_block_creation() + # Test invalid tx in block creation + self.invalid_evm_tx_in_block_creation() - # # Test for block size overflow from fee mismatch between tx queue and block - # self.state_dependent_txs_in_block_and_queue() + # Test for block size overflow from fee mismatch between tx queue and block + self.state_dependent_txs_in_block_and_queue() - # # Test for multiple expensive evm txs and transferdomain txs in the same block - # self.multiple_evm_and_transferdomain_txs() + # Test for multiple expensive evm txs and transferdomain txs in the same block + self.multiple_evm_and_transferdomain_txs() - # # Test for multiple transferdomain txs in the same block - # self.multiple_transferdomain_txs() + # Test for multiple transferdomain txs in the same block + self.multiple_transferdomain_txs() if __name__ == "__main__": From 6979680808491052ce1c1e844dd0789e497f370f Mon Sep 17 00:00:00 2001 From: Niven Date: Mon, 16 Oct 2023 12:59:15 +0800 Subject: [PATCH 4/6] Add dst20 test --- test/functional/feature_evm_miner.py | 104 ++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 3 deletions(-) diff --git a/test/functional/feature_evm_miner.py b/test/functional/feature_evm_miner.py index 74bf6b23de3..a8c9d552c9e 100755 --- a/test/functional/feature_evm_miner.py +++ b/test/functional/feature_evm_miner.py @@ -9,6 +9,7 @@ from test_framework.util import ( assert_equal, assert_raises_rpc_error, + get_solc_artifact_path, ) from decimal import Decimal from time import time @@ -83,6 +84,8 @@ def setup(self): "v0/params/feature/evm": "true", "v0/params/feature/transferdomain": "true", "v0/transferdomain/dvm-evm/enabled": "true", + "v0/transferdomain/dvm-evm/dat-enabled": "true", + "v0/transferdomain/evm-dvm/dat-enabled": "true", "v0/transferdomain/dvm-evm/src-formats": ["p2pkh", "bech32"], "v0/transferdomain/dvm-evm/dest-formats": ["erc55"], "v0/transferdomain/evm-dvm/src-formats": ["erc55"], @@ -293,7 +296,7 @@ def varying_block_base_fee(self): tx_info = block_info["tx"][1] assert_equal(tx_info["vm"]["msg"]["hash"], hash[2:]) - def block_with_multiple_transfer_domain_txs(self): + def block_with_multiple_transfer_domain_dfi_txs(self): self.rollback_to(self.start_height) # Send transferdomain txs to be included in the first block @@ -337,6 +340,98 @@ def block_with_multiple_transfer_domain_txs(self): else: assert_equal(tx_info["vm"]["txtype"], "AutoAuth") + def block_with_multiple_transfer_domain_dst20_txs(self): + self.rollback_to(self.start_height) + + self.nodes[0].createtoken( + { + "symbol": "BTC", + "name": "BTC token", + "isDAT": True, + "collateralAddress": self.address, + } + ) + self.nodes[0].generate(1) + self.contract_address_btc = self.nodes[0].w3.to_checksum_address( + "0xff00000000000000000000000000000000000001" + ) + # should have code on contract address + assert ( + self.nodes[0].w3.to_hex( + self.nodes[0].w3.eth.get_code(self.contract_address_btc) + ) + != "0x" + ) + self.abi = open( + get_solc_artifact_path("dst20_v1", "abi.json"), + "r", + encoding="utf8", + ).read() + self.btc = self.nodes[0].w3.eth.contract( + address=self.contract_address_btc, abi=self.abi + ) + assert_equal(self.btc.functions.name().call(), "BTC token") + assert_equal(self.btc.functions.symbol().call(), "BTC") + block = self.nodes[0].eth_getBlockByNumber("latest") + btc_tx = block["transactions"][0] + receipt = self.nodes[0].eth_getTransactionReceipt(btc_tx) + tx = self.nodes[0].eth_getTransactionByHash(btc_tx) + assert_equal( + self.nodes[0].w3.to_checksum_address(receipt["contractAddress"]), + self.contract_address_btc, + ) + assert_equal(receipt["from"], tx["from"]) + assert_equal(receipt["gasUsed"], "0x0") + assert_equal(receipt["logs"], []) + assert_equal(receipt["status"], "0x1") + assert_equal(receipt["to"], None) + + self.nodes[0].minttokens("100@BTC") + self.nodes[0].generate(1) + [beforeBTC] = [x for x in self.nodes[0].getaccount(self.address) if "BTC" in x] + assert_equal(beforeBTC, "100.00000000@BTC") + + # Send transferdomain txs to be included in the first block + total_unspent = len(self.nodes[0].listunspent()) + total_transferdomain_txs = 52 + transferdomaintx_hashes = [] + start_nonce_erc55 = self.nodes[0].w3.eth.get_transaction_count( + self.address_erc55 + ) + for i in range(total_transferdomain_txs): + hash = self.nodes[0].transferdomain( + [ + { + "src": { + "address": self.address, + "amount": "1@BTC", + "domain": 2, + }, + "dst": { + "address": self.ethAddress, + "amount": "1@BTC", + "domain": 3, + }, + "nonce": start_nonce_erc55 + i, + } + ] + ) + transferdomaintx_hashes.append(hash) + + self.nodes[0].generate(1) + block_info = self.nodes[0].getblock(self.nodes[0].getbestblockhash(), 4) + assert_equal( + len(block_info["tx"][1:]), total_transferdomain_txs * 2 - total_unspent + ) + + idx = 0 + for tx_info in block_info["tx"][1:]: + if tx_info["vm"]["txtype"] == "TransferDomain": + assert_equal(tx_info["txid"], transferdomaintx_hashes[idx]) + idx += 1 + else: + assert_equal(tx_info["vm"]["txtype"], "AutoAuth") + def blocks_size_gas_limit_with_transferdomain_txs(self): self.rollback_to(self.start_height) abi, bytecode, _ = EVMContract.from_file("Loop.sol", "Loop").compile() @@ -953,8 +1048,11 @@ def run_test(self): # Test mining txs into blocks with varying block fees self.varying_block_base_fee() - # Test mining multiple transferdomain txs in the same block - self.block_with_multiple_transfer_domain_txs() + # Test mining multiple transferdomain dfi txs in the same block + self.block_with_multiple_transfer_domain_dfi_txs() + + # Test mining multiple transferdomain dst20 txs in the same block + self.block_with_multiple_transfer_domain_dst20_txs() # Test mining full block with transferdomain txs self.blocks_size_gas_limit_with_transferdomain_txs() From 2d23335a997a910be645cd858898d83b99536430 Mon Sep 17 00:00:00 2001 From: Niven Date: Mon, 16 Oct 2023 15:30:05 +0800 Subject: [PATCH 5/6] Add balance check --- test/functional/feature_evm_miner.py | 36 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/test/functional/feature_evm_miner.py b/test/functional/feature_evm_miner.py index a8c9d552c9e..82321fc95a5 100755 --- a/test/functional/feature_evm_miner.py +++ b/test/functional/feature_evm_miner.py @@ -301,8 +301,15 @@ def block_with_multiple_transfer_domain_dfi_txs(self): # Send transferdomain txs to be included in the first block total_unspent = len(self.nodes[0].listunspent()) - total_transferdomain_txs = 52 + dvm_before_balance = Decimal( + self.nodes[0].getaccount(self.address)[0].split("@")[0] + ) + evm_before_balance = Decimal( + self.nodes[0].getaccount(self.ethAddress)[0].split("@")[0] + ) + transferdomaintx_hashes = [] + total_transferdomain_txs = 52 start_nonce_erc55 = self.nodes[0].w3.eth.get_transaction_count( self.address_erc55 ) @@ -327,6 +334,17 @@ def block_with_multiple_transfer_domain_dfi_txs(self): transferdomaintx_hashes.append(hash) self.nodes[0].generate(1) + dvm_after_balance = Decimal( + self.nodes[0].getaccount(self.address)[0].split("@")[0] + ) + evm_after_balance = Decimal( + self.nodes[0].getaccount(self.ethAddress)[0].split("@")[0] + ) + dvm_balance = dvm_before_balance - dvm_after_balance + evm_balance = evm_after_balance - evm_before_balance + assert_equal(dvm_balance, Decimal(total_transferdomain_txs)) + assert_equal(evm_balance, Decimal(total_transferdomain_txs)) + block_info = self.nodes[0].getblock(self.nodes[0].getbestblockhash(), 4) assert_equal( len(block_info["tx"][1:]), total_transferdomain_txs * 2 - total_unspent @@ -388,13 +406,16 @@ def block_with_multiple_transfer_domain_dst20_txs(self): self.nodes[0].minttokens("100@BTC") self.nodes[0].generate(1) - [beforeBTC] = [x for x in self.nodes[0].getaccount(self.address) if "BTC" in x] - assert_equal(beforeBTC, "100.00000000@BTC") # Send transferdomain txs to be included in the first block total_unspent = len(self.nodes[0].listunspent()) - total_transferdomain_txs = 52 + dvm_before_btc = Decimal([x for x in self.nodes[0].getaccount(self.address) if "BTC" in x][0].split("@")[0]) + evm_before_btc = Decimal(self.btc.functions.balanceOf(self.ethAddress).call() / math.pow(10, self.btc.functions.decimals().call())) + assert_equal(evm_before_btc, Decimal(0)) + assert_equal(dvm_before_btc, Decimal(100)) + transferdomaintx_hashes = [] + total_transferdomain_txs = 52 start_nonce_erc55 = self.nodes[0].w3.eth.get_transaction_count( self.address_erc55 ) @@ -419,6 +440,13 @@ def block_with_multiple_transfer_domain_dst20_txs(self): transferdomaintx_hashes.append(hash) self.nodes[0].generate(1) + dvm_after_btc = Decimal([x for x in self.nodes[0].getaccount(self.address) if "BTC" in x][0].split("@")[0]) + evm_after_btc = Decimal(self.btc.functions.balanceOf(self.ethAddress).call() / math.pow(10, self.btc.functions.decimals().call())) + dvm_balance = dvm_before_btc - dvm_after_btc + evm_balance = evm_after_btc - evm_before_btc + assert_equal(dvm_balance, Decimal(total_transferdomain_txs)) + assert_equal(evm_balance, Decimal(total_transferdomain_txs)) + block_info = self.nodes[0].getblock(self.nodes[0].getbestblockhash(), 4) assert_equal( len(block_info["tx"][1:]), total_transferdomain_txs * 2 - total_unspent From 59e03e2ee1ca26775deb33d452035a808d8dd153 Mon Sep 17 00:00:00 2001 From: Niven Date: Mon, 16 Oct 2023 15:30:28 +0800 Subject: [PATCH 6/6] fmt py --- test/functional/feature_evm_miner.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/functional/feature_evm_miner.py b/test/functional/feature_evm_miner.py index 82321fc95a5..38578b74469 100755 --- a/test/functional/feature_evm_miner.py +++ b/test/functional/feature_evm_miner.py @@ -409,8 +409,15 @@ def block_with_multiple_transfer_domain_dst20_txs(self): # Send transferdomain txs to be included in the first block total_unspent = len(self.nodes[0].listunspent()) - dvm_before_btc = Decimal([x for x in self.nodes[0].getaccount(self.address) if "BTC" in x][0].split("@")[0]) - evm_before_btc = Decimal(self.btc.functions.balanceOf(self.ethAddress).call() / math.pow(10, self.btc.functions.decimals().call())) + dvm_before_btc = Decimal( + [x for x in self.nodes[0].getaccount(self.address) if "BTC" in x][0].split( + "@" + )[0] + ) + evm_before_btc = Decimal( + self.btc.functions.balanceOf(self.ethAddress).call() + / math.pow(10, self.btc.functions.decimals().call()) + ) assert_equal(evm_before_btc, Decimal(0)) assert_equal(dvm_before_btc, Decimal(100)) @@ -440,8 +447,15 @@ def block_with_multiple_transfer_domain_dst20_txs(self): transferdomaintx_hashes.append(hash) self.nodes[0].generate(1) - dvm_after_btc = Decimal([x for x in self.nodes[0].getaccount(self.address) if "BTC" in x][0].split("@")[0]) - evm_after_btc = Decimal(self.btc.functions.balanceOf(self.ethAddress).call() / math.pow(10, self.btc.functions.decimals().call())) + dvm_after_btc = Decimal( + [x for x in self.nodes[0].getaccount(self.address) if "BTC" in x][0].split( + "@" + )[0] + ) + evm_after_btc = Decimal( + self.btc.functions.balanceOf(self.ethAddress).call() + / math.pow(10, self.btc.functions.decimals().call()) + ) dvm_balance = dvm_before_btc - dvm_after_btc evm_balance = evm_after_btc - evm_before_btc assert_equal(dvm_balance, Decimal(total_transferdomain_txs))