diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f1d9a952a..235efbf98 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -554,6 +554,98 @@ jobs: exit 1 fi + contract_dynamic_callee_contract: + name: dynamic_callee_contract + runs-on: ubuntu-latest + env: + working-directory: ./contracts/dynamic-callee-contract + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.57.0 + target: wasm32-unknown-unknown + profile: minimal + override: true + - name: Cache cargo + uses: actions/cache@v2 + with: + path: ~/.cargo + key: cargocache-v2-contract_dynamic_callee_contract-rust:1.57.0-${{ hashFiles('contracts/dynamic-callee-contract/Cargo.lock') }} + - name: Version information + run: rustc --version; cargo --version; rustup --version; rustup target list --installed + - name: Add wasm32 target + run: rustup target add wasm32-unknown-unknown && rustup target list --installed + - name: Build wasm binary + working-directory: ${{env.working-directory}} + run: cargo wasm --locked + - name: Unit tests + working-directory: ${{env.working-directory}} + run: cargo unit-test --locked + - name: Integration tests (singlepass backend) + working-directory: ${{env.working-directory}} + run: cargo integration-test --locked --no-default-features + - name: Build and run schema generator + working-directory: ${{env.working-directory}} + run: cargo schema --locked + - name: Ensure schemas are up-to-date + working-directory: ${{env.working-directory}} + run: | + CHANGES_IN_REPO=$(git status --porcelain) + if [[ -n "$CHANGES_IN_REPO" ]]; then + echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:" + git status && git --no-pager diff + exit 1 + fi + + contract_dynamic_caller_contract: + name: dynamic_caller_contract + runs-on: ubuntu-latest + env: + working-directory: ./contracts/dynamic-caller-contract + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.57.0 + target: wasm32-unknown-unknown + profile: minimal + override: true + - name: Cache cargo + uses: actions/cache@v2 + with: + path: ~/.cargo + key: cargocache-v2-contract_dynamic_caller_contract-rust:1.57.0-${{ hashFiles('contracts/dynamic-caller-contract/Cargo.lock') }} + - name: Version information + run: rustc --version; cargo --version; rustup --version; rustup target list --installed + - name: Add wasm32 target + run: rustup target add wasm32-unknown-unknown && rustup target list --installed + - name: Build wasm binary + working-directory: ${{env.working-directory}} + run: cargo wasm --locked + - name: Unit tests + working-directory: ${{env.working-directory}} + run: cargo unit-test --locked + - name: Integration tests (singlepass backend) + working-directory: ${{env.working-directory}} + run: cargo integration-test --locked --no-default-features + - name: Build and run schema generator + working-directory: ${{env.working-directory}} + run: cargo schema --locked + - name: Ensure schemas are up-to-date + working-directory: ${{env.working-directory}} + run: | + CHANGES_IN_REPO=$(git status --porcelain) + if [[ -n "$CHANGES_IN_REPO" ]]; then + echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:" + git status && git --no-pager diff + exit 1 + fi + contract_number: name: contract_number runs-on: ubuntu-latest @@ -599,6 +691,7 @@ jobs: git status && git --no-pager diff exit 1 fi + contract_call_number: name: contract_call_number runs-on: ubuntu-latest @@ -689,6 +782,12 @@ jobs: - name: Check formatting of contract staking working-directory: ${{env.root-directory}}/staking run: cargo fmt -- --check + - name: Check formatting of contract dynamic callee contract + working-directory: ${{env.root-directory}}/dynamic-callee-contract + run: cargo fmt -- --check + - name: Check formatting of contract dynamic caller contract + working-directory: ${{env.root-directory}}/dynamic-caller-contract + run: cargo fmt -- --check clippy: name: clippy @@ -790,7 +889,19 @@ jobs: mkdir -p target/wasm32-unknown-unknown/release touch target/wasm32-unknown-unknown/release/staking.wasm cargo clippy --tests -- -D warnings - # These two tests issue errors in 1.51.0. In 1.57.0, they succeeds. + # These four tests issue errors in 1.51.0. In 1.57.0, they succeeds. + # - name: Clippy linting on dynamic-callee-contract + # working-directory: ${{env.contracts}}/dynamic-callee-contract + # run: | + # mkdir -p target/wasm32-unknown-unknown/release + # touch target/wasm32-unknown-unknown/release/dynamic_callee_contract.wasm + # cargo clippy --tests -- -D warnings + # - name: Clippy linting on dynamic-caller-contract + # working-directory: ${{env.contracts}}/dynamic-caller-contract + # run: | + # mkdir -p target/wasm32-unknown-unknown/release + # touch target/wasm32-unknown-unknown/release/dynamic_caller_contract.wasm + # cargo clippy --tests -- -D warnings # - name: Clippy linting on number # working-directory: ${{env.contracts}}/number # run: | diff --git a/contracts/dynamic-callee-contract/examples/schema.rs b/contracts/dynamic-callee-contract/examples/schema.rs index 3b6691a3e..38182147e 100644 --- a/contracts/dynamic-callee-contract/examples/schema.rs +++ b/contracts/dynamic-callee-contract/examples/schema.rs @@ -3,7 +3,7 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use dynamic_callee_contract::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use dynamic_callee_contract::msg::{ExecuteMsg, InstantiateMsg}; fn main() { let mut out_dir = current_dir().unwrap(); @@ -13,5 +13,4 @@ fn main() { export_schema(&schema_for!(InstantiateMsg), &out_dir); export_schema(&schema_for!(ExecuteMsg), &out_dir); - export_schema(&schema_for!(QueryMsg), &out_dir); } diff --git a/contracts/dynamic-callee-contract/schema/query_msg.json b/contracts/dynamic-callee-contract/schema/query_msg.json deleted file mode 100644 index 0f592a1af..000000000 --- a/contracts/dynamic-callee-contract/schema/query_msg.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "QueryMsg", - "type": "string", - "enum": [] -} diff --git a/contracts/dynamic-callee-contract/tests/integration.rs b/contracts/dynamic-callee-contract/tests/integration.rs index 1b63933eb..d92734b1d 100644 --- a/contracts/dynamic-callee-contract/tests/integration.rs +++ b/contracts/dynamic-callee-contract/tests/integration.rs @@ -22,6 +22,10 @@ fn required_exports() -> Vec<(String, FunctionType)> { String::from("stub_pong_with_tuple"), ([Type::I32], [Type::I32]).into(), ), + ( + String::from("stub_pong_with_tuple_takes_2_args"), + ([Type::I32, Type::I32], [Type::I32]).into(), + ), (String::from("stub_pong_env"), ([], [Type::I32]).into()), ] } @@ -59,7 +63,7 @@ fn callable_point_export_works() { Some(exported_function) => { assert_eq!(*exported_function, required_export.1); } - None => assert!(false), + None => panic!("{} is not exported.", required_export.0), } } } @@ -72,9 +76,11 @@ fn callable_point_pong_works() { let param_region_ptr = write_data_to_mock_env(&instance.env, &serialized_param).unwrap(); let required_exports = required_exports(); + let export_index = 0; + assert_eq!("stub_pong".to_string(), required_exports[export_index].0); let call_result = instance .call_function_strict( - &required_exports[0].1, + &required_exports[export_index].1, "stub_pong", &[param_region_ptr.into()], ) @@ -99,9 +105,14 @@ fn callable_point_pong_with_struct_works() { let param_region_ptr = write_data_to_mock_env(&instance.env, &serialized_param).unwrap(); let required_exports = required_exports(); + let export_index = 1; + assert_eq!( + "stub_pong_with_struct".to_string(), + required_exports[export_index].0 + ); let call_result = instance .call_function_strict( - &required_exports[1].1, + &required_exports[export_index].1, "stub_pong_with_struct", &[param_region_ptr.into()], ) @@ -123,9 +134,14 @@ fn callable_point_pong_with_tuple_works() { let param_region_ptr = write_data_to_mock_env(&instance.env, &serialized_param).unwrap(); let required_exports = required_exports(); + let export_index = 2; + assert_eq!( + "stub_pong_with_tuple".to_string(), + required_exports[export_index].0 + ); let call_result = instance .call_function_strict( - &required_exports[1].1, + &required_exports[export_index].1, "stub_pong_with_tuple", &[param_region_ptr.into()], ) @@ -150,9 +166,14 @@ fn callable_point_pong_with_tuple_takes_2_args_works() { let param_region_ptr2 = write_data_to_mock_env(&instance.env, &serialized_param2).unwrap(); let required_exports = required_exports(); + let export_index = 3; + assert_eq!( + "stub_pong_with_tuple_takes_2_args".to_string(), + required_exports[export_index].0 + ); let call_result = instance .call_function_strict( - &required_exports[1].1, + &required_exports[export_index].1, "stub_pong_with_tuple_takes_2_args", &[param_region_ptr1.into(), param_region_ptr2.into()], ) @@ -174,8 +195,13 @@ fn callable_point_pong_env_works() { instance .env .set_serialized_env(&to_vec(&mock_env()).unwrap()); + let export_index = 4; + assert_eq!( + "stub_pong_env".to_string(), + required_exports[export_index].0 + ); let call_result = instance - .call_function_strict(&required_exports[2].1, "stub_pong_env", &[]) + .call_function_strict(&required_exports[export_index].1, "stub_pong_env", &[]) .unwrap(); assert_eq!(call_result.len(), 1); @@ -184,19 +210,3 @@ fn callable_point_pong_env_works() { let result: Env = from_slice(&serialized_return).unwrap(); assert_eq!(result.contract.address, Addr::unchecked(MOCK_CONTRACT_ADDR)); } - -#[test] -fn callable_point_pong_deps_works() { - let instance = make_callee_instance(); - - let required_exports = required_exports(); - let call_result = instance - .call_function_strict(&required_exports[1].1, "stub_pong_env", &[]) - .unwrap(); - assert_eq!(call_result.len(), 1); - - let serialized_return = - read_data_from_mock_env(&instance.env, &call_result[0], u32::MAX as usize).unwrap(); - let result: Env = from_slice(&serialized_return).unwrap(); - assert_eq!(result.contract.address, Addr::unchecked("cosmos2contract")); -} diff --git a/contracts/dynamic-caller-contract/tests/integration.rs b/contracts/dynamic-caller-contract/tests/integration.rs index a6cb5c8aa..ffd5a60be 100644 --- a/contracts/dynamic-caller-contract/tests/integration.rs +++ b/contracts/dynamic-caller-contract/tests/integration.rs @@ -56,15 +56,15 @@ fn dynamic_link_import_works() { .collect(); let required_imports = required_imports(); - for required_export in required_imports { - match import_function_map.get(&required_export.0) { - Some(exported_function) => { - let module_name = &exported_function.0; - let function_type = &exported_function.1; - assert_eq!(*module_name, required_export.1); - assert_eq!(*function_type, required_export.2); + for required_import in required_imports { + match import_function_map.get(&required_import.0) { + Some(imported_function) => { + let module_name = &imported_function.0; + let function_type = &imported_function.1; + assert_eq!(*module_name, required_import.1); + assert_eq!(*function_type, required_import.2); } - None => assert!(false), + None => panic!("{} is not imported.", required_import.0), } } }