Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
47aec8d
feat: bump near-sdk to 5.1.0
mitinarseny May 27, 2024
efdd935
fix: access_controllable
aleksuss May 27, 2024
9b18ce6
Merge pull request #1 from aleksuss/fix/access_contollable
mitinarseny May 27, 2024
66d3601
fix(tests): borsh usage
mitinarseny May 27, 2024
b9bd442
fix: use LookupMap where iteration isn't needed
mitinarseny May 27, 2024
906db1d
chore: make clippy happy
aleksuss May 27, 2024
52197b3
Update test.yml
aleksuss May 27, 2024
7e83739
fix: do not gitignore Cargo.lock
mitinarseny May 27, 2024
4551714
chore: bump msrv
aleksuss May 27, 2024
32a829d
chore: bump rust in contracts for tests
aleksuss May 27, 2024
73b3522
chore: decrease gas
aleksuss May 27, 2024
f553f59
Merge pull request #2 from aleksuss/patch-1
mitinarseny May 27, 2024
f570af8
fix: rm Cargo.lock from lib crates
mitinarseny May 28, 2024
2d7b478
fix: bring UnorderedMap back
mitinarseny May 28, 2024
c896ce7
fix: use #[near] instead of #[near_bindgen]
mitinarseny May 29, 2024
18d2b4c
fix: bump version in separate PR
mitinarseny May 29, 2024
69eeab1
fix(tests): gas consumption is slightly bigger now
mitinarseny May 29, 2024
ad279c0
fix: #[allow(deprecated)] on UnorderedMap/UnorderedSet
mitinarseny May 29, 2024
3ef3340
fix: #[allow(depreated)] attributes syntax
mitinarseny May 29, 2024
7933a4a
docs: comment on deprecated collections from near_sdk::store
mitinarseny May 29, 2024
2910c87
fix: use FQDNs for #[derive(...)] in macros
mitinarseny May 29, 2024
542009b
fix: use FQDNs everywhere in quote!{...}
mitinarseny May 29, 2024
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
14 changes: 4 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ jobs:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.69.0 # MSRV
toolchain: 1.74.0 # MSRV
Comment thread
mooori marked this conversation as resolved.
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
Comment thread
mitinarseny marked this conversation as resolved.
key: rust-version-1.74.0-msrv-2

- name: add wasm32-unknown-unknown
run: rustup target add wasm32-unknown-unknown
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/target
Cargo.lock
Comment thread
mitinarseny marked this conversation as resolved.
**/Cargo.lock
near-plugins-derive/tests/contracts/*/target

# Ignore IDE data
Expand Down
19 changes: 6 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
[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"

[workspace.package]
version = "0.2.0"
version = "0.3.0"
Comment thread
mitinarseny marked this conversation as resolved.
Outdated
edition = "2021"
authors = ["Aurora Labs <hello@aurora.dev>"]
# 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"
Expand All @@ -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"}
2 changes: 1 addition & 1 deletion near-plugins-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions near-plugins-derive/src/access_control_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream {
#cratename::bitflags::bitflags! {
/// Encodes permissions for roles and admins.
#[derive(BorshDeserialize, BorshSerialize, Default)]
#[borsh(crate = "near_sdk::borsh")]
struct #bitflags_type_ident: u128 {
#(
const #bitflags_idents = 1u128 << #bitflags_idxs;
Expand Down
12 changes: 7 additions & 5 deletions near-plugins-derive/src/access_controllable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = &macro_args.role_type[0];
Expand All @@ -49,6 +50,7 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream
#input

#[derive(::near_sdk::borsh::BorshDeserialize, ::near_sdk::borsh::BorshSerialize)]
#[borsh(crate = "near_sdk::borsh")]
struct #acl_type {
/// Stores permissions per account.
permissions: ::near_sdk::store::UnorderedMap<
Expand Down Expand Up @@ -80,6 +82,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,
Expand All @@ -89,8 +92,7 @@ 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<u8> {
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()
}
Expand All @@ -117,7 +119,7 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream
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
}
Expand Down
2 changes: 1 addition & 1 deletion near-plugins-derive/src/ownable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
};
Expand Down
6 changes: 2 additions & 4 deletions near-plugins-derive/src/pausable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down Expand Up @@ -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(),
);
Expand Down
10 changes: 5 additions & 5 deletions near-plugins-derive/src/upgradable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -119,16 +120,15 @@ 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<u8> {
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()
}
Expand All @@ -138,7 +138,7 @@ pub fn derive_upgradable(input: TokenStream) -> TokenStream {
}

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());
}
}

Expand Down
12 changes: 6 additions & 6 deletions near-plugins-derive/tests/access_controllable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,15 +1193,15 @@ 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();
let actual = setup
.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 {
Expand Down Expand Up @@ -1264,15 +1264,15 @@ 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();
let actual = setup
.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 {
Expand Down Expand Up @@ -1335,15 +1335,15 @@ 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();
let actual = setup
.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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.69.0"
channel = "1.74.0"
components = ["clippy", "rustfmt"]
targets = [ "wasm32-unknown-unknown" ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 std::collections::HashMap;
Expand All @@ -22,6 +22,7 @@ pub enum Role {
#[access_control(role_type(Role))]
#[near_bindgen]
#[derive(PanicOnDefault, BorshDeserialize, BorshSerialize)]
#[borsh(crate = "near_sdk::borsh")]
pub struct Counter {
counter: u64,
}
Expand Down
7 changes: 1 addition & 6 deletions near-plugins-derive/tests/contracts/ownable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"}
2 changes: 1 addition & 1 deletion near-plugins-derive/tests/contracts/ownable/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.69.0"
channel = "1.74.0"
components = ["clippy", "rustfmt"]
targets = [ "wasm32-unknown-unknown" ]
3 changes: 2 additions & 1 deletion near-plugins-derive/tests/contracts/ownable/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use near_plugins::{only, Ownable};
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::{near_bindgen, AccountId, PanicOnDefault};

#[near_bindgen]
#[derive(Ownable, PanicOnDefault, BorshDeserialize, BorshSerialize)]
#[borsh(crate = "near_sdk::borsh")]
pub struct Counter {
counter: u64,
}
Expand Down
7 changes: 1 addition & 6 deletions near-plugins-derive/tests/contracts/pausable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.69.0"
channel = "1.74.0"
components = ["clippy", "rustfmt"]
targets = [ "wasm32-unknown-unknown" ]
1 change: 1 addition & 0 deletions near-plugins-derive/tests/contracts/pausable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum Role {
#[access_control(role_type(Role))]
#[near_bindgen]
#[derive(Pausable, PanicOnDefault, BorshDeserialize, BorshSerialize)]
#[borsh(crate = "near_sdk::borsh")]
#[pausable(manager_roles(Role::PauseManager))]
pub struct Counter {
counter: u64,
Expand Down
Loading