Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split set_paused_withdraw into pause & unpause #236

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>"]
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.
Loading