Skip to content

Commit

Permalink
Fixes to EVM functional tests (#2191)
Browse files Browse the repository at this point in the history
* Add functional test for burnt fees

* Fix bug to check for min gas limit in validate tx, add test

* Bug fixes EIP1559 tx gas fees

* Refactor cmp pipeline

* Add changi intermediate forkguard

* Fix lint

* Include changi intermediates in all evm tests

* Fixes to evm functional tests

* Revert test runner

* Revert test runner

* Update expected strings to include new keys

---------

Co-authored-by: Prasanna Loganathar <[email protected]>
Co-authored-by: Bushstar <[email protected]>
  • Loading branch information
3 people authored Jul 19, 2023
1 parent a5fa496 commit 57a76e6
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 21 deletions.
20 changes: 18 additions & 2 deletions test/functional/feature_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,16 @@ def run_test(self):
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 10000000000000000000)
assert_equal(int(self.nodes[0].eth_getBalance(to_address)[2:], 16), 0)

# Get miner DFI balance before transaction
# Send tokens to burn address
burn_address = "mfburnZSAM7Gs1hpDeNaMotJXSGA7edosG"
self.nodes[0].importprivkey("93ViFmLeJVgKSPxWGQHmSdT5RbeGDtGW4bsiwQM2qnQyucChMqQ")
result = self.nodes[0].getburninfo()
assert_equal(result['address'], burn_address)
self.nodes[0].accounttoaccount(address, {burn_address: "1@DFI"})
self.nodes[0].generate(1)

# Get burn address and miner account balance before transaction
burn_before = Decimal(self.nodes[0].getaccount(burn_address)[0].split('@')[0])
miner_before = Decimal(self.nodes[0].getaccount(self.nodes[0].get_genesis_keys().ownerAuthAddress)[0].split('@')[0])
before_blockheight = self.nodes[0].getblockcount()

Expand Down Expand Up @@ -202,8 +211,10 @@ def run_test(self):
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 4996564910000000000)
assert_equal(int(self.nodes[0].eth_getBalance(to_address)[2:], 16), 5000000000000000000)

# Check miner account balance after transfer
# Get burn address and miner account balance after transfer
burn_after = Decimal(self.nodes[0].getaccount(burn_address)[0].split('@')[0])
miner_after = Decimal(self.nodes[0].getaccount(self.nodes[0].get_genesis_keys().ownerAuthAddress)[0].split('@')[0])
burnt_fee = burn_after - burn_before
miner_fee = miner_after - miner_before

# Check EVM Tx shows in block on EVM side
Expand Down Expand Up @@ -247,6 +258,11 @@ def run_test(self):
block_hash = raw_tx['vout'][1]['scriptPubKey']['hex'][20:84]
assert_equal(block_hash, eth_hash)

# Check EVM burnt fee
opreturn_burnt_fee_amount = raw_tx['vout'][1]['scriptPubKey']['hex'][84:]
opreturn_burnt_fee_sats = Decimal(int(opreturn_burnt_fee_amount[4:6] + opreturn_burnt_fee_amount[2:4] + opreturn_burnt_fee_amount[0:2], 16)) / 100000000
assert_equal(opreturn_burnt_fee_sats, burnt_fee)

# Check EVM miner fee
opreturn_priority_fee_amount = raw_tx['vout'][1]['scriptPubKey']['hex'][100:]
opreturn_priority_fee_sats = Decimal(int(opreturn_priority_fee_amount[4:6] + opreturn_priority_fee_amount[2:4] + opreturn_priority_fee_amount[0:2], 16)) / 100000000
Expand Down
3 changes: 2 additions & 1 deletion test/functional/feature_evm_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def set_test_params(self):
'-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86',
'-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94',
'-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105',
'-changiintermediate3height=105', '-subsidytest=1', '-txindex=1'],
'-changiintermediateheight=105', '-changiintermediate2height=105', '-changiintermediate3height=105',
'-changiintermediate4height=105', '-subsidytest=1', '-txindex=1'],
]

