diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2d66252470..18d598136a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -276,7 +276,7 @@ jobs: toolchain: ${{ env.RUST_VERSION }} - uses: Swatinem/rust-cache@v2 - name: Build All Tests - run: cd test/src/sdk-harness && bash build.sh --locked && cd ../../../ + run: cargo run --locked -p forc -- build --locked --path ./test/src/sdk-harness - name: Cargo Test sway-lib-std run: cargo test --locked --manifest-path ./test/src/sdk-harness/Cargo.toml -- --nocapture diff --git a/test/src/sdk-harness/Forc.lock b/test/src/sdk-harness/Forc.lock new file mode 100644 index 00000000000..1ccb7446f94 --- /dev/null +++ b/test/src/sdk-harness/Forc.lock @@ -0,0 +1,327 @@ +[[package]] +name = 'auth_caller_contract' +source = 'member' +dependencies = [ + 'auth_testing_abi', + 'std', +] + +[[package]] +name = 'auth_caller_script' +source = 'member' +dependencies = [ + 'auth_testing_abi', + 'std', +] + +[[package]] +name = 'auth_testing_abi' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'auth_testing_contract' +source = 'member' +dependencies = [ + 'auth_testing_abi', + 'std', +] + +[[package]] +name = 'balance_contract' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'block' +source = 'member' +dependencies = [ + 'block_test_abi', + 'std', +] + +[[package]] +name = 'block_test_abi' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'call_frames' +source = 'member' +dependencies = [ + 'call_frames_test_abi', + 'std', +] + +[[package]] +name = 'call_frames_test_abi' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'configurables_in_contract' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'configurables_in_script' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'context' +source = 'member' +dependencies = [ + 'context_testing_abi', + 'std', +] + +[[package]] +name = 'context_caller_contract' +source = 'member' +dependencies = [ + 'context_testing_abi', + 'std', +] + +[[package]] +name = 'context_testing_abi' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'contract_bytecode' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'core' +source = 'path+from-root-5781B31F5E4458CC' + +[[package]] +name = 'ec_recover' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'ec_recover_and_match_predicate' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'evm' +source = 'member' +dependencies = [ + 'evm_test_abi', + 'std', +] + +[[package]] +name = 'evm_ec_recover' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'evm_test_abi' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'generics_in_abi' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'hashing' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'logging' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'messages' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'methods_abi' +source = 'member' + +[[package]] +name = 'methods_contract' +source = 'member' +dependencies = [ + 'methods_abi', + 'std', +] + +[[package]] +name = 'option_field_order' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'option_in_abi' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'parsing_logs' +source = 'member' +dependencies = [ + 'parsing_logs_test_abi', + 'std', +] + +[[package]] +name = 'parsing_logs_test_abi' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'pow' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'predicate_data_simple' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'predicate_data_struct' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'registers' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'result_in_abi' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'script_bytecode' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'script_data' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'std' +source = 'path+from-root-5781B31F5E4458CC' +dependencies = ['core'] + +[[package]] +name = 'storage' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'storage_bytes' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'storage_map' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_array' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_b256' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_bool' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_enum' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_str' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_struct' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_tuple' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_u16' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_u32' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_u64' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'svec_u8' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'test_contract' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'test_script' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'token_ops' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'tx_contract' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'tx_predicate' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'type_aliases' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'vec_in_abi' +source = 'member' +dependencies = ['std'] diff --git a/test/src/sdk-harness/Forc.toml b/test/src/sdk-harness/Forc.toml new file mode 100644 index 00000000000..6cf05fbb2cf --- /dev/null +++ b/test/src/sdk-harness/Forc.toml @@ -0,0 +1,61 @@ +[workspace] +members = [ + "test_projects/block", + "test_projects/call_frames", + "test_projects/configurables_in_contract", + "test_projects/configurables_in_script", + "test_projects/context", + "test_projects/contract_bytecode", + "test_projects/ec_recover", + "test_projects/ec_recover_and_match_predicate", + "test_projects/evm", + "test_projects/evm_ec_recover", + "test_projects/generics_in_abi", + "test_projects/hashing", + "test_projects/logging", + "test_projects/low_level_call", + "test_projects/messages", + "test_projects/option_field_order", + "test_projects/option_in_abi", + "test_projects/parsing_logs", + "test_projects/predicate_data_simple", + "test_projects/predicate_data_struct", + "test_projects/registers", + "test_projects/result_in_abi", + "test_projects/script_bytecode", + "test_projects/script_data", + "test_projects/storage", + "test_projects/storage_bytes", + "test_projects/storage_map", + "test_projects/token_ops", + "test_projects/tx_fields", + "test_projects/type_aliases", + "test_projects/vec_in_abi", + "test_artifacts/auth_caller_contract", + "test_artifacts/auth_caller_script", + "test_artifacts/auth_testing_abi", + "test_artifacts/auth_testing_contract", + "test_artifacts/balance_contract", + "test_artifacts/block_test_abi", + "test_artifacts/call_frames_test_abi", + "test_artifacts/context_caller_contract", + "test_artifacts/context_testing_abi", + "test_artifacts/evm_test_abi", + "test_artifacts/low_level_callee_contract", + "test_artifacts/methods_abi", + "test_artifacts/methods_contract", + "test_artifacts/parsing_logs_test_abi", + "test_artifacts/pow", + "test_artifacts/storage_vec/svec_array", + "test_artifacts/storage_vec/svec_bool", + "test_artifacts/storage_vec/svec_str", + "test_artifacts/storage_vec/svec_tuple", + "test_artifacts/storage_vec/svec_u32", + "test_artifacts/storage_vec/svec_u8", + "test_artifacts/storage_vec/svec_b256", + "test_artifacts/storage_vec/svec_enum", + "test_artifacts/storage_vec/svec_struct", + "test_artifacts/storage_vec/svec_u16", + "test_artifacts/storage_vec/svec_u64", + "test_artifacts/tx_contract", +] diff --git a/test/src/sdk-harness/README.md b/test/src/sdk-harness/README.md index 5777593abea..0bc407fd7c9 100644 --- a/test/src/sdk-harness/README.md +++ b/test/src/sdk-harness/README.md @@ -2,18 +2,11 @@ ## Building test projects -First, ensure we have the current version of `forc` installed. +Compile all the Sway programs in the workspace as follows: ```sh -cd sway -cargo install --path ./forc -``` - -In the `sway/test/src/sdk-harness` directory is a bash build script. To run it: - -```sh -cd sway/test/src/sdk-harness -./build.sh +# from project root +cargo run --bin=forc build --path test/src/sdk-harness ``` This will build all contracts and scripts under the `sway/test/src/sdk-harness` directory. diff --git a/test/src/sdk-harness/build.sh b/test/src/sdk-harness/build.sh deleted file mode 100755 index dbee086e35d..00000000000 --- a/test/src/sdk-harness/build.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash - -# Pass `--locked` when running this script in CI to ensure both cargo and forc -# lock files are up to date. -locked="$1" - -# Cross platform version of `realpath` or `readlink`. -abs_path() { - (cd "$1"; pwd) -} - -# Grab the absolute path to this script. -base_dir="$(abs_path $(dirname $0))" - -# Search for the parent Cargo manifest for Forc. -parent_manifest_dir="${base_dir}" -while true; do - parent_manifest_dir=$(abs_path "${parent_manifest_dir}/..") - if [[ -f "${parent_manifest_dir}/Cargo.toml" ]]; then - forc="cargo run $locked --manifest-path ${parent_manifest_dir}/Cargo.toml --package forc --" - break - fi - if [[ "${parent_manifest_dir}" = "/" ]]; then - # Not found for some reason. Default to an installed binary. - forc="forc" - break - fi -done - -test_dirs="${base_dir}/test_artifacts/* ${base_dir}/test_projects/* ${base_dir}/test_artifacts/*/*" - -for test_dir in $test_dirs; do - if [[ -f "${test_dir}/Forc.toml" ]]; then - echo "Building test $test_dir..." - # This can be done in a better way, but I'm not going to invest time in it - # because it is temporary - if [[ ${test_dir} == *"experimental_storage"* ]]; then - ${forc} build $locked --experimental-storage -o temp -p "${test_dir}" && echo ✔ - else - echo ✔ - ${forc} build $locked -o temp -p "${test_dir}" && echo ✔ - fi - if ! [[ -f temp ]]; then - echo "❌ Failed to build $test_dir" - exit 1 - fi - rm -f temp - else - echo "Skipping test $test_dir..." - fi -done - -echo "Successfully built all projects." diff --git a/test/src/sdk-harness/test_projects/block/src/main.sw b/test/src/sdk-harness/test_projects/block/src/main.sw index 67e44fc6d03..9d424e77ebf 100644 --- a/test/src/sdk-harness/test_projects/block/src/main.sw +++ b/test/src/sdk-harness/test_projects/block/src/main.sw @@ -17,9 +17,6 @@ impl BlockTest for Contract { } fn get_block_and_timestamp() -> (u64, u64) { - ( - height(), - timestamp(), - ) + (height(), timestamp()) } } diff --git a/test/src/sdk-harness/test_projects/configurables_in_contract/src/main.sw b/test/src/sdk-harness/test_projects/configurables_in_contract/src/main.sw index d734f724a88..47e8d2f04f3 100644 --- a/test/src/sdk-harness/test_projects/configurables_in_contract/src/main.sw +++ b/test/src/sdk-harness/test_projects/configurables_in_contract/src/main.sw @@ -27,7 +27,7 @@ abi TestContract { } impl TestContract for Contract { - fn return_configurables( ) -> (u8, bool, [u32; 3], str[4], StructWithGeneric, EnumWithGeneric) { + fn return_configurables() -> (u8, bool, [u32; 3], str[4], StructWithGeneric, EnumWithGeneric) { (U8, BOOL, ARRAY, STR_4, STRUCT, ENUM) } } diff --git a/test/src/sdk-harness/test_projects/context/src/main.sw b/test/src/sdk-harness/test_projects/context/src/main.sw index c30d864902a..e4abf359d02 100644 --- a/test/src/sdk-harness/test_projects/context/src/main.sw +++ b/test/src/sdk-harness/test_projects/context/src/main.sw @@ -1,10 +1,6 @@ contract; -use std::{ - context::*, - call_frames::*, - registers::*, -}; +use std::{call_frames::*, context::*, registers::*}; use context_testing_abi::*; impl ContextTesting for Contract { diff --git a/test/src/sdk-harness/test_projects/ec_recover_and_match_predicate/src/main.sw b/test/src/sdk-harness/test_projects/ec_recover_and_match_predicate/src/main.sw index 52362f5056c..0604c843ce8 100644 --- a/test/src/sdk-harness/test_projects/ec_recover_and_match_predicate/src/main.sw +++ b/test/src/sdk-harness/test_projects/ec_recover_and_match_predicate/src/main.sw @@ -13,7 +13,6 @@ fn extract_public_key_and_match(signature: B512, expected_public_key: b256) -> u } fn main(signatures: [B512; 3]) -> bool { - // let signatures: [B512; 3] = input_predicate_data(0); let public_keys = [ 0xd58573593432a30a800f97ad32f877425c223a9e427ab557aab5d5bb89156db0, diff --git a/test/src/sdk-harness/test_projects/evm_ec_recover/Forc.toml b/test/src/sdk-harness/test_projects/evm_ec_recover/Forc.toml index b0ce2694d7f..c265cd616f8 100644 --- a/test/src/sdk-harness/test_projects/evm_ec_recover/Forc.toml +++ b/test/src/sdk-harness/test_projects/evm_ec_recover/Forc.toml @@ -5,4 +5,4 @@ license = "Apache-2.0" name = "evm_ec_recover" [dependencies] -std = { path = "../../../../../sway-lib-std" } \ No newline at end of file +std = { path = "../../../../../sway-lib-std" } diff --git a/test/src/sdk-harness/test_projects/generics_in_abi/src/main.sw b/test/src/sdk-harness/test_projects/generics_in_abi/src/main.sw index 99aedd24be4..4077bd588d2 100644 --- a/test/src/sdk-harness/test_projects/generics_in_abi/src/main.sw +++ b/test/src/sdk-harness/test_projects/generics_in_abi/src/main.sw @@ -95,7 +95,6 @@ impl MyContract for Contract { expected } - fn enum_w_generic(arg1: EnumWGeneric) -> EnumWGeneric { match arg1 { EnumWGeneric::b(value) => { diff --git a/test/src/sdk-harness/test_projects/harness.rs b/test/src/sdk-harness/test_projects/harness.rs index dfc1e94f560..fac09311f03 100644 --- a/test/src/sdk-harness/test_projects/harness.rs +++ b/test/src/sdk-harness/test_projects/harness.rs @@ -11,9 +11,6 @@ mod ec_recover; mod ec_recover_and_match_predicate; mod evm; mod evm_ec_recover; -mod experimental_storage; -mod experimental_storage_init; -mod experimental_storage_map; mod exponentiation; mod generics_in_abi; mod hashing; diff --git a/test/src/sdk-harness/test_projects/low_level_call/src/main.sw b/test/src/sdk-harness/test_projects/low_level_call/src/main.sw index 772b7476151..e2d46a197dd 100644 --- a/test/src/sdk-harness/test_projects/low_level_call/src/main.sw +++ b/test/src/sdk-harness/test_projects/low_level_call/src/main.sw @@ -1,10 +1,14 @@ script; -use std::constants::BASE_ASSET_ID ; +use std::constants::BASE_ASSET_ID; use std::low_level_call::{call_with_function_selector_vec, CallParams}; -fn main(target: ContractId, function_selector: Vec, calldata: Vec, single_value_type_arg: bool) { - +fn main( + target: ContractId, + function_selector: Vec, + calldata: Vec, + single_value_type_arg: bool, +) { let call_params = CallParams { coins: 0, asset_id: BASE_ASSET_ID, diff --git a/test/src/sdk-harness/test_projects/option_in_abi/src/main.sw b/test/src/sdk-harness/test_projects/option_in_abi/src/main.sw index 6746548bb5d..69b79310275 100644 --- a/test/src/sdk-harness/test_projects/option_in_abi/src/main.sw +++ b/test/src/sdk-harness/test_projects/option_in_abi/src/main.sw @@ -63,7 +63,9 @@ impl MyContract for Contract { fn string_test(input: Option) -> Option { input } - fn result_in_option_test(input: Option>) -> Option> { + fn result_in_option_test( + input: Option>, + ) -> Option> { input } } diff --git a/test/src/sdk-harness/test_projects/registers/src/main.sw b/test/src/sdk-harness/test_projects/registers/src/main.sw index c4adb4e0b5a..dc52ec8e557 100644 --- a/test/src/sdk-harness/test_projects/registers/src/main.sw +++ b/test/src/sdk-harness/test_projects/registers/src/main.sw @@ -1,10 +1,6 @@ contract; -use std::{ - context::*, - call_frames::*, - registers::* -}; +use std::{call_frames::*, context::*, registers::*}; abi Registers { fn get_overflow() -> u64; diff --git a/test/src/sdk-harness/test_projects/result_in_abi/src/main.sw b/test/src/sdk-harness/test_projects/result_in_abi/src/main.sw index aef47932496..e40ce92fc2b 100644 --- a/test/src/sdk-harness/test_projects/result_in_abi/src/main.sw +++ b/test/src/sdk-harness/test_projects/result_in_abi/src/main.sw @@ -67,7 +67,9 @@ impl MyContract for Contract { fn string_test(input: Result) -> Result { input } - fn option_in_result_test(input: Result, SomeError>) -> Result, SomeError> { + fn option_in_result_test( + input: Result, SomeError>, + ) -> Result, SomeError> { input } } diff --git a/test/src/sdk-harness/test_projects/storage/src/main.sw b/test/src/sdk-harness/test_projects/storage/src/main.sw index ae42d9d3bbc..b2318cfc2ea 100644 --- a/test/src/sdk-harness/test_projects/storage/src/main.sw +++ b/test/src/sdk-harness/test_projects/storage/src/main.sw @@ -83,7 +83,7 @@ abi StorageTest { fn store_b256(value: b256); #[storage(read)] fn get_b256() -> Option; - + #[storage(write)] fn clear_small_struct() -> bool; #[storage(write)] @@ -207,7 +207,6 @@ impl StorageTest for Contract { clear::(S_5) } - #[storage(write)] fn store_u64(value: u64) { store(S_5, value); @@ -371,11 +370,11 @@ impl StorageTest for Contract { let post_sp = stack_ptr(); if pre_sp != post_sp { - 111 // Code to indicate bad stack (it would probably crash before here though). + 111 // Code to indicate bad stack (it would probably crash before here though). } else if !res { - 222 // Code to indicate storage I/O failure. + 222 // Code to indicate storage I/O failure. } else { - 333 // Code for success - something non-trivial so we can't accidentally succeed. + 333 // Code for success - something non-trivial so we can't accidentally succeed. } } }