diff --git a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc index b70bd6e3..32c2edd3 100644 --- a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc +++ b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc @@ -239,6 +239,9 @@ contract FlowEVMBridgeConfig { /// access(Pause) fun pauseBridge() { + if FlowEVMBridgeConfig.isPaused() { + return + } FlowEVMBridgeConfig.paused = true emit PauseStatusUpdated(paused: true) } @@ -247,6 +250,9 @@ contract FlowEVMBridgeConfig { /// access(Pause) fun unpauseBridge() { + if !FlowEVMBridgeConfig.isPaused() { + return + } FlowEVMBridgeConfig.paused = false emit PauseStatusUpdated(paused: false) } diff --git a/cadence/scripts/bridge/is_paused.cdc b/cadence/scripts/bridge/is_paused.cdc new file mode 100644 index 00000000..21f65ebb --- /dev/null +++ b/cadence/scripts/bridge/is_paused.cdc @@ -0,0 +1,6 @@ +import "FlowEVMBridgeConfig" + +access(all) +fun main(): Bool { + return FlowEVMBridgeConfig.isPaused() +} diff --git a/cadence/tests/flow_evm_bridge_tests.cdc b/cadence/tests/flow_evm_bridge_tests.cdc index 6ff39bcc..252cf3f4 100644 --- a/cadence/tests/flow_evm_bridge_tests.cdc +++ b/cadence/tests/flow_evm_bridge_tests.cdc @@ -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) @@ -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) diff --git a/cadence/transactions/bridge/admin/pause/pause_bridge.cdc b/cadence/transactions/bridge/admin/pause/pause_bridge.cdc deleted file mode 100644 index b0ffafb3..00000000 --- a/cadence/transactions/bridge/admin/pause/pause_bridge.cdc +++ /dev/null @@ -1,13 +0,0 @@ -import "FlowEVMBridgeConfig" - -/// Pauses bridging operations. -/// -/// @emits FlowEVMBridgeConfig.PauseStatusUpdated(paused: true) -/// -transaction { - prepare(signer: auth(BorrowValue) &Account) { - signer.storage.borrow(from: FlowEVMBridgeConfig.adminStoragePath) - ?.pauseBridge() - ?? panic("Could not borrow FlowEVMBridgeConfig Admin reference") - } -} diff --git a/cadence/transactions/bridge/admin/pause/unpause_bridge.cdc b/cadence/transactions/bridge/admin/pause/unpause_bridge.cdc deleted file mode 100644 index 7fc924cb..00000000 --- a/cadence/transactions/bridge/admin/pause/unpause_bridge.cdc +++ /dev/null @@ -1,13 +0,0 @@ -import "FlowEVMBridgeConfig" - -/// Pauses bridging operations. -/// -/// @emits FlowEVMBridgeConfig.PauseStatusUpdated(paused: true) -/// -transaction { - prepare(signer: auth(BorrowValue) &Account) { - signer.storage.borrow(from: FlowEVMBridgeConfig.adminStoragePath) - ?.unpauseBridge() - ?? panic("Could not borrow FlowEVMBridgeConfig Admin reference") - } -} diff --git a/cadence/transactions/bridge/admin/pause/update_bridge_pause_status.cdc b/cadence/transactions/bridge/admin/pause/update_bridge_pause_status.cdc new file mode 100644 index 00000000..92a742e8 --- /dev/null +++ b/cadence/transactions/bridge/admin/pause/update_bridge_pause_status.cdc @@ -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(from: FlowEVMBridgeConfig.adminStoragePath) + ?? panic("Could not borrow FlowEVMBridgeConfig Admin reference") + } + + execute { + if pause { + self.admin.pauseBridge() + } else { + self.admin.unpauseBridge() + } + } +}