def setup(self):
Expand Down
7 changes: 6 additions & 1 deletion test/functional/feature_evm_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
self.extra_args = [
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105', '-changiintermediateheight=105', '-changiintermediate4height=105', '-subsidytest=1', '-txindex=1'],
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80',
'-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86',
'-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94',
'-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105',
'-changiintermediateheight=105', '-changiintermediate2height=105', '-changiintermediate3height=105',
'-changiintermediate4height=105', '-subsidytest=1', '-txindex=1'],
]

def setup(self):
Expand Down
4 changes: 4 additions & 0 deletions test/functional/feature_evm_genesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def set_test_params(self):
"-fortcanningepilogueheight=96",
"-grandcentralheight=101",
"-nextnetworkupgradeheight=105",
'-changiintermediateheight=105',
'-changiintermediate2height=105',
'-changiintermediate3height=105',
'-changiintermediate4height=105',
"-subsidytest=1",
"-txindex=1",
],
Expand Down
9 changes: 7 additions & 2 deletions test/functional/feature_evm_rollback.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
self.extra_args = [
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105', '-subsidytest=1', '-txindex=1'],
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80',
'-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86',
'-fortcanningcrunchheight=88','-fortcanningspringheight=90', '-fortcanninggreatworldheight=94',
'-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105',
'-changiintermediateheight=105', '-changiintermediate2height=105', '-changiintermediate3height=105',
'-changiintermediate4height=105', '-subsidytest=1', '-txindex=1'],
]

def setup(self):
Expand Down Expand Up @@ -69,7 +74,7 @@ def test_rollback_transactions(self):
'to': self.toAddress,
'value': '0xa',
'gas': '0x7a120',
'gasPrice': '0x7a120',
'gasPrice': '0x2540BE400',
})
self.nodes[0].generate(1)

Expand Down
7 changes: 6 additions & 1 deletion test/functional/feature_evm_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
self.extra_args = [
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105', '-subsidytest=1', '-txindex=1'],
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80',
'-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86',
'-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94',
'-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105',
'-changiintermediateheight=105', '-changiintermediate2height=105', '-changiintermediate3height=105',
'-changiintermediate4height=105', '-subsidytest=1', '-txindex=1'],
]

def setup(self):
Expand Down
13 changes: 9 additions & 4 deletions test/functional/feature_evm_rpc_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
self.extra_args = [
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105', '-subsidytest=1', '-txindex=1'],
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80',
'-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86',
'-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94',
'-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105',
'-changiintermediateheight=105', '-changiintermediate2height=105', '-changiintermediate3height=105',
'-changiintermediate4height=105', '-subsidytest=1', '-txindex=1'],
]

def setup(self):
Expand Down Expand Up @@ -107,7 +112,7 @@ def test_sign_and_send_raw_transaction(self):
# nonce: 1,
# value: 0,
# data: CONTRACT_BYTECODE,
# gasLimit: 3_000,
# gasLimit: 500_000,
# gasPrice: 150_000_000_000,
# accessList: [
# {
Expand All @@ -131,7 +136,7 @@ def test_sign_and_send_raw_transaction(self):
'from': self.ethAddress,
'value': '0x0',
'data': CONTRACT_BYTECODE,
'gas': '0xbb8', # 3_000
'gas': '0x7a120', # 500_000
'maxPriorityFeePerGas': '0x2363e7f000', # 152_000_000_000
'maxFeePerGas': '0x22ecb25c00', # 150_000_000_000
'type': '0x2',
Expand All @@ -147,7 +152,7 @@ def test_sign_and_send_raw_transaction(self):
# maxPriorityFeePerGas: 152_000_000_000, # 152 gwei
# maxFeePerGas: 150_000_000_000, type: 2,
# }
rawtx = '0x02f9015982046d02852363e7f0008522ecb25c00820bb88080b8fe608060405234801561001057600080fd5b5060df8061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063165c4a1614602d575b600080fd5b603c6038366004605f565b604e565b60405190815260200160405180910390f35b600060588284607f565b9392505050565b600080604083850312156070578182fd5b50508035926020909101359150565b600081600019048311821515161560a457634e487b7160e01b81526011600452602481fd5b50029056fea2646970667358221220223df7833fd08eb1cd3ce363a9c4cb4619c1068a5f5517ea8bb862ed45d994f764736f6c63430008020033c080a047375bb73a006fdfcbecaf027305e0889b49277a151763799d68cfcbd06a84c6a0255b585e390c63f8d2c501606aa6fa1e1f3dffa7a8705a431f6a0ad99a1cc7e4'
rawtx = '0x02f9015a82046d02852363e7f0008522ecb25c008307a1208080b8fe608060405234801561001057600080fd5b5060df8061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063165c4a1614602d575b600080fd5b603c6038366004605f565b604e565b60405190815260200160405180910390f35b600060588284607f565b9392505050565b600080604083850312156070578182fd5b50508035926020909101359150565b600081600019048311821515161560a457634e487b7160e01b81526011600452602481fd5b50029056fea2646970667358221220223df7833fd08eb1cd3ce363a9c4cb4619c1068a5f5517ea8bb862ed45d994f764736f6c63430008020033c080a05eceb8ff0ce33c95106051d82896aaf41bc899f625189922d12edeb7ce6fd56da07c37f48b1f4dfbf89a81cbe62c93ab23eec00808f7daca0cc5cf29860d112759'
assert_equal(f"0x{signed}", rawtx)

