From 9090dc0db1185540a66d9de248d8c173a3457c67 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:55:25 -0600 Subject: [PATCH 1/3] add FlowEVMBridgeConfig.setGasLimit txn & test coverage --- .../contracts/bridge/FlowEVMBridgeConfig.cdc | 1 + cadence/scripts/bridge/get_gas_limit.cdc | 6 ++++ cadence/tests/flow_evm_bridge_tests.cdc | 33 +++++++++++++++++++ .../bridge/admin/gas/set_gas_limit.cdc | 23 +++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 cadence/scripts/bridge/get_gas_limit.cdc create mode 100644 cadence/transactions/bridge/admin/gas/set_gas_limit.cdc diff --git a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc index be03a483..2bef3205 100644 --- a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc +++ b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc @@ -30,6 +30,7 @@ contract FlowEVMBridgeConfig { /// Default ERC20.decimals() value access(all) let defaultDecimals: UInt8 + /// The gas limit for all EVM calls related to bridge operations access(all) var gasLimit: UInt64 /// Flag enabling pausing of bridge operations diff --git a/cadence/scripts/bridge/get_gas_limit.cdc b/cadence/scripts/bridge/get_gas_limit.cdc new file mode 100644 index 00000000..42610d5d --- /dev/null +++ b/cadence/scripts/bridge/get_gas_limit.cdc @@ -0,0 +1,6 @@ +import "FlowEVMBridgeConfig" + +access(all) +fun main(): UInt64 { + return FlowEVMBridgeConfig.gasLimit +} diff --git a/cadence/tests/flow_evm_bridge_tests.cdc b/cadence/tests/flow_evm_bridge_tests.cdc index 992b60e5..647bd49e 100644 --- a/cadence/tests/flow_evm_bridge_tests.cdc +++ b/cadence/tests/flow_evm_bridge_tests.cdc @@ -7,6 +7,7 @@ import "ExampleNFT" import "ExampleToken" import "FlowStorageFees" import "EVM" +import "FlowEVMBridgeConfig" import "test_helpers.cdc" @@ -324,6 +325,38 @@ fun setup() { Test.expect(err, Test.beNil()) } +/* --- CONFIG TEST --- */ + +access(all) +fun testSetGasLimitSucceeds() { + + fun getGasLimit(): UInt64 { + let gasLimitResult = executeScript( + "../scripts/bridge/get_gas_limit.cdc", + [] + ) + Test.expect(gasLimitResult, Test.beSucceeded()) + return gasLimitResult.returnValue as! UInt64? ?? panic("Problem getting gas limit") + } + + snapshot = getCurrentBlockHeight() + + let preGasLimit = getGasLimit() + let gasLimit = preGasLimit + 1_000 + + let setGasLimitResult = executeTransaction( + "../transactions/bridge/admin/gas/set_gas_limit.cdc", + [gasLimit], + bridgeAccount + ) + Test.expect(setGasLimitResult, Test.beSucceeded()) + + let postGasLimit = getGasLimit() + Test.assertEqual(gasLimit, postGasLimit) + + Test.reset(to: snapshot) +} + /* --- ASSET & ACCOUNT SETUP - Configure test accounts with assets to bridge --- */ access(all) diff --git a/cadence/transactions/bridge/admin/gas/set_gas_limit.cdc b/cadence/transactions/bridge/admin/gas/set_gas_limit.cdc new file mode 100644 index 00000000..26d27ed4 --- /dev/null +++ b/cadence/transactions/bridge/admin/gas/set_gas_limit.cdc @@ -0,0 +1,23 @@ +import "FlowEVMBridgeConfig" + +/// Sets the gas limit for all bridge-related operations in EVM. +/// +/// @param gasLimit: The new gas limit for all bridge-related operations in EVM. +/// +transaction(gasLimit: UInt64) { + + let admin: auth(FlowEVMBridgeConfig.Gas) &FlowEVMBridgeConfig.Admin + + prepare(signer: auth(BorrowValue) &Account) { + self.admin = signer.storage.borrow(from: FlowEVMBridgeConfig.adminStoragePath) + ?? panic("Could not borrow FlowEVMBridgeConfig Admin reference") + } + + execute { + self.admin.setGasLimit(gasLimit) + } + + post { + FlowEVMBridgeConfig.gasLimit == gasLimit: "Problem setting gasLimit to: ".concat(gasLimit.toString()) + } +} From 2d632846aabd574c8c173d46fd2689dc4ef8690e Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:59:57 -0600 Subject: [PATCH 2/3] add script comments --- cadence/scripts/bridge/get_gas_limit.cdc | 4 ++++ cadence/tests/flow_evm_bridge_tests.cdc | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cadence/scripts/bridge/get_gas_limit.cdc b/cadence/scripts/bridge/get_gas_limit.cdc index 42610d5d..be2aff46 100644 --- a/cadence/scripts/bridge/get_gas_limit.cdc +++ b/cadence/scripts/bridge/get_gas_limit.cdc @@ -1,5 +1,9 @@ import "FlowEVMBridgeConfig" +/// Returns the gas limit for the Flow-EVM bridge. +/// +/// @returns The current gas limit shared by all the bridge-related EVM operations. +/// access(all) fun main(): UInt64 { return FlowEVMBridgeConfig.gasLimit diff --git a/cadence/tests/flow_evm_bridge_tests.cdc b/cadence/tests/flow_evm_bridge_tests.cdc index 647bd49e..fcb9315c 100644 --- a/cadence/tests/flow_evm_bridge_tests.cdc +++ b/cadence/tests/flow_evm_bridge_tests.cdc @@ -7,7 +7,6 @@ import "ExampleNFT" import "ExampleToken" import "FlowStorageFees" import "EVM" -import "FlowEVMBridgeConfig" import "test_helpers.cdc" From f0690650be28a74551b335af3d53cb2b69d00444 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:02:27 -0600 Subject: [PATCH 3/3] move dry_run txn --- .../{tests/transactions => transactions/bridge/admin}/dry_run.cdc | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cadence/{tests/transactions => transactions/bridge/admin}/dry_run.cdc (100%) diff --git a/cadence/tests/transactions/dry_run.cdc b/cadence/transactions/bridge/admin/dry_run.cdc similarity index 100% rename from cadence/tests/transactions/dry_run.cdc rename to cadence/transactions/bridge/admin/dry_run.cdc