Skip to content

Commit

Permalink
Merge branch 'master' into feat/adding-wasmcov
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/coverage.yml
  • Loading branch information
jrmncos committed Aug 15, 2024
2 parents 0d4b12a + 4551e43 commit be6ddd5
Show file tree
Hide file tree
Showing 24 changed files with 168 additions and 72 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- master
pull_request:
env:
RUSTFLAGS: -D warnings
RUSTFLAGS: "-D warnings"

jobs:
coverage:
Expand All @@ -14,9 +14,7 @@ jobs:
strategy:
matrix:
platform: [macos-latest]
toolchain: [nightly-aarch64-apple-darwin]
package: [cross-contract-calls, fungible-token]
features: ['', '--features unstable,legacy,__abi-generate']
toolchain: [stable]
steps:
- uses: actions/checkout@v3
- name: Install Homebrew
Expand All @@ -26,6 +24,8 @@ jobs:
run: brew install llvm
- name: Add LLVM to PATH
run: echo "/opt/homebrew/opt/llvm/bin" >> $GITHUB_PATH
- name: Install cargo-llvm-cov
run: brew install cargo-llvm-cov
- name: Llvm version
run: llvm-config --version
- name: Clang version
Expand All @@ -36,13 +36,20 @@ jobs:
profile: minimal
toolchain: ${{ matrix.toolchain }}
target: wasm32-unknown-unknown
- name: Set Default Toolchain
run: rustup override set ${{ matrix.toolchain }}
- name: Rust version
run: rustc --version --verbose
- name: Install wasmcov
run: cargo +${{ matrix.toolchain }} install wasmcov
- name: Add rust-src component
run: rustup component add rust-src --toolchain ${{ matrix.toolchain }}
- name: Run script
env:
RUSTFLAGS: '-C link-arg=-s'
run: bash ./examples/build_wasm_test_all.sh ${{ matrix.toolchain }}
- name: Verify Rust Toolchain
run: rustup show
- name: Generate code coverage
run: cargo +${{ matrix.toolchain }} llvm-cov --lcov --output-path llvm-cov-output.lcov
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: ./llvm-cov-output.lcov
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

## [Unreleased]

## [5.3.0](https://github.com/near/near-sdk-rs/compare/near-sdk-v5.2.1...near-sdk-v5.3.0) - 2024-08-13