hash = self.nodes[0].eth_sendRawTransaction(rawtx)
Expand Down
7 changes: 6 additions & 1 deletion test/functional/feature_evm_smart_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
self.extra_args = [
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105', '-subsidytest=1', '-txindex=1'],
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80',
'-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86',
'-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94',
'-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105',
'-changiintermediateheight=105', '-changiintermediate2height=105', '-changiintermediate3height=105',
'-changiintermediate4height=105', '-subsidytest=1', '-txindex=1'],
]

def setup(self):
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_evm_transferdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def invalid_parameters(self):
def invalid_values_dvm_evm(self):
# Check for valid values DVM->EVM in transferdomain rpc
assert_raises_rpc_error(-32600, "Src address must be a legacy or Bech32 address in case of \"DVM\" domain", self.nodes[0].transferdomain, [{"src": {"address":self.eth_address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.eth_address, "amount":"100@DFI", "domain": 3}}])
assert_raises_rpc_error(-32600, "Dst address must be an ETH address in case of \"EVM\" domain", self.nodes[0].transferdomain, [{"src": {"address":self.address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.address, "amount":"100@DFI", "domain": 3}}])
assert_raises_rpc_error(-32600, "Dst address must be an ERC55 address in case of \"EVM\" domain", self.nodes[0].transferdomain, [{"src": {"address":self.address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.address, "amount":"100@DFI", "domain": 3}}])
assert_raises_rpc_error(-32600, "Cannot transfer inside same domain", self.nodes[0].transferdomain, [{"src": {"address":self.address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.eth_address, "amount":"100@DFI", "domain": 2}}])
assert_raises_rpc_error(-32600, "Source amount must be equal to destination amount", self.nodes[0].transferdomain, [{"src": {"address":self.address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.eth_address, "amount":"101@DFI", "domain": 3}}])
assert_raises_rpc_error(-32600, "For transferdomain, only DFI token is currently supported", self.nodes[0].transferdomain, [{"src": {"address":self.address, "amount":"100@BTC", "domain": 2}, "dst":{"address":self.eth_address, "amount":"100@DFI", "domain": 3}}])
Expand Down Expand Up @@ -148,7 +148,7 @@ def valid_transfer_dvm_evm(self):

