From 9ff59d943a681dce8a2da0d999bc3acf89f1f885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= Date: Wed, 6 Nov 2024 13:46:00 +0200 Subject: [PATCH] test: add near_workspaces test for versioned contract --- .github/workflows/test.yml | 1 + .github/workflows/test_examples.yml | 1 + .github/workflows/test_examples_small.yml | 1 + examples/versioned/Cargo.toml | 7 ++++++- examples/versioned/src/lib.rs | 23 ++++++++++++++++++++++- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2fc4f9b77..8341d3ddc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.github/workflows/test_examples.yml b/.github/workflows/test_examples.yml index fb2363624..d8790f7c8 100644 --- a/.github/workflows/test_examples.yml +++ b/.github/workflows/test_examples.yml @@ -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] diff --git a/.github/workflows/test_examples_small.yml b/.github/workflows/test_examples_small.yml index f04392245..b4e442ef8 100644 --- a/.github/workflows/test_examples_small.yml +++ b/.github/workflows/test_examples_small.yml @@ -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] diff --git a/examples/versioned/Cargo.toml b/examples/versioned/Cargo.toml index 3f07f872f..b75787ec8 100644 --- a/examples/versioned/Cargo.toml +++ b/examples/versioned/Cargo.toml @@ -19,4 +19,9 @@ debug = false panic = "abort" [dev-dependencies] -near-sdk = { path = "../../near-sdk", features = ["unit-testing"] } \ No newline at end of file +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" diff --git a/examples/versioned/src/lib.rs b/examples/versioned/src/lib.rs index 6739de4d2..c950221b8 100644 --- a/examples/versioned/src/lib.rs +++ b/examples/versioned/src/lib.rs @@ -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() @@ -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::(&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(()) + } }