Skip to content

Commit

Permalink
add pause script & test validation + update setter transaction interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Apr 26, 2024
1 parent eea0627 commit 36718c2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 30 deletions.
6 changes: 6 additions & 0 deletions cadence/contracts/bridge/FlowEVMBridgeConfig.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ contract FlowEVMBridgeConfig {
///
access(Pause)
fun pauseBridge() {
if FlowEVMBridgeConfig.isPaused() {
return
}
FlowEVMBridgeConfig.paused = true
emit PauseStatusUpdated(paused: true)
}
Expand All @@ -247,6 +250,9 @@ contract FlowEVMBridgeConfig {
///
access(Pause)
fun unpauseBridge() {
if !FlowEVMBridgeConfig.isPaused() {
return
}
FlowEVMBridgeConfig.paused = false
emit PauseStatusUpdated(paused: false)
}
Expand Down
6 changes: 6 additions & 0 deletions cadence/scripts/bridge/is_paused.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "FlowEVMBridgeConfig"

access(all)
fun main(): Bool {
return FlowEVMBridgeConfig.isPaused()
}
21 changes: 17 additions & 4 deletions cadence/tests/flow_evm_bridge_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,17 @@ access(all)
fun testPauseBridgeSucceeds() {
// Pause the bridge
let pauseResult = executeTransaction(
"../transactions/bridge/admin/pause/pause_bridge.cdc",
[],
"../transactions/bridge/admin/pause/update_bridge_pause_status.cdc",
[true],
bridgeAccount
)
Test.expect(pauseResult, Test.beSucceeded())
var isPausedResult = executeScript(
"../scripts/bridge/is_paused.cdc",
[]
)
Test.expect(isPausedResult, Test.beSucceeded())
Test.assertEqual(true, isPausedResult.returnValue as! Bool? ?? panic("Problem getting pause status"))

var aliceOwnedIDs = getIDs(ownerAddr: alice.address, storagePathIdentifier: "cadenceExampleNFTCollection")
Test.assertEqual(1, aliceOwnedIDs.length)
Expand All @@ -736,11 +742,18 @@ fun testPauseBridgeSucceeds() {

// Unpause bridging
let unpauseResult = executeTransaction(
"../transactions/bridge/admin/pause/unpause_bridge.cdc",
[],
"../transactions/bridge/admin/pause/update_bridge_pause_status.cdc",
[false],
bridgeAccount
)
Test.expect(unpauseResult, Test.beSucceeded())

isPausedResult = executeScript(
"../scripts/bridge/is_paused.cdc",
[]
)
Test.expect(isPausedResult, Test.beSucceeded())
Test.assertEqual(false, isPausedResult.returnValue as! Bool? ?? panic("Problem getting pause status"))
}

access(all)
Expand Down
13 changes: 0 additions & 13 deletions cadence/transactions/bridge/admin/pause/pause_bridge.cdc

This file was deleted.

13 changes: 0 additions & 13 deletions cadence/transactions/bridge/admin/pause/unpause_bridge.cdc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "FlowEVMBridgeConfig"

/// Sets the pause status of the FlowEVM Bridge as specified.
///
/// @param pause: A boolean indicating whether the FlowEVM Bridge should be paused or unpaused.
///
/// @emits FlowEVMBridgeConfig.PauseStatusUpdated(paused: true)
///
transaction(pause: Bool) {

let admin: auth(FlowEVMBridgeConfig.Pause) &FlowEVMBridgeConfig.Admin

prepare(signer: auth(BorrowValue) &Account) {
self.admin = signer.storage.borrow<auth(FlowEVMBridgeConfig.Pause) &FlowEVMBridgeConfig.Admin>(from: FlowEVMBridgeConfig.adminStoragePath)
?? panic("Could not borrow FlowEVMBridgeConfig Admin reference")
}

execute {
if pause {
self.admin.pauseBridge()
} else {
self.admin.unpauseBridge()
}
}
}

0 comments on commit 36718c2

Please sign in to comment.