def invalid_values_evm_dvm(self):
# Check for valid values EVM->DVM in transferdomain rpc
assert_raises_rpc_error(-32600, "Src address must be an ETH address in case of \"EVM\" domain", self.nodes[0].transferdomain, [{"src": {"address":self.address, "amount":"100@DFI", "domain": 3}, "dst":{"address":self.address, "amount":"100@DFI", "domain": 2}}])
assert_raises_rpc_error(-32600, "Src address must be an ERC55 address in case of \"EVM\" domain", self.nodes[0].transferdomain, [{"src": {"address":self.address, "amount":"100@DFI", "domain": 3}, "dst":{"address":self.address, "amount":"100@DFI", "domain": 2}}])
assert_raises_rpc_error(-32600, "Dst address must be a legacy or Bech32 address in case of \"DVM\" domain", self.nodes[0].transferdomain, [{"src": {"address":self.eth_address, "amount":"100@DFI", "domain": 3}, "dst":{"address":self.eth_address, "amount":"100@DFI", "domain": 2}}])
assert_raises_rpc_error(-32600, "Cannot transfer inside same domain", self.nodes[0].transferdomain, [{"src": {"address":self.eth_address, "amount":"100@DFI", "domain": 3}, "dst":{"address":self.address, "amount":"100@DFI", "domain": 3}}])
assert_raises_rpc_error(-32600, "Source amount must be equal to destination amount", self.nodes[0].transferdomain, [{"src": {"address":self.eth_address, "amount":"100@DFI", "domain": 3}, "dst":{"address":self.address, "amount":"101@DFI", "domain": 2}}])
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_evm_vmmap_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True
self.extra_args = [
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105', '-subsidytest=1', '-txindex=1'],
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105', '-subsidytest=1', '-txindex=1'],
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105', '-changiintermediateheight=105', '-changiintermediate2height=105', '-changiintermediate3height=105', '-changiintermediate4height=105', '-subsidytest=1', '-txindex=1'],
['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=51', '-eunosheight=80', '-fortcanningheight=82', '-fortcanninghillheight=84', '-fortcanningroadheight=86', '-fortcanningcrunchheight=88', '-fortcanningspringheight=90', '-fortcanninggreatworldheight=94', '-fortcanningepilogueheight=96', '-grandcentralheight=101', '-nextnetworkupgradeheight=105', '-changiintermediateheight=105', '-changiintermediate2height=105', '-changiintermediate3height=105', '-changiintermediate4height=105', '-subsidytest=1', '-txindex=1'],
]

def setup(self):
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_loan_payback_dfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def run_test(self):
})

assert_raises_rpc_error(-5,
'Unrecognised type argument provided, valid types are: consortium, gov, locks, oracles, params, poolpairs, token,',
'Unrecognised type argument provided, valid types are: consortium, evm, gov, locks, oracles, params, poolpairs, token, transferdomain, vaults,',
self.nodes[0].setgov, {"ATTRIBUTES": {'v0/live/economy/dfi_payback_tokens': '1'}})

# Disable loan payback
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_loan_payback_dfi_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def payback_with_DFI_prior_to_atribute_activation(self):

def setgov_attribute_to_false_and_payback(self):
assert_raises_rpc_error(-5,
'Unrecognised type argument provided, valid types are: consortium, gov, locks, oracles, params, poolpairs, token,',
'Unrecognised type argument provided, valid types are: consortium, evm, gov, locks, oracles, params, poolpairs, token, transferdomain, vaults,',
self.nodes[0].setgov, {"ATTRIBUTES": {'v0/live/economy/dfi_payback_tokens': '1'}})

# Disable loan payback
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_setgov.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def run_test(self):
"Incorrect key for <type>. Object of ['<version>/<type>/ID/<key>','value'] expected",
self.nodes[0].setgov, {"ATTRIBUTES": {'v0/token/payback_dfi': 'true'}})
assert_raises_rpc_error(-5,
"Unrecognised type argument provided, valid types are: consortium, gov, locks, oracles, params, poolpairs, token,",
"Unrecognised type argument provided, valid types are: consortium, evm, gov, locks, oracles, params, poolpairs, token, transferdomain, vaults,",
self.nodes[0].setgov, {"ATTRIBUTES": {'v0/unrecognised/5/payback_dfi': 'true'}})
assert_raises_rpc_error(-5,
"Unrecognised key argument provided, valid keys are: dex_in_fee_pct, dex_out_fee_pct, dfip2203, fixed_interval_price_id, loan_collateral_enabled, loan_collateral_factor, loan_minting_enabled, loan_minting_interest, loan_payback, loan_payback_collateral, loan_payback_fee_pct, payback_dfi, payback_dfi_fee_pct,",
Expand Down
Loading

0 comments on commit 57a76e6

Please sign in to comment.