Skip to content
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
22 changes: 11 additions & 11 deletions near-plugins/tests/access_controllable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Setup {
) -> anyhow::Result<Self> {
let worker = workspaces::sandbox().await?;
let wasm =
common::repo::compile_project(&Path::new(PROJECT_PATH), "access_controllable").await?;
common::repo::compile_project(Path::new(PROJECT_PATH), "access_controllable").await?;
let contract = AccessControllableContract::new(worker.dev_deploy(&wasm).await?);
let account = worker.dev_create_account().await?;

Expand Down Expand Up @@ -171,15 +171,15 @@ async fn test_acl_is_super_admin() -> anyhow::Result<()> {
} = Setup::new().await?;

let is_super_admin = contract.acl_is_super_admin(&account, account.id()).await?;
assert_eq!(is_super_admin, false);
assert!(!is_super_admin);

contract
.acl_add_super_admin_unchecked(contract.contract().as_account(), account.id())
.await?
.into_result()?;

let is_super_admin = contract.acl_is_super_admin(&account, account.id()).await?;
assert_eq!(is_super_admin, true);
assert!(is_super_admin);

Ok(())
}
Expand Down Expand Up @@ -387,15 +387,15 @@ async fn test_acl_is_admin() -> anyhow::Result<()> {
let role = "ByMax2Increaser";

let is_admin = contract.acl_is_admin(&account, role, account.id()).await?;
assert_eq!(is_admin, false);
assert!(!is_admin);

contract
.acl_add_admin_unchecked(contract_account, role, account.id())
.await?
.into_result()?;

let is_admin = contract.acl_is_admin(&account, role, account.id()).await?;
assert_eq!(is_admin, true);
assert!(is_admin);

Ok(())
}
Expand Down Expand Up @@ -535,7 +535,7 @@ async fn test_acl_renounce_admin() -> anyhow::Result<()> {
.contract
.acl_renounce_admin(&setup.account, role)
.await?;
assert_eq!(res, false);
assert!(!res);

// An admin calls `acl_renounce_admin`.
let admin = setup.new_account_as_admin(&[role]).await?;
Expand All @@ -544,7 +544,7 @@ async fn test_acl_renounce_admin() -> anyhow::Result<()> {
.assert_acl_is_admin(true, role, admin.id())
.await;
let res = setup.contract.acl_renounce_admin(&admin, role).await?;
assert_eq!(res, true);
assert!(res);
setup
.contract
.assert_acl_is_admin(false, role, admin.id())
Expand Down Expand Up @@ -618,15 +618,15 @@ async fn test_acl_has_role() -> anyhow::Result<()> {
let role = "ByMax2Increaser";

let has_role = contract.acl_has_role(&account, role, account.id()).await?;
assert_eq!(has_role, false);
assert!(!has_role);

contract
.acl_grant_role_unchecked(contract_account, role, account.id())
.await?
.into_result()?;

let has_role = contract.acl_has_role(&account, role, account.id()).await?;
assert_eq!(has_role, true);
assert!(has_role);

Ok(())
}
Expand Down Expand Up @@ -766,7 +766,7 @@ async fn test_acl_renounce_role() -> anyhow::Result<()> {
.contract
.acl_renounce_role(&setup.account, role)
.await?;
assert_eq!(res, false);
assert!(!res);

// A grantee calls `acl_renounce_admin`.
let grantee = setup.new_account_with_roles(&[role]).await?;
Expand All @@ -775,7 +775,7 @@ async fn test_acl_renounce_role() -> anyhow::Result<()> {
.assert_acl_has_role(true, role, grantee.id())
.await;
let res = setup.contract.acl_renounce_role(&grantee, role).await?;
assert_eq!(res, true);
assert!(res);
setup
.contract
.assert_acl_has_role(false, role, grantee.id())
Expand Down
29 changes: 11 additions & 18 deletions near-plugins/tests/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ where
pub fn assert_private_method_failure(res: ExecutionFinalResult, method: &str) {
let err = res
.into_result()
.err()
.expect("Transaction should have failed");
.expect_err("Transaction should have failed");
let err = format!("{}", err);
let must_contain = format!("Method {} is private", method);
assert!(
Expand All @@ -50,8 +49,7 @@ pub fn assert_insufficient_acl_permissions(
) {
let err = res
.into_result()
.err()
.expect("Transaction should have failed");
.expect_err("Transaction should have failed");
let err = format!("{}", err);

// TODO fix escaping issue to also verify second sentence of the error
Expand All @@ -73,12 +71,11 @@ pub fn assert_insufficient_acl_permissions(
pub fn assert_method_is_paused(res: ExecutionFinalResult) {
let err = res
.into_result()
.err()
.expect("Transaction should have failed");
.expect_err("Transaction should have failed");
let err = format!("{}", err);
let must_contain = "Pausable: Method is paused";
assert!(
err.contains(&must_contain),
err.contains(must_contain),
"Expected method to be paused, instead it failed with: {}",
err
);
Expand All @@ -87,12 +84,11 @@ pub fn assert_method_is_paused(res: ExecutionFinalResult) {
pub fn assert_owner_update_failure(res: ExecutionFinalResult) {
let err = res
.into_result()
.err()
.expect("Transaction should have failed");
.expect_err("Transaction should have failed");
let err = format!("{}", err);
let must_contain = "Ownable: Only owner can update current owner";
assert!(
err.contains(&must_contain),
err.contains(must_contain),
"Expected failure due to caller not being owner, instead it failed with: {}",
err
);
Expand All @@ -102,12 +98,11 @@ pub fn assert_owner_update_failure(res: ExecutionFinalResult) {
pub fn assert_ownable_permission_failure(res: ExecutionFinalResult) {
let err = res
.into_result()
.err()
.expect("Transaction should have failed");
.expect_err("Transaction should have failed");
let err = format!("{}", err);
let must_contain = "Method is private";
assert!(
err.contains(&must_contain),
err.contains(must_contain),
"Expected failure due to insufficient permissions, instead it failed with: {}",
err
);
Expand All @@ -118,12 +113,11 @@ pub fn assert_ownable_permission_failure(res: ExecutionFinalResult) {
pub fn assert_only_owner_permission_failure(res: ExecutionFinalResult) {
let err = res
.into_result()
.err()
.expect("Transaction should have failed");
.expect_err("Transaction should have failed");
let err = format!("{}", err);
let must_contain = "Ownable: Method must be called from owner";
assert!(
err.contains(&must_contain),
err.contains(must_contain),
"Expected failure due to caller not being owner, instead it failed with: {}",
err
);
Expand All @@ -133,8 +127,7 @@ pub fn assert_only_owner_permission_failure(res: ExecutionFinalResult) {
pub fn assert_failure_with(res: ExecutionFinalResult, must_contain: &str) {
let err = res
.into_result()
.err()
.expect("Transaction should have failed");
.expect_err("Transaction should have failed");
let err = format!("{}", err);
assert!(
err.contains(must_contain),
Expand Down
18 changes: 7 additions & 11 deletions near-plugins/tests/ownable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const PROJECT_PATH: &str = "./tests/contracts/ownable";
/// Allows spinning up a setup for testing the contract in [`PROJECT_PATH`] and bundles related
/// resources.
struct Setup {
/// The worker interacting with the current sandbox.
worker: Worker<Sandbox>,
/// Instance of the deployed contract.
contract: Contract,
/// Wrapper around the deployed contract that facilitates interacting with methods provided by
Expand All @@ -37,7 +35,7 @@ impl Setup {
/// the owner during initialization.
async fn new(worker: Worker<Sandbox>, owner: Option<AccountId>) -> anyhow::Result<Self> {
// Compile and deploy the contract.
let wasm = common::repo::compile_project(&Path::new(PROJECT_PATH), "ownable").await?;
let wasm = common::repo::compile_project(Path::new(PROJECT_PATH), "ownable").await?;
let contract = worker.dev_deploy(&wasm).await?;
let ownable_contract = OwnableContract::new(contract.clone());

Expand All @@ -54,7 +52,6 @@ impl Setup {

let unauth_account = worker.dev_create_account().await?;
Ok(Self {
worker,
contract,
ownable_contract,
unauth_account,
Expand Down Expand Up @@ -123,16 +120,15 @@ async fn test_owner_is() -> anyhow::Result<()> {
let setup = Setup::new(worker, Some(owner.id().clone())).await?;

// Returns false for an account that isn't owner.
assert_eq!(
setup
assert!(
!setup
.ownable_contract
.owner_is(&setup.unauth_account)
.await?,
false
.await?
);

// Returns true for the owner.
assert_eq!(setup.ownable_contract.owner_is(&owner).await?, true);
assert!(setup.ownable_contract.owner_is(&owner).await?);

Ok(())
}
Expand All @@ -147,7 +143,7 @@ async fn test_set_owner_ok() -> anyhow::Result<()> {
let owner_id = setup.unauth_account.id();
setup
.ownable_contract
.owner_set(&setup.contract.as_account(), Some(owner_id.clone()))
.owner_set(setup.contract.as_account(), Some(owner_id.clone()))
.await?
.into_result()?;
setup.assert_owner_is(Some(owner_id)).await;
Expand Down Expand Up @@ -200,7 +196,7 @@ async fn test_only_self_ok() -> anyhow::Result<()> {

assert_eq!(setup.get_counter().await?, 0);
let res = setup
.call_counter_increaser(&setup.contract.as_account(), "increase_4")
.call_counter_increaser(setup.contract.as_account(), "increase_4")
.await?;
assert_success_with(res, 4);
assert_eq!(setup.get_counter().await?, 4);
Expand Down
8 changes: 4 additions & 4 deletions near-plugins/tests/pausable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Setup {
async fn new() -> anyhow::Result<Self> {
// Compile and deploy the contract.
let worker = workspaces::sandbox().await?;
let wasm = common::repo::compile_project(&Path::new(PROJECT_PATH), "pausable").await?;
let wasm = common::repo::compile_project(Path::new(PROJECT_PATH), "pausable").await?;
let contract = worker.dev_deploy(&wasm).await?;
let pausable_contract = PausableContract::new(contract.clone());
let acl_contract = AccessControllableContract::new(contract.clone());
Expand Down Expand Up @@ -324,7 +324,7 @@ async fn assert_paused_list(
contract: &PausableContract,
caller: &Account,
) {
let paused_list = contract.pa_all_paused(&caller).await.unwrap();
let paused_list = contract.pa_all_paused(caller).await.unwrap();
assert_eq!(paused_list, expected);
}

Expand Down Expand Up @@ -474,7 +474,7 @@ async fn test_pause_except_ok() -> anyhow::Result<()> {
// Grantee of `Role::Unrestricted4Increaser` is exempted.
let increaser = setup.worker.dev_create_account().await?;
setup
.must_grant_acl_role("Unrestricted4Increaser", &increaser.id())
.must_grant_acl_role("Unrestricted4Increaser", increaser.id())
.await;
let res = setup
.call_counter_modifier(&increaser, "increase_4")
Expand All @@ -485,7 +485,7 @@ async fn test_pause_except_ok() -> anyhow::Result<()> {
// Grantee of `Role::Unrestricted4Modifier` is exempted.
let modifier = setup.worker.dev_create_account().await?;
setup
.must_grant_acl_role("Unrestricted4Modifier", &modifier.id())
.must_grant_acl_role("Unrestricted4Modifier", modifier.id())
.await;
let res = setup.call_counter_modifier(&modifier, "increase_4").await?;
assert_success_with_unit_return(res);
Expand Down