Skip to content

Commit

Permalink
Merge pull request #92 from onflow/add-gas-setting-txn
Browse files Browse the repository at this point in the history
Add FlowEVMBridgeConfig.setGasLimit() transaction & test coverage
  • Loading branch information
sisyphusSmiling committed Jul 1, 2024
2 parents 1a7f269 + f069065 commit 8e04119
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions cadence/contracts/bridge/FlowEVMBridgeConfig.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cadence/scripts/bridge/get_gas_limit.cdc
Original file line number Diff line number Diff line change
@@ -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
}
32 changes: 32 additions & 0 deletions cadence/tests/flow_evm_bridge_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions cadence/transactions/bridge/admin/gas/set_gas_limit.cdc
Original file line number Diff line number Diff line change
@@ -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<auth(FlowEVMBridgeConfig.Gas) &FlowEVMBridgeConfig.Admin>(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())
}
}

0 comments on commit 8e04119

Please sign in to comment.