Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI workflow and examples tests #1228

Merged
merged 14 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/test_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ jobs:
matrix:
platform: [ubuntu-latest, macos-latest]
toolchain: [stable]
example: [cross-contract-calls, fungible-token]
example: [
adder,
callback-results,
cross-contract-calls,
factory-contract,
fungible-token,
non-fungible-token,
versioned
]
steps:
- uses: actions/checkout@v3
- name: "${{ matrix.toolchain }} with rustfmt, and wasm32"
Expand All @@ -26,9 +34,18 @@ jobs:
- uses: Swatinem/rust-cache@v1
with:
working-directory: ./examples/${{ matrix.example }}
- name: Build status-message
if: matrix.example == 'factory-contract'
env:
RUSTFLAGS: '-C link-arg=-s'
run: |
cargo +${{ matrix.toolchain }} build --manifest-path="./examples/status-message/Cargo.toml" --target wasm32-unknown-unknown --release --all &&
cp ./examples/status-message/target/wasm32-unknown-unknown/release/*.wasm ./examples/status-message/res/
- name: Build
env:
RUSTFLAGS: '-C link-arg=-s'
run: cargo +${{ matrix.toolchain }} build --manifest-path=./examples/${{matrix.example}}/Cargo.toml --target wasm32-unknown-unknown --release --all && cp ./examples/${{matrix.example}}/target/wasm32-unknown-unknown/release/*.wasm ./examples/${{matrix.example}}/res/
run: |
cargo +${{ matrix.toolchain }} build --manifest-path="./examples/${{matrix.example}}/Cargo.toml" --target wasm32-unknown-unknown --release --all &&
cp ./examples/${{matrix.example}}/target/wasm32-unknown-unknown/release/*.wasm ./examples/${{matrix.example}}/res/
- name: Test
run: cargo +${{ matrix.toolchain }} test --manifest-path=./examples/${{ matrix.example }}/Cargo.toml --all
run: cargo +${{ matrix.toolchain }} test --manifest-path="./examples/${{ matrix.example }}/Cargo.toml" --all
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Ensure the following are satisfied before opening a PR:

- The `git-hooks.sh` script has been run to install the git hooks.
- Code is formatted with `rustfmt` by running `cargo fmt`
- Before running the tests, ensure that all example `.wasm` files are built by executing [./examples/build_all.sh](./examples/build_all.sh)
- Run all tests and linters with [./run-tests.sh](./run-tests.sh)
- Ensure any new functionality is adequately tested
- If any new public types or functions are added, ensure they have appropriate [rustdoc](https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html) documentation
4 changes: 1 addition & 3 deletions examples/factory-contract/tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ async fn test_deploy_status_message(contract_name: &str) -> anyhow::Result<()> {
let contract =
worker.dev_deploy(&std::fs::read(format!("res/{}.wasm", contract_name))?).await?;

// Needed because of 32 character minimum for TLA
// https://docs.near.org/docs/concepts/account#top-level-accounts
let status_id: AccountId = "status-top-level-account-long-name".parse()?;
let status_id: AccountId = format!("status.{}", contract.id()).parse()?;
let status_amt = NearToken::from_near(20);
let res = contract
.call("deploy_status_message")
Expand Down
2 changes: 1 addition & 1 deletion examples/non-fungible-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
[dev-dependencies]
anyhow = "1.0"
near-contract-standards = { path = "../../near-contract-standards" }
near-sdk = { path = "../../near-sdk" }
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
tokio = { version = "1.14", features = ["full"] }
near-workspaces = "0.11.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct ApprovalReceiver {
}

// Have to repeat the same trait for our own implementation.
trait ValueReturnTrait {
pub trait ValueReturnTrait {
fn ok_go(&self, msg: String) -> PromiseOrValue<String>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct TokenReceiver {
}

// Have to repeat the same trait for our own implementation.
trait ValueReturnTrait {
pub trait ValueReturnTrait {
fn ok_go(&self, return_it: bool) -> PromiseOrValue<bool>;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/versioned/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
crate-type = ["cdylib"]

[dependencies]
near-sdk = { path = "../../near-sdk", features = ["unstable"] }
near-sdk = { path = "../../near-sdk", features = ["unstable", "unit-testing"] }

[profile.release]
codegen-units = 1
Expand Down
14 changes: 7 additions & 7 deletions examples/versioned/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_sdk::store::UnorderedMap;
use near_sdk::store::IterableMap;
use near_sdk::{env, log, near, AccountId, NearToken};

/// An example of a versioned contract. This is a simple contract that tracks how much
Expand Down Expand Up @@ -30,7 +30,7 @@ impl VersionedContract {
}
}

fn funders(&self) -> &UnorderedMap<AccountId, NearToken> {
fn funders(&self) -> &IterableMap<AccountId, NearToken> {
match self {
Self::V0(contract) => &contract.funders,
Self::V1(contract) => &contract.funders,
Expand All @@ -46,24 +46,24 @@ impl Default for VersionedContract {

#[near]
pub struct ContractV0 {
funders: UnorderedMap<AccountId, NearToken>,
funders: IterableMap<AccountId, NearToken>,
}

impl Default for ContractV0 {
fn default() -> Self {
Self { funders: UnorderedMap::new(b"f") }
Self { funders: IterableMap::new(b"f") }
}
}

#[near]
pub struct Contract {
funders: UnorderedMap<AccountId, NearToken>,
funders: IterableMap<AccountId, NearToken>,
nonce: u64,
}

impl Default for Contract {
fn default() -> Self {
Self { funders: UnorderedMap::new(b"f"), nonce: 0 }
Self { funders: IterableMap::new(b"f"), nonce: 0 }
}
}

Expand Down Expand Up @@ -128,7 +128,7 @@ mod tests {
#[test]
fn contract_v0_interactions() {
let mut contract = {
let mut funders = UnorderedMap::new(b"f");
let mut funders = IterableMap::new(b"f");
funders.insert(bob(), NearToken::from_yoctonear(8));
VersionedContract::V0(ContractV0 { funders })
};
Expand Down
2 changes: 1 addition & 1 deletion near-sdk/src/store/unordered_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use super::{FreeList, LookupMap, ERR_INCONSISTENT_STATE, ERR_NOT_EXIST};
/// [`with_hasher`]: Self::with_hasher
#[deprecated(
since = "5.0.0",
note = "Suboptimal iteration performance. See performance considerations doc for details."
note = "Suboptimal iteration performance. See performance considerations doc for details. Consider using IterableMap instead (WARNING: manual storage migration is required if contract was previously deployed)"
)]
#[near(inside_nearsdk)]
pub struct UnorderedMap<K, V, H = Sha256>
Expand Down
2 changes: 1 addition & 1 deletion near-sdk/src/store/unordered_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ use std::fmt;
#[near(inside_nearsdk)]
#[deprecated(
since = "5.0.0",
note = "Suboptimal iteration performance. See performance considerations doc for details."
note = "Suboptimal iteration performance. See performance considerations doc for details. Consider using IterableSet instead (WARNING: manual storage migration is required if contract was previously deployed)"
)]
pub struct UnorderedSet<T, H = Sha256>
where
Expand Down
Loading