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..be2aff46 --- /dev/null +++ b/cadence/scripts/bridge/get_gas_limit.cdc @@ -0,0 +1,10 @@ +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 6ab64d01..ea1bf5bc 100644 --- a/cadence/tests/flow_evm_bridge_tests.cdc +++ b/cadence/tests/flow_evm_bridge_tests.cdc @@ -325,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/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 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()) + } +}