Skip to content

Commit

Permalink
test: add near_workspaces test for versioned contract
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Nov 6, 2024
1 parent 9a98143 commit 9ff59d9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
runs-on: ${{ matrix.platform.os }}
name: "${{ matrix.platform.os }} ${{ matrix.platform.rs }} ${{ matrix.features }}"
strategy:
fail-fast: false
matrix:
platform:
- os: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
runs-on: ${{ matrix.platform }}
name: "${{ matrix.example }} - ${{ matrix.platform }}"
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest]
toolchain: [stable]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_examples_small.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
runs-on: ${{ matrix.platform }}
name: "${{ matrix.platform }} ${{ matrix.toolchain }}"
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest]
toolchain: [1.81]
Expand Down
7 changes: 6 additions & 1 deletion examples/versioned/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ debug = false
panic = "abort"

[dev-dependencies]
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
near-workspaces = { version = "0.14.1", features = ["unstable"]}
tokio = { version = "1.14", features = ["full"] }
anyhow = "1.0"
near-abi = "0.4.0"
zstd = "0.13"
23 changes: 22 additions & 1 deletion examples/versioned/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ impl VersionedContract {
#[cfg(test)]
mod tests {
use super::*;
use near_abi::AbiRoot;
use near_sdk::test_utils::test_env::{alice, bob};
use near_sdk::test_utils::VMContextBuilder;
use near_sdk::testing_env;
use near_sdk::{serde_json, testing_env};

fn set_predecessor_and_deposit(predecessor: AccountId, deposit: NearToken) {
testing_env!(VMContextBuilder::new()
Expand Down Expand Up @@ -143,4 +144,24 @@ mod tests {
assert_eq!(contract.get_deposit(&alice()), Some(&NearToken::from_yoctonear(1000)));
assert_eq!(contract.get_deposit(&bob()), Some(&NearToken::from_yoctonear(8)));
}

// TODO: add more near_workspaces tests for logic of specifically this contract
// this only tests that contract can be built with ABI and responds to __contract_abi
// view call
#[tokio::test]
async fn embedded_abi_test() -> anyhow::Result<()> {
let wasm = near_workspaces::compile_project("./").await?;
let worker = near_workspaces::sandbox().await?;
let contract = worker.dev_deploy(&wasm).await?;

let res = contract.view("__contract_abi").await?;

let abi_root =
serde_json::from_slice::<AbiRoot>(&zstd::decode_all(&res.result[..])?)?;

assert_eq!(abi_root.schema_version, "0.4.0");
assert_eq!(abi_root.metadata.name, Some("versioned".to_string()));

Ok(())
}
}

0 comments on commit 9ff59d9

Please sign in to comment.