From 12d3feec8686a9200173d3c72dbf5159309ded13 Mon Sep 17 00:00:00 2001 From: Arseny Mitin Date: Wed, 29 May 2024 23:17:12 +0400 Subject: [PATCH] feat: bump near-sdk to 5.1.0 (#134) * feat: bump near-sdk to 5.1.0 * fix: access_controllable * fix(tests): borsh usage * fix: use LookupMap where iteration isn't needed * chore: make clippy happy * Update test.yml * fix: do not gitignore Cargo.lock * chore: bump msrv * chore: bump rust in contracts for tests * chore: decrease gas * fix: rm Cargo.lock from lib crates * fix: bring UnorderedMap back * fix: use #[near] instead of #[near_bindgen] * fix: bump version in separate PR * fix(tests): gas consumption is slightly bigger now * fix: #[allow(deprecated)] on UnorderedMap/UnorderedSet * fix: #[allow(depreated)] attributes syntax * docs: comment on deprecated collections from near_sdk::store * fix: use FQDNs for #[derive(...)] in macros * fix: use FQDNs everywhere in quote!{...} --------- Co-authored-by: Oleksandr Anyshchenko --- .github/workflows/test.yml | 14 ++---- .gitignore | 2 +- Cargo.toml | 17 ++----- README.md | 4 +- near-plugins-derive/Cargo.toml | 2 +- .../src/access_control_role.rs | 9 +++- .../src/access_controllable.rs | 43 +++++++++++------ near-plugins-derive/src/ownable.rs | 6 +-- near-plugins-derive/src/pausable.rs | 10 ++-- near-plugins-derive/src/upgradable.rs | 46 +++++++++---------- .../tests/access_controllable.rs | 12 ++--- .../contracts/access_controllable/Cargo.toml | 9 +--- .../access_controllable/rust-toolchain | 2 +- .../contracts/access_controllable/src/lib.rs | 30 +++++++----- .../tests/contracts/ownable/Cargo.toml | 7 +-- .../tests/contracts/ownable/rust-toolchain | 2 +- .../tests/contracts/ownable/src/lib.rs | 10 ++-- .../tests/contracts/pausable/Cargo.toml | 7 +-- .../tests/contracts/pausable/rust-toolchain | 2 +- .../tests/contracts/pausable/src/lib.rs | 8 ++-- .../tests/contracts/upgradable/Cargo.toml | 7 +-- .../tests/contracts/upgradable/rust-toolchain | 2 +- .../tests/contracts/upgradable/src/lib.rs | 10 ++-- .../tests/contracts/upgradable_2/Cargo.toml | 7 +-- .../contracts/upgradable_2/rust-toolchain | 2 +- .../tests/contracts/upgradable_2/src/lib.rs | 10 ++-- .../upgradable_state_migration/Cargo.toml | 7 +-- .../upgradable_state_migration/rust-toolchain | 2 +- .../upgradable_state_migration/src/lib.rs | 11 +++-- near-plugins-derive/tests/upgradable.rs | 22 ++++----- near-plugins/Cargo.toml | 3 ++ near-plugins/src/upgradable.rs | 4 +- scripts/fix_dependencies.sh | 22 --------- 33 files changed, 156 insertions(+), 195 deletions(-) delete mode 100755 scripts/fix_dependencies.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fbb8c83..55cb2fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,16 +17,13 @@ jobs: - name: Install toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.69.0 # MSRV + toolchain: 1.74.0 # MSRV override: true target: wasm32-unknown-unknown - uses: Swatinem/rust-cache@v1 with: - key: rust-version-1.69.0-msrv-2 - - - name: downgrade some dev-dependencies for msrv, see https://github.com/near/near-workspaces-rs/issues/336 - run: ./scripts/fix_dependencies.sh + key: rust-version-1.74.0-msrv-2 - name: add wasm32-unknown-unknown run: rustup target add wasm32-unknown-unknown @@ -44,16 +41,13 @@ jobs: - name: Install toolchain uses: actions-rs/toolchain@v1 with: - toolchain: 1.69.0 # MSRV + toolchain: 1.74.0 # MSRV override: true components: rustfmt, clippy - uses: Swatinem/rust-cache@v1 with: - key: rust-version-1.69.0-msrv-2 - - - name: downgrade some dev-dependencies for msrv, see https://github.com/near/near-workspaces-rs/issues/336 - run: ./scripts/fix_dependencies.sh + key: rust-version-1.74.0-msrv-2 - name: cargo fmt run: cargo fmt --all -- --check diff --git a/.gitignore b/.gitignore index 5a86e8a..376cb0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /target -Cargo.lock +**/Cargo.lock near-plugins-derive/tests/contracts/*/target # Ignore IDE data diff --git a/Cargo.toml b/Cargo.toml index 5f4aa79..36a5984 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,7 @@ [workspace] -members = [ - "near-plugins", - "near-plugins-derive" -] +members = ["near-plugins", "near-plugins-derive"] exclude = ["target", "examples"] +resolver = "2" [workspace.metadata.workspaces] version = "0.15.0" @@ -15,7 +13,7 @@ authors = ["Aurora Labs "] # An update of the MSRV requires updating: # - `rust-toolchain` files in `near-plugins-derive/tests/contracts/**` # - the toolchain installed in CI via the `toolchain` parameter of `actions-rs/toolchain@v1` -rust-version = "1.69.0" +rust-version = "1.74.0" description = "Ergonomic plugin system to extend NEAR contracts." license = "CC0-1.0" readme = "README.md" @@ -25,21 +23,16 @@ keywords = ["near", "smart contract", "plugin"] [workspace.dependencies] bitflags = "1.3" -near-sdk = "4.1.1" +near-sdk = "5.1.0" near-plugins = { path = "near-plugins" } near-plugins-derive = { path = "near-plugins-derive" } serde = "1" anyhow = "1.0" tokio = { version = "1", features = ["full"] } -near-workspaces = "0.9" +near-workspaces = "0.10" toml = "0.5" darling = "0.13.1" proc-macro2 = "1.0" quote = "1.0.9" syn = { version = "1.0.69", features = ["full"] } proc-macro-crate = "0.1.5" - -# Required to build tests with near-sdk v4.1.1, see #128. -# TODO(#125): Remove after upgrading to near-sdk v5. -[patch.crates-io] -parity-secp256k1 = {git = "https://github.com/paritytech/rust-secp256k1", tag = "parity-secp256k1-v0.7.0"} diff --git a/README.md b/README.md index 89e7a94..3fe773b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # NEAR Smart Contracts Plugins Implementation of common patterns used for NEAR smart contracts. Macros provided by default assumes the contract is -using near-sdk-rs and `#[near_bindgen]` macro. +using near-sdk-rs and `#[near]` macro. ## Plugins @@ -71,7 +71,7 @@ Tests should verify that once the macros provided by this crate are expanded, th ## 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 +It is this way since `near` macro from near-sdk-rs will only expose as public methods those that are implemented during the trait implementation for the contract. In the documentation all comments under Default Implementation makes remarks about the current implementation derived diff --git a/near-plugins-derive/Cargo.toml b/near-plugins-derive/Cargo.toml index a13504a..599a427 100644 --- a/near-plugins-derive/Cargo.toml +++ b/near-plugins-derive/Cargo.toml @@ -18,7 +18,7 @@ proc-macro-crate.workspace = true [dev-dependencies] anyhow.workspace = true near-plugins.workspace = true -near-sdk.workspace = true +near-sdk = { workspace = true, features = ["unit-testing"] } tokio.workspace = true near-workspaces.workspace = true toml.workspace = true diff --git a/near-plugins-derive/src/access_control_role.rs b/near-plugins-derive/src/access_control_role.rs index 30552b6..7b98479 100644 --- a/near-plugins-derive/src/access_control_role.rs +++ b/near-plugins-derive/src/access_control_role.rs @@ -166,7 +166,7 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream { .unwrap_or_else(|| ::near_sdk::env::panic_str("Too many enum variants to be represented by bitflags")) } - impl AccessControlRole for #ident { + impl #cratename::AccessControlRole for #ident { fn acl_role_variants() -> Vec<&'static str> { vec![ #(#variant_names,)* @@ -196,7 +196,12 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream { #cratename::bitflags::bitflags! { /// Encodes permissions for roles and admins. - #[derive(BorshDeserialize, BorshSerialize, Default)] + #[derive( + Default, + ::near_sdk::borsh::BorshDeserialize, + ::near_sdk::borsh::BorshSerialize, + )] + #[borsh(crate = "near_sdk::borsh")] struct #bitflags_type_ident: u128 { #( const #bitflags_idents = 1u128 << #bitflags_idxs; diff --git a/near-plugins-derive/src/access_controllable.rs b/near-plugins-derive/src/access_controllable.rs index 9e6aa65..c68d704 100644 --- a/near-plugins-derive/src/access_controllable.rs +++ b/near-plugins-derive/src/access_controllable.rs @@ -39,8 +39,9 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream let storage_prefix = macro_args .storage_prefix .unwrap_or_else(|| DEFAULT_STORAGE_PREFIX.to_string()); - assert!( - macro_args.role_type.len() == 1, + assert_eq!( + macro_args.role_type.len(), + 1, "role_type should be exactly one path" ); let role_type = ¯o_args.role_type[0]; @@ -49,13 +50,22 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream #input #[derive(::near_sdk::borsh::BorshDeserialize, ::near_sdk::borsh::BorshSerialize)] + #[borsh(crate = "near_sdk::borsh")] + /// NOTE: Despite `near_sdk::store::UnorderedMap` and `near_sdk::store::UnorderedSet` + /// have been deprecated, it still makes sense to use them here as we might still + /// need to iterate over the keys. + /// The impact on gas consumption compared to `near_sdk::store::LookupMap` is negligible + /// as it lazily loads list of keys to iterate over internally. Compiled size of a + /// contract is not affected that much as well. struct #acl_type { /// Stores permissions per account. + #[allow(deprecated)] permissions: ::near_sdk::store::UnorderedMap< ::near_sdk::AccountId, #bitflags_type, >, /// Stores the set of accounts that bear a permission. + #[allow(deprecated)] bearers: ::near_sdk::store::UnorderedMap< #bitflags_type, ::near_sdk::store::UnorderedSet<::near_sdk::AccountId>, @@ -64,11 +74,13 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream impl Default for #acl_type { fn default() -> Self { - let base_prefix = <#ident as AccessControllable>::acl_storage_prefix(); + let base_prefix = <#ident as #cratename::AccessControllable>::acl_storage_prefix(); Self { - permissions: ::near_sdk::store::UnorderedMap::new( + #[allow(deprecated)] + permissions: ::near_sdk::store::UnorderedMap::new( __acl_storage_prefix(base_prefix, __AclStorageKey::Permissions), ), + #[allow(deprecated)] bearers: ::near_sdk::store::UnorderedMap::new( __acl_storage_prefix(base_prefix, __AclStorageKey::Bearers), ), @@ -80,6 +92,7 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream /// instead it should be prepended to the storage prefix specified by /// the user. #[derive(::near_sdk::borsh::BorshSerialize)] + #[borsh(crate = "near_sdk::borsh")] enum __AclStorageKey { Permissions, Bearers, @@ -89,21 +102,20 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream /// Generates a prefix by concatenating the input parameters. fn __acl_storage_prefix(base: &[u8], specifier: __AclStorageKey) -> Vec { - let specifier = specifier - .try_to_vec() + let specifier = near_sdk::borsh::to_vec(&specifier) .unwrap_or_else(|_| ::near_sdk::env::panic_str("Storage key should be serializable")); [base, specifier.as_slice()].concat() } impl #ident { fn acl_get_storage(&self) -> Option<#acl_type> { - let base_prefix = <#ident as AccessControllable>::acl_storage_prefix(); + let base_prefix = <#ident as #cratename::AccessControllable>::acl_storage_prefix(); near_sdk::env::storage_read(&__acl_storage_prefix( base_prefix, __AclStorageKey::AclStorage, )) .map(|acl_storage_bytes| { - #acl_type::try_from_slice(&acl_storage_bytes) + ::near_sdk::borsh::BorshDeserialize::try_from_slice(&acl_storage_bytes) .unwrap_or_else(|_| near_sdk::env::panic_str("ACL: invalid acl storage format")) }) } @@ -113,19 +125,20 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream } fn acl_init_storage_unchecked(&mut self) -> #acl_type { - let base_prefix = <#ident as AccessControllable>::acl_storage_prefix(); + let base_prefix = <#ident as #cratename::AccessControllable>::acl_storage_prefix(); let acl_storage: #acl_type = Default::default(); near_sdk::env::storage_write( &__acl_storage_prefix(base_prefix, __AclStorageKey::AclStorage), - &acl_storage.try_to_vec().unwrap(), + &near_sdk::borsh::to_vec(&acl_storage).unwrap(), ); acl_storage } } impl #acl_type { + #[allow(deprecated)] fn new_bearers_set(permission: #bitflags_type) -> ::near_sdk::store::UnorderedSet<::near_sdk::AccountId> { - let base_prefix = <#ident as AccessControllable>::acl_storage_prefix(); + let base_prefix = <#ident as #cratename::AccessControllable>::acl_storage_prefix(); let specifier = __AclStorageKey::BearersSet { permission }; ::near_sdk::store::UnorderedSet::new(__acl_storage_prefix(base_prefix, specifier)) } @@ -566,13 +579,13 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream }; } - // Note that `#[near-bindgen]` exposes non-public functions in trait + // Note that `#[near]` exposes non-public functions in trait // implementations. This is [documented] behavior. Therefore some // functions are made `#[private]` despite _not_ being public. // - // [documented]: https://docs.near.org/sdk/rust/contract-interface/public-methods#exposing-trait-implementations - #[near_bindgen] - impl AccessControllable for #ident { + // [documented]: https://docs.near.org/sdk/rust/contract-structure/near-bindgen + #[near] + impl #cratename::AccessControllable for #ident { fn acl_storage_prefix() -> &'static [u8] { (#storage_prefix).as_bytes() } diff --git a/near-plugins-derive/src/ownable.rs b/near-plugins-derive/src/ownable.rs index a37baa9..0404646 100644 --- a/near-plugins-derive/src/ownable.rs +++ b/near-plugins-derive/src/ownable.rs @@ -24,8 +24,8 @@ pub fn derive_ownable(input: TokenStream) -> TokenStream { .unwrap_or_else(|| "__OWNER__".to_string()); let output = quote! { - #[near_bindgen] - impl Ownable for #ident { + #[near] + impl #cratename::Ownable for #ident { fn owner_storage_key(&self) -> &'static [u8] { (#owner_storage_key).as_bytes() } @@ -66,7 +66,7 @@ pub fn derive_ownable(input: TokenStream) -> TokenStream { match owner.as_ref() { Some(owner) => ::near_sdk::env::storage_write( &self.owner_storage_key(), - owner.as_ref().as_bytes(), + owner.as_bytes(), ), None => ::near_sdk::env::storage_remove(&self.owner_storage_key()), }; diff --git a/near-plugins-derive/src/pausable.rs b/near-plugins-derive/src/pausable.rs index 6158e6d..bda149b 100644 --- a/near-plugins-derive/src/pausable.rs +++ b/near-plugins-derive/src/pausable.rs @@ -34,8 +34,8 @@ pub fn derive_pausable(input: TokenStream) -> TokenStream { ); let output = quote! { - #[near_bindgen] - impl Pausable for #ident { + #[near] + impl #cratename::Pausable for #ident { fn pa_storage_key(&self) -> &'static [u8] { (#paused_storage_key).as_bytes() } @@ -65,8 +65,7 @@ pub fn derive_pausable(input: TokenStream) -> TokenStream { ::near_sdk::env::storage_write( self.pa_storage_key().as_ref(), - paused_keys - .try_to_vec() + ::near_sdk::borsh::to_vec(&paused_keys) .unwrap_or_else(|_| ::near_sdk::env::panic_str("Pausable: Unexpected error serializing keys")) .as_ref(), ); @@ -96,8 +95,7 @@ pub fn derive_pausable(input: TokenStream) -> TokenStream { } else { ::near_sdk::env::storage_write( self.pa_storage_key().as_ref(), - paused_keys - .try_to_vec() + ::near_sdk::borsh::to_vec(&paused_keys) .unwrap_or_else(|_| ::near_sdk::env::panic_str("Pausable: Unexpected error serializing keys")) .as_ref(), ); diff --git a/near-plugins-derive/src/upgradable.rs b/near-plugins-derive/src/upgradable.rs index be573e7..f42cb5b 100644 --- a/near-plugins-derive/src/upgradable.rs +++ b/near-plugins-derive/src/upgradable.rs @@ -93,6 +93,7 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream { /// instead it should be prepended to the storage prefix specified by /// the user. #[derive(::near_sdk::borsh::BorshSerialize)] + #[borsh(crate = "near_sdk::borsh")] enum __UpgradableStorageKey { Code, StagingTimestamp, @@ -111,7 +112,7 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream { } fn up_get_duration(&self, key: __UpgradableStorageKey) -> Option<::near_sdk::Duration> { - near_sdk::env::storage_read(self.up_storage_key(key).as_ref()).map(|duration_bytes| { + ::near_sdk::env::storage_read(self.up_storage_key(key).as_ref()).map(|duration_bytes| { ::near_sdk::Duration::try_from_slice(&duration_bytes).unwrap_or_else(|_| near_sdk::env::panic_str("Upgradable: Invalid u64 Duration format") ) @@ -119,37 +120,36 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream { } fn up_set_timestamp(&self, key: __UpgradableStorageKey, value: ::near_sdk::Timestamp) { - self.up_storage_write(key, &value.try_to_vec().unwrap()); + self.up_storage_write(key, &::near_sdk::borsh::to_vec(&value).unwrap()); } fn up_set_duration(&self, key: __UpgradableStorageKey, value: ::near_sdk::Duration) { - self.up_storage_write(key, &value.try_to_vec().unwrap()); + self.up_storage_write(key, &::near_sdk::borsh::to_vec(&value).unwrap()); } fn up_storage_key(&self, key: __UpgradableStorageKey) -> Vec { - let key_vec = key - .try_to_vec() + let key_vec = ::near_sdk::borsh::to_vec(&key) .unwrap_or_else(|_| ::near_sdk::env::panic_str("Storage key should be serializable")); [(#storage_prefix).as_bytes(), key_vec.as_slice()].concat() } fn up_storage_write(&self, key: __UpgradableStorageKey, value: &[u8]) { - near_sdk::env::storage_write(self.up_storage_key(key).as_ref(), &value); + ::near_sdk::env::storage_write(self.up_storage_key(key).as_ref(), &value); } fn up_set_staging_duration_unchecked(&self, staging_duration: near_sdk::Duration) { - self.up_storage_write(__UpgradableStorageKey::StagingDuration, &staging_duration.try_to_vec().unwrap()); + self.up_storage_write(__UpgradableStorageKey::StagingDuration, &::near_sdk::borsh::to_vec(&staging_duration).unwrap()); } } - #[near_bindgen] + #[near] impl Upgradable for #ident { fn up_storage_prefix(&self) -> &'static [u8] { (#storage_prefix).as_bytes() } fn up_get_delay_status(&self) -> #cratename::UpgradableDurationStatus { - near_plugins::UpgradableDurationStatus { + #cratename::UpgradableDurationStatus { staging_duration: self.up_get_duration(__UpgradableStorageKey::StagingDuration), staging_timestamp: self.up_get_timestamp(__UpgradableStorageKey::StagingTimestamp), new_staging_duration: self.up_get_duration(__UpgradableStorageKey::NewStagingDuration), @@ -160,10 +160,10 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream { #[#cratename::access_control_any(roles(#(#acl_roles_code_stagers),*))] fn up_stage_code(&mut self, #[serializer(borsh)] code: Vec) { if code.is_empty() { - near_sdk::env::storage_remove(self.up_storage_key(__UpgradableStorageKey::Code).as_ref()); - near_sdk::env::storage_remove(self.up_storage_key(__UpgradableStorageKey::StagingTimestamp).as_ref()); + ::near_sdk::env::storage_remove(self.up_storage_key(__UpgradableStorageKey::Code).as_ref()); + ::near_sdk::env::storage_remove(self.up_storage_key(__UpgradableStorageKey::StagingTimestamp).as_ref()); } else { - let timestamp = near_sdk::env::block_timestamp() + self.up_get_duration(__UpgradableStorageKey::StagingDuration).unwrap_or(0); + let timestamp = ::near_sdk::env::block_timestamp() + self.up_get_duration(__UpgradableStorageKey::StagingDuration).unwrap_or(0); self.up_storage_write(__UpgradableStorageKey::Code, &code); self.up_set_timestamp(__UpgradableStorageKey::StagingTimestamp, timestamp); } @@ -171,12 +171,12 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream { #[result_serializer(borsh)] fn up_staged_code(&self) -> Option> { - near_sdk::env::storage_read(self.up_storage_key(__UpgradableStorageKey::Code).as_ref()) + ::near_sdk::env::storage_read(self.up_storage_key(__UpgradableStorageKey::Code).as_ref()) } fn up_staged_code_hash(&self) -> Option<::near_sdk::CryptoHash> { self.up_staged_code() - .map(|code| std::convert::TryInto::try_into(near_sdk::env::sha256(code.as_ref())).unwrap()) + .map(|code| std::convert::TryInto::try_into(::near_sdk::env::sha256(code.as_ref())).unwrap()) } #[#cratename::access_control_any(roles(#(#acl_roles_code_deployers),*))] @@ -184,8 +184,8 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream { let staging_timestamp = self.up_get_timestamp(__UpgradableStorageKey::StagingTimestamp) .unwrap_or_else(|| ::near_sdk::env::panic_str("Upgradable: staging timestamp isn't set")); - if near_sdk::env::block_timestamp() < staging_timestamp { - near_sdk::env::panic_str( + if ::near_sdk::env::block_timestamp() < staging_timestamp { + ::near_sdk::env::panic_str( format!( "Upgradable: Deploy code too early: staging ends on {}", staging_timestamp @@ -195,7 +195,7 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream { } let code = self.up_staged_code().unwrap_or_else(|| ::near_sdk::env::panic_str("Upgradable: No staged code")); - let promise = near_sdk::Promise::new(near_sdk::env::current_account_id()) + let promise = ::near_sdk::Promise::new(::near_sdk::env::current_account_id()) .deploy_contract(code); match function_call_args { None => promise, @@ -209,18 +209,18 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream { } #[#cratename::access_control_any(roles(#(#acl_roles_duration_initializers),*))] - fn up_init_staging_duration(&mut self, staging_duration: near_sdk::Duration) { - near_sdk::require!(self.up_get_duration(__UpgradableStorageKey::StagingDuration).is_none(), "Upgradable: staging duration was already initialized"); + fn up_init_staging_duration(&mut self, staging_duration: ::near_sdk::Duration) { + ::near_sdk::require!(self.up_get_duration(__UpgradableStorageKey::StagingDuration).is_none(), "Upgradable: staging duration was already initialized"); self.up_set_staging_duration_unchecked(staging_duration); } #[#cratename::access_control_any(roles(#(#acl_roles_duration_update_stagers),*))] - fn up_stage_update_staging_duration(&mut self, staging_duration: near_sdk::Duration) { + fn up_stage_update_staging_duration(&mut self, staging_duration: ::near_sdk::Duration) { let current_staging_duration = self.up_get_duration(__UpgradableStorageKey::StagingDuration) .unwrap_or_else(|| ::near_sdk::env::panic_str("Upgradable: staging duration isn't initialized")); self.up_set_duration(__UpgradableStorageKey::NewStagingDuration, staging_duration); - let staging_duration_timestamp = near_sdk::env::block_timestamp() + current_staging_duration; + let staging_duration_timestamp = ::near_sdk::env::block_timestamp() + current_staging_duration; self.up_set_timestamp(__UpgradableStorageKey::NewStagingDurationTimestamp, staging_duration_timestamp); } @@ -229,8 +229,8 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream { let staging_timestamp = self.up_get_timestamp(__UpgradableStorageKey::NewStagingDurationTimestamp) .unwrap_or_else(|| ::near_sdk::env::panic_str("Upgradable: No staged update")); - if near_sdk::env::block_timestamp() < staging_timestamp { - near_sdk::env::panic_str( + if ::near_sdk::env::block_timestamp() < staging_timestamp { + ::near_sdk::env::panic_str( format!( "Upgradable: Update duration too early: staging ends on {}", staging_timestamp diff --git a/near-plugins-derive/tests/access_controllable.rs b/near-plugins-derive/tests/access_controllable.rs index d08af48..056b35a 100644 --- a/near-plugins-derive/tests/access_controllable.rs +++ b/near-plugins-derive/tests/access_controllable.rs @@ -1193,7 +1193,7 @@ async fn test_acl_get_super_admins() -> anyhow::Result<()> { .contract .acl_get_super_admins(&setup.account, 0, 0) .await?; - assert_eq!(actual, vec![],); + assert!(actual.is_empty()); // Skip outside of the number of existing super-admins. let n = u64::try_from(super_admin_ids.len()).unwrap(); @@ -1201,7 +1201,7 @@ async fn test_acl_get_super_admins() -> anyhow::Result<()> { .contract .acl_get_super_admins(&setup.account, n, 1) .await?; - assert_eq!(actual, vec![],); + assert!(actual.is_empty()); // Retrieve super-admins with step size 1. for i in 0..3 { @@ -1264,7 +1264,7 @@ async fn test_acl_get_admins() -> anyhow::Result<()> { .contract .acl_get_admins(&setup.account, role, 0, 0) .await?; - assert_eq!(actual, vec![],); + assert!(actual.is_empty()); // Skip outside of the number of existing admins. let n = u64::try_from(admin_ids.len()).unwrap(); @@ -1272,7 +1272,7 @@ async fn test_acl_get_admins() -> anyhow::Result<()> { .contract .acl_get_admins(&setup.account, role, n, 1) .await?; - assert_eq!(actual, vec![],); + assert!(actual.is_empty()); // Retrieve admins with step size 1. for i in 0..3 { @@ -1335,7 +1335,7 @@ async fn test_acl_get_grantees() -> anyhow::Result<()> { .contract .acl_get_grantees(&setup.account, role, 0, 0) .await?; - assert_eq!(actual, vec![],); + assert!(actual.is_empty()); // Skip outside of the number of existing grantees. let n = u64::try_from(grantee_ids.len()).unwrap(); @@ -1343,7 +1343,7 @@ async fn test_acl_get_grantees() -> anyhow::Result<()> { .contract .acl_get_grantees(&setup.account, role, n, 1) .await?; - assert_eq!(actual, vec![],); + assert!(actual.is_empty()); // Retrieve grantees with step size 1. for i in 0..3 { diff --git a/near-plugins-derive/tests/contracts/access_controllable/Cargo.toml b/near-plugins-derive/tests/contracts/access_controllable/Cargo.toml index b583c72..9719bdb 100644 --- a/near-plugins-derive/tests/contracts/access_controllable/Cargo.toml +++ b/near-plugins-derive/tests/contracts/access_controllable/Cargo.toml @@ -1,14 +1,14 @@ [package] name = "access_controllable" version = "0.0.0" -edition = "2018" +edition = "2021" [lib] crate-type = ["cdylib", "rlib"] [dependencies] near-plugins = { path = "../../../../near-plugins" } -near-sdk = "4.1.1" +near-sdk = "5.1" [profile.release] codegen-units = 1 @@ -19,8 +19,3 @@ panic = "abort" overflow-checks = true [workspace] - -# Required to build tests with near-sdk v4.1.1, see #128. -# TODO(#125): Remove after upgrading to near-sdk v5. -[patch.crates-io] -parity-secp256k1 = {git = "https://github.com/paritytech/rust-secp256k1", tag = "parity-secp256k1-v0.7.0"} diff --git a/near-plugins-derive/tests/contracts/access_controllable/rust-toolchain b/near-plugins-derive/tests/contracts/access_controllable/rust-toolchain index 6649306..e2ff79e 100644 --- a/near-plugins-derive/tests/contracts/access_controllable/rust-toolchain +++ b/near-plugins-derive/tests/contracts/access_controllable/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "1.69.0" +channel = "1.74.0" components = ["clippy", "rustfmt"] targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/access_controllable/src/lib.rs b/near-plugins-derive/tests/contracts/access_controllable/src/lib.rs index 4a0e740..147dfb3 100644 --- a/near-plugins-derive/tests/contracts/access_controllable/src/lib.rs +++ b/near-plugins-derive/tests/contracts/access_controllable/src/lib.rs @@ -1,7 +1,7 @@ use near_plugins::{access_control, access_control_any, AccessControlRole, AccessControllable}; -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::{env, near_bindgen, AccountId, PanicOnDefault}; +use near_sdk::{env, near, AccountId, PanicOnDefault}; use std::collections::HashMap; /// Roles are represented by enum variants. @@ -20,13 +20,13 @@ pub enum Role { /// Pass `Role` to the `access_controllable` macro. #[access_control(role_type(Role))] -#[near_bindgen] -#[derive(PanicOnDefault, BorshDeserialize, BorshSerialize)] +#[near(contract_state)] +#[derive(PanicOnDefault)] pub struct Counter { counter: u64, } -#[near_bindgen] +#[near] impl Counter { /// Constructor of the contract which optionally adds access control admins and grants roles if /// either of the maps passed as parameters contains account ids. In that case, the contract @@ -132,21 +132,24 @@ impl Counter { self.acl_is_super_admin(env::predecessor_account_id()), "Only super admins are allowed to add other super admins." ); - self.acl_get_or_init().add_super_admin_unchecked(&account_id) + self.acl_get_or_init() + .add_super_admin_unchecked(&account_id) } } /// Exposing internal methods to facilitate integration testing. -#[near_bindgen] +#[near] impl Counter { #[private] pub fn acl_add_super_admin_unchecked(&mut self, account_id: AccountId) -> bool { - self.acl_get_or_init().add_super_admin_unchecked(&account_id) + self.acl_get_or_init() + .add_super_admin_unchecked(&account_id) } #[private] pub fn acl_revoke_super_admin_unchecked(&mut self, account_id: AccountId) -> bool { - self.acl_get_or_init().revoke_super_admin_unchecked(&account_id) + self.acl_get_or_init() + .revoke_super_admin_unchecked(&account_id) } #[private] @@ -157,16 +160,19 @@ impl Counter { #[private] pub fn acl_add_admin_unchecked(&mut self, role: Role, account_id: AccountId) -> bool { - self.acl_get_or_init().add_admin_unchecked(role, &account_id) + self.acl_get_or_init() + .add_admin_unchecked(role, &account_id) } #[private] pub fn acl_revoke_admin_unchecked(&mut self, role: Role, account_id: AccountId) -> bool { - self.acl_get_or_init().revoke_admin_unchecked(role, &account_id) + self.acl_get_or_init() + .revoke_admin_unchecked(role, &account_id) } #[private] pub fn acl_grant_role_unchecked(&mut self, role: Role, account_id: AccountId) -> bool { - self.acl_get_or_init().grant_role_unchecked(role, &account_id) + self.acl_get_or_init() + .grant_role_unchecked(role, &account_id) } } diff --git a/near-plugins-derive/tests/contracts/ownable/Cargo.toml b/near-plugins-derive/tests/contracts/ownable/Cargo.toml index 7815288..8de6595 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.1" +near-sdk = "5.1.0" [profile.release] codegen-units = 1 @@ -19,8 +19,3 @@ panic = "abort" overflow-checks = true [workspace] - -# Required to build tests with near-sdk v4.1.1, see #128. -# TODO(#125): Remove after upgrading to near-sdk v5. -[patch.crates-io] -parity-secp256k1 = {git = "https://github.com/paritytech/rust-secp256k1", tag = "parity-secp256k1-v0.7.0"} diff --git a/near-plugins-derive/tests/contracts/ownable/rust-toolchain b/near-plugins-derive/tests/contracts/ownable/rust-toolchain index 6649306..e2ff79e 100644 --- a/near-plugins-derive/tests/contracts/ownable/rust-toolchain +++ b/near-plugins-derive/tests/contracts/ownable/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "1.69.0" +channel = "1.74.0" components = ["clippy", "rustfmt"] targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/ownable/src/lib.rs b/near-plugins-derive/tests/contracts/ownable/src/lib.rs index 652bfa9..7786ace 100644 --- a/near-plugins-derive/tests/contracts/ownable/src/lib.rs +++ b/near-plugins-derive/tests/contracts/ownable/src/lib.rs @@ -1,14 +1,14 @@ use near_plugins::{only, Ownable}; -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; -use near_sdk::{near_bindgen, AccountId, PanicOnDefault}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; +use near_sdk::{near, AccountId, PanicOnDefault}; -#[near_bindgen] -#[derive(Ownable, PanicOnDefault, BorshDeserialize, BorshSerialize)] +#[near(contract_state)] +#[derive(Ownable, PanicOnDefault)] pub struct Counter { counter: u64, } -#[near_bindgen] +#[near] impl Counter { /// Optionally set the owner in the constructor. #[init] diff --git a/near-plugins-derive/tests/contracts/pausable/Cargo.toml b/near-plugins-derive/tests/contracts/pausable/Cargo.toml index e5b6e09..7e54676 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.1" +near-sdk = "5.1.0" [profile.release] codegen-units = 1 @@ -19,8 +19,3 @@ panic = "abort" overflow-checks = true [workspace] - -# Required to build tests with near-sdk v4.1.1, see #128. -# TODO(#125): Remove after upgrading to near-sdk v5. -[patch.crates-io] -parity-secp256k1 = {git = "https://github.com/paritytech/rust-secp256k1", tag = "parity-secp256k1-v0.7.0"} diff --git a/near-plugins-derive/tests/contracts/pausable/rust-toolchain b/near-plugins-derive/tests/contracts/pausable/rust-toolchain index 6649306..e2ff79e 100644 --- a/near-plugins-derive/tests/contracts/pausable/rust-toolchain +++ b/near-plugins-derive/tests/contracts/pausable/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "1.69.0" +channel = "1.74.0" components = ["clippy", "rustfmt"] targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/pausable/src/lib.rs b/near-plugins-derive/tests/contracts/pausable/src/lib.rs index 5940c68..9d7fec9 100644 --- a/near-plugins-derive/tests/contracts/pausable/src/lib.rs +++ b/near-plugins-derive/tests/contracts/pausable/src/lib.rs @@ -3,7 +3,7 @@ use near_plugins::{ }; use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::{env, near_bindgen, AccountId, PanicOnDefault}; +use near_sdk::{env, near, AccountId, PanicOnDefault}; /// Define roles for access control of `Pausable` features. Accounts which are /// granted a role are authorized to execute the corresponding action. @@ -21,14 +21,14 @@ pub enum Role { } #[access_control(role_type(Role))] -#[near_bindgen] -#[derive(Pausable, PanicOnDefault, BorshDeserialize, BorshSerialize)] +#[near(contract_state)] +#[derive(Pausable, PanicOnDefault)] #[pausable(manager_roles(Role::PauseManager))] pub struct Counter { counter: u64, } -#[near_bindgen] +#[near] impl Counter { /// Permissons for `AccessControllable` can be initialized in the constructor. Here we are: /// diff --git a/near-plugins-derive/tests/contracts/upgradable/Cargo.toml b/near-plugins-derive/tests/contracts/upgradable/Cargo.toml index 510be6b..ebfc9b6 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.1" +near-sdk = "5.1.0" [profile.release] codegen-units = 1 @@ -19,8 +19,3 @@ panic = "abort" overflow-checks = true [workspace] - -# Required to build tests with near-sdk v4.1.1, see #128. -# TODO(#125): Remove after upgrading to near-sdk v5. -[patch.crates-io] -parity-secp256k1 = {git = "https://github.com/paritytech/rust-secp256k1", tag = "parity-secp256k1-v0.7.0"} diff --git a/near-plugins-derive/tests/contracts/upgradable/rust-toolchain b/near-plugins-derive/tests/contracts/upgradable/rust-toolchain index 6649306..e2ff79e 100644 --- a/near-plugins-derive/tests/contracts/upgradable/rust-toolchain +++ b/near-plugins-derive/tests/contracts/upgradable/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "1.69.0" +channel = "1.74.0" components = ["clippy", "rustfmt"] targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/upgradable/src/lib.rs b/near-plugins-derive/tests/contracts/upgradable/src/lib.rs index a399cbe..b233a8f 100644 --- a/near-plugins-derive/tests/contracts/upgradable/src/lib.rs +++ b/near-plugins-derive/tests/contracts/upgradable/src/lib.rs @@ -1,8 +1,8 @@ use near_plugins::{access_control, AccessControlRole, AccessControllable, Upgradable}; -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::env; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::{near_bindgen, AccountId, Duration, PanicOnDefault}; +use near_sdk::{near, AccountId, Duration, PanicOnDefault}; /// Defines roles for access control of protected methods provided by the `Upgradable` plugin. #[derive(AccessControlRole, Deserialize, Serialize, Copy, Clone)] @@ -41,8 +41,8 @@ pub enum Role { /// method panics if it is called by an account which is not a grantee of at least one of the /// whitelisted roles. #[access_control(role_type(Role))] -#[near_bindgen] -#[derive(Upgradable, PanicOnDefault, BorshDeserialize, BorshSerialize)] +#[near(contract_state)] +#[derive(Upgradable, PanicOnDefault)] #[upgradable(access_control_roles( code_stagers(Role::CodeStager, Role::DAO), code_deployers(Role::CodeDeployer, Role::DAO), @@ -52,7 +52,7 @@ pub enum Role { ))] pub struct Contract; -#[near_bindgen] +#[near] impl Contract { /// Makes the contract itself `AccessControllable` super admin to allow it granting and revoking /// permissions. If parameter `dao` is `Some(account_id)`, then `account_id` is granted diff --git a/near-plugins-derive/tests/contracts/upgradable_2/Cargo.toml b/near-plugins-derive/tests/contracts/upgradable_2/Cargo.toml index a2726a6..5bf4ae8 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.1" +near-sdk = "5.1.0" [profile.release] codegen-units = 1 @@ -19,8 +19,3 @@ panic = "abort" overflow-checks = true [workspace] - -# Required to build tests with near-sdk v4.1.1, see #128. -# TODO(#125): Remove after upgrading to near-sdk v5. -[patch.crates-io] -parity-secp256k1 = {git = "https://github.com/paritytech/rust-secp256k1", tag = "parity-secp256k1-v0.7.0"} diff --git a/near-plugins-derive/tests/contracts/upgradable_2/rust-toolchain b/near-plugins-derive/tests/contracts/upgradable_2/rust-toolchain index 6649306..e2ff79e 100644 --- a/near-plugins-derive/tests/contracts/upgradable_2/rust-toolchain +++ b/near-plugins-derive/tests/contracts/upgradable_2/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "1.69.0" +channel = "1.74.0" components = ["clippy", "rustfmt"] targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/upgradable_2/src/lib.rs b/near-plugins-derive/tests/contracts/upgradable_2/src/lib.rs index 5f7ba94..688732d 100644 --- a/near-plugins-derive/tests/contracts/upgradable_2/src/lib.rs +++ b/near-plugins-derive/tests/contracts/upgradable_2/src/lib.rs @@ -1,9 +1,9 @@ //! A simple contract to be deployed via `Upgradable`. use near_plugins::{access_control, AccessControlRole, AccessControllable, Upgradable}; -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::{near_bindgen, PanicOnDefault}; +use near_sdk::{near, PanicOnDefault}; /// Roles correspond to those defined in the initial contract `../upgradable`, to make permissions /// granted before the upgrade remain valid. @@ -21,8 +21,8 @@ pub enum Role { /// /// [state migration]: https://docs.near.org/develop/upgrade#migrating-the-state #[access_control(role_type(Role))] -#[near_bindgen] -#[derive(Upgradable, PanicOnDefault, BorshDeserialize, BorshSerialize)] +#[near(contract_state)] +#[derive(Upgradable, PanicOnDefault)] #[upgradable(access_control_roles( code_stagers(Role::CodeStager, Role::DAO), code_deployers(Role::CodeDeployer, Role::DAO), @@ -32,7 +32,7 @@ pub enum Role { ))] pub struct Contract; -#[near_bindgen] +#[near] impl Contract { /// A method that is _not_ defined in the initial contract, so its existence proves the /// contract defined in this file was deployed. 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 4c3e337..0deed5e 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.1" +near-sdk = "5.1.0" [profile.release] codegen-units = 1 @@ -19,8 +19,3 @@ panic = "abort" overflow-checks = true [workspace] - -# Required to build tests with near-sdk v4.1.1, see #128. -# TODO(#125): Remove after upgrading to near-sdk v5. -[patch.crates-io] -parity-secp256k1 = {git = "https://github.com/paritytech/rust-secp256k1", tag = "parity-secp256k1-v0.7.0"} 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 6649306..e2ff79e 100644 --- a/near-plugins-derive/tests/contracts/upgradable_state_migration/rust-toolchain +++ b/near-plugins-derive/tests/contracts/upgradable_state_migration/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "1.69.0" +channel = "1.74.0" components = ["clippy", "rustfmt"] targets = [ "wasm32-unknown-unknown" ] diff --git a/near-plugins-derive/tests/contracts/upgradable_state_migration/src/lib.rs b/near-plugins-derive/tests/contracts/upgradable_state_migration/src/lib.rs index cd55082..784a499 100644 --- a/near-plugins-derive/tests/contracts/upgradable_state_migration/src/lib.rs +++ b/near-plugins-derive/tests/contracts/upgradable_state_migration/src/lib.rs @@ -3,9 +3,9 @@ //! [state migration]: https://docs.near.org/develop/upgrade#migrating-the-state use near_plugins::{access_control, AccessControlRole, AccessControllable, Upgradable}; -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::{env, near_bindgen, PanicOnDefault}; +use near_sdk::{env, near, PanicOnDefault}; /// Roles correspond to those defined in the initial contract `../upgradable`, to make permissions /// granted before the upgrade remain valid. @@ -23,8 +23,8 @@ pub enum Role { /// /// [state migration]: https://docs.near.org/develop/upgrade#migrating-the-state #[access_control(role_type(Role))] -#[near_bindgen] -#[derive(Upgradable, PanicOnDefault, BorshDeserialize, BorshSerialize)] +#[near(contract_state)] +#[derive(Upgradable, PanicOnDefault)] #[upgradable(access_control_roles( code_stagers(Role::CodeStager, Role::DAO), code_deployers(Role::CodeDeployer, Role::DAO), @@ -36,7 +36,7 @@ pub struct Contract { is_migrated: bool, } -#[near_bindgen] +#[near] impl Contract { /// Migrates state from [`OldContract`] to [`Contract`]. /// @@ -69,4 +69,5 @@ impl Contract { /// Corresponds to the state defined in the initial `../upgradable` contract. #[derive(BorshDeserialize)] +#[borsh(crate = "near_sdk::borsh")] pub struct OldContract; diff --git a/near-plugins-derive/tests/upgradable.rs b/near-plugins-derive/tests/upgradable.rs index 3ae57da..2401572 100644 --- a/near-plugins-derive/tests/upgradable.rs +++ b/near-plugins-derive/tests/upgradable.rs @@ -12,7 +12,7 @@ use common::utils::{ }; use near_plugins::upgradable::FunctionCallArgs; use near_sdk::serde_json::json; -use near_sdk::{CryptoHash, Duration, Gas, Timestamp}; +use near_sdk::{CryptoHash, Duration, Gas, NearToken, Timestamp}; use near_workspaces::network::Sandbox; use near_workspaces::result::ExecutionFinalResult; use near_workspaces::{Account, AccountId, Contract, Worker}; @@ -99,7 +99,7 @@ impl Setup { // Grab the receipt corresponding to the function call. let receipt = result .receipt_outcomes() - .get(0) + .first() .expect("There should be at least one receipt outcome"); let block_timestamp = get_transaction_block(&self.worker, receipt) .await @@ -508,8 +508,8 @@ async fn test_deploy_code_with_migration() -> anyhow::Result<()> { let function_call_args = FunctionCallArgs { function_name: "migrate".to_string(), arguments: Vec::new(), - amount: 0, - gas: Gas::ONE_TERA, + amount: NearToken::from_yoctonear(0), + gas: Gas::from_tgas(1), }; let res = setup .upgradable_contract @@ -551,8 +551,8 @@ async fn test_deploy_code_with_migration_failure_rollback() -> anyhow::Result<() let function_call_args = FunctionCallArgs { function_name: "migrate_with_failure".to_string(), arguments: Vec::new(), - amount: 0, - gas: Gas::ONE_TERA, + amount: NearToken::from_yoctonear(0), + gas: Gas::from_tgas(1), }; let res = setup .upgradable_contract @@ -561,7 +561,7 @@ async fn test_deploy_code_with_migration_failure_rollback() -> anyhow::Result<() assert_failure_with(res, "Failing migration on purpose"); // Verify `code` wasn't deployed by calling a function that is defined only in the initial - // contract but not in the contract contract corresponding to `code`. + // contract but not in the contract corresponding to the `code`. setup.assert_is_set_up(&setup.unauth_account).await; Ok(()) @@ -599,13 +599,13 @@ async fn test_deploy_code_in_batch_transaction_pitfall() -> anyhow::Result<()> { .args_json(json!({ "function_call_args": FunctionCallArgs { function_name: "migrate_with_failure".to_string(), arguments: Vec::new(), - amount: 0, - gas: Gas::ONE_TERA, + amount: NearToken::from_yoctonear(0), + gas: Gas::from_tgas(1), } })) - .gas(near_workspaces::types::Gas::from_tgas(200)); + .gas(Gas::from_tgas(201)); let fn_call_remove_code = near_workspaces::operations::Function::new("up_stage_code") .args_borsh(Vec::::new()) - .gas(near_workspaces::types::Gas::from_tgas(90)); + .gas(Gas::from_tgas(90)); let res = dao .batch(setup.contract.id()) diff --git a/near-plugins/Cargo.toml b/near-plugins/Cargo.toml index f28d8fa..c316c9d 100644 --- a/near-plugins/Cargo.toml +++ b/near-plugins/Cargo.toml @@ -13,3 +13,6 @@ bitflags.workspace = true near-sdk.workspace = true near-plugins-derive.workspace = true serde.workspace = true + +[dev-dependencies] +near-sdk = { workspace = true, features = ["unit-testing"] } diff --git a/near-plugins/src/upgradable.rs b/near-plugins/src/upgradable.rs index 356c1cd..1df00ad 100644 --- a/near-plugins/src/upgradable.rs +++ b/near-plugins/src/upgradable.rs @@ -61,7 +61,7 @@ //! [time between scheduling and execution]: https://docs.near.org/sdk/rust/promises/intro use crate::events::{AsEvent, EventMetadata}; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::{AccountId, Balance, CryptoHash, Gas, Promise}; +use near_sdk::{AccountId, CryptoHash, Gas, NearToken, Promise}; /// Trait describing the functionality of the _Upgradable_ plugin. pub trait Upgradable { @@ -199,7 +199,7 @@ pub struct FunctionCallArgs { /// The arguments to pass to the function. pub arguments: Vec, /// The amount of tokens to transfer to the receiver. - pub amount: Balance, + pub amount: NearToken, /// The gas limit for the function call. pub gas: Gas, } diff --git a/scripts/fix_dependencies.sh b/scripts/fix_dependencies.sh deleted file mode 100755 index c0bbaf1..0000000 --- a/scripts/fix_dependencies.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/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 ahash@0.8.7 --precise 0.8.4 -cargo update -p anstyle@1.0.4 --precise 1.0.2 -cargo update -p anstyle-parse@0.2.3 --precise 0.2.1 -cargo update -p anstyle-query@1.0.2 --precise 1.0.0 -cargo update -p cargo-platform@0.1.6 --precise 0.1.5 -cargo update -p clap@4.4.18 --precise 4.3.24 -cargo update -p clap_lex@0.5.1 --precise 0.5.0 -cargo update -p colored@2.1.0 --precise 2.0.4 -cargo update -p home@0.5.9 --precise 0.5.5