### Added
- Introduced 'remove' method for 'near_sdk::store::Lazy' collection ([#1238](https://github.com/near/near-sdk-rs/pull/1238))
- Allow store collection iterators to be cloned (this enables standard Iterator methods like `cycle()`) ([#1224](https://github.com/near/near-sdk-rs/pull/1224))

### Fixed
- Fix storage management error message with proper amount ([#1222](https://github.com/near/near-sdk-rs/pull/1222))
- Fixed compilation errors after Rust 1.80 latest stable release ([#1227](https://github.com/near/near-sdk-rs/pull/1227))

### Other
- updates near-* dependencies to 0.24.0 ([#1237](https://github.com/near/near-sdk-rs/pull/1237))
- Include all examples into CI testing suite ([#1228](https://github.com/near/near-sdk-rs/pull/1228))
- Optimized up to 10% contract binary size by using `near_sdk::env::panic_str` instead of `expect` calls ([#1220](https://github.com/near/near-sdk-rs/pull/1220))
- Fixed Rust 1.80 new warning by adding `cargo:rustc-check-cfg` for `__abi-embed-checked` feature in `near-sdk-macros` build.rs ([#1225](https://github.com/near/near-sdk-rs/pull/1225))

## [5.2.1](https://github.com/near/near-sdk-rs/compare/near-sdk-v5.2.0...near-sdk-v5.2.1) - 2024-07-05

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @frol @agostbiro @uint
* @frol @dj8yfo @ruseinov @akorchyn
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
exclude = ["examples/"]

[workspace.package]
version = "5.2.1"
version = "5.3.0"

# Special triple # comment for ci.
[patch.crates-io]
Expand Down
2 changes: 1 addition & 1 deletion examples/adder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ near-sdk = { path = "../../near-sdk" }
wasmcov = "0.2"

[dev-dependencies]
near-workspaces = "0.11.0"
near-workspaces = "0.11.1"
tokio = { version = "1.14", features = ["full"] }
anyhow = "1.0"
near-abi = "0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/callback-results/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ near-sdk = { path = "../../near-sdk" }
wasmcov = "0.2"

[dev-dependencies]
near-workspaces = "0.11.0"
near-workspaces = "0.11.1"
tokio = { version = "1.14", features = ["full"] }
anyhow = "1.0"
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/cross-contract-calls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ anyhow = "1.0"
near-sdk = { path = "../../near-sdk", features = ["default", "unit-testing"] }
test-case = "2.0"
tokio = { version = "1.14", features = ["full"] }
near-workspaces = "0.11.0"
near-workspaces = "0.11.1"

cross-contract-high-level = { path = "./high-level" }
cross-contract-low-level = { path = "./low-level" }
Expand Down
2 changes: 1 addition & 1 deletion examples/factory-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
anyhow = "1.0"
test-case = "2.0"
tokio = { version = "1.14", features = ["full"] }
near-workspaces = "0.11.0"
near-workspaces = "0.11.1"
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion examples/fungible-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
anyhow = "1.0"
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
tokio = { version = "1.14", features = ["full"] }
near-workspaces = "0.11.0"
near-workspaces = "0.11.1"

[profile.release]
codegen-units = 1
Expand Down
2 changes: 1 addition & 1 deletion examples/lockable-fungible-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ wasmcov = "0.2"
anyhow = "1.0"
tokio = { version = "1.14", features = ["full"] }
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
near-workspaces = "0.11.0"
near-workspaces = "0.11.1"

[profile.release]
codegen-units = 1
Expand Down
4 changes: 2 additions & 2 deletions examples/non-fungible-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2021"
[dev-dependencies]
anyhow = "1.0"
near-contract-standards = { path = "../../near-contract-standards" }
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
tokio = { version = "1.14", features = ["full"] }
near-workspaces = "0.11.0"
near-workspaces = "0.11.1"

[profile.release]
codegen-units = 1
Expand Down
5 changes: 5 additions & 0 deletions near-contract-standards/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [5.3.0](https://github.com/near/near-sdk-rs/compare/near-contract-standards-v5.2.1...near-contract-standards-v5.3.0) - 2024-08-13

### Fixed
- Fix storage management error message with proper amount ([#1222](https://github.com/near/near-sdk-rs/pull/1222))

## [5.2.0](https://github.com/near/near-sdk-rs/compare/near-contract-standards-v5.1.0...near-contract-standards-v5.2.0) - 2024-07-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion near-contract-standards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NEAR smart contracts standard library.
"""

[dependencies]
near-sdk = { path = "../near-sdk", version = "~5.2.1", default-features = false, features = ["legacy"] }
near-sdk = { path = "../near-sdk", version = "~5.3.0", default-features = false, features = ["legacy"] }

[dev-dependencies]
near-sdk = { path = "../near-sdk", default-features = false, features = ["unit-testing"] }
Expand Down
14 changes: 7 additions & 7 deletions near-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ required-features = ["abi", "unstable"]
# Provide near_bidgen macros.
serde = { version = "1", features = ["derive"] }
serde_json = "1"
near-sdk-macros = { path = "../near-sdk-macros", version = "~5.2.1" }
near-sdk-macros = { path = "../near-sdk-macros", version = "~5.3.0" }
near-sys = { path = "../near-sys", version = "0.2.2" }
base64 = "0.21"
borsh = { version = "1.0.0", features = ["derive"] }
Expand All @@ -42,11 +42,11 @@ schemars = { version = "0.8.8", optional = true }
near-abi = { version = "0.4.0", features = [
"__chunked-entries",
], optional = true }
near-vm-runner = { version = "0.23", optional = true }
near-primitives-core = { version = "0.23", optional = true }
near-primitives = { version = "0.23", optional = true }
near-crypto = { version = "0.23", default-features = false, optional = true }
near-parameters = { version = "0.23", optional = true }
near-vm-runner = { version = "0.24", optional = true }
near-primitives-core = { version = "0.24", optional = true }
near-primitives = { version = "0.24", optional = true }
near-crypto = { version = "0.24", default-features = false, optional = true }
near-parameters = { version = "0.24", optional = true }

[dev-dependencies]
near-sdk = { path = ".", features = ["legacy", "unit-testing"] }
Expand All @@ -63,7 +63,7 @@ rand_chacha = "0.3.1"
near-rng = "0.1.1"
near-abi = { version = "0.4.0", features = ["__chunked-entries"] }
symbolic-debuginfo = "12"
near-workspaces = { version = "0.10.1", features = ["unstable"] }
near-workspaces = { version = "0.11.1", features = ["unstable"] }
anyhow = "1.0"
tokio = { version = "1", features = ["full"] }
strum = "0.25.0"
Expand Down
1 change: 1 addition & 0 deletions near-sdk/src/store/free_list/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn decrement_count(count: &mut u32) {
}

/// An iterator over elements in the storage bucket. This only yields the occupied entries.
#[derive(Clone)]
pub struct Iter<'a, T>
where
T: BorshDeserialize + BorshSerialize,
Expand Down
2 changes: 1 addition & 1 deletion near-sdk/src/store/free_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
}

#[near(inside_nearsdk)]
#[derive(Debug)]
#[derive(Debug, Clone)]
enum Slot<T> {
/// Represents a filled cell of a value in the collection.
Occupied(T),
Expand Down
1 change: 1 addition & 0 deletions near-sdk/src/store/iterable_map/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ where
/// An iterator over elements of a [`IterableMap`].
///
/// This `struct` is created by the `iter` method on [`IterableMap`].
#[derive(Clone)]
pub struct Iter<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize,
Expand Down
1 change: 1 addition & 0 deletions near-sdk/src/store/iterable_set/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ where
/// See its documentation for more.
///
/// [`iter`]: IterableSet::iter
#[derive(Clone)]
pub struct Iter<'a, T>
where
T: BorshSerialize + Ord + BorshDeserialize,
Expand Down
14 changes: 14 additions & 0 deletions near-sdk/src/store/lazy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ where
}
}
}

/// Removes the underlying storage item. Useful for deprecating the obsolete [`Lazy`] values.
pub fn remove(&mut self) -> bool {
env::storage_remove(&self.storage_key)
}
}

impl<T> Lazy<T>
Expand Down Expand Up @@ -185,6 +190,15 @@ mod tests {
assert_eq!(lazy_loaded, b);
}

#[test]
pub fn test_remove() {
let mut lazy = Lazy::new(b"m", 8u8);
lazy.flush();
assert!(env::storage_has_key(b"m"));
lazy.remove();
assert!(!env::storage_has_key(b"m"));
}

#[test]
pub fn test_debug() {
let mut lazy = Lazy::new(b"m", 8u8);
Expand Down
3 changes: 3 additions & 0 deletions near-sdk/src/store/tree_map/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ where
/// An iterator over elements of a [`TreeMap`], in sorted order.
///
/// This `struct` is created by the `iter` method on [`TreeMap`].
#[derive(Clone)]
pub struct Iter<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize,
Expand Down Expand Up @@ -408,6 +409,7 @@ where
/// An iterator over the keys of a [`TreeMap`], in sorted order.
///
/// This `struct` is created by the `keys` method on [`TreeMap`].
#[derive(Clone)]
pub struct Keys<'a, K: 'a>
where
K: BorshSerialize + BorshDeserialize + Ord,
Expand Down Expand Up @@ -676,6 +678,7 @@ where
/// An iterator over the values of a [`TreeMap`], in order by key.
///
/// This `struct` is created by the `values` method on [`TreeMap`].
#[derive(Clone)]
pub struct Values<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize,
Expand Down
47 changes: 47 additions & 0 deletions near-sdk/src/store/unordered_map/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ where
/// An iterator over elements of a [`UnorderedMap`].
///
/// This `struct` is created by the `iter` method on [`UnorderedMap`].
#[derive(Clone)]
pub struct Iter<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize,
Expand Down Expand Up @@ -222,6 +223,7 @@ where
/// An iterator over the keys of a [`UnorderedMap`].
///
/// This `struct` is created by the `keys` method on [`UnorderedMap`].
#[derive(Clone)]
pub struct Keys<'a, K: 'a>
where
K: BorshSerialize + BorshDeserialize,
Expand Down Expand Up @@ -277,6 +279,7 @@ where
/// An iterator over the values of a [`UnorderedMap`].
///
/// This `struct` is created by the `values` method on [`UnorderedMap`].
#[derive(Clone)]
pub struct Values<'a, K, V, H>
where
K: BorshSerialize + Ord + BorshDeserialize,
Expand Down Expand Up @@ -521,3 +524,47 @@ where
Some(self.remove_value(key))
}
}

#[cfg(test)]
mod tests {
use super::*;
use borsh::{BorshDeserialize, BorshSerialize};

#[derive(BorshSerialize, BorshDeserialize, Ord, PartialOrd, Eq, PartialEq, Debug, Clone)]
struct Key(i32);

#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq)]
struct Value(String);

#[test]
fn test_unordered_map_iter_clone() {
let mut store = UnorderedMap::new(b'a');

store.insert(Key(1), Value("one".to_string()));
store.insert(Key(2), Value("two".to_string()));
store.insert(Key(3), Value("three".to_string()));

let mut iter = store.iter().cycle();

let mut collected = vec![];
for _ in 0..9 {
if let Some((key, value)) = iter.next() {
collected.push((key.clone(), value.clone()));
}
}

let expected = vec![
(Key(1), Value("one".to_string())),
(Key(2), Value("two".to_string())),
(Key(3), Value("three".to_string())),
(Key(1), Value("one".to_string())),
(Key(2), Value("two".to_string())),
(Key(3), Value("three".to_string())),
(Key(1), Value("one".to_string())),
(Key(2), Value("two".to_string())),
(Key(3), Value("three".to_string())),
];

assert_eq!(collected, expected);
}
}
1 change: 1 addition & 0 deletions near-sdk/src/store/unordered_set/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ where
/// See its documentation for more.
///
/// [`iter`]: UnorderedSet::iter
#[derive(Clone)]
pub struct Iter<'a, T>
where
T: BorshSerialize + Ord + BorshDeserialize,
Expand Down
2 changes: 1 addition & 1 deletion near-sdk/src/store/vec/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{Vector, ERR_INDEX_OUT_OF_BOUNDS};
use crate::env;

/// An iterator over references to each element in the stored vector.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Iter<'a, T>
where
T: BorshSerialize + BorshDeserialize,
Expand Down
Loading

0 comments on commit be6ddd5

Please sign in to comment.