Skip to content

Commit

Permalink
Split set_paused_withdraw into pause & unpause (#236)
Browse files Browse the repository at this point in the history
* Split `set_paused_withdraw` into pause & unpause

* Bump `bridge-token-factory"` version

* Update contract build

* Fix tests
  • Loading branch information
karim-en authored Nov 7, 2023
1 parent 9701263 commit 76b753c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bridge-token-factory/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bridge-token-factory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bridge-token-factory"
version = "0.2.2"
version = "0.2.3"
authors = ["Near Inc <hello@near.org>"]
edition = "2021"
publish = false
Expand Down
20 changes: 16 additions & 4 deletions bridge-token-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,18 +508,30 @@ impl BridgeTokenFactory {
)
}

/// Pause or unpause the withdraw method in the bridge token contract.
/// Pause the withdraw method in the bridge token contract.
///
/// # Arguments
///
/// * `address`: Ethereum address of the token ERC20 contract, in hexadecimal format without `0x`.
/// * `paused`: `true` to pause the withdraw method in the bridge token contract, `false` to unpause.
///
#[access_control_any(roles(Role::DAO, Role::PauseManager))]
pub fn set_paused_withdraw(&mut self, address: String, paused: bool) -> Promise {
pub fn pause_withdraw(&mut self, address: String) -> Promise {
ext_bridge_token::ext(self.get_bridge_token_account_id(address))
.with_static_gas(SET_PAUSED_GAS)
.set_paused(paused)
.set_paused(true)
}

/// Unpause the withdraw method in the bridge token contract.
///
/// # Arguments
///
/// * `address`: Ethereum address of the token ERC20 contract, in hexadecimal format without `0x`.
///
#[access_control_any(roles(Role::DAO, Role::PauseManager))]
pub fn unpause_withdraw(&mut self, address: String) -> Promise {
ext_bridge_token::ext(self.get_bridge_token_account_id(address))
.with_static_gas(SET_PAUSED_GAS)
.set_paused(false)
}

pub fn get_bridge_token_account_id(&self, address: String) -> AccountId {
Expand Down
13 changes: 7 additions & 6 deletions bridge-token-factory/tests/token_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const FACTORY_WASM_PATH: &str = "../res/bridge_token_factory.wasm";
const FACTORY_WASM_PATH_V_0_1_6: &str = "res/bridge_token_factory_v0.1.6.wasm";
const BRIDGE_TOKEN_WASM_PATH: &str = "../res/bridge_token.wasm";
const MOCK_PROVER_WASM_PATH: &str = "../res/mock_prover.wasm";

const LAST_FACTORY_VERSION: &str = env!("CARGO_PKG_VERSION");
const LAST_BRIDGE_TOKEN_VERSION: &str = "0.2.2";
const DEFAULT_DEPOSIT: u128 = ONE_NEAR;

async fn create_contract(factory_wasm_path: &str) -> (Account, Contract, Worker<Sandbox>) {
Expand Down Expand Up @@ -534,7 +535,7 @@ async fn test_upgrade() {

// Verify the factory version
let factory_version: String = factory.view("version").await.unwrap().json().unwrap();
assert_eq!(factory_version, "0.2.2");
assert_eq!(factory_version, LAST_FACTORY_VERSION);

// Set alice as super admin
let result = factory
Expand Down Expand Up @@ -582,7 +583,7 @@ async fn test_upgrade() {
.unwrap()
.json()
.unwrap();
assert_eq!(token_version, "0.2.2");
assert_eq!(token_version, LAST_BRIDGE_TOKEN_VERSION);

// Upgrade the bridge token over factory (redeploy the same version)
let result = alice
Expand All @@ -605,7 +606,7 @@ async fn test_upgrade() {
.unwrap()
.json()
.unwrap();
assert_eq!(token_version, "0.2.2");
assert_eq!(token_version, LAST_BRIDGE_TOKEN_VERSION);

// Grant alice the `PauseManager` role
let result = alice
Expand All @@ -627,9 +628,9 @@ async fn test_upgrade() {

// Pause bridge token withdraw
let result = alice
.call(factory.id(), "set_paused_withdraw")
.call(factory.id(), "pause_withdraw")
.args(
json!({"address": DAI_ADDRESS.to_string(), "paused": true})
json!({"address": DAI_ADDRESS.to_string()})
.to_string()
.into_bytes(),
)
Expand Down
Binary file modified res/bridge_token_factory.wasm
Binary file not shown.

0 comments on commit 76b753c

Please sign in to comment.