diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 99f41cf..621e314 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,10 @@ jobs: - uses: Swatinem/rust-cache@v1 with: - cache-on-failure: true + key: rust-version-1.69.0-msrv + + - name: downgrade some dev-dependencies for msrv, see https://github.com/near/near-workspaces-rs/issues/336 + run: ./scripts/fix_dependencies.sh - name: add wasm32-unknown-unknown run: rustup target add wasm32-unknown-unknown @@ -44,7 +47,10 @@ jobs: - uses: Swatinem/rust-cache@v1 with: - cache-on-failure: true + key: rust-version-1.69.0-msrv + + - name: downgrade some dev-dependencies for msrv, see https://github.com/near/near-workspaces-rs/issues/336 + run: ./scripts/fix_dependencies.sh - name: cargo fmt run: cargo fmt --all -- --check diff --git a/Cargo.toml b/Cargo.toml index 61feeb5..178de3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ version = "0.15.0" version = "0.1.0" edition = "2021" authors = ["Aurora Labs "] -rust-version = "1.64.0" +rust-version = "1.69.0" description = "Ergonomic plugin system to extend NEAR contracts." license = "CC0-1.0" readme = "README.md" @@ -22,14 +22,14 @@ keywords = ["near", "smart contract", "plugin"] [workspace.dependencies] bitflags = "1.3" -near-sdk = "4.1.0" +near-sdk = "4.1.1" near-plugins = { path = "near-plugins" } near-plugins-derive = { path = "near-plugins-derive" } serde = "1" anyhow = "1.0" borsh = "0.9" tokio = { version = "1", features = ["full"] } -workspaces = "0.7" +near-workspaces = "0.9" toml = "0.5" darling = "0.13.1" proc-macro2 = "1.0" diff --git a/README.md b/README.md index f9b9991..efd5dc2 100644 --- a/README.md +++ b/README.md @@ -65,10 +65,10 @@ Tests should verify that once the macros provided by this crate are expanded, th - A contract using the plugin is contained in `near-plugins-derive/tests/contracts//`. - This contract is used in `near-plugins-derive/tests/.rs` which: - - Compiles and deploys the contract on chain via [NEAR `workspaces`](https://docs.rs/workspaces/0.7.0/workspaces/). + - Compiles and deploys the contract on chain via [`near-workspaces`](https://crates.io/crates/near-workspaces). - Sends transactions to the deployed contract to verify plugin functionality. -## Contributors Notes +## Traits and their implementations Traits doesn't contain any implementation, even though some interfaces are self-contained enough to have it. It is this way since `near_bindgen` macro from near-sdk-rs will only expose as public methods those that are implemented @@ -77,6 +77,11 @@ during the trait implementation for the contract. In the documentation all comments under Default Implementation makes remarks about the current implementation derived automatically from macros. They can be changed if the trait is manually implemented rather than deriving the macro. +## Contributor Notes + +When compiling tests for the first time on a machine using the MSRV 1.69.0, an error might occur due to some dependencies of `near-workspaces` requiring a higher version of Rust. You can execute [./script/fix-dependencies.sh](./scripts/fix_dependencies.sh) to install a compatible version of these dependencies. The comments in that script provide additional information. + + ## Roadmap - Factory upgrades: Allow upgrading all deployed contracts from the factory fetching binary upstream. diff --git a/near-plugins-derive/Cargo.toml b/near-plugins-derive/Cargo.toml index 74d99b5..65fce97 100644 --- a/near-plugins-derive/Cargo.toml +++ b/near-plugins-derive/Cargo.toml @@ -21,5 +21,5 @@ borsh.workspace = true near-plugins.workspace = true near-sdk.workspace = true tokio.workspace = true -workspaces.workspace = true +near-workspaces.workspace = true toml.workspace = true diff --git a/near-plugins-derive/tests/access_controllable.rs b/near-plugins-derive/tests/access_controllable.rs index aba6b3e..d08af48 100644 --- a/near-plugins-derive/tests/access_controllable.rs +++ b/near-plugins-derive/tests/access_controllable.rs @@ -9,12 +9,12 @@ use common::utils::{ }; use near_plugins::access_controllable::{PermissionedAccounts, PermissionedAccountsPerRole}; use near_sdk::serde_json::json; +use near_workspaces::network::Sandbox; +use near_workspaces::result::ExecutionFinalResult; +use near_workspaces::{Account, AccountId, Contract, Worker}; use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::path::Path; -use workspaces::network::Sandbox; -use workspaces::result::ExecutionFinalResult; -use workspaces::{Account, AccountId, Contract, Worker}; const PROJECT_PATH: &str = "./tests/contracts/access_controllable"; @@ -48,7 +48,7 @@ impl Setup { admins: HashMap, grantees: HashMap, ) -> anyhow::Result { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let wasm = common::repo::compile_project(Path::new(PROJECT_PATH), "access_controllable").await?; let contract = AccessControllableContract::new(worker.dev_deploy(&wasm).await?); @@ -110,7 +110,7 @@ impl Setup { async fn call_increase_2( contract: &Contract, caller: &Account, -) -> workspaces::Result { +) -> near_workspaces::Result { caller .call(contract.id(), "increase_2") .args_json(()) diff --git a/near-plugins-derive/tests/common/access_controllable_contract.rs b/near-plugins-derive/tests/common/access_controllable_contract.rs index 4e52f26..6e8c1e5 100644 --- a/near-plugins-derive/tests/common/access_controllable_contract.rs +++ b/near-plugins-derive/tests/common/access_controllable_contract.rs @@ -1,8 +1,8 @@ use near_plugins::access_controllable::PermissionedAccounts; use near_sdk::serde_json::json; -use workspaces::result::ExecutionFinalResult; -use workspaces::{Account, AccountId, Contract}; +use near_workspaces::result::ExecutionFinalResult; +use near_workspaces::{Account, AccountId, Contract}; /// Wrapper for a contract that is `#[access_controllable]`. It allows /// implementing helpers for calling contract methods. @@ -56,7 +56,7 @@ impl AccessControllableContract { &self, caller: &Account, account_id: &AccountId, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "acl_init_super_admin") .args_json(json!({ @@ -89,7 +89,7 @@ impl AccessControllableContract { &self, caller: &Account, account_id: &AccountId, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "acl_add_super_admin_unchecked") .args_json(json!({ @@ -140,7 +140,7 @@ impl AccessControllableContract { &self, caller: &Account, account_id: &AccountId, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "acl_revoke_super_admin_unchecked") .args_json(json!({ @@ -201,7 +201,7 @@ impl AccessControllableContract { caller: &Account, role: &str, account_id: &AccountId, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "acl_add_admin_unchecked") .args_json(json!({ @@ -252,7 +252,7 @@ impl AccessControllableContract { caller: &Account, role: &str, account_id: &AccountId, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "acl_revoke_admin_unchecked") .args_json(json!({ @@ -314,7 +314,7 @@ impl AccessControllableContract { caller: &Account, role: &str, account_id: &AccountId, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "acl_grant_role_unchecked") .args_json(json!({ @@ -365,7 +365,7 @@ impl AccessControllableContract { caller: &Account, role: &str, account_id: &AccountId, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "acl_revoke_role_unchecked") .args_json(json!({ diff --git a/near-plugins-derive/tests/common/key.rs b/near-plugins-derive/tests/common/key.rs index badc504..17b6b27 100644 --- a/near-plugins-derive/tests/common/key.rs +++ b/near-plugins-derive/tests/common/key.rs @@ -1,13 +1,13 @@ -use workspaces::result::ExecutionFinalResult; -use workspaces::types::{AccessKeyInfo, PublicKey}; -use workspaces::{Account, AccountId, Contract}; +use near_workspaces::result::ExecutionFinalResult; +use near_workspaces::types::{AccessKeyInfo, PublicKey}; +use near_workspaces::{Account, AccountId, Contract}; /// Creates a transaction signed by `signer` to delete `key` from `contract`. pub async fn delete_access_key( signer: &Account, contract: &AccountId, key: PublicKey, -) -> workspaces::Result { +) -> near_workspaces::Result { signer.batch(contract).delete_key(key).transact().await } diff --git a/near-plugins-derive/tests/common/ownable_contract.rs b/near-plugins-derive/tests/common/ownable_contract.rs index 1d13d32..723601c 100644 --- a/near-plugins-derive/tests/common/ownable_contract.rs +++ b/near-plugins-derive/tests/common/ownable_contract.rs @@ -1,6 +1,6 @@ use near_sdk::serde_json::json; -use workspaces::result::ExecutionFinalResult; -use workspaces::{Account, AccountId, Contract}; +use near_workspaces::result::ExecutionFinalResult; +use near_workspaces::{Account, AccountId, Contract}; /// Wrapper for a contract that is `#[ownable]`. It allows implementing helpers for calling contract /// methods. @@ -26,7 +26,7 @@ impl OwnableContract { &self, caller: &Account, owner: Option, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "owner_set") .args_json(json!({ "owner": owner })) diff --git a/near-plugins-derive/tests/common/pausable_contract.rs b/near-plugins-derive/tests/common/pausable_contract.rs index 783cbf8..6c9c3fa 100644 --- a/near-plugins-derive/tests/common/pausable_contract.rs +++ b/near-plugins-derive/tests/common/pausable_contract.rs @@ -1,7 +1,7 @@ use near_sdk::serde_json::json; +use near_workspaces::result::ExecutionFinalResult; +use near_workspaces::{Account, Contract}; use std::collections::HashSet; -use workspaces::result::ExecutionFinalResult; -use workspaces::{Account, Contract}; /// Wrapper for a contract that is `#[pausable]`. It allows implementing helpers /// for calling contract methods. @@ -33,7 +33,7 @@ impl PausableContract { &self, caller: &Account, key: &str, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "pa_pause_feature") .args_json(json!({ "key": key })) @@ -46,7 +46,7 @@ impl PausableContract { &self, caller: &Account, key: &str, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "pa_unpause_feature") .args_json(json!({ "key": key })) diff --git a/near-plugins-derive/tests/common/upgradable_contract.rs b/near-plugins-derive/tests/common/upgradable_contract.rs index 16d39d8..999e10d 100644 --- a/near-plugins-derive/tests/common/upgradable_contract.rs +++ b/near-plugins-derive/tests/common/upgradable_contract.rs @@ -3,8 +3,8 @@ use near_plugins::upgradable::{FunctionCallArgs, UpgradableDurationStatus}; use near_sdk::serde_json::json; use near_sdk::CryptoHash; use near_sdk::Duration; -use workspaces::result::ExecutionFinalResult; -use workspaces::{Account, Contract}; +use near_workspaces::result::ExecutionFinalResult; +use near_workspaces::{Account, Contract}; /// Wrapper for a contract that derives `Upgradable`. It allows implementing helpers for calling /// contract methods provided by `Upgradable`. @@ -36,7 +36,7 @@ impl UpgradableContract { &self, caller: &Account, code: Vec, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "up_stage_code") .args_borsh(code) @@ -66,13 +66,13 @@ impl UpgradableContract { Ok(res.json::>()?) } - /// The `Promise` returned by trait method `up_deploy_code` is resolved in the `workspaces` + /// The `Promise` returned by trait method `up_deploy_code` is resolved in the `near_workspaces` /// transaction. pub async fn up_deploy_code( &self, caller: &Account, function_call_args: Option, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "up_deploy_code") .args_json(json!({ @@ -87,7 +87,7 @@ impl UpgradableContract { &self, caller: &Account, staging_duration: Duration, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "up_init_staging_duration") .args_json(json!({ "staging_duration": staging_duration })) @@ -100,7 +100,7 @@ impl UpgradableContract { &self, caller: &Account, staging_duration: Duration, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "up_stage_update_staging_duration") .args_json(json!({ "staging_duration": staging_duration })) @@ -112,7 +112,7 @@ impl UpgradableContract { pub async fn up_apply_update_staging_duration( &self, caller: &Account, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), "up_apply_update_staging_duration") .max_gas() diff --git a/near-plugins-derive/tests/common/utils.rs b/near-plugins-derive/tests/common/utils.rs index 04a0f6b..2fb95a9 100644 --- a/near-plugins-derive/tests/common/utils.rs +++ b/near-plugins-derive/tests/common/utils.rs @@ -1,11 +1,11 @@ use near_sdk::serde::de::DeserializeOwned; use near_sdk::Duration; +use near_workspaces::network::Sandbox; +use near_workspaces::result::{ExecutionFinalResult, ExecutionOutcome}; +use near_workspaces::{AccountId, Block, Worker}; use std::cmp::PartialEq; use std::fmt::Debug; use std::str::FromStr; -use workspaces::network::Sandbox; -use workspaces::result::{ExecutionFinalResult, ExecutionOutcome}; -use workspaces::{AccountId, Block, Worker}; /// Converts `account_id` to a `near_sdk::AccountId` and panics on failure. /// @@ -172,7 +172,7 @@ pub fn assert_failure_with(res: ExecutionFinalResult, must_contain: &str) { } pub fn assert_access_key_not_found_error( - res: workspaces::Result, + res: near_workspaces::Result, ) { let err = res.expect_err("Transaction should not have been executed"); @@ -202,7 +202,7 @@ async fn block_timestamp(worker: &Worker) -> u64 { pub async fn get_transaction_block( worker: &Worker, result: &ExecutionOutcome, -) -> workspaces::Result { +) -> near_workspaces::Result { let block_hash = result.block_hash; worker.view_block().block_hash(block_hash).await } @@ -215,7 +215,7 @@ pub async fn get_transaction_block( /// forwarding provided by this function is reasonly fast in our tests for durations that correspond /// to less than 100 seconds. /// -/// [Time travels]: https://github.com/near/workspaces-rs#time-traveling +/// [Time travels]: https://github.com/near/near-workspaces-rs#time-traveling pub async fn fast_forward_beyond(worker: &Worker, duration: Duration) { let initial_timestamp = block_timestamp(worker).await; diff --git a/near-plugins-derive/tests/contracts/README.md b/near-plugins-derive/tests/contracts/README.md index 3721a53..83177aa 100644 --- a/near-plugins-derive/tests/contracts/README.md +++ b/near-plugins-derive/tests/contracts/README.md @@ -1,6 +1,6 @@ Contains contracts that use the plugins provided by `near-plugins`. -These contracts are compiled during tests via Near's `workspaces-rs` and may serve as examples for smart contract developers. +These contracts are compiled during tests via `near-workspaces` and may serve as examples for smart contract developers. # TODO: contract to test optional ACL arguments - `#[access_control]` has optional arguments, e.g. `storage_prefix`. diff --git a/near-plugins-derive/tests/contracts/access_controllable/Cargo.toml b/near-plugins-derive/tests/contracts/access_controllable/Cargo.toml index 133101f..9e5ab96 100644 --- a/near-plugins-derive/tests/contracts/access_controllable/Cargo.toml +++ b/near-plugins-derive/tests/contracts/access_controllable/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] near-plugins = { path = "../../../../near-plugins" } -near-sdk = "4.0.0" +near-sdk = "4.1.1" [profile.release] codegen-units = 1 diff --git a/near-plugins-derive/tests/contracts/access_controllable/rust-toolchain b/near-plugins-derive/tests/contracts/access_controllable/rust-toolchain index 2f3cf78..6649306 100644 --- a/near-plugins-derive/tests/contracts/access_controllable/rust-toolchain +++ b/near-plugins-derive/tests/contracts/access_controllable/rust-toolchain @@ -1,3 +1,4 @@ [toolchain] -channel = "1.66.1" +channel = "1.69.0" components = ["clippy", "rustfmt"] +targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/ownable/Cargo.toml b/near-plugins-derive/tests/contracts/ownable/Cargo.toml index 4937efa..c4e3643 100644 --- a/near-plugins-derive/tests/contracts/ownable/Cargo.toml +++ b/near-plugins-derive/tests/contracts/ownable/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] near-plugins = { path = "../../../../near-plugins" } -near-sdk = "4.1.0" +near-sdk = "4.1.1" [profile.release] codegen-units = 1 diff --git a/near-plugins-derive/tests/contracts/ownable/rust-toolchain b/near-plugins-derive/tests/contracts/ownable/rust-toolchain index 2f3cf78..6649306 100644 --- a/near-plugins-derive/tests/contracts/ownable/rust-toolchain +++ b/near-plugins-derive/tests/contracts/ownable/rust-toolchain @@ -1,3 +1,4 @@ [toolchain] -channel = "1.66.1" +channel = "1.69.0" components = ["clippy", "rustfmt"] +targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/pausable/Cargo.toml b/near-plugins-derive/tests/contracts/pausable/Cargo.toml index 72def35..4869ee8 100644 --- a/near-plugins-derive/tests/contracts/pausable/Cargo.toml +++ b/near-plugins-derive/tests/contracts/pausable/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] near-plugins = { path = "../../../../near-plugins" } -near-sdk = "4.1.0" +near-sdk = "4.1.1" [profile.release] codegen-units = 1 diff --git a/near-plugins-derive/tests/contracts/pausable/rust-toolchain b/near-plugins-derive/tests/contracts/pausable/rust-toolchain index 2f3cf78..6649306 100644 --- a/near-plugins-derive/tests/contracts/pausable/rust-toolchain +++ b/near-plugins-derive/tests/contracts/pausable/rust-toolchain @@ -1,3 +1,4 @@ [toolchain] -channel = "1.66.1" +channel = "1.69.0" components = ["clippy", "rustfmt"] +targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/upgradable/Cargo.toml b/near-plugins-derive/tests/contracts/upgradable/Cargo.toml index bf2f034..e1c3e9e 100644 --- a/near-plugins-derive/tests/contracts/upgradable/Cargo.toml +++ b/near-plugins-derive/tests/contracts/upgradable/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] near-plugins = { path = "../../../../near-plugins" } -near-sdk = "4.1.0" +near-sdk = "4.1.1" [profile.release] codegen-units = 1 diff --git a/near-plugins-derive/tests/contracts/upgradable/rust-toolchain b/near-plugins-derive/tests/contracts/upgradable/rust-toolchain index 2f3cf78..6649306 100644 --- a/near-plugins-derive/tests/contracts/upgradable/rust-toolchain +++ b/near-plugins-derive/tests/contracts/upgradable/rust-toolchain @@ -1,3 +1,4 @@ [toolchain] -channel = "1.66.1" +channel = "1.69.0" components = ["clippy", "rustfmt"] +targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/upgradable_2/Cargo.toml b/near-plugins-derive/tests/contracts/upgradable_2/Cargo.toml index e7a0bc5..bc73531 100644 --- a/near-plugins-derive/tests/contracts/upgradable_2/Cargo.toml +++ b/near-plugins-derive/tests/contracts/upgradable_2/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] near-plugins = { path = "../../../../near-plugins" } -near-sdk = "4.1.0" +near-sdk = "4.1.1" [profile.release] codegen-units = 1 diff --git a/near-plugins-derive/tests/contracts/upgradable_2/rust-toolchain b/near-plugins-derive/tests/contracts/upgradable_2/rust-toolchain index 2f3cf78..6649306 100644 --- a/near-plugins-derive/tests/contracts/upgradable_2/rust-toolchain +++ b/near-plugins-derive/tests/contracts/upgradable_2/rust-toolchain @@ -1,3 +1,4 @@ [toolchain] -channel = "1.66.1" +channel = "1.69.0" components = ["clippy", "rustfmt"] +targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/upgradable_state_migration/Cargo.toml b/near-plugins-derive/tests/contracts/upgradable_state_migration/Cargo.toml index 19c14d4..b756334 100644 --- a/near-plugins-derive/tests/contracts/upgradable_state_migration/Cargo.toml +++ b/near-plugins-derive/tests/contracts/upgradable_state_migration/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] near-plugins = { path = "../../../../near-plugins" } -near-sdk = "4.1.0" +near-sdk = "4.1.1" [profile.release] codegen-units = 1 diff --git a/near-plugins-derive/tests/contracts/upgradable_state_migration/rust-toolchain b/near-plugins-derive/tests/contracts/upgradable_state_migration/rust-toolchain index 2f3cf78..6649306 100644 --- a/near-plugins-derive/tests/contracts/upgradable_state_migration/rust-toolchain +++ b/near-plugins-derive/tests/contracts/upgradable_state_migration/rust-toolchain @@ -1,3 +1,4 @@ [toolchain] -channel = "1.66.1" +channel = "1.69.0" components = ["clippy", "rustfmt"] +targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/ownable.rs b/near-plugins-derive/tests/ownable.rs index 395e4a4..cced1d1 100644 --- a/near-plugins-derive/tests/ownable.rs +++ b/near-plugins-derive/tests/ownable.rs @@ -10,10 +10,10 @@ use common::utils::{ assert_ownable_permission_failure, assert_owner_update_failure, assert_success_with, }; use near_sdk::serde_json::json; +use near_workspaces::network::Sandbox; +use near_workspaces::result::ExecutionFinalResult; +use near_workspaces::{Account, AccountId, Contract, Worker}; use std::path::Path; -use workspaces::network::Sandbox; -use workspaces::result::ExecutionFinalResult; -use workspaces::{Account, AccountId, Contract, Worker}; const PROJECT_PATH: &str = "./tests/contracts/ownable"; @@ -78,7 +78,7 @@ impl Setup { &self, caller: &Account, method_name: &str, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.contract.id(), method_name) .max_gas() @@ -101,7 +101,7 @@ impl Setup { /// Smoke test of contract setup and basic functionality. #[tokio::test] async fn test_setup() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let setup = Setup::new(worker, None).await?; assert_eq!(setup.get_counter().await?, 0); @@ -116,7 +116,7 @@ async fn test_setup() -> anyhow::Result<()> { #[tokio::test] async fn test_owner_is() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let owner = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(owner.id().clone())).await?; @@ -136,7 +136,7 @@ async fn test_owner_is() -> anyhow::Result<()> { #[tokio::test] async fn test_set_owner_ok() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let setup = Setup::new(worker, None).await?; setup.assert_owner_is(None).await; @@ -154,7 +154,7 @@ async fn test_set_owner_ok() -> anyhow::Result<()> { #[tokio::test] async fn test_set_owner_fail() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let owner = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(owner.id().clone())).await?; @@ -173,7 +173,7 @@ async fn test_set_owner_fail() -> anyhow::Result<()> { #[tokio::test] async fn test_remove_owner() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let owner = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(owner.id().clone())).await?; @@ -192,7 +192,7 @@ async fn test_remove_owner() -> anyhow::Result<()> { /// Contract itself may successfully call a method protected by `#[only(self)]`. #[tokio::test] async fn test_only_self_ok() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let setup = Setup::new(worker, None).await?; assert_eq!(setup.get_counter().await?, 0); @@ -208,7 +208,7 @@ async fn test_only_self_ok() -> anyhow::Result<()> { /// A method protected by `#[only(self)]` fails if called from another account. #[tokio::test] async fn test_only_self_fail_unauth() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let setup = Setup::new(worker, None).await?; let res = setup @@ -222,7 +222,7 @@ async fn test_only_self_fail_unauth() -> anyhow::Result<()> { /// A method protected by `#[only(self)]` fails if called by the owner. #[tokio::test] async fn test_only_self_fail_owner() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let owner = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(owner.id().clone())).await?; @@ -235,7 +235,7 @@ async fn test_only_self_fail_owner() -> anyhow::Result<()> { /// Calling a method protected by `#[only(owner)]` from the owner succeeds. #[tokio::test] async fn test_only_owner_ok() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let owner = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(owner.id().clone())).await?; @@ -250,7 +250,7 @@ async fn test_only_owner_ok() -> anyhow::Result<()> { /// A method protected by `#[only(owner)]` fails if called by the contract itself. #[tokio::test] async fn test_only_owner_fail_self() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let setup = Setup::new(worker, None).await?; let res = setup @@ -264,7 +264,7 @@ async fn test_only_owner_fail_self() -> anyhow::Result<()> { /// A method protected by `#[only(owner)]` fails if called by another account. #[tokio::test] async fn test_only_owner_fail() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let setup = Setup::new(worker, None).await?; let res = setup @@ -279,7 +279,7 @@ async fn test_only_owner_fail() -> anyhow::Result<()> { /// or by the owner. #[tokio::test] async fn test_only_self_owner_ok() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let owner = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(owner.id().clone())).await?; @@ -300,7 +300,7 @@ async fn test_only_self_owner_ok() -> anyhow::Result<()> { /// Calling a method protected by `#[only(self, owner)]` fails if called by another account. #[tokio::test] async fn test_only_self_owner_fail() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let setup = Setup::new(worker, None).await?; let res = setup @@ -314,7 +314,7 @@ async fn test_only_self_owner_fail() -> anyhow::Result<()> { /// Verifies that the contract cannot set a new owner after its access keys are removed. #[tokio::test] async fn test_removing_contract_keys_freezes_owner() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let owner = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(owner.id().clone())).await?; diff --git a/near-plugins-derive/tests/pausable.rs b/near-plugins-derive/tests/pausable.rs index 14fc229..6f5604a 100644 --- a/near-plugins-derive/tests/pausable.rs +++ b/near-plugins-derive/tests/pausable.rs @@ -9,11 +9,11 @@ use common::utils::{ assert_pausable_escape_hatch_is_closed, assert_success_with, assert_success_with_unit_return, }; use near_sdk::serde_json::json; +use near_workspaces::network::Sandbox; +use near_workspaces::result::ExecutionFinalResult; +use near_workspaces::{Account, AccountId, Contract, Worker}; use std::collections::HashSet; use std::path::Path; -use workspaces::network::Sandbox; -use workspaces::result::ExecutionFinalResult; -use workspaces::{Account, AccountId, Contract, Worker}; const PROJECT_PATH: &str = "./tests/contracts/pausable"; @@ -39,7 +39,7 @@ impl Setup { /// Deploys the contract in [`PROJECT_PATH`] and initializes `Setup`. async fn new() -> anyhow::Result { // Compile and deploy the contract. - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().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()); @@ -99,7 +99,7 @@ impl Setup { &self, caller: &Account, method_name: &str, - ) -> workspaces::Result { + ) -> near_workspaces::Result { caller .call(self.pausable_contract.contract().id(), method_name) .max_gas() diff --git a/near-plugins-derive/tests/upgradable.rs b/near-plugins-derive/tests/upgradable.rs index fa85fd9..3ae57da 100644 --- a/near-plugins-derive/tests/upgradable.rs +++ b/near-plugins-derive/tests/upgradable.rs @@ -13,10 +13,10 @@ use common::utils::{ use near_plugins::upgradable::FunctionCallArgs; use near_sdk::serde_json::json; use near_sdk::{CryptoHash, Duration, Gas, Timestamp}; +use near_workspaces::network::Sandbox; +use near_workspaces::result::ExecutionFinalResult; +use near_workspaces::{Account, AccountId, Contract, Worker}; use std::path::Path; -use workspaces::network::Sandbox; -use workspaces::result::ExecutionFinalResult; -use workspaces::{Account, AccountId, Contract, Worker}; const PROJECT_PATH: &str = "./tests/contracts/upgradable"; const PROJECT_PATH_2: &str = "./tests/contracts/upgradable_2"; @@ -160,7 +160,10 @@ impl Setup { assert_eq!(status.new_staging_duration_timestamp, expected_timestamp); } - async fn call_is_upgraded(&self, caller: &Account) -> workspaces::Result { + async fn call_is_upgraded( + &self, + caller: &Account, + ) -> near_workspaces::Result { // `is_upgraded` could be called via `view`, however here it is called via `transact` so we // get an `ExecutionFinalResult` that can be passed to `assert_*` methods from // `common::utils`. It is acceptable since all we care about is whether the method exists. @@ -171,7 +174,10 @@ impl Setup { .await } - async fn call_is_migrated(&self, caller: &Account) -> workspaces::Result { + async fn call_is_migrated( + &self, + caller: &Account, + ) -> near_workspaces::Result { // `is_migrated` could be called via `view`, however here it is called via `transact` so we // get an `ExecutionFinalResult` that can be passed to `assert_*` methods from // `common::utils`. It is acceptable since all we care about is whether the method exists @@ -207,7 +213,7 @@ fn convert_code_to_crypto_hash(code: &[u8]) -> CryptoHash { /// Smoke test of contract setup. #[tokio::test] async fn test_setup() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let setup = Setup::new(worker, None, None).await?; setup.assert_is_set_up(&setup.unauth_account).await; @@ -216,7 +222,7 @@ async fn test_setup() -> anyhow::Result<()> { #[tokio::test] async fn test_stage_code_permission_failure() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new( worker, @@ -245,7 +251,7 @@ async fn test_stage_code_permission_failure() -> anyhow::Result<()> { #[tokio::test] async fn test_stage_code_without_delay() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(dao.id().clone()), None).await?; @@ -276,7 +282,7 @@ async fn test_stage_code_without_delay() -> anyhow::Result<()> { #[tokio::test] async fn test_stage_code_with_delay() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let staging_duration = sdk_duration_from_secs(42); let setup = Setup::new(worker, Some(dao.id().clone()), Some(staging_duration)).await?; @@ -310,7 +316,7 @@ async fn test_stage_code_with_delay() -> anyhow::Result<()> { #[tokio::test] async fn test_staging_empty_code_clears_storage() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new( worker, @@ -344,7 +350,7 @@ async fn test_staging_empty_code_clears_storage() -> anyhow::Result<()> { #[tokio::test] async fn test_staged_code() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new( worker, @@ -381,7 +387,7 @@ async fn test_staged_code() -> anyhow::Result<()> { #[tokio::test] async fn test_staged_code_hash() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new( worker, @@ -419,7 +425,7 @@ async fn test_staged_code_hash() -> anyhow::Result<()> { #[tokio::test] async fn test_deploy_code_without_delay() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new(worker.clone(), Some(dao.id().clone()), None).await?; @@ -444,7 +450,7 @@ async fn test_deploy_code_without_delay() -> anyhow::Result<()> { /// explicit state migration. #[tokio::test] async fn test_deploy_code_and_call_method() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new(worker.clone(), Some(dao.id().clone()), None).await?; @@ -477,7 +483,7 @@ async fn test_deploy_code_and_call_method() -> anyhow::Result<()> { /// succeeded. #[tokio::test] async fn test_deploy_code_with_migration() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new(worker.clone(), Some(dao.id().clone()), None).await?; @@ -524,7 +530,7 @@ async fn test_deploy_code_with_migration() -> anyhow::Result<()> { /// code remains active. #[tokio::test] async fn test_deploy_code_with_migration_failure_rollback() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new(worker.clone(), Some(dao.id().clone()), None).await?; @@ -570,7 +576,7 @@ async fn test_deploy_code_with_migration_failure_rollback() -> anyhow::Result<() /// and 2 executes anyway. #[tokio::test] async fn test_deploy_code_in_batch_transaction_pitfall() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new(worker.clone(), Some(dao.id().clone()), None).await?; @@ -589,17 +595,17 @@ async fn test_deploy_code_in_batch_transaction_pitfall() -> anyhow::Result<()> { // Construct the function call actions to be executed in a batch transaction. // Note that we are attaching a call to `migrate_with_failure`, which will fail. - let fn_call_deploy = workspaces::operations::Function::new("up_deploy_code") + let fn_call_deploy = near_workspaces::operations::Function::new("up_deploy_code") .args_json(json!({ "function_call_args": FunctionCallArgs { function_name: "migrate_with_failure".to_string(), arguments: Vec::new(), amount: 0, gas: Gas::ONE_TERA, } })) - .gas(Gas::ONE_TERA.0 * 200); - let fn_call_remove_code = workspaces::operations::Function::new("up_stage_code") + .gas(near_workspaces::types::Gas::from_tgas(200)); + let fn_call_remove_code = near_workspaces::operations::Function::new("up_stage_code") .args_borsh(Vec::::new()) - .gas(Gas::ONE_TERA.0 * 90); + .gas(near_workspaces::types::Gas::from_tgas(90)); let res = dao .batch(setup.contract.id()) @@ -635,7 +641,7 @@ async fn test_deploy_code_in_batch_transaction_pitfall() -> anyhow::Result<()> { #[tokio::test] async fn test_deploy_code_with_delay() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let staging_duration = sdk_duration_from_secs(3); let setup = Setup::new( @@ -666,7 +672,7 @@ async fn test_deploy_code_with_delay() -> anyhow::Result<()> { #[tokio::test] async fn test_deploy_code_with_delay_failure_too_early() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new( worker.clone(), @@ -700,7 +706,7 @@ async fn test_deploy_code_with_delay_failure_too_early() -> anyhow::Result<()> { #[tokio::test] async fn test_deploy_code_permission_failure() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(dao.id().clone()), None).await?; @@ -735,7 +741,7 @@ async fn test_deploy_code_permission_failure() -> anyhow::Result<()> { /// `up_deploy_code` fails if there's no code staged. #[tokio::test] async fn test_deploy_code_empty_failure() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new( worker, @@ -764,7 +770,7 @@ async fn test_deploy_code_empty_failure() -> anyhow::Result<()> { #[tokio::test] async fn test_init_staging_duration_permission_failure() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(dao.id().clone()), None).await?; @@ -787,7 +793,7 @@ async fn test_init_staging_duration_permission_failure() -> anyhow::Result<()> { #[tokio::test] async fn test_init_staging_duration() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let setup = Setup::new(worker, Some(dao.id().clone()), None).await?; @@ -810,7 +816,7 @@ async fn test_init_staging_duration() -> anyhow::Result<()> { #[tokio::test] async fn test_stage_update_staging_duration_permission_failure() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let staging_duration = sdk_duration_from_secs(42); let setup = Setup::new(worker, Some(dao.id().clone()), Some(staging_duration)).await?; @@ -835,7 +841,7 @@ async fn test_stage_update_staging_duration_permission_failure() -> anyhow::Resu #[tokio::test] async fn test_stage_update_staging_duration() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let staging_duration = sdk_duration_from_secs(42); let setup = Setup::new(worker, Some(dao.id().clone()), Some(staging_duration)).await?; @@ -870,7 +876,7 @@ async fn test_stage_update_staging_duration() -> anyhow::Result<()> { #[tokio::test] async fn test_apply_update_staging_duration_permission_failure() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let staging_duration = sdk_duration_from_secs(21); let setup = Setup::new(worker, Some(dao.id().clone()), Some(staging_duration)).await?; @@ -912,7 +918,7 @@ async fn test_apply_update_staging_duration_permission_failure() -> anyhow::Resu #[tokio::test] async fn test_apply_update_staging_duration() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let staging_duration = sdk_duration_from_secs(21); let setup = Setup::new(worker, Some(dao.id().clone()), Some(staging_duration)).await?; @@ -946,7 +952,7 @@ async fn test_apply_update_staging_duration() -> anyhow::Result<()> { #[tokio::test] async fn test_apply_update_staging_duration_failure_too_early() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let dao = worker.dev_create_account().await?; let staging_duration = sdk_duration_from_secs(1024); let setup = Setup::new(worker, Some(dao.id().clone()), Some(staging_duration)).await?; @@ -979,7 +985,7 @@ async fn test_apply_update_staging_duration_failure_too_early() -> anyhow::Resul /// that whitelists only roles other than `r`. #[tokio::test] async fn test_acl_permission_scope() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; + let worker = near_workspaces::sandbox().await?; let setup = Setup::new(worker.clone(), None, None).await?; // Create an account and grant it `Role::CodeStager`. diff --git a/rust-toolchain b/rust-toolchain index 2f3cf78..6649306 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,4 @@ [toolchain] -channel = "1.66.1" +channel = "1.69.0" components = ["clippy", "rustfmt"] +targets = [ "wasm32-unknown-unknown" ] diff --git a/scripts/fix_dependencies.sh b/scripts/fix_dependencies.sh new file mode 100755 index 0000000..6130537 --- /dev/null +++ b/scripts/fix_dependencies.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# Due to upgrades of dependencies of `near-workspaces`, the compilation of tests with the MSRV (min +# supported Rust version) may fail. This can be fixed by downgrading these dependencies to a version +# that supports our MRSV, which is the purpose of this script. +# +# Reference: https://github.com/near/near-workspaces-rs/issues/336 +# +# For some packages, `near-workspaces@0.9` depends on two different versions, requiring below +# downgrade commands to specify the full semver version as in `-p clap@4.4.7`. I assume once a new +# version of `clap` is released, say 4.4.8, then below must be changed to `-p clap@4.4.8`. Even +# though this requires maintenance, it seems to be cleanest approach that works with CI (see #119 +# for some other attempts and how they failed in CI). +cargo update -p anstyle@1.0.4 --precise 1.0.2 +cargo update -p anstyle-parse@0.2.2 --precise 0.2.1 +cargo update -p clap@4.4.7 --precise 4.3.24 +cargo update -p clap_lex@0.5.1 --precise 0.5.0