diff --git a/Cargo.toml b/Cargo.toml index e5a4c57..747d1cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ keywords = ["near", "smart contract", "plugin"] [workspace.dependencies] bitflags = "1.3" -near-sdk = "5.2" +near-sdk = ">=5.2, <5.4" near-plugins = { path = "near-plugins" } near-plugins-derive = { path = "near-plugins-derive" } serde = "1" diff --git a/near-plugins-derive/src/pausable.rs b/near-plugins-derive/src/pausable.rs index bda149b..3c109e4 100644 --- a/near-plugins-derive/src/pausable.rs +++ b/near-plugins-derive/src/pausable.rs @@ -201,6 +201,10 @@ pub fn if_paused(attrs: TokenStream, item: TokenStream) -> TokenStream { } fn get_bypass_condition(args: &ExceptSubArgs) -> proc_macro2::TokenStream { + if args.roles.len() == 0 { + return quote!(); + } + let except_roles = args.roles.clone(); quote!( let __except_roles: Vec<&str> = vec![#(#except_roles.into()),*]; diff --git a/near-plugins-derive/tests/common/utils.rs b/near-plugins-derive/tests/common/utils.rs index 2fb95a9..bbacb85 100644 --- a/near-plugins-derive/tests/common/utils.rs +++ b/near-plugins-derive/tests/common/utils.rs @@ -110,6 +110,16 @@ pub fn assert_method_is_paused(res: ExecutionFinalResult) { ); } +pub fn assert_view_method_is_paused(err: anyhow::Error) { + let err = format!("{:?}", err); + let must_contain = "Pausable: Method is paused"; + assert!( + err.contains(must_contain), + "Expected method to be paused, instead it failed with: {}", + err + ); +} + pub fn assert_pausable_escape_hatch_is_closed(res: ExecutionFinalResult, feature: &str) { let must_contain = format!("Pausable: {feature} must be paused to use this function"); assert_failure_with(res, &must_contain); diff --git a/near-plugins-derive/tests/contracts/pausable/src/lib.rs b/near-plugins-derive/tests/contracts/pausable/src/lib.rs index 9d7fec9..8c66f4a 100644 --- a/near-plugins-derive/tests/contracts/pausable/src/lib.rs +++ b/near-plugins-derive/tests/contracts/pausable/src/lib.rs @@ -57,6 +57,7 @@ impl Counter { } /// Returns the value of the counter. + #[pause] pub fn get_counter(&self) -> u64 { self.counter } diff --git a/near-plugins-derive/tests/pausable.rs b/near-plugins-derive/tests/pausable.rs index 6f5604a..d01bb71 100644 --- a/near-plugins-derive/tests/pausable.rs +++ b/near-plugins-derive/tests/pausable.rs @@ -7,6 +7,7 @@ use common::pausable_contract::PausableContract; use common::utils::{ assert_failure_with, assert_insufficient_acl_permissions, assert_method_is_paused, assert_pausable_escape_hatch_is_closed, assert_success_with, assert_success_with_unit_return, + assert_view_method_is_paused, }; use near_sdk::serde_json::json; use near_workspaces::network::Sandbox; @@ -319,6 +320,11 @@ async fn test_pause_with_all_allows_except() -> anyhow::Result<()> { .call_counter_modifier(&exempted_account, "increase_4") .await?; assert_success_with_unit_return(res); + let res = setup + .pausable_contract + .pa_unpause_feature(&setup.pause_manager, "ALL") + .await?; + assert_success_with(res, true); assert_eq!(setup.get_counter().await?, 4); Ok(()) } @@ -341,6 +347,25 @@ async fn test_not_paused_with_different_key() -> anyhow::Result<()> { Ok(()) } +#[tokio::test] +async fn test_pause_view_method() -> anyhow::Result<()> { + let setup = Setup::new().await?; + let res = setup + .call_counter_modifier(&setup.unauth_account, "increase_1") + .await?; + assert_success_with_unit_return(res); + assert_eq!(setup.get_counter().await?, 1); + + let res = setup + .pausable_contract + .pa_pause_feature(&setup.pause_manager, "get_counter") + .await?; + assert_success_with(res, true); + assert_view_method_is_paused(setup.get_counter().await.unwrap_err()); + + Ok(()) +} + #[tokio::test] async fn test_work_after_unpause() -> anyhow::Result<()> { let setup = Setup::new().await?;