From 4edfedf5199966027a8a2c6cdb350ca76acdd040 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 08:31:20 +0200 Subject: [PATCH 01/70] move e2e tests into separate crate --- .gitignore | 17 +-- Cargo.toml | 5 +- Forc.toml | 113 ++++++++++++++++++ ci_checks.sh | 20 ++-- e2e/Cargo.toml | 27 +++++ .../sharing_types/contract_a/Forc.toml | 0 .../sharing_types/contract_a/src/main.sw | 0 .../sharing_types/contract_b/Forc.toml | 0 .../sharing_types/contract_b/src/main.sw | 0 .../sharing_types/shared_lib/Forc.toml | 0 .../sharing_types/shared_lib/src/lib.sw | 0 .../sway}/bindings/simple_contract/Forc.toml | 0 .../bindings/simple_contract/src/main.sw | 0 .../sway}/bindings/type_paths/Forc.toml | 0 .../bindings/type_paths/src/another_lib.sw | 0 .../type_paths/src/contract_a_types.sw | 0 .../sway}/bindings/type_paths/src/main.sw | 0 .../sway}/contracts/asserts/Forc.toml | 0 .../sway}/contracts/asserts/src/main.sw | 0 .../contracts/auth_testing_abi/Forc.toml | 0 .../contracts/auth_testing_abi/src/main.sw | 0 .../contracts/auth_testing_contract/Forc.toml | 0 .../auth_testing_contract/src/main.sw | 0 .../sway}/contracts/block_timestamp/Forc.toml | 0 .../contracts/block_timestamp/src/main.sw | 0 .../sway}/contracts/configurables/Forc.toml | 0 .../sway}/contracts/configurables/src/main.sw | 0 .../sway}/contracts/contract_test/Forc.toml | 0 .../sway}/contracts/contract_test/src/main.sw | 0 .../contracts/large_return_data/Forc.toml | 0 .../contracts/large_return_data/src/main.sw | 0 .../sway}/contracts/lib_contract/Forc.toml | 0 .../sway}/contracts/lib_contract/src/main.sw | 0 .../contracts/lib_contract_abi/Forc.toml | 0 .../contracts/lib_contract_abi/src/main.sw | 0 .../contracts/lib_contract_caller/Forc.toml | 0 .../contracts/lib_contract_caller/src/main.sw | 0 .../sway}/contracts/library_test/Forc.toml | 0 .../sway}/contracts/library_test/src/main.sw | 0 .../sway}/contracts/liquidity_pool/Forc.toml | 0 .../contracts/liquidity_pool/src/main.sw | 0 .../contracts/low_level_caller/Forc.toml | 0 .../contracts/low_level_caller/src/main.sw | 0 .../sway}/contracts/msg_methods/Forc.toml | 0 .../sway}/contracts/msg_methods/src/main.sw | 0 .../contracts/multiple_read_calls/Forc.toml | 0 .../contracts/multiple_read_calls/src/main.sw | 0 .../contracts/needs_custom_decoder/Forc.toml | 0 .../needs_custom_decoder/src/main.sw | 0 .../contracts/payable_annotation/Forc.toml | 0 .../contracts/payable_annotation/src/main.sw | 0 .../sway}/contracts/require/Forc.toml | 0 .../sway}/contracts/require/src/main.sw | 0 .../revert_transaction_error/Forc.toml | 0 .../revert_transaction_error/src/main.sw | 0 .../sway}/contracts/storage/Forc.toml | 0 .../sway}/contracts/storage/src/main.sw | 0 .../sway}/contracts/token_ops/Forc.toml | 0 .../sway}/contracts/token_ops/src/main.sw | 0 .../transaction_block_height/Forc.toml | 0 .../transaction_block_height/src/main.sw | 0 .../sway}/logs/contract_logs/Forc.toml | 0 .../sway}/logs/contract_logs/src/main.sw | 0 .../sway}/logs/contract_logs_abi/Forc.toml | 0 .../sway}/logs/contract_logs_abi/src/main.sw | 0 .../contract_with_contract_logs/Forc.toml | 0 .../contract_with_contract_logs/src/main.sw | 0 .../sway}/logs/script_heap_logs/Forc.toml | 0 .../sway}/logs/script_heap_logs/src/main.sw | 0 .../sway}/logs/script_logs/Forc.toml | 0 .../sway}/logs/script_logs/src/main.sw | 0 .../Forc.toml | 0 .../src/main.sw | 0 .../logs/script_with_contract_logs/Forc.toml | 0 .../script_with_contract_logs/src/main.sw | 0 .../predicates/basic_predicate/Forc.toml | 0 .../predicates/basic_predicate/src/main.sw | 0 .../predicate_configurables/Forc.toml | 0 .../predicate_configurables/src/main.sw | 0 .../predicates/predicate_witnesses/Forc.toml | 0 .../predicate_witnesses/src/main.sw | 0 .../sway}/predicates/signatures/Forc.toml | 0 .../sway}/predicates/signatures/src/main.sw | 0 .../sway}/predicates/swap/Forc.toml | 0 .../sway}/predicates/swap/src/main.sw | 0 .../sway}/scripts/arguments/Forc.toml | 0 .../sway}/scripts/arguments/src/main.sw | 0 .../sway}/scripts/basic_script/Forc.toml | 0 .../sway}/scripts/basic_script/src/main.sw | 0 .../scripts/require_from_contract/Forc.toml | 0 .../scripts/require_from_contract/src/main.sw | 0 .../sway}/scripts/script_array/Forc.toml | 0 .../sway}/scripts/script_array/src/main.sw | 0 .../sway}/scripts/script_asserts/Forc.toml | 0 .../sway}/scripts/script_asserts/src/main.sw | 0 .../scripts/script_configurables/Forc.toml | 0 .../scripts/script_configurables/src/main.sw | 0 .../sway}/scripts/script_enum/Forc.toml | 0 .../sway}/scripts/script_enum/src/main.sw | 0 .../script_needs_custom_decoder/Forc.toml | 0 .../script_needs_custom_decoder/src/main.sw | 0 .../sway}/scripts/script_require/Forc.toml | 0 .../sway}/scripts/script_require/src/main.sw | 0 .../sway}/scripts/script_struct/Forc.toml | 0 .../sway}/scripts/script_struct/src/main.sw | 0 .../sway}/scripts/transfer_script/Forc.toml | 0 .../sway}/scripts/transfer_script/src/main.sw | 0 .../sway}/types/contracts/b256/Forc.toml | 0 .../sway}/types/contracts/b256/src/main.sw | 0 .../sway}/types/contracts/b512/Forc.toml | 0 .../sway}/types/contracts/b512/src/main.sw | 0 .../sway}/types/contracts/bytes/Forc.toml | 0 .../sway}/types/contracts/bytes/src/main.sw | 0 .../contracts/call_empty_return/Forc.toml | 0 .../contracts/call_empty_return/src/main.sw | 0 .../complex_types_contract/Forc.toml | 0 .../complex_types_contract/src/main.sw | 0 .../contracts/contract_output_test/Forc.toml | 0 .../contract_output_test/src/main.sw | 0 .../types/contracts/empty_arguments/Forc.toml | 0 .../contracts/empty_arguments/src/main.sw | 0 .../types/contracts/enum_as_input/Forc.toml | 0 .../types/contracts/enum_as_input/src/main.sw | 0 .../types/contracts/enum_encoding/Forc.toml | 0 .../types/contracts/enum_encoding/src/main.sw | 0 .../contracts/enum_inside_struct/Forc.toml | 0 .../contracts/enum_inside_struct/src/main.sw | 0 .../types/contracts/evm_address/Forc.toml | 0 .../types/contracts/evm_address/src/main.sw | 0 .../sway}/types/contracts/generics/Forc.toml | 0 .../types/contracts/generics/src/main.sw | 0 .../contracts/heap_type_in_enums/Forc.toml | 0 .../contracts/heap_type_in_enums/src/main.sw | 0 .../types/contracts/heap_types/Forc.toml | 0 .../types/contracts/heap_types/src/main.sw | 0 .../sway}/types/contracts/identity/Forc.toml | 0 .../types/contracts/identity/src/main.sw | 0 .../types/contracts/native_types/Forc.toml | 0 .../types/contracts/native_types/src/main.sw | 0 .../types/contracts/nested_structs/Forc.toml | 0 .../contracts/nested_structs/src/main.sw | 0 .../sway}/types/contracts/options/Forc.toml | 0 .../sway}/types/contracts/options/src/main.sw | 0 .../sway}/types/contracts/raw_slice/Forc.toml | 0 .../types/contracts/raw_slice/src/main.sw | 0 .../sway}/types/contracts/results/Forc.toml | 0 .../sway}/types/contracts/results/src/main.sw | 0 .../types/contracts/std_lib_string/Forc.toml | 0 .../contracts/std_lib_string/src/main.sw | 0 .../types/contracts/str_in_array/Forc.toml | 0 .../types/contracts/str_in_array/src/main.sw | 0 .../types/contracts/string_slice/Forc.toml | 0 .../types/contracts/string_slice/src/main.sw | 0 .../sway}/types/contracts/tuples/Forc.toml | 0 .../sway}/types/contracts/tuples/src/main.sw | 0 .../types/contracts/two_structs/Forc.toml | 0 .../types/contracts/two_structs/src/main.sw | 0 .../contracts/type_inside_enum/Forc.toml | 0 .../contracts/type_inside_enum/src/main.sw | 0 .../sway}/types/contracts/u128/Forc.toml | 0 .../sway}/types/contracts/u128/src/main.sw | 0 .../sway}/types/contracts/u256/Forc.toml | 0 .../sway}/types/contracts/u256/src/main.sw | 0 .../types/contracts/vector_output/Forc.toml | 0 .../types/contracts/vector_output/src/main.sw | 0 .../sway}/types/contracts/vectors/Forc.toml | 0 .../contracts/vectors/src/data_structures.sw | 0 .../types/contracts/vectors/src/eq_impls.sw | 0 .../sway}/types/contracts/vectors/src/main.sw | 0 .../types/contracts/vectors/src/utils.sw | 0 .../sway}/types/predicates/address/Forc.toml | 0 .../types/predicates/address/src/main.sw | 0 .../sway}/types/predicates/enums/Forc.toml | 0 .../sway}/types/predicates/enums/src/main.sw | 0 .../types/predicates/predicate_b256/Forc.toml | 0 .../predicates/predicate_b256/src/main.sw | 0 .../predicates/predicate_bytes/Forc.toml | 0 .../predicates/predicate_bytes/src/main.sw | 0 .../predicates/predicate_bytes_hash/Forc.toml | 0 .../predicate_bytes_hash/src/main.sw | 0 .../predicates/predicate_generics/Forc.toml | 0 .../predicates/predicate_generics/src/main.sw | 0 .../predicates/predicate_raw_slice/Forc.toml | 0 .../predicate_raw_slice/src/main.sw | 0 .../predicate_std_lib_string/Forc.toml | 0 .../predicate_std_lib_string/src/main.sw | 0 .../predicates/predicate_tuples/Forc.toml | 0 .../predicates/predicate_tuples/src/main.sw | 0 .../types/predicates/predicate_u128/Forc.toml | 0 .../predicates/predicate_u128/src/main.sw | 0 .../types/predicates/predicate_u256/Forc.toml | 0 .../predicates/predicate_u256/src/main.sw | 0 .../predicates/predicate_vector/Forc.toml | 0 .../predicates/predicate_vector/src/main.sw | 0 .../predicates/predicate_vectors/Forc.toml | 0 .../predicates/predicate_vectors/src/main.sw | 0 .../sway}/types/predicates/structs/Forc.toml | 0 .../types/predicates/structs/src/main.sw | 0 .../sway}/types/predicates/u64/Forc.toml | 0 .../sway}/types/predicates/u64/src/main.sw | 0 .../types/scripts/options_results/Forc.toml | 0 .../types/scripts/options_results/src/main.sw | 0 .../sway}/types/scripts/script_b256/Forc.toml | 0 .../types/scripts/script_b256/src/main.sw | 0 .../types/scripts/script_bytes/Forc.toml | 0 .../types/scripts/script_bytes/src/main.sw | 0 .../types/scripts/script_generics/Forc.toml | 0 .../types/scripts/script_generics/src/main.sw | 0 .../types/scripts/script_heap_types/Forc.toml | 0 .../scripts/script_heap_types/src/main.sw | 0 .../types/scripts/script_raw_slice/Forc.toml | 0 .../scripts/script_raw_slice/src/main.sw | 0 .../scripts/script_std_lib_string/Forc.toml | 0 .../scripts/script_std_lib_string/src/main.sw | 0 .../types/scripts/script_tuples/Forc.toml | 0 .../types/scripts/script_tuples/src/main.sw | 0 .../sway}/types/scripts/script_u128/Forc.toml | 0 .../types/scripts/script_u128/src/main.sw | 0 .../sway}/types/scripts/script_u256/Forc.toml | 0 .../types/scripts/script_u256/src/main.sw | 0 .../types/scripts/script_vectors/Forc.toml | 0 .../script_vectors/src/data_structures.sw | 0 .../scripts/script_vectors/src/eq_impls.sw | 0 .../types/scripts/script_vectors/src/main.sw | 0 .../types/scripts/script_vectors/src/utils.sw | 0 {packages/fuels => e2e}/tests/bindings.rs | 8 +- .../fuels => e2e}/tests/configurables.rs | 25 ++-- {packages/fuels => e2e}/tests/contracts.rs | 104 ++++++++-------- {packages/fuels => e2e}/tests/from_token.rs | 0 {packages/fuels => e2e}/tests/imports.rs | 0 {packages/fuels => e2e}/tests/logs.rs | 95 +++++++-------- {packages/fuels => e2e}/tests/predicates.rs | 103 ++++++++-------- {packages/fuels => e2e}/tests/providers.rs | 33 +++-- {packages/fuels => e2e}/tests/scripts.rs | 28 ++--- {packages/fuels => e2e}/tests/storage.rs | 12 +- .../fuels => e2e}/tests/types_contracts.rs | 84 ++++++------- .../fuels => e2e}/tests/types_predicates.rs | 68 ++++++----- .../fuels => e2e}/tests/types_scripts.rs | 22 ++-- {packages/fuels => e2e}/tests/wallets.rs | 8 +- examples/contracts/src/lib.rs | 69 +++++------ examples/cookbook/src/lib.rs | 7 +- examples/debugging/src/lib.rs | 5 +- examples/macros/src/lib.rs | 20 +++- examples/predicates/src/lib.rs | 13 +- examples/wallets/src/lib.rs | 2 +- packages/fuels-accounts/src/predicate.rs | 8 +- .../abigen/bindings/script.rs | 2 +- packages/fuels-core/Cargo.toml | 2 +- packages/fuels-core/src/types/errors.rs | 8 +- packages/fuels-programs/src/contract.rs | 8 +- .../src/fuel_bin_service.rs | 7 +- packages/fuels/Cargo.toml | 13 -- packages/fuels/Forc.toml | 113 ------------------ .../.cargo/config.toml | 0 .../wasm-tests => wasm-tests}/Cargo.toml | 8 +- .../wasm-tests => wasm-tests}/src/lib.rs | 0 256 files changed, 540 insertions(+), 517 deletions(-) create mode 100644 Forc.toml create mode 100644 e2e/Cargo.toml rename {packages/fuels/tests => e2e/sway}/bindings/sharing_types/contract_a/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/bindings/sharing_types/contract_a/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/bindings/sharing_types/contract_b/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/bindings/sharing_types/contract_b/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/bindings/sharing_types/shared_lib/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/bindings/sharing_types/shared_lib/src/lib.sw (100%) rename {packages/fuels/tests => e2e/sway}/bindings/simple_contract/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/bindings/simple_contract/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/bindings/type_paths/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/bindings/type_paths/src/another_lib.sw (100%) rename {packages/fuels/tests => e2e/sway}/bindings/type_paths/src/contract_a_types.sw (100%) rename {packages/fuels/tests => e2e/sway}/bindings/type_paths/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/asserts/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/asserts/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/auth_testing_abi/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/auth_testing_abi/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/auth_testing_contract/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/auth_testing_contract/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/block_timestamp/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/block_timestamp/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/configurables/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/configurables/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/contract_test/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/contract_test/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/large_return_data/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/large_return_data/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/lib_contract/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/lib_contract/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/lib_contract_abi/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/lib_contract_abi/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/lib_contract_caller/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/lib_contract_caller/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/library_test/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/library_test/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/liquidity_pool/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/liquidity_pool/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/low_level_caller/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/low_level_caller/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/msg_methods/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/msg_methods/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/multiple_read_calls/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/multiple_read_calls/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/needs_custom_decoder/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/needs_custom_decoder/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/payable_annotation/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/payable_annotation/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/require/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/require/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/revert_transaction_error/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/revert_transaction_error/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/storage/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/storage/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/token_ops/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/token_ops/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/contracts/transaction_block_height/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/contracts/transaction_block_height/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/logs/contract_logs/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/logs/contract_logs/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/logs/contract_logs_abi/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/logs/contract_logs_abi/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/logs/contract_with_contract_logs/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/logs/contract_with_contract_logs/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/logs/script_heap_logs/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/logs/script_heap_logs/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/logs/script_logs/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/logs/script_logs/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/logs/script_needs_custom_decoder_logging/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/logs/script_needs_custom_decoder_logging/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/logs/script_with_contract_logs/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/logs/script_with_contract_logs/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/predicates/basic_predicate/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/predicates/basic_predicate/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/predicates/predicate_configurables/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/predicates/predicate_configurables/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/predicates/predicate_witnesses/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/predicates/predicate_witnesses/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/predicates/signatures/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/predicates/signatures/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/predicates/swap/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/predicates/swap/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/arguments/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/arguments/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/basic_script/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/basic_script/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/require_from_contract/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/require_from_contract/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_array/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_array/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_asserts/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_asserts/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_configurables/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_configurables/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_enum/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_enum/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_needs_custom_decoder/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_needs_custom_decoder/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_require/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_require/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_struct/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/script_struct/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/scripts/transfer_script/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/scripts/transfer_script/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/b256/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/b256/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/b512/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/b512/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/bytes/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/bytes/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/call_empty_return/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/call_empty_return/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/complex_types_contract/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/complex_types_contract/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/contract_output_test/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/contract_output_test/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/empty_arguments/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/empty_arguments/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/enum_as_input/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/enum_as_input/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/enum_encoding/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/enum_encoding/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/enum_inside_struct/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/enum_inside_struct/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/evm_address/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/evm_address/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/generics/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/generics/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/heap_type_in_enums/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/heap_type_in_enums/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/heap_types/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/heap_types/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/identity/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/identity/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/native_types/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/native_types/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/nested_structs/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/nested_structs/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/options/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/options/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/raw_slice/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/raw_slice/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/results/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/results/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/std_lib_string/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/std_lib_string/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/str_in_array/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/str_in_array/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/string_slice/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/string_slice/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/tuples/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/tuples/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/two_structs/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/two_structs/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/type_inside_enum/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/type_inside_enum/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/u128/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/u128/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/u256/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/u256/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/vector_output/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/vector_output/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/vectors/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/vectors/src/data_structures.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/vectors/src/eq_impls.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/vectors/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/contracts/vectors/src/utils.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/address/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/address/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/enums/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/enums/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_b256/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_b256/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_bytes/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_bytes/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_bytes_hash/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_bytes_hash/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_generics/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_generics/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_raw_slice/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_raw_slice/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_std_lib_string/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_std_lib_string/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_tuples/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_tuples/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_u128/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_u128/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_u256/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_u256/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_vector/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_vector/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_vectors/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/predicate_vectors/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/structs/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/structs/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/u64/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/predicates/u64/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/options_results/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/options_results/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_b256/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_b256/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_bytes/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_bytes/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_generics/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_generics/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_heap_types/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_heap_types/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_raw_slice/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_raw_slice/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_std_lib_string/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_std_lib_string/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_tuples/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_tuples/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_u128/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_u128/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_u256/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_u256/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_vectors/Forc.toml (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_vectors/src/data_structures.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_vectors/src/eq_impls.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_vectors/src/main.sw (100%) rename {packages/fuels/tests => e2e/sway}/types/scripts/script_vectors/src/utils.sw (100%) rename {packages/fuels => e2e}/tests/bindings.rs (95%) rename {packages/fuels => e2e}/tests/configurables.rs (86%) rename {packages/fuels => e2e}/tests/contracts.rs (93%) rename {packages/fuels => e2e}/tests/from_token.rs (100%) rename {packages/fuels => e2e}/tests/imports.rs (100%) rename {packages/fuels => e2e}/tests/logs.rs (93%) rename {packages/fuels => e2e}/tests/predicates.rs (88%) rename {packages/fuels => e2e}/tests/providers.rs (95%) rename {packages/fuels => e2e}/tests/scripts.rs (90%) rename {packages/fuels => e2e}/tests/storage.rs (85%) rename {packages/fuels => e2e}/tests/types_contracts.rs (94%) rename {packages/fuels => e2e}/tests/types_predicates.rs (76%) rename {packages/fuels => e2e}/tests/types_scripts.rs (91%) rename {packages/fuels => e2e}/tests/wallets.rs (99%) delete mode 100644 packages/fuels/Forc.toml rename {packages/wasm-tests => wasm-tests}/.cargo/config.toml (100%) rename {packages/wasm-tests => wasm-tests}/Cargo.toml (51%) rename {packages/wasm-tests => wasm-tests}/src/lib.rs (100%) diff --git a/.gitignore b/.gitignore index 75d9a30a7..65acc517a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,17 +12,10 @@ Cargo.lock # Don't add the generated MDBook artifacts docs/book/ -# Don't add lock files in the fuels tests directory. -packages/fuels/tests/**/**/Forc.lock +# Don't add Forc lock files +**/Forc.lock # Don't add out/ files from test Sway projects. -packages/fuels/tests/**/**/out/ - -# Don't add target/ files from test Sway projects. -packages/fuels/tests/**/**/target/ - -# Don't add .gitignore files from test Sway projects. -packages/fuels/tests/**/**/.gitignore - -# Don't add lock files in the fuels directory. -packages/fuels/Forc.lock +e2e/sway/**/out/ +e2e/sway/**/target/ +e2e/sway/**/.gitignore diff --git a/Cargo.toml b/Cargo.toml index ace307541..0cb70f40f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ # https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html#details resolver = "2" members = [ + "e2e", "examples/codec", "examples/contracts", "examples/cookbook", @@ -23,9 +24,9 @@ members = [ "packages/fuels-macros", "packages/fuels-programs", "packages/fuels-test-helpers", - "packages/wasm-tests", "scripts/check-docs", "scripts/versions-replacer", + "wasm-tests", ] [workspace.package] @@ -92,7 +93,7 @@ fuel-types = { version = "0.49.0" } fuel-vm = { version = "0.49.0" } # Workspace projects -fuels = { version = "0.61.0", path = "./packages/fuels" } +fuels = { version = "0.61.0", path = "./packages/fuels", default-features = false } fuels-accounts = { version = "0.61.0", path = "./packages/fuels-accounts", default-features = false } fuels-code-gen = { version = "0.61.0", path = "./packages/fuels-code-gen", default-features = false } fuels-core = { version = "0.61.0", path = "./packages/fuels-core", default-features = false } diff --git a/Forc.toml b/Forc.toml new file mode 100644 index 000000000..0a99a5ade --- /dev/null +++ b/Forc.toml @@ -0,0 +1,113 @@ +[workspace] +members = [ + 'e2e/sway/bindings/sharing_types/contract_a', + 'e2e/sway/bindings/sharing_types/contract_b', + 'e2e/sway/bindings/sharing_types/shared_lib', + 'e2e/sway/bindings/simple_contract', + 'e2e/sway/bindings/type_paths', + 'e2e/sway/contracts/asserts', + 'e2e/sway/contracts/auth_testing_abi', + 'e2e/sway/contracts/auth_testing_contract', + 'e2e/sway/contracts/block_timestamp', + 'e2e/sway/contracts/configurables', + 'e2e/sway/contracts/contract_test', + 'e2e/sway/contracts/large_return_data', + 'e2e/sway/contracts/lib_contract', + 'e2e/sway/contracts/lib_contract_abi', + 'e2e/sway/contracts/lib_contract_caller', + 'e2e/sway/contracts/library_test', + 'e2e/sway/contracts/liquidity_pool', + 'e2e/sway/contracts/low_level_caller', + 'e2e/sway/contracts/msg_methods', + 'e2e/sway/contracts/multiple_read_calls', + 'e2e/sway/contracts/needs_custom_decoder', + 'e2e/sway/contracts/payable_annotation', + 'e2e/sway/contracts/require', + 'e2e/sway/contracts/revert_transaction_error', + 'e2e/sway/contracts/storage', + 'e2e/sway/contracts/token_ops', + 'e2e/sway/contracts/transaction_block_height', + 'e2e/sway/logs/contract_logs', + 'e2e/sway/logs/contract_logs_abi', + 'e2e/sway/logs/contract_with_contract_logs', + 'e2e/sway/logs/script_heap_logs', + 'e2e/sway/logs/script_logs', + 'e2e/sway/logs/script_needs_custom_decoder_logging', + 'e2e/sway/logs/script_with_contract_logs', + 'e2e/sway/predicates/basic_predicate', + 'e2e/sway/predicates/predicate_configurables', + 'e2e/sway/predicates/predicate_witnesses', + 'e2e/sway/predicates/signatures', + 'e2e/sway/predicates/swap', + 'e2e/sway/scripts/arguments', + 'e2e/sway/scripts/basic_script', + 'e2e/sway/scripts/require_from_contract', + 'e2e/sway/scripts/script_array', + 'e2e/sway/scripts/script_asserts', + 'e2e/sway/scripts/script_configurables', + 'e2e/sway/scripts/script_enum', + 'e2e/sway/scripts/script_needs_custom_decoder', + 'e2e/sway/scripts/script_require', + 'e2e/sway/scripts/script_struct', + 'e2e/sway/scripts/transfer_script', + 'e2e/sway/types/contracts/b256', + 'e2e/sway/types/contracts/b512', + 'e2e/sway/types/contracts/bytes', + 'e2e/sway/types/contracts/call_empty_return', + 'e2e/sway/types/contracts/complex_types_contract', + 'e2e/sway/types/contracts/empty_arguments', + 'e2e/sway/types/contracts/enum_as_input', + 'e2e/sway/types/contracts/enum_encoding', + 'e2e/sway/types/contracts/enum_inside_struct', + 'e2e/sway/types/contracts/evm_address', + 'e2e/sway/types/contracts/generics', + 'e2e/sway/types/contracts/heap_type_in_enums', + 'e2e/sway/types/contracts/heap_types', + 'e2e/sway/types/contracts/identity', + 'e2e/sway/types/contracts/native_types', + 'e2e/sway/types/contracts/nested_structs', + 'e2e/sway/types/contracts/options', + 'e2e/sway/types/contracts/raw_slice', + 'e2e/sway/types/contracts/results', + 'e2e/sway/types/contracts/std_lib_string', + 'e2e/sway/types/contracts/str_in_array', + 'e2e/sway/types/contracts/string_slice', + 'e2e/sway/types/contracts/tuples', + 'e2e/sway/types/contracts/two_structs', + 'e2e/sway/types/contracts/type_inside_enum', + 'e2e/sway/types/contracts/u128', + 'e2e/sway/types/contracts/u256', + 'e2e/sway/types/contracts/vector_output', + 'e2e/sway/types/contracts/vectors', + 'e2e/sway/types/predicates/address', + 'e2e/sway/types/predicates/enums', + 'e2e/sway/types/predicates/predicate_b256', + 'e2e/sway/types/predicates/predicate_bytes', + 'e2e/sway/types/predicates/predicate_bytes_hash', + 'e2e/sway/types/predicates/predicate_generics', + 'e2e/sway/types/predicates/predicate_raw_slice', + 'e2e/sway/types/predicates/predicate_std_lib_string', + 'e2e/sway/types/predicates/predicate_tuples', + 'e2e/sway/types/predicates/predicate_u128', + 'e2e/sway/types/predicates/predicate_u256', + 'e2e/sway/types/predicates/predicate_vector', + 'e2e/sway/types/predicates/predicate_vectors', + 'e2e/sway/types/predicates/structs', + 'e2e/sway/types/predicates/u64', + 'e2e/sway/types/scripts/options_results', + 'e2e/sway/types/scripts/script_b256', + 'e2e/sway/types/scripts/script_bytes', + 'e2e/sway/types/scripts/script_generics', + 'e2e/sway/types/scripts/script_heap_types', + #TODO: Decide what to do with this test project once + # https://github.com/FuelLabs/sway/issues/5727 is resolved + # 'e2e/sway/types/scripts/script_raw_slice', + 'e2e/sway/types/scripts/script_std_lib_string', + 'e2e/sway/types/scripts/script_tuples', + 'e2e/sway/types/scripts/script_u128', + 'e2e/sway/types/scripts/script_u256', + 'e2e/sway/types/scripts/script_vectors', +] + +[patch.'https://github.com/fuellabs/sway'] +std = { git = "https://github.com/fuellabs/sway", branch = "xunilrj/new-encoding-configurables" } diff --git a/ci_checks.sh b/ci_checks.sh index cdea15e6d..faaf36815 100755 --- a/ci_checks.sh +++ b/ci_checks.sh @@ -8,13 +8,13 @@ # Note, if you need a custom branch, you can replace `--tag {RELEASE}` with the `--branch {BRANCH_NAME}`. cargo fmt --all -- --check && -forc fmt --check --path packages/fuels && -forc build --release --terse --path packages/fuels && -forc build --release --terse --json-abi-with-callpaths --path packages/fuels && -cargo clippy --all-targets && -cargo clippy --all-targets --all-features && -cargo test --all-targets --all-features && -cargo test --all-targets --all-features --workspace && -cargo test --all-targets --workspace && -cargo run --bin check-docs && -$(cargo doc |& grep -A 6 "warning: unresolved link to") + forc fmt --check && + forc build --release --terse && + cargo clippy --all-targets && + forc build --release --terse --json-abi-with-callpaths && + cargo clippy --all-targets --all-features && + cargo test --all-targets --all-features && + cargo test --all-targets --all-features --workspace && + cargo test --all-targets --workspace && + cargo run --bin check-docs && + $(cargo doc |& grep -A 6 "warning: unresolved link to") diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml new file mode 100644 index 000000000..e9d774952 --- /dev/null +++ b/e2e/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "e2e" +authors = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +readme = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } +publish = false + +[dev-dependencies] +# used in test assertions +chrono = { workspace = true } +# needs to be removed, `ScriptTransaction` and `CreateTransaction` in `fuels` use `fuel_tx::Input` but don't reexport or convert it into a `fuels` owned type +fuel-tx = { workspace = true } +fuels = { workspace = true } +# because setup-program-test uses it but `fuels` did not reexport `rand` +rand = { workspace = true } +# used in test assertions +tai64 = { workspace = true } +tempfile = { workspace = true } +tokio = { workspace = true } + +[features] +fuel-core-lib = ["fuels/fuel-core-lib"] diff --git a/packages/fuels/tests/bindings/sharing_types/contract_a/Forc.toml b/e2e/sway/bindings/sharing_types/contract_a/Forc.toml similarity index 100% rename from packages/fuels/tests/bindings/sharing_types/contract_a/Forc.toml rename to e2e/sway/bindings/sharing_types/contract_a/Forc.toml diff --git a/packages/fuels/tests/bindings/sharing_types/contract_a/src/main.sw b/e2e/sway/bindings/sharing_types/contract_a/src/main.sw similarity index 100% rename from packages/fuels/tests/bindings/sharing_types/contract_a/src/main.sw rename to e2e/sway/bindings/sharing_types/contract_a/src/main.sw diff --git a/packages/fuels/tests/bindings/sharing_types/contract_b/Forc.toml b/e2e/sway/bindings/sharing_types/contract_b/Forc.toml similarity index 100% rename from packages/fuels/tests/bindings/sharing_types/contract_b/Forc.toml rename to e2e/sway/bindings/sharing_types/contract_b/Forc.toml diff --git a/packages/fuels/tests/bindings/sharing_types/contract_b/src/main.sw b/e2e/sway/bindings/sharing_types/contract_b/src/main.sw similarity index 100% rename from packages/fuels/tests/bindings/sharing_types/contract_b/src/main.sw rename to e2e/sway/bindings/sharing_types/contract_b/src/main.sw diff --git a/packages/fuels/tests/bindings/sharing_types/shared_lib/Forc.toml b/e2e/sway/bindings/sharing_types/shared_lib/Forc.toml similarity index 100% rename from packages/fuels/tests/bindings/sharing_types/shared_lib/Forc.toml rename to e2e/sway/bindings/sharing_types/shared_lib/Forc.toml diff --git a/packages/fuels/tests/bindings/sharing_types/shared_lib/src/lib.sw b/e2e/sway/bindings/sharing_types/shared_lib/src/lib.sw similarity index 100% rename from packages/fuels/tests/bindings/sharing_types/shared_lib/src/lib.sw rename to e2e/sway/bindings/sharing_types/shared_lib/src/lib.sw diff --git a/packages/fuels/tests/bindings/simple_contract/Forc.toml b/e2e/sway/bindings/simple_contract/Forc.toml similarity index 100% rename from packages/fuels/tests/bindings/simple_contract/Forc.toml rename to e2e/sway/bindings/simple_contract/Forc.toml diff --git a/packages/fuels/tests/bindings/simple_contract/src/main.sw b/e2e/sway/bindings/simple_contract/src/main.sw similarity index 100% rename from packages/fuels/tests/bindings/simple_contract/src/main.sw rename to e2e/sway/bindings/simple_contract/src/main.sw diff --git a/packages/fuels/tests/bindings/type_paths/Forc.toml b/e2e/sway/bindings/type_paths/Forc.toml similarity index 100% rename from packages/fuels/tests/bindings/type_paths/Forc.toml rename to e2e/sway/bindings/type_paths/Forc.toml diff --git a/packages/fuels/tests/bindings/type_paths/src/another_lib.sw b/e2e/sway/bindings/type_paths/src/another_lib.sw similarity index 100% rename from packages/fuels/tests/bindings/type_paths/src/another_lib.sw rename to e2e/sway/bindings/type_paths/src/another_lib.sw diff --git a/packages/fuels/tests/bindings/type_paths/src/contract_a_types.sw b/e2e/sway/bindings/type_paths/src/contract_a_types.sw similarity index 100% rename from packages/fuels/tests/bindings/type_paths/src/contract_a_types.sw rename to e2e/sway/bindings/type_paths/src/contract_a_types.sw diff --git a/packages/fuels/tests/bindings/type_paths/src/main.sw b/e2e/sway/bindings/type_paths/src/main.sw similarity index 100% rename from packages/fuels/tests/bindings/type_paths/src/main.sw rename to e2e/sway/bindings/type_paths/src/main.sw diff --git a/packages/fuels/tests/contracts/asserts/Forc.toml b/e2e/sway/contracts/asserts/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/asserts/Forc.toml rename to e2e/sway/contracts/asserts/Forc.toml diff --git a/packages/fuels/tests/contracts/asserts/src/main.sw b/e2e/sway/contracts/asserts/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/asserts/src/main.sw rename to e2e/sway/contracts/asserts/src/main.sw diff --git a/packages/fuels/tests/contracts/auth_testing_abi/Forc.toml b/e2e/sway/contracts/auth_testing_abi/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/auth_testing_abi/Forc.toml rename to e2e/sway/contracts/auth_testing_abi/Forc.toml diff --git a/packages/fuels/tests/contracts/auth_testing_abi/src/main.sw b/e2e/sway/contracts/auth_testing_abi/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/auth_testing_abi/src/main.sw rename to e2e/sway/contracts/auth_testing_abi/src/main.sw diff --git a/packages/fuels/tests/contracts/auth_testing_contract/Forc.toml b/e2e/sway/contracts/auth_testing_contract/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/auth_testing_contract/Forc.toml rename to e2e/sway/contracts/auth_testing_contract/Forc.toml diff --git a/packages/fuels/tests/contracts/auth_testing_contract/src/main.sw b/e2e/sway/contracts/auth_testing_contract/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/auth_testing_contract/src/main.sw rename to e2e/sway/contracts/auth_testing_contract/src/main.sw diff --git a/packages/fuels/tests/contracts/block_timestamp/Forc.toml b/e2e/sway/contracts/block_timestamp/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/block_timestamp/Forc.toml rename to e2e/sway/contracts/block_timestamp/Forc.toml diff --git a/packages/fuels/tests/contracts/block_timestamp/src/main.sw b/e2e/sway/contracts/block_timestamp/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/block_timestamp/src/main.sw rename to e2e/sway/contracts/block_timestamp/src/main.sw diff --git a/packages/fuels/tests/contracts/configurables/Forc.toml b/e2e/sway/contracts/configurables/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/configurables/Forc.toml rename to e2e/sway/contracts/configurables/Forc.toml diff --git a/packages/fuels/tests/contracts/configurables/src/main.sw b/e2e/sway/contracts/configurables/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/configurables/src/main.sw rename to e2e/sway/contracts/configurables/src/main.sw diff --git a/packages/fuels/tests/contracts/contract_test/Forc.toml b/e2e/sway/contracts/contract_test/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/contract_test/Forc.toml rename to e2e/sway/contracts/contract_test/Forc.toml diff --git a/packages/fuels/tests/contracts/contract_test/src/main.sw b/e2e/sway/contracts/contract_test/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/contract_test/src/main.sw rename to e2e/sway/contracts/contract_test/src/main.sw diff --git a/packages/fuels/tests/contracts/large_return_data/Forc.toml b/e2e/sway/contracts/large_return_data/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/large_return_data/Forc.toml rename to e2e/sway/contracts/large_return_data/Forc.toml diff --git a/packages/fuels/tests/contracts/large_return_data/src/main.sw b/e2e/sway/contracts/large_return_data/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/large_return_data/src/main.sw rename to e2e/sway/contracts/large_return_data/src/main.sw diff --git a/packages/fuels/tests/contracts/lib_contract/Forc.toml b/e2e/sway/contracts/lib_contract/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/lib_contract/Forc.toml rename to e2e/sway/contracts/lib_contract/Forc.toml diff --git a/packages/fuels/tests/contracts/lib_contract/src/main.sw b/e2e/sway/contracts/lib_contract/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/lib_contract/src/main.sw rename to e2e/sway/contracts/lib_contract/src/main.sw diff --git a/packages/fuels/tests/contracts/lib_contract_abi/Forc.toml b/e2e/sway/contracts/lib_contract_abi/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/lib_contract_abi/Forc.toml rename to e2e/sway/contracts/lib_contract_abi/Forc.toml diff --git a/packages/fuels/tests/contracts/lib_contract_abi/src/main.sw b/e2e/sway/contracts/lib_contract_abi/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/lib_contract_abi/src/main.sw rename to e2e/sway/contracts/lib_contract_abi/src/main.sw diff --git a/packages/fuels/tests/contracts/lib_contract_caller/Forc.toml b/e2e/sway/contracts/lib_contract_caller/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/lib_contract_caller/Forc.toml rename to e2e/sway/contracts/lib_contract_caller/Forc.toml diff --git a/packages/fuels/tests/contracts/lib_contract_caller/src/main.sw b/e2e/sway/contracts/lib_contract_caller/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/lib_contract_caller/src/main.sw rename to e2e/sway/contracts/lib_contract_caller/src/main.sw diff --git a/packages/fuels/tests/contracts/library_test/Forc.toml b/e2e/sway/contracts/library_test/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/library_test/Forc.toml rename to e2e/sway/contracts/library_test/Forc.toml diff --git a/packages/fuels/tests/contracts/library_test/src/main.sw b/e2e/sway/contracts/library_test/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/library_test/src/main.sw rename to e2e/sway/contracts/library_test/src/main.sw diff --git a/packages/fuels/tests/contracts/liquidity_pool/Forc.toml b/e2e/sway/contracts/liquidity_pool/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/liquidity_pool/Forc.toml rename to e2e/sway/contracts/liquidity_pool/Forc.toml diff --git a/packages/fuels/tests/contracts/liquidity_pool/src/main.sw b/e2e/sway/contracts/liquidity_pool/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/liquidity_pool/src/main.sw rename to e2e/sway/contracts/liquidity_pool/src/main.sw diff --git a/packages/fuels/tests/contracts/low_level_caller/Forc.toml b/e2e/sway/contracts/low_level_caller/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/low_level_caller/Forc.toml rename to e2e/sway/contracts/low_level_caller/Forc.toml diff --git a/packages/fuels/tests/contracts/low_level_caller/src/main.sw b/e2e/sway/contracts/low_level_caller/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/low_level_caller/src/main.sw rename to e2e/sway/contracts/low_level_caller/src/main.sw diff --git a/packages/fuels/tests/contracts/msg_methods/Forc.toml b/e2e/sway/contracts/msg_methods/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/msg_methods/Forc.toml rename to e2e/sway/contracts/msg_methods/Forc.toml diff --git a/packages/fuels/tests/contracts/msg_methods/src/main.sw b/e2e/sway/contracts/msg_methods/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/msg_methods/src/main.sw rename to e2e/sway/contracts/msg_methods/src/main.sw diff --git a/packages/fuels/tests/contracts/multiple_read_calls/Forc.toml b/e2e/sway/contracts/multiple_read_calls/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/multiple_read_calls/Forc.toml rename to e2e/sway/contracts/multiple_read_calls/Forc.toml diff --git a/packages/fuels/tests/contracts/multiple_read_calls/src/main.sw b/e2e/sway/contracts/multiple_read_calls/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/multiple_read_calls/src/main.sw rename to e2e/sway/contracts/multiple_read_calls/src/main.sw diff --git a/packages/fuels/tests/contracts/needs_custom_decoder/Forc.toml b/e2e/sway/contracts/needs_custom_decoder/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/needs_custom_decoder/Forc.toml rename to e2e/sway/contracts/needs_custom_decoder/Forc.toml diff --git a/packages/fuels/tests/contracts/needs_custom_decoder/src/main.sw b/e2e/sway/contracts/needs_custom_decoder/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/needs_custom_decoder/src/main.sw rename to e2e/sway/contracts/needs_custom_decoder/src/main.sw diff --git a/packages/fuels/tests/contracts/payable_annotation/Forc.toml b/e2e/sway/contracts/payable_annotation/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/payable_annotation/Forc.toml rename to e2e/sway/contracts/payable_annotation/Forc.toml diff --git a/packages/fuels/tests/contracts/payable_annotation/src/main.sw b/e2e/sway/contracts/payable_annotation/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/payable_annotation/src/main.sw rename to e2e/sway/contracts/payable_annotation/src/main.sw diff --git a/packages/fuels/tests/contracts/require/Forc.toml b/e2e/sway/contracts/require/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/require/Forc.toml rename to e2e/sway/contracts/require/Forc.toml diff --git a/packages/fuels/tests/contracts/require/src/main.sw b/e2e/sway/contracts/require/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/require/src/main.sw rename to e2e/sway/contracts/require/src/main.sw diff --git a/packages/fuels/tests/contracts/revert_transaction_error/Forc.toml b/e2e/sway/contracts/revert_transaction_error/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/revert_transaction_error/Forc.toml rename to e2e/sway/contracts/revert_transaction_error/Forc.toml diff --git a/packages/fuels/tests/contracts/revert_transaction_error/src/main.sw b/e2e/sway/contracts/revert_transaction_error/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/revert_transaction_error/src/main.sw rename to e2e/sway/contracts/revert_transaction_error/src/main.sw diff --git a/packages/fuels/tests/contracts/storage/Forc.toml b/e2e/sway/contracts/storage/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/storage/Forc.toml rename to e2e/sway/contracts/storage/Forc.toml diff --git a/packages/fuels/tests/contracts/storage/src/main.sw b/e2e/sway/contracts/storage/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/storage/src/main.sw rename to e2e/sway/contracts/storage/src/main.sw diff --git a/packages/fuels/tests/contracts/token_ops/Forc.toml b/e2e/sway/contracts/token_ops/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/token_ops/Forc.toml rename to e2e/sway/contracts/token_ops/Forc.toml diff --git a/packages/fuels/tests/contracts/token_ops/src/main.sw b/e2e/sway/contracts/token_ops/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/token_ops/src/main.sw rename to e2e/sway/contracts/token_ops/src/main.sw diff --git a/packages/fuels/tests/contracts/transaction_block_height/Forc.toml b/e2e/sway/contracts/transaction_block_height/Forc.toml similarity index 100% rename from packages/fuels/tests/contracts/transaction_block_height/Forc.toml rename to e2e/sway/contracts/transaction_block_height/Forc.toml diff --git a/packages/fuels/tests/contracts/transaction_block_height/src/main.sw b/e2e/sway/contracts/transaction_block_height/src/main.sw similarity index 100% rename from packages/fuels/tests/contracts/transaction_block_height/src/main.sw rename to e2e/sway/contracts/transaction_block_height/src/main.sw diff --git a/packages/fuels/tests/logs/contract_logs/Forc.toml b/e2e/sway/logs/contract_logs/Forc.toml similarity index 100% rename from packages/fuels/tests/logs/contract_logs/Forc.toml rename to e2e/sway/logs/contract_logs/Forc.toml diff --git a/packages/fuels/tests/logs/contract_logs/src/main.sw b/e2e/sway/logs/contract_logs/src/main.sw similarity index 100% rename from packages/fuels/tests/logs/contract_logs/src/main.sw rename to e2e/sway/logs/contract_logs/src/main.sw diff --git a/packages/fuels/tests/logs/contract_logs_abi/Forc.toml b/e2e/sway/logs/contract_logs_abi/Forc.toml similarity index 100% rename from packages/fuels/tests/logs/contract_logs_abi/Forc.toml rename to e2e/sway/logs/contract_logs_abi/Forc.toml diff --git a/packages/fuels/tests/logs/contract_logs_abi/src/main.sw b/e2e/sway/logs/contract_logs_abi/src/main.sw similarity index 100% rename from packages/fuels/tests/logs/contract_logs_abi/src/main.sw rename to e2e/sway/logs/contract_logs_abi/src/main.sw diff --git a/packages/fuels/tests/logs/contract_with_contract_logs/Forc.toml b/e2e/sway/logs/contract_with_contract_logs/Forc.toml similarity index 100% rename from packages/fuels/tests/logs/contract_with_contract_logs/Forc.toml rename to e2e/sway/logs/contract_with_contract_logs/Forc.toml diff --git a/packages/fuels/tests/logs/contract_with_contract_logs/src/main.sw b/e2e/sway/logs/contract_with_contract_logs/src/main.sw similarity index 100% rename from packages/fuels/tests/logs/contract_with_contract_logs/src/main.sw rename to e2e/sway/logs/contract_with_contract_logs/src/main.sw diff --git a/packages/fuels/tests/logs/script_heap_logs/Forc.toml b/e2e/sway/logs/script_heap_logs/Forc.toml similarity index 100% rename from packages/fuels/tests/logs/script_heap_logs/Forc.toml rename to e2e/sway/logs/script_heap_logs/Forc.toml diff --git a/packages/fuels/tests/logs/script_heap_logs/src/main.sw b/e2e/sway/logs/script_heap_logs/src/main.sw similarity index 100% rename from packages/fuels/tests/logs/script_heap_logs/src/main.sw rename to e2e/sway/logs/script_heap_logs/src/main.sw diff --git a/packages/fuels/tests/logs/script_logs/Forc.toml b/e2e/sway/logs/script_logs/Forc.toml similarity index 100% rename from packages/fuels/tests/logs/script_logs/Forc.toml rename to e2e/sway/logs/script_logs/Forc.toml diff --git a/packages/fuels/tests/logs/script_logs/src/main.sw b/e2e/sway/logs/script_logs/src/main.sw similarity index 100% rename from packages/fuels/tests/logs/script_logs/src/main.sw rename to e2e/sway/logs/script_logs/src/main.sw diff --git a/packages/fuels/tests/logs/script_needs_custom_decoder_logging/Forc.toml b/e2e/sway/logs/script_needs_custom_decoder_logging/Forc.toml similarity index 100% rename from packages/fuels/tests/logs/script_needs_custom_decoder_logging/Forc.toml rename to e2e/sway/logs/script_needs_custom_decoder_logging/Forc.toml diff --git a/packages/fuels/tests/logs/script_needs_custom_decoder_logging/src/main.sw b/e2e/sway/logs/script_needs_custom_decoder_logging/src/main.sw similarity index 100% rename from packages/fuels/tests/logs/script_needs_custom_decoder_logging/src/main.sw rename to e2e/sway/logs/script_needs_custom_decoder_logging/src/main.sw diff --git a/packages/fuels/tests/logs/script_with_contract_logs/Forc.toml b/e2e/sway/logs/script_with_contract_logs/Forc.toml similarity index 100% rename from packages/fuels/tests/logs/script_with_contract_logs/Forc.toml rename to e2e/sway/logs/script_with_contract_logs/Forc.toml diff --git a/packages/fuels/tests/logs/script_with_contract_logs/src/main.sw b/e2e/sway/logs/script_with_contract_logs/src/main.sw similarity index 100% rename from packages/fuels/tests/logs/script_with_contract_logs/src/main.sw rename to e2e/sway/logs/script_with_contract_logs/src/main.sw diff --git a/packages/fuels/tests/predicates/basic_predicate/Forc.toml b/e2e/sway/predicates/basic_predicate/Forc.toml similarity index 100% rename from packages/fuels/tests/predicates/basic_predicate/Forc.toml rename to e2e/sway/predicates/basic_predicate/Forc.toml diff --git a/packages/fuels/tests/predicates/basic_predicate/src/main.sw b/e2e/sway/predicates/basic_predicate/src/main.sw similarity index 100% rename from packages/fuels/tests/predicates/basic_predicate/src/main.sw rename to e2e/sway/predicates/basic_predicate/src/main.sw diff --git a/packages/fuels/tests/predicates/predicate_configurables/Forc.toml b/e2e/sway/predicates/predicate_configurables/Forc.toml similarity index 100% rename from packages/fuels/tests/predicates/predicate_configurables/Forc.toml rename to e2e/sway/predicates/predicate_configurables/Forc.toml diff --git a/packages/fuels/tests/predicates/predicate_configurables/src/main.sw b/e2e/sway/predicates/predicate_configurables/src/main.sw similarity index 100% rename from packages/fuels/tests/predicates/predicate_configurables/src/main.sw rename to e2e/sway/predicates/predicate_configurables/src/main.sw diff --git a/packages/fuels/tests/predicates/predicate_witnesses/Forc.toml b/e2e/sway/predicates/predicate_witnesses/Forc.toml similarity index 100% rename from packages/fuels/tests/predicates/predicate_witnesses/Forc.toml rename to e2e/sway/predicates/predicate_witnesses/Forc.toml diff --git a/packages/fuels/tests/predicates/predicate_witnesses/src/main.sw b/e2e/sway/predicates/predicate_witnesses/src/main.sw similarity index 100% rename from packages/fuels/tests/predicates/predicate_witnesses/src/main.sw rename to e2e/sway/predicates/predicate_witnesses/src/main.sw diff --git a/packages/fuels/tests/predicates/signatures/Forc.toml b/e2e/sway/predicates/signatures/Forc.toml similarity index 100% rename from packages/fuels/tests/predicates/signatures/Forc.toml rename to e2e/sway/predicates/signatures/Forc.toml diff --git a/packages/fuels/tests/predicates/signatures/src/main.sw b/e2e/sway/predicates/signatures/src/main.sw similarity index 100% rename from packages/fuels/tests/predicates/signatures/src/main.sw rename to e2e/sway/predicates/signatures/src/main.sw diff --git a/packages/fuels/tests/predicates/swap/Forc.toml b/e2e/sway/predicates/swap/Forc.toml similarity index 100% rename from packages/fuels/tests/predicates/swap/Forc.toml rename to e2e/sway/predicates/swap/Forc.toml diff --git a/packages/fuels/tests/predicates/swap/src/main.sw b/e2e/sway/predicates/swap/src/main.sw similarity index 100% rename from packages/fuels/tests/predicates/swap/src/main.sw rename to e2e/sway/predicates/swap/src/main.sw diff --git a/packages/fuels/tests/scripts/arguments/Forc.toml b/e2e/sway/scripts/arguments/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/arguments/Forc.toml rename to e2e/sway/scripts/arguments/Forc.toml diff --git a/packages/fuels/tests/scripts/arguments/src/main.sw b/e2e/sway/scripts/arguments/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/arguments/src/main.sw rename to e2e/sway/scripts/arguments/src/main.sw diff --git a/packages/fuels/tests/scripts/basic_script/Forc.toml b/e2e/sway/scripts/basic_script/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/basic_script/Forc.toml rename to e2e/sway/scripts/basic_script/Forc.toml diff --git a/packages/fuels/tests/scripts/basic_script/src/main.sw b/e2e/sway/scripts/basic_script/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/basic_script/src/main.sw rename to e2e/sway/scripts/basic_script/src/main.sw diff --git a/packages/fuels/tests/scripts/require_from_contract/Forc.toml b/e2e/sway/scripts/require_from_contract/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/require_from_contract/Forc.toml rename to e2e/sway/scripts/require_from_contract/Forc.toml diff --git a/packages/fuels/tests/scripts/require_from_contract/src/main.sw b/e2e/sway/scripts/require_from_contract/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/require_from_contract/src/main.sw rename to e2e/sway/scripts/require_from_contract/src/main.sw diff --git a/packages/fuels/tests/scripts/script_array/Forc.toml b/e2e/sway/scripts/script_array/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/script_array/Forc.toml rename to e2e/sway/scripts/script_array/Forc.toml diff --git a/packages/fuels/tests/scripts/script_array/src/main.sw b/e2e/sway/scripts/script_array/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/script_array/src/main.sw rename to e2e/sway/scripts/script_array/src/main.sw diff --git a/packages/fuels/tests/scripts/script_asserts/Forc.toml b/e2e/sway/scripts/script_asserts/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/script_asserts/Forc.toml rename to e2e/sway/scripts/script_asserts/Forc.toml diff --git a/packages/fuels/tests/scripts/script_asserts/src/main.sw b/e2e/sway/scripts/script_asserts/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/script_asserts/src/main.sw rename to e2e/sway/scripts/script_asserts/src/main.sw diff --git a/packages/fuels/tests/scripts/script_configurables/Forc.toml b/e2e/sway/scripts/script_configurables/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/script_configurables/Forc.toml rename to e2e/sway/scripts/script_configurables/Forc.toml diff --git a/packages/fuels/tests/scripts/script_configurables/src/main.sw b/e2e/sway/scripts/script_configurables/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/script_configurables/src/main.sw rename to e2e/sway/scripts/script_configurables/src/main.sw diff --git a/packages/fuels/tests/scripts/script_enum/Forc.toml b/e2e/sway/scripts/script_enum/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/script_enum/Forc.toml rename to e2e/sway/scripts/script_enum/Forc.toml diff --git a/packages/fuels/tests/scripts/script_enum/src/main.sw b/e2e/sway/scripts/script_enum/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/script_enum/src/main.sw rename to e2e/sway/scripts/script_enum/src/main.sw diff --git a/packages/fuels/tests/scripts/script_needs_custom_decoder/Forc.toml b/e2e/sway/scripts/script_needs_custom_decoder/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/script_needs_custom_decoder/Forc.toml rename to e2e/sway/scripts/script_needs_custom_decoder/Forc.toml diff --git a/packages/fuels/tests/scripts/script_needs_custom_decoder/src/main.sw b/e2e/sway/scripts/script_needs_custom_decoder/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/script_needs_custom_decoder/src/main.sw rename to e2e/sway/scripts/script_needs_custom_decoder/src/main.sw diff --git a/packages/fuels/tests/scripts/script_require/Forc.toml b/e2e/sway/scripts/script_require/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/script_require/Forc.toml rename to e2e/sway/scripts/script_require/Forc.toml diff --git a/packages/fuels/tests/scripts/script_require/src/main.sw b/e2e/sway/scripts/script_require/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/script_require/src/main.sw rename to e2e/sway/scripts/script_require/src/main.sw diff --git a/packages/fuels/tests/scripts/script_struct/Forc.toml b/e2e/sway/scripts/script_struct/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/script_struct/Forc.toml rename to e2e/sway/scripts/script_struct/Forc.toml diff --git a/packages/fuels/tests/scripts/script_struct/src/main.sw b/e2e/sway/scripts/script_struct/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/script_struct/src/main.sw rename to e2e/sway/scripts/script_struct/src/main.sw diff --git a/packages/fuels/tests/scripts/transfer_script/Forc.toml b/e2e/sway/scripts/transfer_script/Forc.toml similarity index 100% rename from packages/fuels/tests/scripts/transfer_script/Forc.toml rename to e2e/sway/scripts/transfer_script/Forc.toml diff --git a/packages/fuels/tests/scripts/transfer_script/src/main.sw b/e2e/sway/scripts/transfer_script/src/main.sw similarity index 100% rename from packages/fuels/tests/scripts/transfer_script/src/main.sw rename to e2e/sway/scripts/transfer_script/src/main.sw diff --git a/packages/fuels/tests/types/contracts/b256/Forc.toml b/e2e/sway/types/contracts/b256/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/b256/Forc.toml rename to e2e/sway/types/contracts/b256/Forc.toml diff --git a/packages/fuels/tests/types/contracts/b256/src/main.sw b/e2e/sway/types/contracts/b256/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/b256/src/main.sw rename to e2e/sway/types/contracts/b256/src/main.sw diff --git a/packages/fuels/tests/types/contracts/b512/Forc.toml b/e2e/sway/types/contracts/b512/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/b512/Forc.toml rename to e2e/sway/types/contracts/b512/Forc.toml diff --git a/packages/fuels/tests/types/contracts/b512/src/main.sw b/e2e/sway/types/contracts/b512/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/b512/src/main.sw rename to e2e/sway/types/contracts/b512/src/main.sw diff --git a/packages/fuels/tests/types/contracts/bytes/Forc.toml b/e2e/sway/types/contracts/bytes/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/bytes/Forc.toml rename to e2e/sway/types/contracts/bytes/Forc.toml diff --git a/packages/fuels/tests/types/contracts/bytes/src/main.sw b/e2e/sway/types/contracts/bytes/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/bytes/src/main.sw rename to e2e/sway/types/contracts/bytes/src/main.sw diff --git a/packages/fuels/tests/types/contracts/call_empty_return/Forc.toml b/e2e/sway/types/contracts/call_empty_return/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/call_empty_return/Forc.toml rename to e2e/sway/types/contracts/call_empty_return/Forc.toml diff --git a/packages/fuels/tests/types/contracts/call_empty_return/src/main.sw b/e2e/sway/types/contracts/call_empty_return/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/call_empty_return/src/main.sw rename to e2e/sway/types/contracts/call_empty_return/src/main.sw diff --git a/packages/fuels/tests/types/contracts/complex_types_contract/Forc.toml b/e2e/sway/types/contracts/complex_types_contract/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/complex_types_contract/Forc.toml rename to e2e/sway/types/contracts/complex_types_contract/Forc.toml diff --git a/packages/fuels/tests/types/contracts/complex_types_contract/src/main.sw b/e2e/sway/types/contracts/complex_types_contract/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/complex_types_contract/src/main.sw rename to e2e/sway/types/contracts/complex_types_contract/src/main.sw diff --git a/packages/fuels/tests/types/contracts/contract_output_test/Forc.toml b/e2e/sway/types/contracts/contract_output_test/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/contract_output_test/Forc.toml rename to e2e/sway/types/contracts/contract_output_test/Forc.toml diff --git a/packages/fuels/tests/types/contracts/contract_output_test/src/main.sw b/e2e/sway/types/contracts/contract_output_test/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/contract_output_test/src/main.sw rename to e2e/sway/types/contracts/contract_output_test/src/main.sw diff --git a/packages/fuels/tests/types/contracts/empty_arguments/Forc.toml b/e2e/sway/types/contracts/empty_arguments/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/empty_arguments/Forc.toml rename to e2e/sway/types/contracts/empty_arguments/Forc.toml diff --git a/packages/fuels/tests/types/contracts/empty_arguments/src/main.sw b/e2e/sway/types/contracts/empty_arguments/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/empty_arguments/src/main.sw rename to e2e/sway/types/contracts/empty_arguments/src/main.sw diff --git a/packages/fuels/tests/types/contracts/enum_as_input/Forc.toml b/e2e/sway/types/contracts/enum_as_input/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/enum_as_input/Forc.toml rename to e2e/sway/types/contracts/enum_as_input/Forc.toml diff --git a/packages/fuels/tests/types/contracts/enum_as_input/src/main.sw b/e2e/sway/types/contracts/enum_as_input/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/enum_as_input/src/main.sw rename to e2e/sway/types/contracts/enum_as_input/src/main.sw diff --git a/packages/fuels/tests/types/contracts/enum_encoding/Forc.toml b/e2e/sway/types/contracts/enum_encoding/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/enum_encoding/Forc.toml rename to e2e/sway/types/contracts/enum_encoding/Forc.toml diff --git a/packages/fuels/tests/types/contracts/enum_encoding/src/main.sw b/e2e/sway/types/contracts/enum_encoding/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/enum_encoding/src/main.sw rename to e2e/sway/types/contracts/enum_encoding/src/main.sw diff --git a/packages/fuels/tests/types/contracts/enum_inside_struct/Forc.toml b/e2e/sway/types/contracts/enum_inside_struct/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/enum_inside_struct/Forc.toml rename to e2e/sway/types/contracts/enum_inside_struct/Forc.toml diff --git a/packages/fuels/tests/types/contracts/enum_inside_struct/src/main.sw b/e2e/sway/types/contracts/enum_inside_struct/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/enum_inside_struct/src/main.sw rename to e2e/sway/types/contracts/enum_inside_struct/src/main.sw diff --git a/packages/fuels/tests/types/contracts/evm_address/Forc.toml b/e2e/sway/types/contracts/evm_address/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/evm_address/Forc.toml rename to e2e/sway/types/contracts/evm_address/Forc.toml diff --git a/packages/fuels/tests/types/contracts/evm_address/src/main.sw b/e2e/sway/types/contracts/evm_address/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/evm_address/src/main.sw rename to e2e/sway/types/contracts/evm_address/src/main.sw diff --git a/packages/fuels/tests/types/contracts/generics/Forc.toml b/e2e/sway/types/contracts/generics/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/generics/Forc.toml rename to e2e/sway/types/contracts/generics/Forc.toml diff --git a/packages/fuels/tests/types/contracts/generics/src/main.sw b/e2e/sway/types/contracts/generics/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/generics/src/main.sw rename to e2e/sway/types/contracts/generics/src/main.sw diff --git a/packages/fuels/tests/types/contracts/heap_type_in_enums/Forc.toml b/e2e/sway/types/contracts/heap_type_in_enums/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/heap_type_in_enums/Forc.toml rename to e2e/sway/types/contracts/heap_type_in_enums/Forc.toml diff --git a/packages/fuels/tests/types/contracts/heap_type_in_enums/src/main.sw b/e2e/sway/types/contracts/heap_type_in_enums/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/heap_type_in_enums/src/main.sw rename to e2e/sway/types/contracts/heap_type_in_enums/src/main.sw diff --git a/packages/fuels/tests/types/contracts/heap_types/Forc.toml b/e2e/sway/types/contracts/heap_types/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/heap_types/Forc.toml rename to e2e/sway/types/contracts/heap_types/Forc.toml diff --git a/packages/fuels/tests/types/contracts/heap_types/src/main.sw b/e2e/sway/types/contracts/heap_types/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/heap_types/src/main.sw rename to e2e/sway/types/contracts/heap_types/src/main.sw diff --git a/packages/fuels/tests/types/contracts/identity/Forc.toml b/e2e/sway/types/contracts/identity/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/identity/Forc.toml rename to e2e/sway/types/contracts/identity/Forc.toml diff --git a/packages/fuels/tests/types/contracts/identity/src/main.sw b/e2e/sway/types/contracts/identity/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/identity/src/main.sw rename to e2e/sway/types/contracts/identity/src/main.sw diff --git a/packages/fuels/tests/types/contracts/native_types/Forc.toml b/e2e/sway/types/contracts/native_types/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/native_types/Forc.toml rename to e2e/sway/types/contracts/native_types/Forc.toml diff --git a/packages/fuels/tests/types/contracts/native_types/src/main.sw b/e2e/sway/types/contracts/native_types/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/native_types/src/main.sw rename to e2e/sway/types/contracts/native_types/src/main.sw diff --git a/packages/fuels/tests/types/contracts/nested_structs/Forc.toml b/e2e/sway/types/contracts/nested_structs/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/nested_structs/Forc.toml rename to e2e/sway/types/contracts/nested_structs/Forc.toml diff --git a/packages/fuels/tests/types/contracts/nested_structs/src/main.sw b/e2e/sway/types/contracts/nested_structs/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/nested_structs/src/main.sw rename to e2e/sway/types/contracts/nested_structs/src/main.sw diff --git a/packages/fuels/tests/types/contracts/options/Forc.toml b/e2e/sway/types/contracts/options/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/options/Forc.toml rename to e2e/sway/types/contracts/options/Forc.toml diff --git a/packages/fuels/tests/types/contracts/options/src/main.sw b/e2e/sway/types/contracts/options/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/options/src/main.sw rename to e2e/sway/types/contracts/options/src/main.sw diff --git a/packages/fuels/tests/types/contracts/raw_slice/Forc.toml b/e2e/sway/types/contracts/raw_slice/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/raw_slice/Forc.toml rename to e2e/sway/types/contracts/raw_slice/Forc.toml diff --git a/packages/fuels/tests/types/contracts/raw_slice/src/main.sw b/e2e/sway/types/contracts/raw_slice/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/raw_slice/src/main.sw rename to e2e/sway/types/contracts/raw_slice/src/main.sw diff --git a/packages/fuels/tests/types/contracts/results/Forc.toml b/e2e/sway/types/contracts/results/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/results/Forc.toml rename to e2e/sway/types/contracts/results/Forc.toml diff --git a/packages/fuels/tests/types/contracts/results/src/main.sw b/e2e/sway/types/contracts/results/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/results/src/main.sw rename to e2e/sway/types/contracts/results/src/main.sw diff --git a/packages/fuels/tests/types/contracts/std_lib_string/Forc.toml b/e2e/sway/types/contracts/std_lib_string/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/std_lib_string/Forc.toml rename to e2e/sway/types/contracts/std_lib_string/Forc.toml diff --git a/packages/fuels/tests/types/contracts/std_lib_string/src/main.sw b/e2e/sway/types/contracts/std_lib_string/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/std_lib_string/src/main.sw rename to e2e/sway/types/contracts/std_lib_string/src/main.sw diff --git a/packages/fuels/tests/types/contracts/str_in_array/Forc.toml b/e2e/sway/types/contracts/str_in_array/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/str_in_array/Forc.toml rename to e2e/sway/types/contracts/str_in_array/Forc.toml diff --git a/packages/fuels/tests/types/contracts/str_in_array/src/main.sw b/e2e/sway/types/contracts/str_in_array/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/str_in_array/src/main.sw rename to e2e/sway/types/contracts/str_in_array/src/main.sw diff --git a/packages/fuels/tests/types/contracts/string_slice/Forc.toml b/e2e/sway/types/contracts/string_slice/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/string_slice/Forc.toml rename to e2e/sway/types/contracts/string_slice/Forc.toml diff --git a/packages/fuels/tests/types/contracts/string_slice/src/main.sw b/e2e/sway/types/contracts/string_slice/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/string_slice/src/main.sw rename to e2e/sway/types/contracts/string_slice/src/main.sw diff --git a/packages/fuels/tests/types/contracts/tuples/Forc.toml b/e2e/sway/types/contracts/tuples/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/tuples/Forc.toml rename to e2e/sway/types/contracts/tuples/Forc.toml diff --git a/packages/fuels/tests/types/contracts/tuples/src/main.sw b/e2e/sway/types/contracts/tuples/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/tuples/src/main.sw rename to e2e/sway/types/contracts/tuples/src/main.sw diff --git a/packages/fuels/tests/types/contracts/two_structs/Forc.toml b/e2e/sway/types/contracts/two_structs/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/two_structs/Forc.toml rename to e2e/sway/types/contracts/two_structs/Forc.toml diff --git a/packages/fuels/tests/types/contracts/two_structs/src/main.sw b/e2e/sway/types/contracts/two_structs/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/two_structs/src/main.sw rename to e2e/sway/types/contracts/two_structs/src/main.sw diff --git a/packages/fuels/tests/types/contracts/type_inside_enum/Forc.toml b/e2e/sway/types/contracts/type_inside_enum/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/type_inside_enum/Forc.toml rename to e2e/sway/types/contracts/type_inside_enum/Forc.toml diff --git a/packages/fuels/tests/types/contracts/type_inside_enum/src/main.sw b/e2e/sway/types/contracts/type_inside_enum/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/type_inside_enum/src/main.sw rename to e2e/sway/types/contracts/type_inside_enum/src/main.sw diff --git a/packages/fuels/tests/types/contracts/u128/Forc.toml b/e2e/sway/types/contracts/u128/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/u128/Forc.toml rename to e2e/sway/types/contracts/u128/Forc.toml diff --git a/packages/fuels/tests/types/contracts/u128/src/main.sw b/e2e/sway/types/contracts/u128/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/u128/src/main.sw rename to e2e/sway/types/contracts/u128/src/main.sw diff --git a/packages/fuels/tests/types/contracts/u256/Forc.toml b/e2e/sway/types/contracts/u256/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/u256/Forc.toml rename to e2e/sway/types/contracts/u256/Forc.toml diff --git a/packages/fuels/tests/types/contracts/u256/src/main.sw b/e2e/sway/types/contracts/u256/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/u256/src/main.sw rename to e2e/sway/types/contracts/u256/src/main.sw diff --git a/packages/fuels/tests/types/contracts/vector_output/Forc.toml b/e2e/sway/types/contracts/vector_output/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/vector_output/Forc.toml rename to e2e/sway/types/contracts/vector_output/Forc.toml diff --git a/packages/fuels/tests/types/contracts/vector_output/src/main.sw b/e2e/sway/types/contracts/vector_output/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/vector_output/src/main.sw rename to e2e/sway/types/contracts/vector_output/src/main.sw diff --git a/packages/fuels/tests/types/contracts/vectors/Forc.toml b/e2e/sway/types/contracts/vectors/Forc.toml similarity index 100% rename from packages/fuels/tests/types/contracts/vectors/Forc.toml rename to e2e/sway/types/contracts/vectors/Forc.toml diff --git a/packages/fuels/tests/types/contracts/vectors/src/data_structures.sw b/e2e/sway/types/contracts/vectors/src/data_structures.sw similarity index 100% rename from packages/fuels/tests/types/contracts/vectors/src/data_structures.sw rename to e2e/sway/types/contracts/vectors/src/data_structures.sw diff --git a/packages/fuels/tests/types/contracts/vectors/src/eq_impls.sw b/e2e/sway/types/contracts/vectors/src/eq_impls.sw similarity index 100% rename from packages/fuels/tests/types/contracts/vectors/src/eq_impls.sw rename to e2e/sway/types/contracts/vectors/src/eq_impls.sw diff --git a/packages/fuels/tests/types/contracts/vectors/src/main.sw b/e2e/sway/types/contracts/vectors/src/main.sw similarity index 100% rename from packages/fuels/tests/types/contracts/vectors/src/main.sw rename to e2e/sway/types/contracts/vectors/src/main.sw diff --git a/packages/fuels/tests/types/contracts/vectors/src/utils.sw b/e2e/sway/types/contracts/vectors/src/utils.sw similarity index 100% rename from packages/fuels/tests/types/contracts/vectors/src/utils.sw rename to e2e/sway/types/contracts/vectors/src/utils.sw diff --git a/packages/fuels/tests/types/predicates/address/Forc.toml b/e2e/sway/types/predicates/address/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/address/Forc.toml rename to e2e/sway/types/predicates/address/Forc.toml diff --git a/packages/fuels/tests/types/predicates/address/src/main.sw b/e2e/sway/types/predicates/address/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/address/src/main.sw rename to e2e/sway/types/predicates/address/src/main.sw diff --git a/packages/fuels/tests/types/predicates/enums/Forc.toml b/e2e/sway/types/predicates/enums/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/enums/Forc.toml rename to e2e/sway/types/predicates/enums/Forc.toml diff --git a/packages/fuels/tests/types/predicates/enums/src/main.sw b/e2e/sway/types/predicates/enums/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/enums/src/main.sw rename to e2e/sway/types/predicates/enums/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_b256/Forc.toml b/e2e/sway/types/predicates/predicate_b256/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_b256/Forc.toml rename to e2e/sway/types/predicates/predicate_b256/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_b256/src/main.sw b/e2e/sway/types/predicates/predicate_b256/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_b256/src/main.sw rename to e2e/sway/types/predicates/predicate_b256/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_bytes/Forc.toml b/e2e/sway/types/predicates/predicate_bytes/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_bytes/Forc.toml rename to e2e/sway/types/predicates/predicate_bytes/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_bytes/src/main.sw b/e2e/sway/types/predicates/predicate_bytes/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_bytes/src/main.sw rename to e2e/sway/types/predicates/predicate_bytes/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_bytes_hash/Forc.toml b/e2e/sway/types/predicates/predicate_bytes_hash/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_bytes_hash/Forc.toml rename to e2e/sway/types/predicates/predicate_bytes_hash/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_bytes_hash/src/main.sw b/e2e/sway/types/predicates/predicate_bytes_hash/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_bytes_hash/src/main.sw rename to e2e/sway/types/predicates/predicate_bytes_hash/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_generics/Forc.toml b/e2e/sway/types/predicates/predicate_generics/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_generics/Forc.toml rename to e2e/sway/types/predicates/predicate_generics/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_generics/src/main.sw b/e2e/sway/types/predicates/predicate_generics/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_generics/src/main.sw rename to e2e/sway/types/predicates/predicate_generics/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_raw_slice/Forc.toml b/e2e/sway/types/predicates/predicate_raw_slice/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_raw_slice/Forc.toml rename to e2e/sway/types/predicates/predicate_raw_slice/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_raw_slice/src/main.sw b/e2e/sway/types/predicates/predicate_raw_slice/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_raw_slice/src/main.sw rename to e2e/sway/types/predicates/predicate_raw_slice/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_std_lib_string/Forc.toml b/e2e/sway/types/predicates/predicate_std_lib_string/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_std_lib_string/Forc.toml rename to e2e/sway/types/predicates/predicate_std_lib_string/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_std_lib_string/src/main.sw b/e2e/sway/types/predicates/predicate_std_lib_string/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_std_lib_string/src/main.sw rename to e2e/sway/types/predicates/predicate_std_lib_string/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_tuples/Forc.toml b/e2e/sway/types/predicates/predicate_tuples/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_tuples/Forc.toml rename to e2e/sway/types/predicates/predicate_tuples/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_tuples/src/main.sw b/e2e/sway/types/predicates/predicate_tuples/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_tuples/src/main.sw rename to e2e/sway/types/predicates/predicate_tuples/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_u128/Forc.toml b/e2e/sway/types/predicates/predicate_u128/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_u128/Forc.toml rename to e2e/sway/types/predicates/predicate_u128/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_u128/src/main.sw b/e2e/sway/types/predicates/predicate_u128/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_u128/src/main.sw rename to e2e/sway/types/predicates/predicate_u128/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_u256/Forc.toml b/e2e/sway/types/predicates/predicate_u256/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_u256/Forc.toml rename to e2e/sway/types/predicates/predicate_u256/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_u256/src/main.sw b/e2e/sway/types/predicates/predicate_u256/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_u256/src/main.sw rename to e2e/sway/types/predicates/predicate_u256/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_vector/Forc.toml b/e2e/sway/types/predicates/predicate_vector/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_vector/Forc.toml rename to e2e/sway/types/predicates/predicate_vector/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_vector/src/main.sw b/e2e/sway/types/predicates/predicate_vector/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_vector/src/main.sw rename to e2e/sway/types/predicates/predicate_vector/src/main.sw diff --git a/packages/fuels/tests/types/predicates/predicate_vectors/Forc.toml b/e2e/sway/types/predicates/predicate_vectors/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_vectors/Forc.toml rename to e2e/sway/types/predicates/predicate_vectors/Forc.toml diff --git a/packages/fuels/tests/types/predicates/predicate_vectors/src/main.sw b/e2e/sway/types/predicates/predicate_vectors/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/predicate_vectors/src/main.sw rename to e2e/sway/types/predicates/predicate_vectors/src/main.sw diff --git a/packages/fuels/tests/types/predicates/structs/Forc.toml b/e2e/sway/types/predicates/structs/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/structs/Forc.toml rename to e2e/sway/types/predicates/structs/Forc.toml diff --git a/packages/fuels/tests/types/predicates/structs/src/main.sw b/e2e/sway/types/predicates/structs/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/structs/src/main.sw rename to e2e/sway/types/predicates/structs/src/main.sw diff --git a/packages/fuels/tests/types/predicates/u64/Forc.toml b/e2e/sway/types/predicates/u64/Forc.toml similarity index 100% rename from packages/fuels/tests/types/predicates/u64/Forc.toml rename to e2e/sway/types/predicates/u64/Forc.toml diff --git a/packages/fuels/tests/types/predicates/u64/src/main.sw b/e2e/sway/types/predicates/u64/src/main.sw similarity index 100% rename from packages/fuels/tests/types/predicates/u64/src/main.sw rename to e2e/sway/types/predicates/u64/src/main.sw diff --git a/packages/fuels/tests/types/scripts/options_results/Forc.toml b/e2e/sway/types/scripts/options_results/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/options_results/Forc.toml rename to e2e/sway/types/scripts/options_results/Forc.toml diff --git a/packages/fuels/tests/types/scripts/options_results/src/main.sw b/e2e/sway/types/scripts/options_results/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/options_results/src/main.sw rename to e2e/sway/types/scripts/options_results/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_b256/Forc.toml b/e2e/sway/types/scripts/script_b256/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_b256/Forc.toml rename to e2e/sway/types/scripts/script_b256/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_b256/src/main.sw b/e2e/sway/types/scripts/script_b256/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_b256/src/main.sw rename to e2e/sway/types/scripts/script_b256/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_bytes/Forc.toml b/e2e/sway/types/scripts/script_bytes/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_bytes/Forc.toml rename to e2e/sway/types/scripts/script_bytes/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_bytes/src/main.sw b/e2e/sway/types/scripts/script_bytes/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_bytes/src/main.sw rename to e2e/sway/types/scripts/script_bytes/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_generics/Forc.toml b/e2e/sway/types/scripts/script_generics/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_generics/Forc.toml rename to e2e/sway/types/scripts/script_generics/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_generics/src/main.sw b/e2e/sway/types/scripts/script_generics/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_generics/src/main.sw rename to e2e/sway/types/scripts/script_generics/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_heap_types/Forc.toml b/e2e/sway/types/scripts/script_heap_types/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_heap_types/Forc.toml rename to e2e/sway/types/scripts/script_heap_types/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_heap_types/src/main.sw b/e2e/sway/types/scripts/script_heap_types/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_heap_types/src/main.sw rename to e2e/sway/types/scripts/script_heap_types/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_raw_slice/Forc.toml b/e2e/sway/types/scripts/script_raw_slice/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_raw_slice/Forc.toml rename to e2e/sway/types/scripts/script_raw_slice/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_raw_slice/src/main.sw b/e2e/sway/types/scripts/script_raw_slice/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_raw_slice/src/main.sw rename to e2e/sway/types/scripts/script_raw_slice/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_std_lib_string/Forc.toml b/e2e/sway/types/scripts/script_std_lib_string/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_std_lib_string/Forc.toml rename to e2e/sway/types/scripts/script_std_lib_string/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_std_lib_string/src/main.sw b/e2e/sway/types/scripts/script_std_lib_string/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_std_lib_string/src/main.sw rename to e2e/sway/types/scripts/script_std_lib_string/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_tuples/Forc.toml b/e2e/sway/types/scripts/script_tuples/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_tuples/Forc.toml rename to e2e/sway/types/scripts/script_tuples/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_tuples/src/main.sw b/e2e/sway/types/scripts/script_tuples/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_tuples/src/main.sw rename to e2e/sway/types/scripts/script_tuples/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_u128/Forc.toml b/e2e/sway/types/scripts/script_u128/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_u128/Forc.toml rename to e2e/sway/types/scripts/script_u128/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_u128/src/main.sw b/e2e/sway/types/scripts/script_u128/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_u128/src/main.sw rename to e2e/sway/types/scripts/script_u128/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_u256/Forc.toml b/e2e/sway/types/scripts/script_u256/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_u256/Forc.toml rename to e2e/sway/types/scripts/script_u256/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_u256/src/main.sw b/e2e/sway/types/scripts/script_u256/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_u256/src/main.sw rename to e2e/sway/types/scripts/script_u256/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_vectors/Forc.toml b/e2e/sway/types/scripts/script_vectors/Forc.toml similarity index 100% rename from packages/fuels/tests/types/scripts/script_vectors/Forc.toml rename to e2e/sway/types/scripts/script_vectors/Forc.toml diff --git a/packages/fuels/tests/types/scripts/script_vectors/src/data_structures.sw b/e2e/sway/types/scripts/script_vectors/src/data_structures.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_vectors/src/data_structures.sw rename to e2e/sway/types/scripts/script_vectors/src/data_structures.sw diff --git a/packages/fuels/tests/types/scripts/script_vectors/src/eq_impls.sw b/e2e/sway/types/scripts/script_vectors/src/eq_impls.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_vectors/src/eq_impls.sw rename to e2e/sway/types/scripts/script_vectors/src/eq_impls.sw diff --git a/packages/fuels/tests/types/scripts/script_vectors/src/main.sw b/e2e/sway/types/scripts/script_vectors/src/main.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_vectors/src/main.sw rename to e2e/sway/types/scripts/script_vectors/src/main.sw diff --git a/packages/fuels/tests/types/scripts/script_vectors/src/utils.sw b/e2e/sway/types/scripts/script_vectors/src/utils.sw similarity index 100% rename from packages/fuels/tests/types/scripts/script_vectors/src/utils.sw rename to e2e/sway/types/scripts/script_vectors/src/utils.sw diff --git a/packages/fuels/tests/bindings.rs b/e2e/tests/bindings.rs similarity index 95% rename from packages/fuels/tests/bindings.rs rename to e2e/tests/bindings.rs index 3533fefa4..a3e013bca 100644 --- a/packages/fuels/tests/bindings.rs +++ b/e2e/tests/bindings.rs @@ -13,7 +13,7 @@ async fn compile_bindings_from_contract_file() { Wallets("wallet"), Abigen(Contract( name = "SimpleContract", - project = "packages/fuels/tests/bindings/simple_contract" + project = "e2e/sway/bindings/simple_contract" )), Deploy( name = "simple_contract_instance", @@ -91,11 +91,11 @@ async fn shared_types() -> Result<()> { Abigen( Contract( name = "ContractA", - project = "packages/fuels/tests/bindings/sharing_types/contract_a" + project = "e2e/sway/bindings/sharing_types/contract_a" ), Contract( name = "ContractB", - project = "packages/fuels/tests/bindings/sharing_types/contract_b" + project = "e2e/sway/bindings/sharing_types/contract_b" ), ), Deploy( @@ -208,7 +208,7 @@ async fn type_paths_respected() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "ContractA", - project = "packages/fuels/tests/bindings/type_paths" + project = "e2e/sway/bindings/type_paths" )), Deploy( name = "contract_a_instance", diff --git a/packages/fuels/tests/configurables.rs b/e2e/tests/configurables.rs similarity index 86% rename from packages/fuels/tests/configurables.rs rename to e2e/tests/configurables.rs index b329979fd..fa3b1affc 100644 --- a/packages/fuels/tests/configurables.rs +++ b/e2e/tests/configurables.rs @@ -1,20 +1,20 @@ use fuels::{ + core::codec::EncoderConfig, prelude::*, types::{Bits256, SizedAsciiString, U256}, }; -use fuels_core::codec::EncoderConfig; #[tokio::test] async fn contract_default_configurables() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/configurables/out/release/configurables-abi.json" + abi = "e2e/sway/contracts/configurables/out/release/configurables-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; let contract_id = Contract::load_from( - "tests/contracts/configurables/out/release/configurables.bin", + "sway/contracts/configurables/out/release/configurables.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -57,7 +57,7 @@ async fn script_default_configurables() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/scripts/script_configurables" + project = "e2e/sway/scripts/script_configurables" )), LoadScript( name = "script_instance", @@ -96,7 +96,7 @@ async fn contract_configurables() -> Result<()> { // ANCHOR: contract_configurables abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/configurables/out/release/configurables-abi.json" + abi = "e2e/sway/contracts/configurables/out/release/configurables-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; @@ -123,7 +123,7 @@ async fn contract_configurables() -> Result<()> { .with_ENUM(new_enum.clone())?; let contract_id = Contract::load_from( - "tests/contracts/configurables/out/release/configurables.bin", + "sway/contracts/configurables/out/release/configurables.bin", LoadConfiguration::default().with_configurables(configurables), )? .deploy(&wallet, TxPolicies::default()) @@ -161,11 +161,13 @@ async fn contract_configurables() -> Result<()> { #[tokio::test] async fn script_configurables() -> Result<()> { // ANCHOR: script_configurables - abigen!(Script(name="MyScript", abi="packages/fuels/tests/scripts/script_configurables/out/release/script_configurables-abi.json")); + abigen!(Script( + name = "MyScript", + abi = "e2e/sway/scripts/script_configurables/out/release/script_configurables-abi.json" + )); let wallet = launch_provider_and_get_wallet().await?; - let bin_path = - "../fuels/tests/scripts/script_configurables/out/release/script_configurables.bin"; + let bin_path = "sway/scripts/script_configurables/out/release/script_configurables.bin"; let instance = MyScript::new(wallet, bin_path); let str_4: SizedAsciiString<4> = "FUEL".try_into()?; @@ -221,7 +223,10 @@ async fn script_configurables() -> Result<()> { #[tokio::test] async fn configurable_encoder_config_is_applied() { - abigen!(Script(name="MyScript", abi="packages/fuels/tests/scripts/script_configurables/out/release/script_configurables-abi.json")); + abigen!(Script( + name = "MyScript", + abi = "e2e/sway/scripts/script_configurables/out/release/script_configurables-abi.json" + )); let new_struct = StructWithGeneric { field_1: 16u8, diff --git a/packages/fuels/tests/contracts.rs b/e2e/tests/contracts.rs similarity index 93% rename from packages/fuels/tests/contracts.rs rename to e2e/tests/contracts.rs index 602bff426..ec78407fc 100644 --- a/packages/fuels/tests/contracts.rs +++ b/e2e/tests/contracts.rs @@ -1,7 +1,7 @@ -use fuel_tx::ContractParameters; use fuels::{ core::codec::{calldata, encode_fn_selector, DecoderConfig, EncoderConfig}, prelude::*, + tx::ContractParameters, types::{errors::transaction::Reason, Bits256, Identity}, }; @@ -11,7 +11,7 @@ async fn test_multiple_args() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -43,11 +43,11 @@ async fn test_contract_calling_contract() -> Result<()> { Abigen( Contract( name = "LibContract", - project = "packages/fuels/tests/contracts/lib_contract" + project = "e2e/sway/contracts/lib_contract" ), Contract( name = "LibContractCaller", - project = "packages/fuels/tests/contracts/lib_contract_caller" + project = "e2e/sway/contracts/lib_contract_caller" ), ), Deploy( @@ -114,7 +114,7 @@ async fn test_reverting_transaction() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "RevertContract", - project = "packages/fuels/tests/contracts/revert_transaction_error" + project = "e2e/sway/contracts/revert_transaction_error" )), Deploy( name = "contract_instance", @@ -143,7 +143,7 @@ async fn test_multiple_read_calls() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "MultiReadContract", - project = "packages/fuels/tests/contracts/multiple_read_calls" + project = "e2e/sway/contracts/multiple_read_calls" )), Deploy( name = "contract_instance", @@ -174,7 +174,7 @@ async fn test_multi_call_beginner() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -207,7 +207,7 @@ async fn test_multi_call_pro() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -262,7 +262,7 @@ async fn test_contract_call_fee_estimation() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -299,7 +299,7 @@ async fn contract_call_has_same_estimated_and_used_gas() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -334,7 +334,7 @@ async fn mult_call_has_same_estimated_and_used_gas() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -372,7 +372,7 @@ async fn contract_method_call_respects_maturity() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "BlockHeightContract", - project = "packages/fuels/tests/contracts/transaction_block_height" + project = "e2e/sway/contracts/transaction_block_height" )), Deploy( name = "contract_instance", @@ -407,7 +407,7 @@ async fn test_auth_msg_sender_from_sdk() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "AuthContract", - project = "packages/fuels/tests/contracts/auth_testing_contract" + project = "e2e/sway/contracts/auth_testing_contract" )), Deploy( name = "contract_instance", @@ -433,7 +433,7 @@ async fn test_large_return_data() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/large_return_data" + project = "e2e/sway/contracts/large_return_data" )), Deploy( name = "contract_instance", @@ -490,7 +490,7 @@ async fn can_handle_function_called_new() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -513,11 +513,11 @@ async fn test_contract_setup_macro_deploy_with_salt() -> Result<()> { Abigen( Contract( name = "LibContract", - project = "packages/fuels/tests/contracts/lib_contract" + project = "e2e/sway/contracts/lib_contract" ), Contract( name = "LibContractCaller", - project = "packages/fuels/tests/contracts/lib_contract_caller" + project = "e2e/sway/contracts/lib_contract_caller" ), ), Deploy( @@ -574,7 +574,7 @@ async fn test_wallet_getter() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -601,7 +601,7 @@ async fn test_connect_wallet() -> Result<()> { setup_program_test!( Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -655,7 +655,7 @@ async fn setup_output_variable_estimation_test() -> Result<( let wallets = launch_custom_provider_and_get_wallets(wallet_config, None, None).await?; let contract_id = Contract::load_from( - "tests/contracts/token_ops/out/release/token_ops.bin", + "sway/contracts/token_ops/out/release/token_ops.bin", LoadConfiguration::default(), )? .deploy(&wallets[0], TxPolicies::default()) @@ -676,7 +676,7 @@ async fn setup_output_variable_estimation_test() -> Result<( async fn test_output_variable_estimation() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/token_ops/out/release/token_ops-abi.json" + abi = "e2e/sway/contracts/token_ops/out/release/token_ops-abi.json" )); let (wallets, addresses, mint_asset_id, contract_id) = @@ -734,7 +734,7 @@ async fn test_output_variable_estimation() -> Result<()> { async fn test_output_variable_estimation_default_attempts() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/token_ops/out/release/token_ops-abi.json" + abi = "e2e/sway/contracts/token_ops/out/release/token_ops-abi.json" )); let (wallets, addresses, mint_asset_id, contract_id) = @@ -763,7 +763,7 @@ async fn test_output_variable_estimation_default_attempts() -> Result<()> { async fn test_output_variable_estimation_multicall() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/token_ops/out/release/token_ops-abi.json" + abi = "e2e/sway/contracts/token_ops/out/release/token_ops-abi.json" )); let (wallets, addresses, mint_asset_id, contract_id) = @@ -821,7 +821,7 @@ async fn test_contract_instance_get_balances() -> Result<()> { setup_program_test!( Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -865,7 +865,7 @@ async fn contract_call_futures_implement_send() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -892,11 +892,11 @@ async fn test_contract_set_estimation() -> Result<()> { Abigen( Contract( name = "LibContract", - project = "packages/fuels/tests/contracts/lib_contract" + project = "e2e/sway/contracts/lib_contract" ), Contract( name = "LibContractCaller", - project = "packages/fuels/tests/contracts/lib_contract_caller" + project = "e2e/sway/contracts/lib_contract_caller" ), ), Deploy( @@ -948,15 +948,15 @@ async fn test_output_variable_contract_id_estimation_multicall() -> Result<()> { Abigen( Contract( name = "LibContract", - project = "packages/fuels/tests/contracts/lib_contract" + project = "e2e/sway/contracts/lib_contract" ), Contract( name = "LibContractCaller", - project = "packages/fuels/tests/contracts/lib_contract_caller" + project = "e2e/sway/contracts/lib_contract_caller" ), Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" ), ), Deploy( @@ -1040,7 +1040,7 @@ async fn test_contract_call_with_non_default_max_input() -> Result<()> { setup_program_test!( Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -1090,7 +1090,7 @@ async fn test_add_custom_assets() -> Result<()> { setup_program_test!( Abigen(Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -1127,7 +1127,7 @@ async fn test_add_custom_assets() -> Result<()> { #[tokio::test] async fn contract_load_error_messages() { { - let binary_path = "tests/contracts/contract_test/out/release/no_file_on_path.bin"; + let binary_path = "sway/contracts/contract_test/out/release/no_file_on_path.bin"; let expected_error = format!("io: file \"{binary_path}\" does not exist"); let error = Contract::load_from(binary_path, LoadConfiguration::default()) @@ -1136,7 +1136,7 @@ async fn contract_load_error_messages() { assert_eq!(error.to_string(), expected_error); } { - let binary_path = "tests/contracts/contract_test/out/release/contract_test-abi.json"; + let binary_path = "sway/contracts/contract_test/out/release/contract_test-abi.json"; let expected_error = format!("expected \"{binary_path}\" to have '.bin' extension"); let error = Contract::load_from(binary_path, LoadConfiguration::default()) @@ -1152,7 +1152,7 @@ async fn test_payable_annotation() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/payable_annotation" + project = "e2e/sway/contracts/payable_annotation" )), Deploy( name = "contract_instance", @@ -1201,7 +1201,7 @@ async fn multi_call_from_calls_with_different_account_types() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let wallet = WalletUnlocked::new_random(None); @@ -1233,11 +1233,11 @@ async fn low_level_call() -> Result<()> { Abigen( Contract( name = "MyCallerContract", - project = "packages/fuels/tests/contracts/low_level_caller" + project = "e2e/sway/contracts/low_level_caller" ), Contract( name = "MyTargetContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" ), ), Deploy( @@ -1445,7 +1445,7 @@ async fn can_configure_decoding_of_contract_return() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/needs_custom_decoder" + project = "e2e/sway/contracts/needs_custom_decoder" ),), Deploy( contract = "MyContract", @@ -1506,7 +1506,7 @@ async fn test_contract_submit_and_response() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -1548,11 +1548,11 @@ async fn test_heap_type_multicall() -> Result<()> { Abigen( Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" ), Contract( name = "VectorOutputContract", - project = "packages/fuels/tests/types/contracts/vector_output" + project = "e2e/sway/types/contracts/vector_output" ) ), Deploy( @@ -1597,14 +1597,14 @@ async fn heap_types_correctly_offset_in_create_transactions_w_storage_slots() -> Wallets("wallet"), Abigen(Predicate( name = "MyPredicate", - project = "packages/fuels/tests/types/predicates/predicate_vector" + project = "e2e/sway/types/predicates/predicate_vector" ),), ); let provider = wallet.try_provider()?.clone(); let data = MyPredicateEncoder::default().encode_data(18, 24, vec![2, 4, 42])?; let predicate = Predicate::load_from( - "tests/types/predicates/predicate_vector/out/release/predicate_vector.bin", + "sway/types/predicates/predicate_vector/out/release/predicate_vector.bin", )? .with_data(data) .with_provider(provider); @@ -1622,7 +1622,7 @@ async fn heap_types_correctly_offset_in_create_transactions_w_storage_slots() -> // the offsets were setup correctly since the predicate uses heap types in its arguments. // Storage slots were loaded automatically by default Contract::load_from( - "tests/contracts/storage/out/release/storage.bin", + "sway/contracts/storage/out/release/storage.bin", LoadConfiguration::default(), )? .deploy(&predicate, TxPolicies::default()) @@ -1638,11 +1638,11 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { Abigen( Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" ), Contract( name = "VectorOutputContract", - project = "packages/fuels/tests/types/contracts/vectors" + project = "e2e/sway/types/contracts/vectors" ) ), Deploy( @@ -1701,7 +1701,7 @@ async fn contract_custom_call_build_without_signatures() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -1744,12 +1744,12 @@ async fn contract_encoder_config_is_applied() -> Result<()> { setup_program_test!( Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Wallets("wallet") ); let contract_id = Contract::load_from( - "tests/contracts/contract_test/out/release/contract_test.bin", + "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -1805,7 +1805,7 @@ async fn test_reentrant_calls() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "LibContractCaller", - project = "packages/fuels/tests/contracts/lib_contract_caller" + project = "e2e/sway/contracts/lib_contract_caller" ),), Deploy( name = "contract_caller_instance", @@ -1846,7 +1846,7 @@ async fn msg_sender_gas_estimation_issue() { setup_program_test!( Abigen(Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/msg_methods" + project = "e2e/sway/contracts/msg_methods" )), Deploy( contract = "MyContract", diff --git a/packages/fuels/tests/from_token.rs b/e2e/tests/from_token.rs similarity index 100% rename from packages/fuels/tests/from_token.rs rename to e2e/tests/from_token.rs diff --git a/packages/fuels/tests/imports.rs b/e2e/tests/imports.rs similarity index 100% rename from packages/fuels/tests/imports.rs rename to e2e/tests/imports.rs diff --git a/packages/fuels/tests/logs.rs b/e2e/tests/logs.rs similarity index 93% rename from packages/fuels/tests/logs.rs rename to e2e/tests/logs.rs index 801e93e60..6d5f06d71 100644 --- a/packages/fuels/tests/logs.rs +++ b/e2e/tests/logs.rs @@ -1,7 +1,7 @@ use fuels::{ core::codec::DecoderConfig, prelude::*, - types::{errors::transaction::Reason, Bits256, SizedAsciiString}, + types::{errors::transaction::Reason, AsciiString, Bits256, SizedAsciiString}, }; #[tokio::test] @@ -10,7 +10,7 @@ async fn test_parse_logged_variables() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "LogContract", - project = "packages/fuels/tests/logs/contract_logs" + project = "e2e/sway/logs/contract_logs" )), Deploy( name = "contract_instance", @@ -48,7 +48,7 @@ async fn test_parse_logs_values() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "LogContract", - project = "packages/fuels/tests/logs/contract_logs" + project = "e2e/sway/logs/contract_logs" )), Deploy( name = "contract_instance", @@ -82,7 +82,7 @@ async fn test_parse_logs_custom_types() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "LogContract", - project = "packages/fuels/tests/logs/contract_logs" + project = "e2e/sway/logs/contract_logs" )), Deploy( name = "contract_instance", @@ -122,7 +122,7 @@ async fn test_parse_logs_generic_types() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "LogContract", - project = "packages/fuels/tests/logs/contract_logs" + project = "e2e/sway/logs/contract_logs" )), Deploy( name = "contract_instance", @@ -174,7 +174,7 @@ async fn test_decode_logs() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "LogContract", - project = "packages/fuels/tests/logs/contract_logs" + project = "e2e/sway/logs/contract_logs" )), Deploy( name = "contract_instance", @@ -228,7 +228,7 @@ async fn test_decode_logs_with_no_logs() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -255,7 +255,7 @@ async fn test_multi_call_log_single_contract() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "LogContract", - project = "packages/fuels/tests/logs/contract_logs" + project = "e2e/sway/logs/contract_logs" )), Deploy( name = "contract_instance", @@ -305,7 +305,7 @@ async fn test_multi_call_log_multiple_contracts() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "LogContract", - project = "packages/fuels/tests/logs/contract_logs" + project = "e2e/sway/logs/contract_logs" )), Deploy( name = "contract_instance", @@ -357,13 +357,10 @@ async fn test_multi_call_contract_with_contract_logs() -> Result<()> { setup_program_test!( Wallets("wallet"), Abigen( - Contract( - name = "MyContract", - project = "packages/fuels/tests/logs/contract_logs" - ), + Contract(name = "MyContract", project = "e2e/sway/logs/contract_logs"), Contract( name = "ContractCaller", - project = "packages/fuels/tests/logs/contract_with_contract_logs" + project = "e2e/sway/logs/contract_with_contract_logs" ) ), Deploy( @@ -379,7 +376,7 @@ async fn test_multi_call_contract_with_contract_logs() -> Result<()> { ); let contract_id = Contract::load_from( - "../../packages/fuels/tests/logs/contract_logs/out/release/contract_logs.bin", + "./sway/logs/contract_logs/out/release/contract_logs.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -437,7 +434,7 @@ async fn test_require_log() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "RequireContract", - project = "packages/fuels/tests/contracts/require" + project = "e2e/sway/contracts/require" )), Deploy( name = "contract_instance", @@ -484,7 +481,7 @@ async fn test_multi_call_require_log_single_contract() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "RequireContract", - project = "packages/fuels/tests/contracts/require" + project = "e2e/sway/contracts/require" )), Deploy( name = "contract_instance", @@ -555,7 +552,7 @@ async fn test_multi_call_require_log_multi_contract() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "RequireContract", - project = "packages/fuels/tests/contracts/require" + project = "e2e/sway/contracts/require" )), Deploy( name = "contract_instance", @@ -632,11 +629,11 @@ async fn test_script_decode_logs() -> Result<()> { // ANCHOR: script_logs abigen!(Script( name = "log_script", - abi = "packages/fuels/tests/logs/script_logs/out/release/script_logs-abi.json" + abi = "e2e/sway/logs/script_logs/out/release/script_logs-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; - let bin_path = "../fuels/tests/logs/script_logs/out/release/script_logs.bin"; + let bin_path = "sway/logs/script_logs/out/release/script_logs.bin"; let instance = log_script::new(wallet.clone(), bin_path); let response = instance.main().call().await?; @@ -699,13 +696,10 @@ async fn test_contract_with_contract_logs() -> Result<()> { setup_program_test!( Wallets("wallet"), Abigen( - Contract( - name = "MyContract", - project = "packages/fuels/tests/logs/contract_logs", - ), + Contract(name = "MyContract", project = "e2e/sway/logs/contract_logs",), Contract( name = "ContractCaller", - project = "packages/fuels/tests/logs/contract_with_contract_logs", + project = "e2e/sway/logs/contract_with_contract_logs", ) ), Deploy( @@ -716,7 +710,7 @@ async fn test_contract_with_contract_logs() -> Result<()> { ); let contract_id = Contract::load_from( - "../../packages/fuels/tests/logs/contract_logs/out/release/contract_logs.bin", + "./sway/logs/contract_logs/out/release/contract_logs.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -750,13 +744,10 @@ async fn test_script_logs_with_contract_logs() -> Result<()> { setup_program_test!( Wallets("wallet"), Abigen( - Contract( - name = "MyContract", - project = "packages/fuels/tests/logs/contract_logs", - ), + Contract(name = "MyContract", project = "e2e/sway/logs/contract_logs",), Script( name = "LogScript", - project = "packages/fuels/tests/logs/script_with_contract_logs" + project = "e2e/sway/logs/script_with_contract_logs" ) ), Deploy( @@ -830,7 +821,7 @@ async fn test_script_decode_logs_with_type() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "LogScript", - project = "packages/fuels/tests/logs/script_logs" + project = "e2e/sway/logs/script_logs" )), LoadScript( name = "script_instance", @@ -907,7 +898,7 @@ async fn test_script_require_log() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "LogScript", - project = "packages/fuels/tests/scripts/script_require" + project = "e2e/sway/scripts/script_require" )), LoadScript( name = "script_instance", @@ -957,11 +948,11 @@ async fn test_contract_require_from_contract() -> Result<()> { Abigen( Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/lib_contract", + project = "e2e/sway/contracts/lib_contract", ), Contract( name = "ContractCaller", - project = "packages/fuels/tests/contracts/lib_contract_caller", + project = "e2e/sway/contracts/lib_contract_caller", ) ), Deploy( @@ -972,7 +963,7 @@ async fn test_contract_require_from_contract() -> Result<()> { ); let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/lib_contract/out/release/lib_contract.bin", + "./sway/contracts/lib_contract/out/release/lib_contract.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -1000,15 +991,15 @@ async fn test_multi_call_contract_require_from_contract() -> Result<()> { Abigen( Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/lib_contract", + project = "e2e/sway/contracts/lib_contract", ), Contract( name = "ContractLogs", - project = "packages/fuels/tests/logs/contract_logs", + project = "e2e/sway/logs/contract_logs", ), Contract( name = "ContractCaller", - project = "packages/fuels/tests/contracts/lib_contract_caller", + project = "e2e/sway/contracts/lib_contract_caller", ) ), Deploy( @@ -1024,7 +1015,7 @@ async fn test_multi_call_contract_require_from_contract() -> Result<()> { ); let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/lib_contract/out/release/lib_contract.bin", + "./sway/contracts/lib_contract/out/release/lib_contract.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -1062,11 +1053,11 @@ async fn test_script_require_from_contract() -> Result<()> { Abigen( Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/lib_contract", + project = "e2e/sway/contracts/lib_contract", ), Script( name = "LogScript", - project = "packages/fuels/tests/scripts/require_from_contract" + project = "e2e/sway/scripts/require_from_contract" ) ), Deploy( @@ -1104,7 +1095,7 @@ async fn test_contract_asserts_log() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "LogContract", - project = "packages/fuels/tests/contracts/asserts" + project = "e2e/sway/contracts/asserts" )), Deploy( name = "contract_instance", @@ -1197,7 +1188,7 @@ async fn test_script_asserts_log() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "LogScript", - project = "packages/fuels/tests/scripts/script_asserts" + project = "e2e/sway/scripts/script_asserts" )), LoadScript( name = "script_instance", @@ -1296,7 +1287,7 @@ async fn contract_token_ops_error_messages() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/token_ops" + project = "e2e/sway/contracts/token_ops" )), Deploy( name = "contract_instance", @@ -1336,7 +1327,7 @@ async fn test_log_results() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "MyContract", - project = "packages/fuels/tests/logs/contract_logs" + project = "e2e/sway/logs/contract_logs" ),), Deploy( contract = "MyContract", @@ -1374,7 +1365,7 @@ async fn can_configure_decoder_for_contract_log_decoding() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/needs_custom_decoder" + project = "e2e/sway/contracts/needs_custom_decoder" ),), Deploy( contract = "MyContract", @@ -1464,7 +1455,7 @@ async fn can_configure_decoder_for_script_log_decoding() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "LogScript", - project = "packages/fuels/tests/logs/script_needs_custom_decoder_logging" + project = "e2e/sway/logs/script_needs_custom_decoder_logging" )), LoadScript( name = "script_instance", @@ -1514,13 +1505,11 @@ async fn can_configure_decoder_for_script_log_decoding() -> Result<()> { #[tokio::test] async fn contract_heap_log() -> Result<()> { - use fuels_core::types::AsciiString; - setup_program_test!( Wallets("wallet"), Abigen(Contract( name = "MyContract", - project = "packages/fuels/tests/logs/contract_logs" + project = "e2e/sway/logs/contract_logs" ),), Deploy( contract = "MyContract", @@ -1572,13 +1561,11 @@ async fn contract_heap_log() -> Result<()> { #[tokio::test] async fn script_heap_log() -> Result<()> { - use fuels_core::types::AsciiString; - setup_program_test!( Wallets("wallet"), Abigen(Script( name = "LogScript", - project = "packages/fuels/tests/logs/script_heap_logs" + project = "e2e/sway/logs/script_heap_logs" )), LoadScript( name = "script_instance", diff --git a/packages/fuels/tests/predicates.rs b/e2e/tests/predicates.rs similarity index 88% rename from packages/fuels/tests/predicates.rs rename to e2e/tests/predicates.rs index c3fac47f3..480cc91c8 100644 --- a/packages/fuels/tests/predicates.rs +++ b/e2e/tests/predicates.rs @@ -117,7 +117,7 @@ async fn transfer_coins_and_messages_to_predicate() -> Result<()> { wallet.set_provider(provider.clone()); let predicate = - Predicate::load_from("tests/predicates/basic_predicate/out/release/basic_predicate.bin")? + Predicate::load_from("sway/predicates/basic_predicate/out/release/basic_predicate.bin")? .with_provider(provider.clone()); wallet @@ -138,14 +138,13 @@ async fn transfer_coins_and_messages_to_predicate() -> Result<()> { async fn spend_predicate_coins_messages_basic() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = - "packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate-abi.json" + abi = "e2e/sway/predicates/basic_predicate/out/release/basic_predicate-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(4097, 4097)?; let mut predicate: Predicate = - Predicate::load_from("tests/predicates/basic_predicate/out/release/basic_predicate.bin")? + Predicate::load_from("sway/predicates/basic_predicate/out/release/basic_predicate.bin")? .with_data(predicate_data); let num_coins = 4; @@ -185,18 +184,18 @@ async fn pay_with_predicate() -> Result<()> { abigen!( Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" ), Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/u64/out/release/u64-abi.json" + abi = "e2e/sway/types/predicates/u64/out/release/u64-abi.json" ) ); let predicate_data = MyPredicateEncoder::default().encode_data(32768)?; let mut predicate: Predicate = - Predicate::load_from("tests/types/predicates/u64/out/release/u64.bin")? + Predicate::load_from("sway/types/predicates/u64/out/release/u64.bin")? .with_data(predicate_data); let num_coins = 4; @@ -208,7 +207,7 @@ async fn pay_with_predicate() -> Result<()> { predicate.set_provider(provider.clone()); let contract_id = Contract::load_from( - "tests/contracts/contract_test/out/release/contract_test.bin", + "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&predicate, TxPolicies::default()) @@ -248,19 +247,19 @@ async fn pay_with_predicate_vector_data() -> Result<()> { abigen!( Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" ), Predicate( - name = "MyPredicate", - abi = - "packages/fuels/tests/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" + name = "MyPredicate", + abi = + "e2e/sway/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" ) ); let predicate_data = MyPredicateEncoder::default().encode_data(12, 30, vec![2, 4, 42])?; let mut predicate: Predicate = Predicate::load_from( - "tests/types/predicates/predicate_vector/out/release/predicate_vector.bin", + "sway/types/predicates/predicate_vector/out/release/predicate_vector.bin", )? .with_data(predicate_data); @@ -273,7 +272,7 @@ async fn pay_with_predicate_vector_data() -> Result<()> { predicate.set_provider(provider.clone()); let contract_id = Contract::load_from( - "tests/contracts/contract_test/out/release/contract_test.bin", + "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&predicate, TxPolicies::default()) @@ -312,14 +311,13 @@ async fn pay_with_predicate_vector_data() -> Result<()> { async fn predicate_contract_transfer() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = - "packages/fuels/tests/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" + abi = "e2e/sway/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(2, 40, vec![2, 4, 42])?; let mut predicate: Predicate = Predicate::load_from( - "tests/types/predicates/predicate_vector/out/release/predicate_vector.bin", + "sway/types/predicates/predicate_vector/out/release/predicate_vector.bin", )? .with_data(predicate_data); @@ -332,7 +330,7 @@ async fn predicate_contract_transfer() -> Result<()> { predicate.set_provider(provider.clone()); let contract_id = Contract::load_from( - "tests/contracts/contract_test/out/release/contract_test.bin", + "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&predicate, TxPolicies::default()) @@ -369,14 +367,13 @@ async fn predicate_transfer_to_base_layer() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = - "packages/fuels/tests/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" + abi = "e2e/sway/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(22, 20, vec![2, 4, 42])?; let mut predicate: Predicate = Predicate::load_from( - "tests/types/predicates/predicate_vector/out/release/predicate_vector.bin", + "sway/types/predicates/predicate_vector/out/release/predicate_vector.bin", )? .with_data(predicate_data); @@ -416,14 +413,13 @@ async fn predicate_transfer_to_base_layer() -> Result<()> { async fn predicate_transfer_with_signed_resources() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = - "packages/fuels/tests/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" + abi = "e2e/sway/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(2, 40, vec![2, 4, 42])?; let mut predicate: Predicate = Predicate::load_from( - "tests/types/predicates/predicate_vector/out/release/predicate_vector.bin", + "sway/types/predicates/predicate_vector/out/release/predicate_vector.bin", )? .with_data(predicate_data); @@ -496,19 +492,19 @@ async fn contract_tx_and_call_params_with_predicate() -> Result<()> { abigen!( Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" ), Predicate( - name = "MyPredicate", - abi = - "packages/fuels/tests/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" + name = "MyPredicate", + abi = + "e2e/sway/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" ) ); let predicate_data = MyPredicateEncoder::default().encode_data(22, 20, vec![2, 4, 42])?; let mut predicate: Predicate = Predicate::load_from( - "tests/types/predicates/predicate_vector/out/release/predicate_vector.bin", + "sway/types/predicates/predicate_vector/out/release/predicate_vector.bin", )? .with_data(predicate_data); @@ -521,7 +517,7 @@ async fn contract_tx_and_call_params_with_predicate() -> Result<()> { predicate.set_provider(provider.clone()); let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "./sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&predicate, TxPolicies::default()) @@ -571,19 +567,19 @@ async fn diff_asset_predicate_payment() -> Result<()> { abigen!( Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" ), Predicate( - name = "MyPredicate", - abi = - "packages/fuels/tests/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" + name = "MyPredicate", + abi = + "e2e/sway/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" ) ); let predicate_data = MyPredicateEncoder::default().encode_data(28, 14, vec![2, 4, 42])?; let mut predicate: Predicate = Predicate::load_from( - "tests/types/predicates/predicate_vector/out/release/predicate_vector.bin", + "sway/types/predicates/predicate_vector/out/release/predicate_vector.bin", )? .with_data(predicate_data); @@ -596,7 +592,7 @@ async fn diff_asset_predicate_payment() -> Result<()> { predicate.set_provider(provider.clone()); let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "./sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&predicate, TxPolicies::default()) @@ -621,7 +617,7 @@ async fn diff_asset_predicate_payment() -> Result<()> { async fn predicate_default_configurables() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/predicates/predicate_configurables/out/release/predicate_configurables-abi.json" + abi = "e2e/sway/predicates/predicate_configurables/out/release/predicate_configurables-abi.json" )); let new_struct = StructWithGeneric { @@ -634,7 +630,7 @@ async fn predicate_default_configurables() -> Result<()> { MyPredicateEncoder::default().encode_data(true, 8, new_struct, new_enum)?; let mut predicate: Predicate = Predicate::load_from( - "tests/predicates/predicate_configurables/out/release/predicate_configurables.bin", + "sway/predicates/predicate_configurables/out/release/predicate_configurables.bin", )? .with_data(predicate_data); @@ -675,7 +671,7 @@ async fn predicate_configurables() -> Result<()> { // ANCHOR: predicate_configurables abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/predicates/predicate_configurables/out/release/predicate_configurables-abi.json" + abi = "e2e/sway/predicates/predicate_configurables/out/release/predicate_configurables-abi.json" )); let new_struct = StructWithGeneric { @@ -693,7 +689,7 @@ async fn predicate_configurables() -> Result<()> { MyPredicateEncoder::default().encode_data(true, 8u8, new_struct, new_enum)?; let mut predicate: Predicate = Predicate::load_from( - "tests/predicates/predicate_configurables/out/release/predicate_configurables.bin", + "sway/predicates/predicate_configurables/out/release/predicate_configurables.bin", )? .with_data(predicate_data) .with_configurables(configurables); @@ -735,14 +731,13 @@ async fn predicate_configurables() -> Result<()> { async fn predicate_adjust_fee_persists_message_w_data() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = - "packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate-abi.json" + abi = "e2e/sway/predicates/basic_predicate/out/release/basic_predicate-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(4097, 4097)?; let mut predicate: Predicate = - Predicate::load_from("tests/predicates/basic_predicate/out/release/basic_predicate.bin")? + Predicate::load_from("sway/predicates/basic_predicate/out/release/basic_predicate.bin")? .with_data(predicate_data); let amount = 1000; @@ -775,14 +770,13 @@ async fn predicate_adjust_fee_persists_message_w_data() -> Result<()> { async fn predicate_transfer_non_base_asset() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = - "packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate-abi.json" + abi = "e2e/sway/predicates/basic_predicate/out/release/basic_predicate-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(32, 32)?; let mut predicate: Predicate = - Predicate::load_from("tests/predicates/basic_predicate/out/release/basic_predicate.bin")? + Predicate::load_from("sway/predicates/basic_predicate/out/release/basic_predicate.bin")? .with_data(predicate_data); let mut wallet = WalletUnlocked::new_random(None); @@ -838,13 +832,13 @@ async fn predicate_transfer_non_base_asset() -> Result<()> { async fn predicate_can_access_manually_added_witnesses() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/predicates/predicate_witnesses/out/release/predicate_witnesses-abi.json" + abi = "e2e/sway/predicates/predicate_witnesses/out/release/predicate_witnesses-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(0, 1)?; let mut predicate: Predicate = Predicate::load_from( - "tests/predicates/predicate_witnesses/out/release/predicate_witnesses.bin", + "sway/predicates/predicate_witnesses/out/release/predicate_witnesses.bin", )? .with_data(predicate_data); @@ -904,13 +898,13 @@ async fn predicate_can_access_manually_added_witnesses() -> Result<()> { async fn tx_id_not_changed_after_adding_witnesses() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/predicates/predicate_witnesses/out/release/predicate_witnesses-abi.json" + abi = "e2e/sway/predicates/predicate_witnesses/out/release/predicate_witnesses-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(0, 1)?; let mut predicate: Predicate = Predicate::load_from( - "tests/predicates/predicate_witnesses/out/release/predicate_witnesses.bin", + "sway/predicates/predicate_witnesses/out/release/predicate_witnesses.bin", )? .with_data(predicate_data); @@ -958,8 +952,7 @@ async fn tx_id_not_changed_after_adding_witnesses() -> Result<()> { async fn predicate_encoder_config_is_applied() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = - "packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate-abi.json" + abi = "e2e/sway/predicates/basic_predicate/out/release/basic_predicate-abi.json" )); { let _encoding_ok = MyPredicateEncoder::default() @@ -1014,11 +1007,9 @@ async fn predicate_validation() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = - "packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate-abi.json" + abi = "e2e/sway/predicates/basic_predicate/out/release/basic_predicate-abi.json" )); - let code_path = - "../../packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate.bin"; + let code_path = "./sway/predicates/basic_predicate/out/release/basic_predicate.bin"; // the predicate evaluates to true if the two arguments are equal let correct_predicate_data = MyPredicateEncoder::default().encode_data(4096, 4096)?; diff --git a/packages/fuels/tests/providers.rs b/e2e/tests/providers.rs similarity index 95% rename from packages/fuels/tests/providers.rs rename to e2e/tests/providers.rs index 1fa744b23..b4764cd39 100644 --- a/packages/fuels/tests/providers.rs +++ b/e2e/tests/providers.rs @@ -1,7 +1,6 @@ use std::ops::Add; use chrono::{DateTime, Duration, TimeZone, Utc}; -use fuel_core::chain_config::StateConfig; use fuels::{ accounts::Account, client::{PageDirection, PaginationRequest}, @@ -22,7 +21,7 @@ use fuels::{ async fn test_provider_launch_and_connect() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let mut wallet = WalletUnlocked::new_random(None); @@ -37,7 +36,7 @@ async fn test_provider_launch_and_connect() -> Result<()> { wallet.set_provider(provider.clone()); let contract_id = Contract::load_from( - "tests/contracts/contract_test/out/release/contract_test.bin", + "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -68,7 +67,7 @@ async fn test_provider_launch_and_connect() -> Result<()> { async fn test_network_error() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let mut wallet = WalletUnlocked::new_random(None); @@ -85,7 +84,7 @@ async fn test_network_error() -> Result<()> { service.stop().await.unwrap(); let response = Contract::load_from( - "tests/contracts/contract_test/out/release/contract_test.bin", + "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -127,7 +126,7 @@ async fn test_input_message() -> Result<()> { setup_program_test!( Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -172,11 +171,11 @@ async fn test_input_message_pays_fee() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let contract_id = Contract::load_from( - "tests/contracts/contract_test/out/release/contract_test.bin", + "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -279,7 +278,7 @@ async fn can_retrieve_latest_block_time() -> Result<()> { #[tokio::test] async fn contract_deployment_respects_maturity() -> Result<()> { - abigen!(Contract(name="MyContract", abi="packages/fuels/tests/contracts/transaction_block_height/out/release/transaction_block_height-abi.json")); + abigen!(Contract(name="MyContract", abi="e2e/sway/contracts/transaction_block_height/out/release/transaction_block_height-abi.json")); let wallets = launch_custom_provider_and_get_wallets(WalletsConfig::default(), None, None).await?; @@ -288,7 +287,7 @@ async fn contract_deployment_respects_maturity() -> Result<()> { let deploy_w_maturity = |maturity| { Contract::load_from( - "tests/contracts/transaction_block_height/out/release/transaction_block_height.bin", + "sway/contracts/transaction_block_height/out/release/transaction_block_height.bin", LoadConfiguration::default(), ) .map(|loaded_contract| { @@ -319,7 +318,7 @@ async fn test_gas_forwarded_defaults_to_tx_limit() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -357,7 +356,7 @@ async fn test_amount_and_asset_forwarding() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TokenContract", - project = "packages/fuels/tests/contracts/token_ops" + project = "e2e/sway/contracts/token_ops" )), Deploy( name = "contract_instance", @@ -468,7 +467,7 @@ async fn test_gas_errors() -> Result<()> { setup_program_test!( Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -520,7 +519,7 @@ async fn test_call_param_gas_errors() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -562,7 +561,7 @@ async fn test_get_gas_used() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -709,7 +708,7 @@ async fn test_sway_timestamp() -> Result<()> { setup_program_test!( Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/block_timestamp" + project = "e2e/sway/contracts/block_timestamp" )), Deploy( name = "contract_instance", @@ -870,7 +869,7 @@ async fn can_fetch_mint_transactions() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", diff --git a/packages/fuels/tests/scripts.rs b/e2e/tests/scripts.rs similarity index 90% rename from packages/fuels/tests/scripts.rs rename to e2e/tests/scripts.rs index 728e26f36..56b597163 100644 --- a/packages/fuels/tests/scripts.rs +++ b/e2e/tests/scripts.rs @@ -1,8 +1,8 @@ use fuels::{ core::codec::{DecoderConfig, EncoderConfig}, prelude::*, + types::Identity, }; -use fuels_core::types::Identity; #[tokio::test] async fn main_function_arguments() -> Result<()> { @@ -10,10 +10,10 @@ async fn main_function_arguments() -> Result<()> { // The abigen is used for the same purpose as with contracts (Rust bindings) abigen!(Script( name = "MyScript", - abi = "packages/fuels/tests/scripts/arguments/out/release/arguments-abi.json" + abi = "e2e/sway/scripts/arguments/out/release/arguments-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; - let bin_path = "../fuels/tests/scripts/arguments/out/release/arguments.bin"; + let bin_path = "sway/scripts/arguments/out/release/arguments.bin"; let script_instance = MyScript::new(wallet, bin_path); let bim = Bimbam { val: 90 }; @@ -36,7 +36,7 @@ async fn script_call_has_same_estimated_and_used_gas() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/scripts/basic_script" + project = "e2e/sway/scripts/basic_script" )), LoadScript( name = "script_instance", @@ -69,7 +69,7 @@ async fn test_basic_script_with_tx_policies() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "bimbam_script", - project = "packages/fuels/tests/scripts/basic_script" + project = "e2e/sway/scripts/basic_script" )), LoadScript( name = "script_instance", @@ -102,7 +102,7 @@ async fn test_output_variable_estimation() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "transfer_script", - project = "packages/fuels/tests/scripts/transfer_script" + project = "e2e/sway/scripts/transfer_script" )), LoadScript( name = "script_instance", @@ -142,7 +142,7 @@ async fn test_script_struct() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/scripts/script_struct" + project = "e2e/sway/scripts/script_struct" )), LoadScript( name = "script_instance", @@ -167,7 +167,7 @@ async fn test_script_enum() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/scripts/script_enum" + project = "e2e/sway/scripts/script_enum" )), LoadScript( name = "script_instance", @@ -189,7 +189,7 @@ async fn test_script_array() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/scripts/script_array" + project = "e2e/sway/scripts/script_array" )), LoadScript( name = "script_instance", @@ -211,7 +211,7 @@ async fn can_configure_decoder_on_script_call() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/scripts/script_needs_custom_decoder" + project = "e2e/sway/scripts/script_needs_custom_decoder" )), LoadScript( name = "script_instance", @@ -258,7 +258,7 @@ async fn test_script_submit_and_response() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/scripts/script_struct" + project = "e2e/sway/scripts/script_struct" )), LoadScript( name = "script_instance", @@ -287,7 +287,7 @@ async fn test_script_transaction_builder() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/scripts/basic_script" + project = "e2e/sway/scripts/basic_script" )), LoadScript( name = "script_instance", @@ -324,10 +324,10 @@ async fn test_script_transaction_builder() -> Result<()> { async fn script_encoder_config_is_applied() { abigen!(Script( name = "MyScript", - abi = "packages/fuels/tests/scripts/basic_script/out/release/basic_script-abi.json" + abi = "e2e/sway/scripts/basic_script/out/release/basic_script-abi.json" )); let wallet = launch_provider_and_get_wallet().await.expect(""); - let bin_path = "../fuels/tests/scripts/basic_script/out/release/basic_script.bin"; + let bin_path = "sway/scripts/basic_script/out/release/basic_script.bin"; let script_instance_without_encoder_config = MyScript::new(wallet.clone(), bin_path); { diff --git a/packages/fuels/tests/storage.rs b/e2e/tests/storage.rs similarity index 85% rename from packages/fuels/tests/storage.rs rename to e2e/tests/storage.rs index 6d7719a62..290ebdd0b 100644 --- a/packages/fuels/tests/storage.rs +++ b/e2e/tests/storage.rs @@ -10,7 +10,7 @@ use fuels::{ async fn test_storage_initialization() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/storage/out/release/storage-abi.json" + abi = "e2e/sway/contracts/storage/out/release/storage-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; @@ -22,7 +22,7 @@ async fn test_storage_initialization() -> Result<()> { let storage_configuration = StorageConfiguration::default().add_slot_overrides(storage_vec); let contract_id = Contract::load_from( - "tests/contracts/storage/out/release/storage.bin", + "sway/contracts/storage/out/release/storage.bin", LoadConfiguration::default().with_storage_configuration(storage_configuration), )? .deploy(&wallet, TxPolicies::default()) @@ -45,13 +45,13 @@ async fn test_storage_initialization() -> Result<()> { async fn test_init_storage_automatically() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/storage/out/release/storage-abi.json" + abi = "e2e/sway/contracts/storage/out/release/storage-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; let contract_id = Contract::load_from( - "tests/contracts/storage/out/release/storage.bin", + "sway/contracts/storage/out/release/storage.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -85,7 +85,7 @@ async fn test_init_storage_automatically() -> Result<()> { #[tokio::test] async fn storage_load_error_messages() { { - let json_path = "tests/contracts/storage/out/release/no_file_on_path.json"; + let json_path = "sway/contracts/storage/out/release/no_file_on_path.json"; let expected_error = format!("io: file \"{json_path}\" does not exist"); let error = StorageConfiguration::default() @@ -95,7 +95,7 @@ async fn storage_load_error_messages() { assert_eq!(error.to_string(), expected_error); } { - let json_path = "tests/contracts/storage/out/release/storage.bin"; + let json_path = "sway/contracts/storage/out/release/storage.bin"; let expected_error = format!("expected \"{json_path}\" to have '.json' extension"); let error = StorageConfiguration::default() diff --git a/packages/fuels/tests/types_contracts.rs b/e2e/tests/types_contracts.rs similarity index 94% rename from packages/fuels/tests/types_contracts.rs rename to e2e/tests/types_contracts.rs index b975a8a40..32dac786f 100644 --- a/packages/fuels/tests/types_contracts.rs +++ b/e2e/tests/types_contracts.rs @@ -17,7 +17,7 @@ async fn test_methods_typeless_argument() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/empty_arguments" + project = "e2e/sway/types/contracts/empty_arguments" )), Deploy( name = "contract_instance", @@ -43,7 +43,7 @@ async fn call_with_empty_return() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/types/contracts/call_empty_return" + project = "e2e/sway/types/contracts/call_empty_return" )), Deploy( name = "contract_instance", @@ -62,7 +62,7 @@ async fn call_with_structs() -> Result<()> { // The generated bindings can be accessed through `MyContract`. // ANCHOR: struct_generation abigen!(Contract(name="MyContract", - abi="packages/fuels/tests/types/contracts/complex_types_contract/out/release/complex_types_contract-abi.json")); + abi="e2e/sway/types/contracts/complex_types_contract/out/release/complex_types_contract-abi.json")); // Here we can use `CounterConfig`, a struct originally // defined in the contract. @@ -75,7 +75,7 @@ async fn call_with_structs() -> Result<()> { let wallet = launch_provider_and_get_wallet().await?; let contract_id = Contract::load_from( - "tests/types/contracts/complex_types_contract/out/release/complex_types_contract.bin", + "sway/types/contracts/complex_types_contract/out/release/complex_types_contract.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -103,7 +103,7 @@ async fn abigen_different_structs_same_arg_name() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/two_structs" + project = "e2e/sway/types/contracts/two_structs" )), Deploy( name = "contract_instance", @@ -132,7 +132,7 @@ async fn nested_structs() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/nested_structs" + project = "e2e/sway/types/contracts/nested_structs" )), Deploy( name = "contract_instance", @@ -189,7 +189,7 @@ async fn calls_with_empty_struct() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/complex_types_contract" + project = "e2e/sway/types/contracts/complex_types_contract" )), Deploy( name = "contract_instance", @@ -220,7 +220,7 @@ async fn calls_with_empty_struct() -> Result<()> { async fn can_use_try_into_to_construct_struct_from_bytes() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/types/contracts/enum_inside_struct/out/release\ + abi = "e2e/sway/types/contracts/enum_inside_struct/out/release\ /enum_inside_struct-abi.json" )); let cocktail_in_bytes: Vec = vec![ @@ -252,7 +252,7 @@ async fn test_tuples() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/tuples" + project = "e2e/sway/types/contracts/tuples" )), Deploy( name = "contract_instance", @@ -326,7 +326,7 @@ async fn test_evm_address() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/evm_address" + project = "e2e/sway/types/contracts/evm_address" )), Deploy( name = "contract_instance", @@ -393,7 +393,7 @@ async fn test_array() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -420,7 +420,7 @@ async fn test_arrays_with_custom_types() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -462,7 +462,7 @@ async fn str_in_array() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/str_in_array" + project = "e2e/sway/types/contracts/str_in_array" )), Deploy( name = "contract_instance", @@ -502,7 +502,7 @@ async fn test_enum_inside_struct() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/enum_inside_struct" + project = "e2e/sway/types/contracts/enum_inside_struct" )), Deploy( name = "contract_instance", @@ -544,7 +544,7 @@ async fn native_types_support() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/native_types" + project = "e2e/sway/types/contracts/native_types" )), Deploy( name = "contract_instance", @@ -582,7 +582,7 @@ async fn enum_coding_w_variable_width_variants() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/enum_encoding" + project = "e2e/sway/types/contracts/enum_encoding" )), Deploy( name = "contract_instance", @@ -623,7 +623,7 @@ async fn enum_coding_w_unit_enums() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/enum_encoding" + project = "e2e/sway/types/contracts/enum_encoding" )), Deploy( name = "contract_instance", @@ -662,7 +662,7 @@ async fn enum_as_input() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/enum_as_input" + project = "e2e/sway/types/contracts/enum_as_input" )), Deploy( name = "contract_instance", @@ -711,7 +711,7 @@ async fn enum_as_input() -> Result<()> { async fn can_use_try_into_to_construct_enum_from_bytes() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/types/contracts/enum_inside_struct/out/release\ + abi = "e2e/sway/types/contracts/enum_inside_struct/out/release\ /enum_inside_struct-abi.json" )); let shaker_in_bytes: Vec = vec![0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2]; @@ -738,7 +738,7 @@ async fn type_inside_enum() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/type_inside_enum" + project = "e2e/sway/types/contracts/type_inside_enum" )), Deploy( name = "contract_instance", @@ -1086,7 +1086,7 @@ async fn test_rust_option_can_be_decoded() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/options" + project = "e2e/sway/types/contracts/options" )), Deploy( name = "contract_instance", @@ -1138,7 +1138,7 @@ async fn test_rust_option_can_be_encoded() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/options" + project = "e2e/sway/types/contracts/options" )), Deploy( name = "contract_instance", @@ -1192,7 +1192,7 @@ async fn test_rust_result_can_be_decoded() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/results" + project = "e2e/sway/types/contracts/results" )), Deploy( name = "contract_instance", @@ -1244,7 +1244,7 @@ async fn test_rust_result_can_be_encoded() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/results" + project = "e2e/sway/types/contracts/results" )), Deploy( name = "contract_instance", @@ -1279,7 +1279,7 @@ async fn test_identity_can_be_decoded() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/identity" + project = "e2e/sway/types/contracts/identity" )), Deploy( name = "contract_instance", @@ -1324,7 +1324,7 @@ async fn test_identity_can_be_encoded() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/identity" + project = "e2e/sway/types/contracts/identity" )), Deploy( name = "contract_instance", @@ -1372,7 +1372,7 @@ async fn test_identity_with_two_contracts() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/identity" + project = "e2e/sway/types/contracts/identity" )), Deploy( name = "contract_instance", @@ -1417,7 +1417,7 @@ async fn generics_test() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/generics" + project = "e2e/sway/types/contracts/generics" )), Deploy( name = "contract_instance", @@ -1552,7 +1552,7 @@ async fn test_vector() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/vectors" + project = "e2e/sway/types/contracts/vectors" )), Deploy( name = "contract_instance", @@ -1639,7 +1639,7 @@ async fn test_b256() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/b256" + project = "e2e/sway/types/contracts/b256" )), Deploy( name = "contract_instance", @@ -1677,7 +1677,7 @@ async fn test_b512() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/b512" + project = "e2e/sway/types/contracts/b512" )), Deploy( name = "contract_instance", @@ -1725,7 +1725,7 @@ async fn test_u128() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/u128" + project = "e2e/sway/types/contracts/u128" )), Deploy( name = "contract_instance", @@ -1777,7 +1777,7 @@ async fn test_u256() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "TypesContract", - project = "packages/fuels/tests/types/contracts/u256" + project = "e2e/sway/types/contracts/u256" )), Deploy( name = "contract_instance", @@ -1814,7 +1814,7 @@ async fn test_base_type_in_vec_output() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "VectorOutputContract", - project = "packages/fuels/tests/types/contracts/vector_output" + project = "e2e/sway/types/contracts/vector_output" )), Deploy( name = "contract_instance", @@ -1853,7 +1853,7 @@ async fn test_composite_types_in_vec_output() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "VectorOutputContract", - project = "packages/fuels/tests/types/contracts/vector_output" + project = "e2e/sway/types/contracts/vector_output" )), Deploy( name = "contract_instance", @@ -1922,7 +1922,7 @@ async fn test_bytes_output() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "BytesOutputContract", - project = "packages/fuels/tests/types/contracts/bytes" + project = "e2e/sway/types/contracts/bytes" )), Deploy( name = "contract_instance", @@ -1945,7 +1945,7 @@ async fn test_bytes_as_input() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "BytesInputContract", - project = "packages/fuels/tests/types/contracts/bytes" + project = "e2e/sway/types/contracts/bytes" )), Deploy( name = "contract_instance", @@ -1981,7 +1981,7 @@ async fn test_contract_raw_slice() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "RawSliceContract", - project = "packages/fuels/tests/types/contracts/raw_slice" + project = "e2e/sway/types/contracts/raw_slice" )), Deploy( name = "contract_instance", @@ -2026,7 +2026,7 @@ async fn test_contract_returning_string_slice() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "StringSliceContract", - project = "packages/fuels/tests/types/contracts/string_slice" + project = "e2e/sway/types/contracts/string_slice" )), Deploy( name = "contract_instance", @@ -2051,7 +2051,7 @@ async fn test_contract_std_lib_string() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "StdLibString", - project = "packages/fuels/tests/types/contracts/std_lib_string" + project = "e2e/sway/types/contracts/std_lib_string" )), Deploy( name = "contract_instance", @@ -2089,7 +2089,7 @@ async fn test_heap_type_in_enums() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "HeapTypeInEnum", - project = "packages/fuels/tests/types/contracts/heap_type_in_enums" + project = "e2e/sway/types/contracts/heap_type_in_enums" )), Deploy( name = "contract_instance", @@ -2201,7 +2201,7 @@ async fn nested_heap_types() -> Result<()> { Wallets("wallet"), Abigen(Contract( name = "HeapTypeInEnum", - project = "packages/fuels/tests/types/contracts/heap_types" + project = "e2e/sway/types/contracts/heap_types" )), Deploy( name = "contract_instance", diff --git a/packages/fuels/tests/types_predicates.rs b/e2e/tests/types_predicates.rs similarity index 76% rename from packages/fuels/tests/types_predicates.rs rename to e2e/tests/types_predicates.rs index c1a515b3f..67dc7cd90 100644 --- a/packages/fuels/tests/types_predicates.rs +++ b/e2e/tests/types_predicates.rs @@ -126,12 +126,12 @@ async fn setup_predicate_test( async fn spend_predicate_coins_messages_single_u64() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/u64/out/release/u64-abi.json" + abi = "e2e/sway/types/predicates/u64/out/release/u64-abi.json" )); let data = MyPredicateEncoder::default().encode_data(32768)?; - assert_predicate_spendable(data, "tests/types/predicates/u64").await?; + assert_predicate_spendable(data, "sway/types/predicates/u64").await?; Ok(()) } @@ -140,7 +140,7 @@ async fn spend_predicate_coins_messages_single_u64() -> Result<()> { async fn spend_predicate_coins_messages_address() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/address/out/release/address-abi.json" + abi = "e2e/sway/types/predicates/address/out/release/address-abi.json" )); let addr: Address = @@ -148,7 +148,7 @@ async fn spend_predicate_coins_messages_address() -> Result<()> { let data = MyPredicateEncoder::default().encode_data(addr)?; - assert_predicate_spendable(data, "tests/types/predicates/address").await?; + assert_predicate_spendable(data, "sway/types/predicates/address").await?; Ok(()) } @@ -157,13 +157,13 @@ async fn spend_predicate_coins_messages_address() -> Result<()> { async fn spend_predicate_coins_messages_enums() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/enums/out/release/enums-abi.json" + abi = "e2e/sway/types/predicates/enums/out/release/enums-abi.json" )); let data = MyPredicateEncoder::default().encode_data(TestEnum::A(32), AnotherTestEnum::B(32))?; - assert_predicate_spendable(data, "tests/types/predicates/enums").await?; + assert_predicate_spendable(data, "sway/types/predicates/enums").await?; Ok(()) } @@ -172,7 +172,7 @@ async fn spend_predicate_coins_messages_enums() -> Result<()> { async fn spend_predicate_coins_messages_structs() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/structs/out/release/structs-abi.json" + abi = "e2e/sway/types/predicates/structs/out/release/structs-abi.json" )); let data = MyPredicateEncoder::default().encode_data( @@ -183,7 +183,7 @@ async fn spend_predicate_coins_messages_structs() -> Result<()> { }, )?; - assert_predicate_spendable(data, "tests/types/predicates/structs").await?; + assert_predicate_spendable(data, "sway/types/predicates/structs").await?; Ok(()) } @@ -192,13 +192,13 @@ async fn spend_predicate_coins_messages_structs() -> Result<()> { async fn spend_predicate_coins_messages_tuple() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/predicate_tuples/out/release/predicate_tuples-abi.json" + abi = "e2e/sway/types/predicates/predicate_tuples/out/release/predicate_tuples-abi.json" )); let data = MyPredicateEncoder::default() .encode_data((16, TestStruct { value: 32 }, TestEnum::Value(64)), 128)?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_tuples").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_tuples").await?; Ok(()) } @@ -207,20 +207,22 @@ async fn spend_predicate_coins_messages_tuple() -> Result<()> { async fn spend_predicate_coins_messages_vector() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = - "packages/fuels/tests/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" + abi = "e2e/sway/types/predicates/predicate_vector/out/release/predicate_vector-abi.json" )); let data = MyPredicateEncoder::default().encode_data(18, 24, vec![2, 4, 42])?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_vector").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_vector").await?; Ok(()) } #[tokio::test] async fn spend_predicate_coins_messages_vectors() -> Result<()> { - abigen!(Predicate(name="MyPredicate", abi="packages/fuels/tests/types/predicates/predicate_vectors/out/release/predicate_vectors-abi.json")); + abigen!(Predicate( + name = "MyPredicate", + abi = "e2e/sway/types/predicates/predicate_vectors/out/release/predicate_vectors-abi.json" + )); let u32_vec = vec![0, 4, 3]; let vec_in_vec = vec![vec![0, 2, 2], vec![0, 1, 2]]; @@ -258,21 +260,25 @@ async fn spend_predicate_coins_messages_vectors() -> Result<()> { vec_in_a_vec_in_a_struct_in_a_vec, )?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_vectors").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_vectors").await?; Ok(()) } #[tokio::test] async fn spend_predicate_coins_messages_generics() -> Result<()> { - abigen!(Predicate(name="MyPredicate", abi="packages/fuels/tests/types/predicates/predicate_generics/out/release/predicate_generics-abi.json")); + abigen!(Predicate( + name = "MyPredicate", + abi = + "e2e/sway/types/predicates/predicate_generics/out/release/predicate_generics-abi.json" + )); let data = MyPredicateEncoder::default().encode_data( GenericStruct { value: 64u8 }, GenericEnum::Generic(GenericStruct { value: 64u16 }), )?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_generics").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_generics").await?; Ok(()) } @@ -281,7 +287,7 @@ async fn spend_predicate_coins_messages_generics() -> Result<()> { async fn spend_predicate_coins_messages_bytes_hash() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/predicate_bytes_hash/out/release/predicate_bytes_hash-abi.json" + abi = "e2e/sway/types/predicates/predicate_bytes_hash/out/release/predicate_bytes_hash-abi.json" )); @@ -295,7 +301,7 @@ async fn spend_predicate_coins_messages_bytes_hash() -> Result<()> { let data = MyPredicateEncoder::default().encode_data(bytes, bits256)?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_bytes_hash").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_bytes_hash").await?; Ok(()) } @@ -304,7 +310,7 @@ async fn spend_predicate_coins_messages_bytes_hash() -> Result<()> { async fn spend_predicate_coins_messages_bytes() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/predicate_bytes/out/release/predicate_bytes-abi.json" + abi = "e2e/sway/types/predicates/predicate_bytes/out/release/predicate_bytes-abi.json" )); let bytes = Bytes(vec![40, 41, 42]); @@ -315,7 +321,7 @@ async fn spend_predicate_coins_messages_bytes() -> Result<()> { let data = MyPredicateEncoder::default().encode_data(wrapper)?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_bytes").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_bytes").await?; Ok(()) } @@ -324,7 +330,7 @@ async fn spend_predicate_coins_messages_bytes() -> Result<()> { async fn spend_predicate_coins_messages_raw_slice() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/predicate_raw_slice/out/release/predicate_raw_slice-abi.json" + abi = "e2e/sway/types/predicates/predicate_raw_slice/out/release/predicate_raw_slice-abi.json" )); let raw_slice = RawSlice(vec![40, 41, 42]); @@ -335,7 +341,7 @@ async fn spend_predicate_coins_messages_raw_slice() -> Result<()> { let data = MyPredicateEncoder::default().encode_data(wrapper)?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_raw_slice").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_raw_slice").await?; Ok(()) } @@ -352,11 +358,11 @@ fn u128_from(parts: (u64, u64)) -> u128 { async fn predicate_handles_u128() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/predicate_u128/out/release/predicate_u128-abi.json" + abi = "e2e/sway/types/predicates/predicate_u128/out/release/predicate_u128-abi.json" )); let data = MyPredicateEncoder::default().encode_data(u128_from((8, 2)))?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_u128").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_u128").await?; Ok(()) } @@ -365,11 +371,11 @@ async fn predicate_handles_u128() -> Result<()> { async fn predicate_handles_b256() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/predicate_b256/out/release/predicate_b256-abi.json" + abi = "e2e/sway/types/predicates/predicate_b256/out/release/predicate_b256-abi.json" )); let data = MyPredicateEncoder::default().encode_data(Bits256([1; 32]))?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_b256").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_b256").await?; Ok(()) } @@ -391,11 +397,11 @@ fn u256_from(parts: (u64, u64, u64, u64)) -> U256 { async fn predicate_handles_u256() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/predicate_u256/out/release/predicate_u256-abi.json" + abi = "e2e/sway/types/predicates/predicate_u256/out/release/predicate_u256-abi.json" )); let data = MyPredicateEncoder::default().encode_data(u256_from((10, 11, 12, 13)))?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_u256").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_u256").await?; Ok(()) } @@ -404,11 +410,11 @@ async fn predicate_handles_u256() -> Result<()> { async fn predicate_handles_std_string() -> Result<()> { abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/types/predicates/predicate_std_lib_string/out/release/predicate_std_lib_string-abi.json" + abi = "e2e/sway/types/predicates/predicate_std_lib_string/out/release/predicate_std_lib_string-abi.json" )); let data = MyPredicateEncoder::default().encode_data(10, 11, String::from("Hello World"))?; - assert_predicate_spendable(data, "tests/types/predicates/predicate_std_lib_string").await?; + assert_predicate_spendable(data, "sway/types/predicates/predicate_std_lib_string").await?; Ok(()) } diff --git a/packages/fuels/tests/types_scripts.rs b/e2e/tests/types_scripts.rs similarity index 91% rename from packages/fuels/tests/types_scripts.rs rename to e2e/tests/types_scripts.rs index 2de55f0a9..dcb00797c 100644 --- a/packages/fuels/tests/types_scripts.rs +++ b/e2e/tests/types_scripts.rs @@ -9,7 +9,7 @@ async fn script_b256() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/types/scripts/script_b256" + project = "e2e/sway/types/scripts/script_b256" )), LoadScript( name = "script_instance", @@ -32,7 +32,7 @@ async fn main_function_generic_arguments() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/types/scripts/script_generics" + project = "e2e/sway/types/scripts/script_generics" )), LoadScript( name = "script_instance", @@ -74,7 +74,7 @@ async fn main_function_option_result() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/types/scripts/options_results" + project = "e2e/sway/types/scripts/options_results" )), LoadScript( name = "script_instance", @@ -108,7 +108,7 @@ async fn main_function_tuple_types() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/types/scripts/script_tuples" + project = "e2e/sway/types/scripts/script_tuples" )), LoadScript( name = "script_instance", @@ -153,7 +153,7 @@ async fn main_function_vector_arguments() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/types/scripts/script_vectors" + project = "e2e/sway/types/scripts/script_vectors" )), LoadScript( name = "script_instance", @@ -214,7 +214,7 @@ async fn main_function_vector_arguments() -> Result<()> { // Wallets("wallet"), // Abigen(Script( // name = "BimBamScript", -// project = "packages/fuels/tests/types/scripts/script_raw_slice", +// project = "e2e/sway/types/scripts/script_raw_slice", // )), // LoadScript( // name = "script_instance", @@ -241,7 +241,7 @@ async fn main_function_bytes_arguments() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "BimBamScript", - project = "packages/fuels/tests/types/scripts/script_bytes", + project = "e2e/sway/types/scripts/script_bytes", )), LoadScript( name = "script_instance", @@ -275,7 +275,7 @@ async fn script_handles_u128() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/types/scripts/script_u128", + project = "e2e/sway/types/scripts/script_u128", )), LoadScript( name = "script_instance", @@ -312,7 +312,7 @@ async fn script_handles_u256() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/types/scripts/script_u256", + project = "e2e/sway/types/scripts/script_u256", )), LoadScript( name = "script_instance", @@ -336,7 +336,7 @@ async fn script_handles_std_string() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/types/scripts/script_std_lib_string", + project = "e2e/sway/types/scripts/script_std_lib_string", )), LoadScript( name = "script_instance", @@ -357,7 +357,7 @@ async fn nested_heap_types() -> Result<()> { Wallets("wallet"), Abigen(Script( name = "MyScript", - project = "packages/fuels/tests/types/scripts/script_heap_types", + project = "e2e/sway/types/scripts/script_heap_types", )), LoadScript( name = "script_instance", diff --git a/packages/fuels/tests/wallets.rs b/e2e/tests/wallets.rs similarity index 99% rename from packages/fuels/tests/wallets.rs rename to e2e/tests/wallets.rs index d329c50ab..8774425a3 100644 --- a/packages/fuels/tests/wallets.rs +++ b/e2e/tests/wallets.rs @@ -1,7 +1,11 @@ use std::iter::repeat; -use fuel_tx::{input::coin::CoinSigned, Bytes32, Input, Output, TxPointer, UtxoId}; -use fuels::prelude::*; +use fuel_tx::{input::coin::CoinSigned, Input}; +use fuels::{ + prelude::*, + tx::{TxPointer, UtxoId}, + types::{output::Output, Bytes32}, +}; #[tokio::test] async fn test_wallet_balance_api_multi_asset() -> Result<()> { diff --git a/examples/contracts/src/lib.rs b/examples/contracts/src/lib.rs index ac4d9010c..6f71274ca 100644 --- a/examples/contracts/src/lib.rs +++ b/examples/contracts/src/lib.rs @@ -41,7 +41,7 @@ mod tests { // This will load and deploy your contract binary to the chain so that its ID can // be used to initialize the instance let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -62,7 +62,7 @@ mod tests { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -89,13 +89,13 @@ mod tests { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -128,7 +128,7 @@ mod tests { let wallet = launch_provider_and_get_wallet().await?; let contract_id_1 = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -158,7 +158,7 @@ mod tests { .with_maturity(0); let contract_id_2 = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", configuration, )? .deploy(&wallet, tx_policies) @@ -176,7 +176,7 @@ mod tests { // ANCHOR: abigen_example abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); // ANCHOR_END: abigen_example @@ -221,14 +221,14 @@ mod tests { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let wallets = launch_custom_provider_and_get_wallets(WalletsConfig::default(), None, None).await?; let contract_id_1 = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallets[0], TxPolicies::default()) @@ -247,7 +247,7 @@ mod tests { assert_eq!(42, response.value); let contract_id_2 = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default().with_salt([1; 32]), )? .deploy(&wallets[1], TxPolicies::default()) @@ -273,13 +273,13 @@ mod tests { use fuels::prelude::*; abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -342,13 +342,13 @@ mod tests { use fuels::prelude::*; abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/token_ops/out/release/token_ops-abi.json" + abi = "e2e/sway/contracts/token_ops/out/release/token_ops-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/token_ops/out/release/token_ops\ + "../../e2e/sway/contracts/token_ops/out/release/token_ops\ .bin", LoadConfiguration::default(), )? @@ -380,22 +380,23 @@ mod tests { #[allow(unused_variables)] async fn dependency_estimation() -> Result<()> { use fuels::prelude::*; - abigen!( - Contract(name="MyContract", - abi="packages/fuels/tests/contracts/lib_contract_caller/out/release/lib_contract_caller-abi.json" + abigen!(Contract( + name = "MyContract", + abi = "e2e/sway/contracts/lib_contract_caller/out/release/lib_contract_caller-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; let called_contract_id: ContractId = Contract::load_from( - "../../packages/fuels/tests/contracts/lib_contract/out/release/lib_contract.bin", + "../../e2e/sway/contracts/lib_contract/out/release/lib_contract.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) .await? .into(); - let bin_path = "../../packages/fuels/tests/contracts/lib_contract_caller/out/release/lib_contract_caller.bin"; + let bin_path = + "../../e2e/sway/contracts/lib_contract_caller/out/release/lib_contract_caller.bin"; let caller_contract_id = Contract::load_from(bin_path, LoadConfiguration::default())? .deploy(&wallet, TxPolicies::default()) .await?; @@ -455,7 +456,7 @@ mod tests { abigen!(Contract( name = "MyContract", // Replace with your contract ABI.json path - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let wallet_original = launch_provider_and_get_wallet().await?; @@ -485,13 +486,13 @@ mod tests { use fuels::prelude::*; abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -523,13 +524,13 @@ mod tests { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -579,13 +580,13 @@ mod tests { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let wallet = launch_provider_and_get_wallet().await?; let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) @@ -623,7 +624,7 @@ mod tests { use fuels::prelude::*; abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json" + abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); let config = WalletsConfig::new(Some(2), Some(1), Some(DEFAULT_COIN_AMOUNT)); @@ -632,7 +633,7 @@ mod tests { let wallet_2 = wallets.pop().unwrap(); let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet_1, TxPolicies::default()) @@ -662,7 +663,7 @@ mod tests { Wallets("wallet"), Abigen(Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -699,11 +700,11 @@ mod tests { Abigen( Contract( name = "MyCallerContract", - project = "packages/fuels/tests/contracts/low_level_caller" + project = "e2e/sway/contracts/low_level_caller" ), Contract( name = "MyTargetContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" ), ), Deploy( @@ -780,7 +781,7 @@ mod tests { Wallets("wallet"), Abigen(Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -841,7 +842,7 @@ mod tests { Wallets("wallet"), Abigen(Contract( name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", @@ -884,7 +885,7 @@ mod tests { Wallets("wallet"), Abigen(Contract( name = "MyContract", - project = "packages/fuels/tests/contracts/contract_test" + project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", diff --git a/examples/cookbook/src/lib.rs b/examples/cookbook/src/lib.rs index 429e67e25..d72bc7221 100644 --- a/examples/cookbook/src/lib.rs +++ b/examples/cookbook/src/lib.rs @@ -28,8 +28,7 @@ mod tests { // ANCHOR: liquidity_abigen abigen!(Contract( name = "MyContract", - abi = - "packages/fuels/tests/contracts/liquidity_pool/out/release/liquidity_pool-abi.json" + abi = "e2e/sway/contracts/liquidity_pool/out/release/liquidity_pool-abi.json" )); // ANCHOR_END: liquidity_abigen @@ -53,7 +52,7 @@ mod tests { // ANCHOR: liquidity_deploy let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/liquidity_pool/out/release/liquidity_pool.bin", + "../../e2e/sway/contracts/liquidity_pool/out/release/liquidity_pool.bin", LoadConfiguration::default(), )? .deploy(wallet, TxPolicies::default()) @@ -226,7 +225,7 @@ mod tests { let mut hot_wallet = WalletUnlocked::new_random(None); let mut cold_wallet = WalletUnlocked::new_random(None); - let code_path = "../../packages/fuels/tests/predicates/swap/out/release/swap.bin"; + let code_path = "../../e2e/sway/predicates/swap/out/release/swap.bin"; let mut predicate = Predicate::load_from(code_path)?; let num_coins = 5; diff --git a/examples/debugging/src/lib.rs b/examples/debugging/src/lib.rs index ecad77466..b00bda830 100644 --- a/examples/debugging/src/lib.rs +++ b/examples/debugging/src/lib.rs @@ -30,11 +30,10 @@ mod tests { fn decoded_debug_matches_rust_debug() -> Result<()> { abigen!(Contract( name = "MyContract", - abi = "packages/fuels/tests/types/contracts/generics/out/release/generics-abi.json" + abi = "e2e/sway/types/contracts/generics/out/release/generics-abi.json" )); - let json_abi_file = - "../../packages/fuels/tests/types/contracts/generics/out/release/generics-abi.json"; + let json_abi_file = "../../e2e/sway/types/contracts/generics/out/release/generics-abi.json"; let abi_file_contents = std::fs::read_to_string(json_abi_file)?; let parsed_abi: ProgramABI = serde_json::from_str(&abi_file_contents)?; diff --git a/examples/macros/src/lib.rs b/examples/macros/src/lib.rs index 80f4c5c79..a888db609 100644 --- a/examples/macros/src/lib.rs +++ b/examples/macros/src/lib.rs @@ -8,10 +8,22 @@ mod tests { fn example_of_abigen_usage() { // ANCHOR: multiple_abigen_program_types abigen!( - Contract(name="ContractA", abi="packages/fuels/tests/bindings/sharing_types/contract_a/out/release/contract_a-abi.json"), - Contract(name="ContractB", abi="packages/fuels/tests/bindings/sharing_types/contract_b/out/release/contract_b-abi.json"), - Script(name="MyScript", abi="packages/fuels/tests/scripts/arguments/out/release/arguments-abi.json"), - Predicate(name="MyPredicateEncoder", abi="packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate-abi.json"), + Contract( + name = "ContractA", + abi = "e2e/sway/bindings/sharing_types/contract_a/out/release/contract_a-abi.json" + ), + Contract( + name = "ContractB", + abi = "e2e/sway/bindings/sharing_types/contract_b/out/release/contract_b-abi.json" + ), + Script( + name = "MyScript", + abi = "e2e/sway/scripts/arguments/out/release/arguments-abi.json" + ), + Predicate( + name = "MyPredicateEncoder", + abi = "e2e/sway/predicates/basic_predicate/out/release/basic_predicate-abi.json" + ), ); // ANCHOR_END: multiple_abigen_program_types } diff --git a/examples/predicates/src/lib.rs b/examples/predicates/src/lib.rs index eea556a61..9aef37678 100644 --- a/examples/predicates/src/lib.rs +++ b/examples/predicates/src/lib.rs @@ -56,12 +56,11 @@ mod tests { // ANCHOR: predicate_load abigen!(Predicate( name = "MyPredicate", - abi = "packages/fuels/tests/predicates/signatures/out/release/signatures-abi.json" + abi = "e2e/sway/predicates/signatures/out/release/signatures-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(signatures)?; - let code_path = - "../../packages/fuels/tests/predicates/signatures/out/release/signatures.bin"; + let code_path = "../../e2e/sway/predicates/signatures/out/release/signatures.bin"; let predicate: Predicate = Predicate::load_from(code_path)? .with_provider(provider) @@ -125,13 +124,15 @@ mod tests { let first_wallet = &wallets[0]; let second_wallet = &wallets[1]; - abigen!(Predicate(name="MyPredicate", abi="packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate-abi.json")); + abigen!(Predicate( + name = "MyPredicate", + abi = "e2e/sway/predicates/basic_predicate/out/release/basic_predicate-abi.json" + )); // ANCHOR_END: predicate_data_setup // ANCHOR: with_predicate_data let predicate_data = MyPredicateEncoder::default().encode_data(4096, 4096)?; - let code_path = - "../../packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate.bin"; + let code_path = "../../e2e/sway/predicates/basic_predicate/out/release/basic_predicate.bin"; let predicate: Predicate = Predicate::load_from(code_path)? .with_provider(first_wallet.try_provider()?.clone()) diff --git a/examples/wallets/src/lib.rs b/examples/wallets/src/lib.rs index 0952dd695..66a46049b 100644 --- a/examples/wallets/src/lib.rs +++ b/examples/wallets/src/lib.rs @@ -175,7 +175,7 @@ mod tests { .unwrap(); let contract_id = Contract::load_from( - "../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin", + "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? .deploy(&wallet, TxPolicies::default()) diff --git a/packages/fuels-accounts/src/predicate.rs b/packages/fuels-accounts/src/predicate.rs index 7983a7878..d27c7d18a 100644 --- a/packages/fuels-accounts/src/predicate.rs +++ b/packages/fuels-accounts/src/predicate.rs @@ -3,6 +3,7 @@ use std::{fmt::Debug, fs}; #[cfg(feature = "std")] use fuels_core::types::{input::Input, AssetId}; use fuels_core::{ + error, types::{bech32::Bech32Address, errors::Result}, Configurables, }; @@ -39,7 +40,12 @@ impl Predicate { } pub fn load_from(file_path: &str) -> Result { - let code = fs::read(file_path)?; + let code = fs::read(file_path).map_err(|e| { + error!( + IO, + "could not read predicate binary {file_path:?}. Reason: {e}" + ) + })?; Ok(Self::from_code(code)) } diff --git a/packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs b/packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs index 18fffa729..0a81a72e7 100644 --- a/packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs +++ b/packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs @@ -50,7 +50,7 @@ pub(crate) fn script_bindings( { pub fn new(account: T, binary_filepath: &str) -> Self { let binary = ::std::fs::read(binary_filepath) - .expect("Could not read from binary filepath"); + .expect(&format!("Could not read binary {binary_filepath:?}")); Self { account, binary, diff --git a/packages/fuels-core/Cargo.toml b/packages/fuels-core/Cargo.toml index a86ee51dd..603d63564 100644 --- a/packages/fuels-core/Cargo.toml +++ b/packages/fuels-core/Cargo.toml @@ -17,10 +17,10 @@ fuel-abi-types = { workspace = true } fuel-asm = { workspace = true } fuel-core-chain-config = { workspace = true } fuel-core-client = { workspace = true, optional = true } +fuel-core-types = { workspace = true } fuel-crypto = { workspace = true } fuel-tx = { workspace = true } fuel-types = { workspace = true, features = ["default"] } -fuel-core-types = { workspace = true } fuel-vm = { workspace = true } fuels-macros = { workspace = true } hex = { workspace = true, features = ["std"] } diff --git a/packages/fuels-core/src/types/errors.rs b/packages/fuels-core/src/types/errors.rs index 58743627b..34812a7d9 100644 --- a/packages/fuels-core/src/types/errors.rs +++ b/packages/fuels-core/src/types/errors.rs @@ -31,7 +31,7 @@ use transaction::Reason; #[derive(Error, Debug)] pub enum Error { #[error("io: {0}")] - IO(#[from] std::io::Error), + IO(String), #[error("codec: {0}")] Codec(String), #[error("transaction {0}")] @@ -42,6 +42,12 @@ pub enum Error { Other(String), } +impl From for Error { + fn from(value: std::io::Error) -> Self { + Self::IO(value.to_string()) + } +} + pub type Result = std::result::Result; /// This macro can only be used for `Error` variants that have a `String` field. diff --git a/packages/fuels-programs/src/contract.rs b/packages/fuels-programs/src/contract.rs index cff116588..e49cb62e6 100644 --- a/packages/fuels-programs/src/contract.rs +++ b/packages/fuels-programs/src/contract.rs @@ -17,7 +17,7 @@ use fuels_core::{ traits::{Parameterize, Tokenizable}, types::{ bech32::{Bech32Address, Bech32ContractId}, - errors::{error, Error, Result}, + errors::{error, Result}, param_types::ParamType, transaction::{ScriptTransaction, Transaction, TxPolicies}, transaction_builders::{CreateTransactionBuilder, ScriptTransactionBuilder}, @@ -381,10 +381,7 @@ fn expected_storage_slots_filepath(contract_binary: &Path) -> Option { fn validate_path_and_extension(file_path: &Path, extension: &str) -> Result<()> { if !file_path.exists() { - return Err(Error::IO(io::Error::new( - io::ErrorKind::NotFound, - format!("file {file_path:?} does not exist"), - ))); + return Err(error!(IO, "file {file_path:?} does not exist")); } let path_extension = file_path @@ -951,6 +948,7 @@ where mod tests { use std::collections::HashSet; + use fuels_core::types::errors::Error; use tempfile::tempdir; use super::*; diff --git a/packages/fuels-test-helpers/src/fuel_bin_service.rs b/packages/fuels-test-helpers/src/fuel_bin_service.rs index bfa9c0dd4..a28c6dc24 100644 --- a/packages/fuels-test-helpers/src/fuel_bin_service.rs +++ b/packages/fuels-test-helpers/src/fuel_bin_service.rs @@ -116,7 +116,12 @@ impl FuelService { let bound_address = match requested_port { 0 => get_socket_address()?, _ if is_free(requested_port) => node_config.addr, - _ => return Err(Error::IO(std::io::ErrorKind::AddrInUse.into())), + _ => { + return Err(error!( + IO, + "could not find a free port to start a fuel node" + )) + } }; let node_config = NodeConfig { diff --git a/packages/fuels/Cargo.toml b/packages/fuels/Cargo.toml index 4a213e9a6..c111aec62 100644 --- a/packages/fuels/Cargo.toml +++ b/packages/fuels/Cargo.toml @@ -24,19 +24,6 @@ fuels-macros = { workspace = true } fuels-programs = { workspace = true, optional = true } fuels-test-helpers = { workspace = true, optional = true } -[dev-dependencies] -chrono = { workspace = true } -fuel-core = { workspace = true, default-features = false } -fuel-core-types = { workspace = true } -fuels-code-gen = { workspace = true } -fuels-test-helpers = { workspace = true } -hex = { workspace = true, default-features = false } -rand = { workspace = true } -sha2 = { workspace = true } -tempfile = { workspace = true } -tokio = { workspace = true, features = ["time", "test-util"] } -tai64 = { workspace = true } - [features] default = ["std", "fuels-test-helpers?/fuels-accounts", "coin-cache"] coin-cache = ["fuels-accounts/coin-cache"] diff --git a/packages/fuels/Forc.toml b/packages/fuels/Forc.toml deleted file mode 100644 index 4db2bab6a..000000000 --- a/packages/fuels/Forc.toml +++ /dev/null @@ -1,113 +0,0 @@ -[workspace] -members = [ - 'tests/bindings/sharing_types/contract_a', - 'tests/bindings/sharing_types/contract_b', - 'tests/bindings/sharing_types/shared_lib', - 'tests/bindings/simple_contract', - 'tests/bindings/type_paths', - 'tests/contracts/asserts', - 'tests/contracts/auth_testing_abi', - 'tests/contracts/auth_testing_contract', - 'tests/contracts/block_timestamp', - 'tests/contracts/configurables', - 'tests/contracts/contract_test', - 'tests/contracts/large_return_data', - 'tests/contracts/lib_contract', - 'tests/contracts/lib_contract_abi', - 'tests/contracts/lib_contract_caller', - 'tests/contracts/library_test', - 'tests/contracts/liquidity_pool', - 'tests/contracts/low_level_caller', - 'tests/contracts/msg_methods', - 'tests/contracts/multiple_read_calls', - 'tests/contracts/needs_custom_decoder', - 'tests/contracts/payable_annotation', - 'tests/contracts/require', - 'tests/contracts/revert_transaction_error', - 'tests/contracts/storage', - 'tests/contracts/token_ops', - 'tests/contracts/transaction_block_height', - 'tests/logs/contract_logs', - 'tests/logs/contract_logs_abi', - 'tests/logs/contract_with_contract_logs', - 'tests/logs/script_heap_logs', - 'tests/logs/script_logs', - 'tests/logs/script_needs_custom_decoder_logging', - 'tests/logs/script_with_contract_logs', - 'tests/predicates/basic_predicate', - 'tests/predicates/predicate_configurables', - 'tests/predicates/predicate_witnesses', - 'tests/predicates/signatures', - 'tests/predicates/swap', - 'tests/scripts/arguments', - 'tests/scripts/basic_script', - 'tests/scripts/require_from_contract', - 'tests/scripts/script_array', - 'tests/scripts/script_asserts', - 'tests/scripts/script_configurables', - 'tests/scripts/script_enum', - 'tests/scripts/script_needs_custom_decoder', - 'tests/scripts/script_require', - 'tests/scripts/script_struct', - 'tests/scripts/transfer_script', - 'tests/types/contracts/b256', - 'tests/types/contracts/b512', - 'tests/types/contracts/bytes', - 'tests/types/contracts/call_empty_return', - 'tests/types/contracts/complex_types_contract', - 'tests/types/contracts/empty_arguments', - 'tests/types/contracts/enum_as_input', - 'tests/types/contracts/enum_encoding', - 'tests/types/contracts/enum_inside_struct', - 'tests/types/contracts/evm_address', - 'tests/types/contracts/generics', - 'tests/types/contracts/heap_type_in_enums', - 'tests/types/contracts/heap_types', - 'tests/types/contracts/identity', - 'tests/types/contracts/native_types', - 'tests/types/contracts/nested_structs', - 'tests/types/contracts/options', - 'tests/types/contracts/raw_slice', - 'tests/types/contracts/results', - 'tests/types/contracts/std_lib_string', - 'tests/types/contracts/str_in_array', - 'tests/types/contracts/string_slice', - 'tests/types/contracts/tuples', - 'tests/types/contracts/two_structs', - 'tests/types/contracts/type_inside_enum', - 'tests/types/contracts/u128', - 'tests/types/contracts/u256', - 'tests/types/contracts/vector_output', - 'tests/types/contracts/vectors', - 'tests/types/predicates/address', - 'tests/types/predicates/enums', - 'tests/types/predicates/predicate_b256', - 'tests/types/predicates/predicate_bytes', - 'tests/types/predicates/predicate_bytes_hash', - 'tests/types/predicates/predicate_generics', - 'tests/types/predicates/predicate_raw_slice', - 'tests/types/predicates/predicate_std_lib_string', - 'tests/types/predicates/predicate_tuples', - 'tests/types/predicates/predicate_u128', - 'tests/types/predicates/predicate_u256', - 'tests/types/predicates/predicate_vector', - 'tests/types/predicates/predicate_vectors', - 'tests/types/predicates/structs', - 'tests/types/predicates/u64', - 'tests/types/scripts/options_results', - 'tests/types/scripts/script_b256', - 'tests/types/scripts/script_bytes', - 'tests/types/scripts/script_generics', - 'tests/types/scripts/script_heap_types', - #TODO: Decide what to do with this test project once - # https://github.com/FuelLabs/sway/issues/5727 is resolved - # 'tests/types/scripts/script_raw_slice', - 'tests/types/scripts/script_std_lib_string', - 'tests/types/scripts/script_tuples', - 'tests/types/scripts/script_u128', - 'tests/types/scripts/script_u256', - 'tests/types/scripts/script_vectors', -] - -[patch.'https://github.com/fuellabs/sway'] -std = { git = "https://github.com/fuellabs/sway", branch = "xunilrj/new-encoding-configurables" } diff --git a/packages/wasm-tests/.cargo/config.toml b/wasm-tests/.cargo/config.toml similarity index 100% rename from packages/wasm-tests/.cargo/config.toml rename to wasm-tests/.cargo/config.toml diff --git a/packages/wasm-tests/Cargo.toml b/wasm-tests/Cargo.toml similarity index 51% rename from packages/wasm-tests/Cargo.toml rename to wasm-tests/Cargo.toml index 8c20d38a2..4d13e5d1a 100644 --- a/packages/wasm-tests/Cargo.toml +++ b/wasm-tests/Cargo.toml @@ -13,11 +13,7 @@ rust-version = { workspace = true } crate-type = ['cdylib'] [dev-dependencies] -# `fuels` intentionally not specified through `workspace=true`. In -# the workspace cargo.toml `fuels` has default features enabled (so -# that our examples don't inherit `fuels` with disabled features). -# Cargo wouldn't respect any attempts here to disable them again. -fuels = { path = "../fuels", default-features = false } -fuels-core = { path = "../fuels-core", default-features = false } +fuels = { workspace = true } +fuels-core = { workspace = true } getrandom = { version = "0.2.11", features = ["js"] } wasm-bindgen-test = "0.3.39" diff --git a/packages/wasm-tests/src/lib.rs b/wasm-tests/src/lib.rs similarity index 100% rename from packages/wasm-tests/src/lib.rs rename to wasm-tests/src/lib.rs From 0024c6f67a99db0f5c4033d536317b3edaf9c382 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 08:58:29 +0200 Subject: [PATCH 02/70] update ci --- .github/workflows/ci.yml | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bfba9bb6..10e518e67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,44 +60,27 @@ jobs: - name: Check format of Sway test projects run: forc fmt --check - working-directory: packages/fuels - name: Build Sway test projects run: forc build --release --terse --error-on-warnings - working-directory: packages/fuels - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: retention-days: 2 name: sway-examples - # cache only the sway build artifacts, skip all src files path: | - packages/fuels/tests - !packages/fuels/tests/*.rs - !packages/fuels/tests/**/*.rs - !packages/fuels/tests/**/*.sw - !packages/fuels/tests/**/Forc.toml - !packages/fuels/tests/**/Forc.lock - !packages/fuels/tests/.gitignore + e2e/sway/**/out/* # TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked. - name: Build Sway test projects w type paths run: forc build --release --terse --error-on-warnings --json-abi-with-callpaths - working-directory: packages/fuels - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: retention-days: 2 name: sway-examples-w-type-paths - # cache only the sway build artifacts, skip all src files path: | - packages/fuels/tests - !packages/fuels/tests/*.rs - !packages/fuels/tests/**/*.rs - !packages/fuels/tests/**/*.sw - !packages/fuels/tests/**/Forc.toml - !packages/fuels/tests/**/Forc.lock - !packages/fuels/tests/.gitignore + e2e/sway/**/out/* get-workspace-members: runs-on: ubuntu-latest @@ -217,10 +200,11 @@ jobs: - name: Download sway example artifacts if: ${{ matrix.download_sway_artifacts }} - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ matrix.download_sway_artifacts }} - path: packages/fuels/tests/ + # Needed because `upload-artifact` will remove 'e2e/sway' because it is shared between all matched files + path: e2e/sway/ - name: Install nextest if: ${{ matrix.cargo_command == 'nextest' }} @@ -249,7 +233,7 @@ jobs: run: | rustup target add wasm32-unknown-unknown curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - cd packages/wasm-tests + cd wasm-tests wasm-pack test --node - name: Check for invalid documentation anchors From ab94801492635edfd08412b0fde0c70409287375 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 09:25:27 +0200 Subject: [PATCH 03/70] fix doc links --- docs/src/calling-contracts/call-params.md | 4 ++-- docs/src/calling-contracts/logs.md | 6 +++--- docs/src/calling-contracts/low-level-calls.md | 4 ++-- docs/src/calling-contracts/other-contracts.md | 4 ++-- docs/src/calling-contracts/variable-outputs.md | 2 +- docs/src/cookbook/deposit-and-withdraw.md | 2 +- docs/src/custom-transactions/custom-calls.md | 2 +- .../custom-transactions/transaction-builders.md | 2 +- docs/src/deploying/configurable-constants.md | 4 ++-- docs/src/getting-started.md | 2 +- docs/src/predicates/index.md | 6 +++--- docs/src/predicates/send-spend-predicate.md | 2 +- docs/src/running-scripts.md | 16 ++++++++-------- docs/src/testing/chains.md | 4 ++-- docs/src/testing/the-setup-program-test-macro.md | 4 ++-- docs/src/types/B512.md | 2 +- docs/src/types/bits256.md | 2 +- docs/src/types/bytes.md | 2 +- docs/src/types/conversion.md | 4 ++-- docs/src/types/custom_types.md | 4 ++-- docs/src/types/evm_address.md | 2 +- docs/src/types/string.md | 2 +- docs/src/types/vectors.md | 4 ++-- docs/src/wallets/signing.md | 2 +- e2e/Cargo.toml | 4 ++-- 25 files changed, 46 insertions(+), 46 deletions(-) diff --git a/docs/src/calling-contracts/call-params.md b/docs/src/calling-contracts/call-params.md index bea40fcb0..ca18043d6 100644 --- a/docs/src/calling-contracts/call-params.md +++ b/docs/src/calling-contracts/call-params.md @@ -15,7 +15,7 @@ You can use these to forward coins to a contract. You can configure these parame For instance, suppose the following contract that uses Sway's `msg_amount()` to return the amount sent in that transaction. ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts/contract_test/src/main.sw:msg_amount}} +{{#include ../../../e2e/sway/contracts/contract_test/src/main.sw:msg_amount}} ``` Then, in Rust, after setting up and deploying the above contract, you can configure the amount being sent in the transaction like this: @@ -31,7 +31,7 @@ Then, in Rust, after setting up and deploying the above contract, you can config In the following example, we try to forward an amount of `100` of the base asset to `non_payable`. As its name suggests, `non_payable` isn't annotated with `#[payable]` in the contract code. Passing `CallParameters` with an amount other than `0` leads to an error: ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts.rs:non_payable_params}} +{{#include ../../../e2e/tests/contracts.rs:non_payable_params}} ``` > **Note:** forwarding gas to a contract call is always possible, regardless of the contract method being non-payable. diff --git a/docs/src/calling-contracts/logs.md b/docs/src/calling-contracts/logs.md index 3d13b22d1..8c7467191 100644 --- a/docs/src/calling-contracts/logs.md +++ b/docs/src/calling-contracts/logs.md @@ -5,19 +5,19 @@ Whenever you log a value within a contract method, the resulting log entry is ad Consider the following contract method: ```rust,ignore -{{#include ../../../packages/fuels/tests/logs/contract_logs/src/main.sw:produce_logs}} +{{#include ../../../e2e/sway/logs/contract_logs/src/main.sw:produce_logs}} ``` You can access the logged values in Rust by calling `decode_logs_with_type::` from a `FuelCallResponse`, where `T` is the type of the logged variables you want to retrieve. The result will be a `Vec`: ```rust,ignore -{{#include ../../../packages/fuels/tests/logs.rs:produce_logs}} +{{#include ../../../e2e/tests/logs.rs:produce_logs}} ``` You can use the `decode_logs()` function to retrieve a `LogResult` struct containing a `results` field that is a vector of `Result` values representing the success or failure of decoding each log. ```rust, ignore -{{#include ../../../packages/fuels/tests/logs.rs:decode_logs}} +{{#include ../../../e2e/tests/logs.rs:decode_logs}} ``` Due to possible performance hits, it is not recommended to use `decode_logs()` outside of a debugging scenario. diff --git a/docs/src/calling-contracts/low-level-calls.md b/docs/src/calling-contracts/low-level-calls.md index 40843a0c7..f3fb2a31b 100644 --- a/docs/src/calling-contracts/low-level-calls.md +++ b/docs/src/calling-contracts/low-level-calls.md @@ -12,7 +12,7 @@ Your caller contract should call `std::low_level_call::call_with_function_select - `std::low_level_call::CallParams` ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts/low_level_caller/src/main.sw:low_level_call_contract}} +{{#include ../../../e2e/sway/contracts/low_level_caller/src/main.sw:low_level_call_contract}} ``` On the SDK side, you can construct an encoded function selector using `fuels::core::encode_fn_selector`, and encoded calldata using the `fuels::core::calldata!` macro. @@ -20,7 +20,7 @@ On the SDK side, you can construct an encoded function selector using `fuels::co E.g. to call the following function on the target contract: ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts/contract_test/src/main.sw:low_level_call}} +{{#include ../../../e2e/sway/contracts/contract_test/src/main.sw:low_level_call}} ``` you would construct the function selector and the calldata as such, and provide them to the caller contract (like the one above): diff --git a/docs/src/calling-contracts/other-contracts.md b/docs/src/calling-contracts/other-contracts.md index 0df2b1b6b..f7a02cad9 100644 --- a/docs/src/calling-contracts/other-contracts.md +++ b/docs/src/calling-contracts/other-contracts.md @@ -5,11 +5,11 @@ If your contract method is calling other contracts you will have to add the appr `with_contracts(&[&contract_instance, ...])` requires contract instances that were created using the `abigen` macro. When setting the external contracts with this method, logs and require revert errors originating from the external contract can be propagated and decoded by the calling contract. ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts.rs:external_contract}} +{{#include ../../../e2e/tests/contracts.rs:external_contract}} ``` If however, you do not need do decode logs or you do not have a contract instance that was generated using the `abigen` macro you can use `with_contract_ids(&[&contract_id, ...])` and provide the required contract ids. ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts.rs:external_contract_ids}} +{{#include ../../../e2e/tests/contracts.rs:external_contract_ids}} ``` diff --git a/docs/src/calling-contracts/variable-outputs.md b/docs/src/calling-contracts/variable-outputs.md index cbd46720e..76f962a66 100644 --- a/docs/src/calling-contracts/variable-outputs.md +++ b/docs/src/calling-contracts/variable-outputs.md @@ -8,7 +8,7 @@ Sometimes, the contract you call might transfer funds to a specific address, dep Let's say you deployed a contract with the following method: ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts/token_ops/src/main.sw:variable_outputs}} +{{#include ../../../e2e/sway/contracts/token_ops/src/main.sw:variable_outputs}} ``` When calling `transfer_coins_to_output` with the SDK, you can specify the number of variable outputs by chaining `append_variable_outputs(amount)` to your call. Like this: diff --git a/docs/src/cookbook/deposit-and-withdraw.md b/docs/src/cookbook/deposit-and-withdraw.md index fc84e48b1..3a084a84e 100644 --- a/docs/src/cookbook/deposit-and-withdraw.md +++ b/docs/src/cookbook/deposit-and-withdraw.md @@ -3,7 +3,7 @@ Consider the following contract: ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts/liquidity_pool/src/main.sw}} +{{#include ../../../e2e/sway/contracts/liquidity_pool/src/main.sw}} ``` As its name suggests, it represents a simplified example of a liquidity pool contract. The method `deposit()` expects you to supply an arbitrary amount of the `BASE_TOKEN`. As a result, it mints double the amount of the liquidity asset to the calling address. Analogously, if you call `withdraw()` supplying it with the liquidity asset, it will transfer half that amount of the `BASE_TOKEN` back to the calling address except for deducting it from the contract balance instead of minting it. diff --git a/docs/src/custom-transactions/custom-calls.md b/docs/src/custom-transactions/custom-calls.md index f8917b8a2..b1727582c 100644 --- a/docs/src/custom-transactions/custom-calls.md +++ b/docs/src/custom-transactions/custom-calls.md @@ -11,5 +11,5 @@ When preparing a contract call via `ContractCallHandler` or a script call via `S ## Custom script call ```rust,ignore -{{#include ../../../packages/fuels/tests/scripts.rs:script_call_tb}} +{{#include ../../../e2e/tests/scripts.rs:script_call_tb}} ``` diff --git a/docs/src/custom-transactions/transaction-builders.md b/docs/src/custom-transactions/transaction-builders.md index de8eaffba..ee3fa223f 100644 --- a/docs/src/custom-transactions/transaction-builders.md +++ b/docs/src/custom-transactions/transaction-builders.md @@ -91,7 +91,7 @@ Finally, we verify the transaction succeeded and that the cold storage indeed ho If you need to build the transaction without signatures, which is useful when estimating transaction costs or simulations, you can use the `build_without_signatures(&provider)` method and later sign the built transaction. ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts.rs:tb_build_without_signatures}} +{{#include ../../../e2e/tests/contracts.rs:tb_build_without_signatures}} ``` > **Note** In contrast to adding signers to a transaction builder, when signing a built transaction, you must ensure that the order of signatures matches the order of signed inputs. Multiple signed inputs with the same owner will have the same witness index. diff --git a/docs/src/deploying/configurable-constants.md b/docs/src/deploying/configurable-constants.md index f247d8b13..3067aeac2 100644 --- a/docs/src/deploying/configurable-constants.md +++ b/docs/src/deploying/configurable-constants.md @@ -3,11 +3,11 @@ In Sway, you can define `configurable` constants which can be changed during the contract deployment in the SDK. Here is an example how the constants are defined. ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts/configurables/src/main.sw}} +{{#include ../../../e2e/sway/contracts/configurables/src/main.sw}} ``` Each of the configurable constants will get a dedicated `with` method in the SDK. For example, the constant `STR_4` will get the `with_STR_4` method which accepts the same type as defined in the contract code. Below is an example where we chain several `with` methods and deploy the contract with the new constants. ```rust,ignore -{{#include ../../../packages/fuels/tests/configurables.rs:contract_configurables}} +{{#include ../../../e2e/tests/configurables.rs:contract_configurables}} ``` diff --git a/docs/src/getting-started.md b/docs/src/getting-started.md index 3a686958a..5aa320e84 100644 --- a/docs/src/getting-started.md +++ b/docs/src/getting-started.md @@ -95,7 +95,7 @@ use fuels::prelude::*; ## The Fuel Rust SDK source code -Another way to experience the SDK is to look at the source code. The `packages/fuels/tests/` folder is full of integration tests that go through almost all aspects of the SDK. +Another way to experience the SDK is to look at the source code. The `e2e/tests/` folder is full of integration tests that go through almost all aspects of the SDK. > **Note** Before running the tests, we need to build all the Sway test projects. The file `packages/fuels/Forc.toml` contains a `[workspace], which members are the paths to all integration tests. > To build these tests, run the following command: diff --git a/docs/src/predicates/index.md b/docs/src/predicates/index.md index 0d84784b4..d1b902396 100644 --- a/docs/src/predicates/index.md +++ b/docs/src/predicates/index.md @@ -7,7 +7,7 @@ Predicates, in Sway, are programs that return a Boolean value and do not have an Let's consider the following predicate example: ```rust,ignore -{{#include ../../../packages/fuels/tests/predicates/basic_predicate/src/main.sw}} +{{#include ../../../e2e/sway/predicates/basic_predicate/src/main.sw}} ``` We will look at a complete example of using the SDK to send and receive funds from a predicate. @@ -46,10 +46,10 @@ Then we can transfer assets owned by the predicate via the [Account](../accounts Same as contracts and scripts, you can define configurable constants in `predicates`, which can be changed during the predicate execution. Here is an example of how the constants are defined. ```rust,ignore -{{#include ../../../packages/fuels/tests/predicates/predicate_configurables/src/main.sw:predicate_configurables}} +{{#include ../../../e2e/sway/predicates/predicate_configurables/src/main.sw:predicate_configurables}} ``` Each configurable constant will get a dedicated `with` method in the SDK. For example, the constant `U8` will get the `with_U8` method which accepts the same type defined in sway. Below is an example where we chain several `with` methods and update the predicate with the new constants. ```rust,ignore -{{#include ../../../packages/fuels/tests/predicates.rs:predicate_configurables}} +{{#include ../../../e2e/tests/predicates.rs:predicate_configurables}} diff --git a/docs/src/predicates/send-spend-predicate.md b/docs/src/predicates/send-spend-predicate.md index 72f11d383..91a972226 100644 --- a/docs/src/predicates/send-spend-predicate.md +++ b/docs/src/predicates/send-spend-predicate.md @@ -3,7 +3,7 @@ This is a more involved example where the predicate accepts three signatures and matches them to three predefined public keys. The `ec_recover_address` function is used to recover the public key from the signatures. If two of the three extracted public keys match the predefined public keys, the funds can be spent. Note that the signature order has to match the order of the predefined public keys. ```rust,ignore -{{#include ../../../packages/fuels/tests/predicates/signatures/src/main.sw}} +{{#include ../../../e2e/sway/predicates/signatures/src/main.sw}} ``` Let's use the SDK to interact with the predicate. First, let's create three wallets with specific keys. Their hashed public keys are already hard-coded in the predicate. Then we create the receiver wallet, which we will use to spend the predicate funds. diff --git a/docs/src/running-scripts.md b/docs/src/running-scripts.md index 29a3b15ba..210109a5e 100644 --- a/docs/src/running-scripts.md +++ b/docs/src/running-scripts.md @@ -3,13 +3,13 @@ You can run a script using its JSON-ABI and the path to its binary file. You can run the scripts with arguments. For this, you have to use the `abigen!` macro seen [previously](./abigen/the-abigen-macro.md). ````rust,ignore -{{#include ../../packages/fuels/tests/scripts.rs:script_with_arguments}} +{{#include ../../e2e/tests/scripts.rs:script_with_arguments}} ```` Furthermore, if you need to separate submission from value retrieval for any reason, you can do so as follows: ```rust,ignore -{{#include ../../packages/fuels/tests/scripts.rs:submit_response_script}} +{{#include ../../e2e/tests/scripts.rs:submit_response_script}} ``` ## Running scripts with transaction policies @@ -17,7 +17,7 @@ Furthermore, if you need to separate submission from value retrieval for any rea The method for passing transaction policies is the same as [with contracts](./calling-contracts/tx-policies.md). As a reminder, the workflow would look like this: ```rust,ignore -{{#include ../../packages/fuels/tests/scripts.rs:script_with_tx_policies}} +{{#include ../../e2e/tests/scripts.rs:script_with_tx_policies}} ``` ## Logs @@ -25,7 +25,7 @@ The method for passing transaction policies is the same as [with contracts](./ca Script calls provide the same logging functions, `decode_logs()` and `decode_logs_with_type()`, as contract calls. As a reminder, the workflow looks like this: ```rust,ignore -{{#include ../../packages/fuels/tests/logs.rs:script_logs}} +{{#include ../../e2e/tests/logs.rs:script_logs}} ``` ## Calling contracts from scripts @@ -35,13 +35,13 @@ Scripts use the same interfaces for setting external contracts as [contract meth Below is an example that uses `with_contracts(&[&contract_instance, ...])`. ```rust,ignore -{{#include ../../packages/fuels/tests/logs.rs:external_contract}} +{{#include ../../e2e/tests/logs.rs:external_contract}} ``` And this is an example that uses `with_contract_ids(&[&contract_id, ...])`. ```rust,ignore -{{#include ../../packages/fuels/tests/logs.rs:external_contract_ids}} +{{#include ../../e2e/tests/logs.rs:external_contract_ids}} ``` ## Configurable constants @@ -49,10 +49,10 @@ And this is an example that uses `with_contract_ids(&[&contract_id, ...])`. Same as contracts, you can define `configurable` constants in `scripts` which can be changed during the script execution. Here is an example how the constants are defined. ```rust,ignore -{{#include ../../packages/fuels/tests/scripts/script_configurables/src/main.sw}} +{{#include ../../e2e/sway/scripts/script_configurables/src/main.sw}} ``` Each configurable constant will get a dedicated `with` method in the SDK. For example, the constant `STR_4` will get the `with_STR_4` method which accepts the same type defined in sway. Below is an example where we chain several `with` methods and execute the script with the new constants. ```rust,ignore -{{#include ../../packages/fuels/tests/configurables.rs:script_configurables}} +{{#include ../../e2e/tests/configurables.rs:script_configurables}} diff --git a/docs/src/testing/chains.md b/docs/src/testing/chains.md index 04a6a062b..336dc520e 100644 --- a/docs/src/testing/chains.md +++ b/docs/src/testing/chains.md @@ -5,11 +5,11 @@ You can use `produce_blocks` to help achieve an arbitrary block height; this is > **Note**: For the `produce_blocks` API to work, it is imperative to have `manual_blocks_enabled = true` in the config for the running node. See example below. ````rust,ignore -{{#include ../../../packages/fuels/tests/providers.rs:use_produce_blocks_to_increase_block_height}} +{{#include ../../../e2e/tests/providers.rs:use_produce_blocks_to_increase_block_height}} ```` You can also set a custom block time as the second, optional argument. Here is an example: ````rust,ignore -{{#include ../../../packages/fuels/tests/providers.rs:use_produce_blocks_custom_time}} +{{#include ../../../e2e/tests/providers.rs:use_produce_blocks_custom_time}} ```` diff --git a/docs/src/testing/the-setup-program-test-macro.md b/docs/src/testing/the-setup-program-test-macro.md index b7a252b3b..72d71fbf6 100644 --- a/docs/src/testing/the-setup-program-test-macro.md +++ b/docs/src/testing/the-setup-program-test-macro.md @@ -84,7 +84,7 @@ The setup code that you have seen in previous sections gets reduced to: > **Note** The same contract can be deployed several times as the macro deploys the contracts with salt. You can also deploy different contracts to the same provider by referencing the same wallet in the `Deploy` command. ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts.rs:contract_setup_macro_multi}} +{{#include ../../../e2e/tests/contracts.rs:contract_setup_macro_multi}} ``` In this example, three contracts are deployed on the same provider using the `wallet` generated by the `Wallets` command. The second and third macros use the same contract but have different IDs because of the deployment with salt. Both of them can call the first contract by using their ID. @@ -92,5 +92,5 @@ In this example, three contracts are deployed on the same provider using the `wa In addition, you can manually create the `wallet` variable and then use it inside the macro. This is useful if you want to create custom wallets or providers but still want to use the macro to reduce boilerplate code. Below is an example of this approach. ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts.rs:contract_setup_macro_manual_wallet}} +{{#include ../../../e2e/tests/contracts.rs:contract_setup_macro_manual_wallet}} ``` diff --git a/docs/src/types/B512.md b/docs/src/types/B512.md index 8d53d5b43..fa4c801a5 100644 --- a/docs/src/types/B512.md +++ b/docs/src/types/B512.md @@ -9,5 +9,5 @@ In the Rust SDK, the `B512` definition matches the Sway standard library type wi Here's an example: ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:b512_example}} +{{#include ../../../e2e/tests/types_contracts.rs:b512_example}} ``` diff --git a/docs/src/types/bits256.md b/docs/src/types/bits256.md index 0a860e460..be001b0e3 100644 --- a/docs/src/types/bits256.md +++ b/docs/src/types/bits256.md @@ -5,7 +5,7 @@ In Fuel, a type called `b256` represents hashes and holds a 256-bit value. The R Here's an example: ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:256_arg}} +{{#include ../../../e2e/tests/types_contracts.rs:256_arg}} ``` If you have a hexadecimal value as a string and wish to convert it to `Bits256`, you may do so with `from_hex_str`: diff --git a/docs/src/types/bytes.md b/docs/src/types/bytes.md index 0b02e0efe..96fc2e9a5 100644 --- a/docs/src/types/bytes.md +++ b/docs/src/types/bytes.md @@ -3,7 +3,7 @@ In Fuel, a type called `Bytes` represents a collection of tightly-packed bytes. The Rust SDK represents `Bytes` as `Bytes(Vec)`. Here's an example of using `Bytes` in a contract call: ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:bytes_arg}} +{{#include ../../../e2e/tests/types_contracts.rs:bytes_arg}} ``` If you have a hexadecimal value as a string and wish to convert it to `Bytes`, you may do so with `from_hex_str`: diff --git a/docs/src/types/conversion.md b/docs/src/types/conversion.md index f11a7b870..1fe84ec0b 100644 --- a/docs/src/types/conversion.md +++ b/docs/src/types/conversion.md @@ -80,7 +80,7 @@ Convert a hex string to a `ContractId`: Convert a contract instance to a `ContractId`: ```rust,ignore -{{#include ../../../packages/fuels/tests/logs.rs:instance_to_contract_id}} +{{#include ../../../e2e/tests/logs.rs:instance_to_contract_id}} ``` ## Convert to `Identity` @@ -202,7 +202,7 @@ Convert a string to `Bytes`: Convert two hex strings to `B512`: ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:b512_example}} +{{#include ../../../e2e/tests/types_contracts.rs:b512_example}} ``` ## Convert to `EvmAddress` diff --git a/docs/src/types/custom_types.md b/docs/src/types/custom_types.md index c151db9f0..c6c4b0556 100644 --- a/docs/src/types/custom_types.md +++ b/docs/src/types/custom_types.md @@ -17,7 +17,7 @@ struct CounterConfig { After using the `abigen!` macro, `CounterConfig` will be accessible in your Rust file! Here's an example: ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:struct_generation}} +{{#include ../../../e2e/tests/types_contracts.rs:struct_generation}} ``` You can freely use your custom types (structs or enums) within this scope. That also means passing custom types to functions and receiving custom types from function calls. @@ -57,7 +57,7 @@ impl MyContract for Contract { Your Rust code would look like this: ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:generic}} +{{#include ../../../e2e/tests/types_contracts.rs:generic}} ``` ### Unused generic type parameters diff --git a/docs/src/types/evm_address.md b/docs/src/types/evm_address.md index 4c4a1de43..03e31559f 100644 --- a/docs/src/types/evm_address.md +++ b/docs/src/types/evm_address.md @@ -9,7 +9,7 @@ In the Rust SDK, Ethereum Virtual Machine (EVM) addresses can be represented wit Here's an example: ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:evm_address_arg}} +{{#include ../../../e2e/tests/types_contracts.rs:evm_address_arg}} ``` > **Note:** when creating an `EvmAddress` from `Bits256`, the first 12 bytes will be cleared because an EVM address is only 20 bytes long. diff --git a/docs/src/types/string.md b/docs/src/types/string.md index 4e44dd59d..2c73d460b 100644 --- a/docs/src/types/string.md +++ b/docs/src/types/string.md @@ -17,5 +17,5 @@ To make working with `SizedAsciiString`s easier, you can use `try_into()` to con If your contract's method takes and returns, for instance, a Sway's `str[23]`. When using the SDK, this method will take and return a `SizedAsciiString<23>`, and you can pass a string to it like this: ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:contract_takes_string}} +{{#include ../../../e2e/tests/types_contracts.rs:contract_takes_string}} ``` diff --git a/docs/src/types/vectors.md b/docs/src/types/vectors.md index 498c1d974..fb909f521 100644 --- a/docs/src/types/vectors.md +++ b/docs/src/types/vectors.md @@ -5,7 +5,7 @@ You can pass a Rust `std::vec::Vec` into your contract method transparently. The following code calls a Sway contract method which accepts a `Vec>`. ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:passing_in_vec}} +{{#include ../../../e2e/tests/types_contracts.rs:passing_in_vec}} ``` You can use a vector just like you would use any other type -- e.g. a `[Vec; 2]` or a `SomeStruct>` etc. @@ -15,7 +15,7 @@ You can use a vector just like you would use any other type -- e.g. a `[Vec Returning vectors from contract methods is supported transparently, with the caveat that you cannot have them nested inside another type. This limitation is temporary. ```rust,ignore -{{#include ../../../packages/fuels/tests/types_contracts.rs:returning_vec}} +{{#include ../../../e2e/tests/types_contracts.rs:returning_vec}} ``` > **Note: you can still interact with contracts containing methods that return vectors nested inside another type, just not interact with the methods themselves** diff --git a/docs/src/wallets/signing.md b/docs/src/wallets/signing.md index 33f54fcfd..4225e8661 100644 --- a/docs/src/wallets/signing.md +++ b/docs/src/wallets/signing.md @@ -23,5 +23,5 @@ Below is a full example of how to create a transaction builder and add signers t If you have a built transaction and want to add a signature, you can use the `sign_with` method. ```rust,ignore -{{#include ../../../packages/fuels/tests/contracts.rs:tx_sign_with}} +{{#include ../../../e2e/tests/contracts.rs:tx_sign_with}} ``` diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index e9d774952..1d3452f58 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -13,10 +13,10 @@ publish = false [dev-dependencies] # used in test assertions chrono = { workspace = true } -# needs to be removed, `ScriptTransaction` and `CreateTransaction` in `fuels` use `fuel_tx::Input` but don't reexport or convert it into a `fuels` owned type +# TODO: [issue](https://github.com/FuelLabs/fuels-rs/issues/1375) needs to be removed, `ScriptTransaction` and `CreateTransaction` in `fuels` use `fuel_tx::Input` but don't reexport or convert it into a `fuels` owned type fuel-tx = { workspace = true } fuels = { workspace = true } -# because setup-program-test uses it but `fuels` did not reexport `rand` +# TODO: [issue](https://github.com/FuelLabs/fuels-rs/issues/1376) because setup-program-test uses it but `fuels` did not reexport `rand` rand = { workspace = true } # used in test assertions tai64 = { workspace = true } From c0526e2ac389e3b92895fd649f12734d5a950c03 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 09:33:57 +0200 Subject: [PATCH 04/70] clippy fix --- packages/fuels-test-helpers/src/fuel_bin_service.rs | 5 +---- packages/fuels/src/lib.rs | 9 --------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/fuels-test-helpers/src/fuel_bin_service.rs b/packages/fuels-test-helpers/src/fuel_bin_service.rs index a28c6dc24..d506e1d36 100644 --- a/packages/fuels-test-helpers/src/fuel_bin_service.rs +++ b/packages/fuels-test-helpers/src/fuel_bin_service.rs @@ -7,10 +7,7 @@ use std::{ use fuel_core_chain_config::{ChainConfig, SnapshotWriter, StateConfig}; use fuel_core_client::client::FuelClient; use fuel_core_services::State; -use fuels_core::{ - error, - types::errors::{Error, Result as FuelResult}, -}; +use fuels_core::{error, types::errors::Result as FuelResult}; use portpicker::{is_free, pick_unused_port}; use tempfile::{tempdir, TempDir}; use tokio::{process::Command, spawn, task::JoinHandle, time::sleep}; diff --git a/packages/fuels/src/lib.rs b/packages/fuels/src/lib.rs index b6603cf12..bffe9132d 100644 --- a/packages/fuels/src/lib.rs +++ b/packages/fuels/src/lib.rs @@ -58,17 +58,8 @@ pub mod test_helpers { pub use fuels_test_helpers::*; } -/// Easy imports of frequently used #[doc(hidden)] pub mod prelude { - //! The fuels-rs prelude - //! - //! The purpose of this module is to alleviate imports of many common types: - //! - //! ``` - //! # #![allow(unused_imports)] - //! use fuels::prelude::*; - //! ``` #[cfg(feature = "std")] pub use super::{ accounts::{ From 07c03555d6341593f8d8ed5e3653229de5166a66 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 10:17:52 +0200 Subject: [PATCH 05/70] move test-type-paths to e2e --- e2e/Cargo.toml | 2 ++ packages/fuels-accounts/Cargo.toml | 1 + packages/fuels-core/Cargo.toml | 1 + packages/fuels/Cargo.toml | 2 -- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index 1d3452f58..797751e92 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -25,3 +25,5 @@ tokio = { workspace = true } [features] fuel-core-lib = ["fuels/fuel-core-lib"] +# TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked. +test-type-paths = [] diff --git a/packages/fuels-accounts/Cargo.toml b/packages/fuels-accounts/Cargo.toml index d6ddadc58..1c6b01d22 100644 --- a/packages/fuels-accounts/Cargo.toml +++ b/packages/fuels-accounts/Cargo.toml @@ -28,6 +28,7 @@ tokio = { workspace = true, features = ["full"], optional = true } zeroize = { workspace = true, features = ["derive"] } [dev-dependencies] +fuel-tx = { workspace = true, features = ["test-helpers", "random"] } tempfile = { workspace = true } tokio = { workspace = true, features = ["test-util"] } diff --git a/packages/fuels-core/Cargo.toml b/packages/fuels-core/Cargo.toml index 603d63564..7c33da1f2 100644 --- a/packages/fuels-core/Cargo.toml +++ b/packages/fuels-core/Cargo.toml @@ -31,6 +31,7 @@ thiserror = { workspace = true, default-features = false } uint = { workspace = true, default-features = false } [dev-dependencies] +fuel-tx = { workspace = true, features = ["test-helpers", "random"] } tokio = { workspace = true, features = ["test-util", "macros"] } [features] diff --git a/packages/fuels/Cargo.toml b/packages/fuels/Cargo.toml index c111aec62..5da952793 100644 --- a/packages/fuels/Cargo.toml +++ b/packages/fuels/Cargo.toml @@ -40,7 +40,5 @@ std = [ "fuels-core/std", "fuels-test-helpers?/std", ] -# TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked. -test-type-paths = [] fuel-core-lib = ["fuels-test-helpers?/fuel-core-lib", "dep:fuel-core"] rocksdb = ["fuel-core?/rocksdb"] From 221ed864f95ea0950e0429fa54b85f847178bf5d Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 16:46:20 +0200 Subject: [PATCH 06/70] cargo hack passing, std needs sorting out --- Cargo.toml | 57 +++++++++++++------------- packages/fuels-accounts/Cargo.toml | 31 ++++++-------- packages/fuels-accounts/src/lib.rs | 2 +- packages/fuels-code-gen/Cargo.toml | 4 +- packages/fuels-core/Cargo.toml | 4 +- packages/fuels-programs/Cargo.toml | 3 +- packages/fuels-programs/src/lib.rs | 4 ++ packages/fuels-test-helpers/Cargo.toml | 15 ++++--- packages/fuels-test-helpers/src/lib.rs | 2 - packages/fuels/Cargo.toml | 6 +-- scripts/check-docs/Cargo.toml | 4 +- wasm-tests/Cargo.toml | 4 +- 12 files changed, 69 insertions(+), 67 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0cb70f40f..46750e824 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,40 +40,41 @@ rust-version = "1.76.0" version = "0.61.0" [workspace.dependencies] -Inflector = "0.11.4" +Inflector = { version = "0.11.4", default-features = false } async-trait = { version = "0.1.74", default-features = false } -bech32 = "0.9.1" +bech32 = { version = "0.9.1", default-features = false } bytes = { version = "1.5.0", default-features = false } -chrono = "0.4.31" +chrono = { version = "0.4.31", default-features = false } elliptic-curve = { version = "0.13.8", default-features = false } -eth-keystore = "0.5.0" -fuel-abi-types = "0.4.0" -futures = "0.3.29" +eth-keystore = { version = "0.5.0", default-features = false } +fuel-abi-types = { version = "0.4.0", default-features = false } +futures = { version = "0.3.29", default-features = false } hex = { version = "0.4.3", default-features = false } -itertools = "0.12.0" -portpicker = "0.1.1" -proc-macro2 = "1.0.70" -quote = "1.0.33" -rand = { version = "0.8.5", default-features = false, features = [ - "std_rng", - "getrandom", -] } -regex = "1.10.2" -semver = "1.0.20" +itertools = { version = "0.12.0", default-features = false } +portpicker = { version = "0.1.1", default-features = false } +proc-macro2 = { version = "1.0.70", default-features = false } +quote = { version = "1.0.33", default-features = false } +rand = { version = "0.8.5", default-features = false } +regex = { version = "1.10.2", default-features = false } +semver = { version = "1.0.20", default-features = false } serde = { version = "1.0.193", default-features = false } -serde_json = "1.0.108" +serde_json = { version = "1.0.108", default-features = false } serde_with = { version = "3.4.0", default-features = false } sha2 = { version = "0.10.8", default-features = false } -syn = "2.0.39" +syn = { version = "2.0.39", default-features = false } tai64 = { version = "4.0.0", default-features = false } tempfile = { version = "3.8.1", default-features = false } thiserror = { version = "1.0.50", default-features = false } tokio = { version = "1.34.0", default-features = false } -tracing = "0.1.40" -trybuild = "1.0.85" +tracing = { version = "0.1.40", default-features = false } +trybuild = { version = "1.0.85", default-features = false } uint = { version = "0.9.5", default-features = false } which = { version = "6.0.0", default-features = false } -zeroize = "1.7.0" +zeroize = { version = "1.7.0", default-features = false } +pretty_assertions = { version = "1.4.0", default-features = false } +anyhow = { version = "1.0", default-features = false } +getrandom = { version = "0.2", default-features = false } +wasm-bindgen-test = { version = "0.3", default-features = false } # Dependencies from the `fuel-core` repository: fuel-core = { version = "0.26.0", default-features = false } @@ -84,13 +85,13 @@ fuel-core-services = { version = "0.26.0", default-features = false } fuel-core-types = { version = "0.26.0", default-features = false } # Dependencies from the `fuel-vm` repository: -fuel-asm = { version = "0.49.0" } -fuel-crypto = { version = "0.49.0" } -fuel-merkle = { version = "0.49.0" } -fuel-storage = { version = "0.49.0" } -fuel-tx = { version = "0.49.0" } -fuel-types = { version = "0.49.0" } -fuel-vm = { version = "0.49.0" } +fuel-asm = { version = "0.49.0", default-features = false } +fuel-crypto = { version = "0.49.0", default-features = false } +fuel-merkle = { version = "0.49.0", default-features = false } +fuel-storage = { version = "0.49.0", default-features = false } +fuel-tx = { version = "0.49.0", default-features = false } +fuel-types = { version = "0.49.0", default-features = false } +fuel-vm = { version = "0.49.0", default-features = false } # Workspace projects fuels = { version = "0.61.0", path = "./packages/fuels", default-features = false } diff --git a/packages/fuels-accounts/Cargo.toml b/packages/fuels-accounts/Cargo.toml index 1c6b01d22..073494bfb 100644 --- a/packages/fuels-accounts/Cargo.toml +++ b/packages/fuels-accounts/Cargo.toml @@ -10,34 +10,29 @@ rust-version = { workspace = true } description = "Fuel Rust SDK accounts." [dependencies] -async-trait = { workspace = true, default-features = false } +async-trait = { workspace = true } chrono = { workspace = true } -elliptic-curve = { workspace = true, default-features = false } +elliptic-curve = { workspace = true } eth-keystore = { workspace = true, optional = true } fuel-core-client = { workspace = true, optional = true } fuel-core-types = { workspace = true } -fuel-crypto = { workspace = true, features = ["random"] } +fuel-crypto = { workspace = true, features = ["std", "random"] } fuel-tx = { workspace = true } -fuel-types = { workspace = true, features = ["random"] } -fuels-core = { workspace = true, default-features = false } -rand = { workspace = true, default-features = false } +fuel-types = { workspace = true } +fuels-core = { workspace = true } +rand = { workspace = true } semver = { workspace = true } -tai64 = { workspace = true, features = ["serde"] } -thiserror = { workspace = true, default-features = false } -tokio = { workspace = true, features = ["full"], optional = true } -zeroize = { workspace = true, features = ["derive"] } +tai64 = { workspace = true } +thiserror = { workspace = true } +tokio = { workspace = true } +zeroize = { workspace = true } [dev-dependencies] fuel-tx = { workspace = true, features = ["test-helpers", "random"] } tempfile = { workspace = true } -tokio = { workspace = true, features = ["test-util"] } +tokio = { workspace = true, features = ["test-util", "macros"] } [features] default = ["std"] -coin-cache = ["tokio?/time"] -std = [ - "fuels-core/std", - "dep:tokio", - "fuel-core-client/default", - "dep:eth-keystore", -] +coin-cache = ["tokio/time"] +std = ["fuels-core/std", "fuel-core-client/default", "dep:eth-keystore"] diff --git a/packages/fuels-accounts/src/lib.rs b/packages/fuels-accounts/src/lib.rs index 94612bf50..d023b56f8 100644 --- a/packages/fuels-accounts/src/lib.rs +++ b/packages/fuels-accounts/src/lib.rs @@ -7,10 +7,10 @@ pub mod provider; #[cfg(feature = "std")] pub mod wallet; -#[cfg(feature = "std")] pub use account::*; #[cfg(feature = "coin-cache")] mod coin_cache; +#[cfg(feature = "std")] pub mod predicate; diff --git a/packages/fuels-code-gen/Cargo.toml b/packages/fuels-code-gen/Cargo.toml index 8eab6bea4..23da1f880 100644 --- a/packages/fuels-code-gen/Cargo.toml +++ b/packages/fuels-code-gen/Cargo.toml @@ -12,7 +12,7 @@ description = "Used for code generation in the Fuel Rust SDK" [dependencies] Inflector = { workspace = true } fuel-abi-types = { workspace = true } -itertools = { workspace = true } +itertools = { workspace = true, features = ["use_std"] } proc-macro2 = { workspace = true } quote = { workspace = true } regex = { workspace = true } @@ -20,7 +20,7 @@ serde_json = { workspace = true } syn = { workspace = true } [dev-dependencies] -pretty_assertions = "1.4.0" +pretty_assertions = { workspace = true, features = ["alloc"] } [package.metadata.cargo-machete] ignored = ["Inflector"] diff --git a/packages/fuels-core/Cargo.toml b/packages/fuels-core/Cargo.toml index 7c33da1f2..6e386ee8c 100644 --- a/packages/fuels-core/Cargo.toml +++ b/packages/fuels-core/Cargo.toml @@ -18,13 +18,13 @@ fuel-asm = { workspace = true } fuel-core-chain-config = { workspace = true } fuel-core-client = { workspace = true, optional = true } fuel-core-types = { workspace = true } -fuel-crypto = { workspace = true } +fuel-crypto = { workspace = true, features = ["std"] } fuel-tx = { workspace = true } fuel-types = { workspace = true, features = ["default"] } fuel-vm = { workspace = true } fuels-macros = { workspace = true } hex = { workspace = true, features = ["std"] } -itertools = { workspace = true } +itertools = { workspace = true, features = ["use_std"] } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, default-features = true } thiserror = { workspace = true, default-features = false } diff --git a/packages/fuels-programs/Cargo.toml b/packages/fuels-programs/Cargo.toml index 3799f8b08..6ad2971ff 100644 --- a/packages/fuels-programs/Cargo.toml +++ b/packages/fuels-programs/Cargo.toml @@ -23,7 +23,8 @@ serde_json = { workspace = true } tokio = { workspace = true } [dev-dependencies] -tempfile = "3.8.1" +tempfile = { workspace = true } +tokio = { workspace = true, features = ["macros", "test-util"] } [features] default = ["std"] diff --git a/packages/fuels-programs/src/lib.rs b/packages/fuels-programs/src/lib.rs index 5a4aa4a9c..899358e94 100644 --- a/packages/fuels-programs/src/lib.rs +++ b/packages/fuels-programs/src/lib.rs @@ -1,6 +1,10 @@ pub mod call_response; +#[cfg(feature = "std")] pub mod call_utils; +#[cfg(feature = "std")] pub mod contract; pub mod receipt_parser; +#[cfg(feature = "std")] pub mod script_calls; +#[cfg(feature = "std")] mod submit_response; diff --git a/packages/fuels-test-helpers/Cargo.toml b/packages/fuels-test-helpers/Cargo.toml index 844fb7c0d..5372296b1 100644 --- a/packages/fuels-test-helpers/Cargo.toml +++ b/packages/fuels-test-helpers/Cargo.toml @@ -10,16 +10,19 @@ rust-version = { workspace = true } description = "Fuel Rust SDK test helpers." [dependencies] -fuel-core = { workspace = true, default-features = false, features = ["test-helpers"], optional = true } -fuel-core-chain-config = { workspace = true, features = ["test-helpers"] } +fuel-core = { workspace = true, features = ["test-helpers"], optional = true } +fuel-core-chain-config = { workspace = true, features = [ + "test-helpers", + "std", +] } fuel-core-client = { workspace = true } fuel-core-poa = { workspace = true } fuel-core-services = { workspace = true } fuel-crypto = { workspace = true } fuel-tx = { workspace = true } fuel-types = { workspace = true, features = ["random"] } -fuels-accounts = { workspace = true, optional = true } -fuels-core = { workspace = true } +fuels-accounts = { workspace = true, features = ["std"] } +fuels-core = { workspace = true, features = ["std"] } futures = { workspace = true } portpicker = { workspace = true } rand = { workspace = true, default-features = false } @@ -28,6 +31,6 @@ tokio = { workspace = true, default-features = false } which = { workspace = true, default-features = false } [features] -default = ["fuels-accounts", "std"] -std = ["fuels-accounts?/std", "fuels-core/std", "fuel-core-chain-config/std"] +default = ["std"] +std = ["fuels-accounts/std", "fuels-core/std", "fuel-core-chain-config/std"] fuel-core-lib = ["dep:fuel-core"] diff --git a/packages/fuels-test-helpers/src/lib.rs b/packages/fuels-test-helpers/src/lib.rs index 3fc19a095..88186f4d9 100644 --- a/packages/fuels-test-helpers/src/lib.rs +++ b/packages/fuels-test-helpers/src/lib.rs @@ -1,6 +1,4 @@ //! Testing helpers/utilities for Fuel SDK. -extern crate core; - #[cfg(feature = "fuels-accounts")] pub use accounts::*; use fuel_tx::{Bytes32, ConsensusParameters, ContractParameters, TxParameters, UtxoId}; diff --git a/packages/fuels/Cargo.toml b/packages/fuels/Cargo.toml index 5da952793..26c739524 100644 --- a/packages/fuels/Cargo.toml +++ b/packages/fuels/Cargo.toml @@ -14,18 +14,18 @@ description = "Fuel Rust SDK." ignored = ["fuel-core"] [dependencies] -fuel-core = { workspace = true, default-features = false, optional = true } +fuel-core = { workspace = true, optional = true } fuel-core-client = { workspace = true, optional = true } fuel-crypto = { workspace = true } fuel-tx = { workspace = true } -fuels-accounts = { workspace = true, default-features = false } +fuels-accounts = { workspace = true } fuels-core = { workspace = true } fuels-macros = { workspace = true } fuels-programs = { workspace = true, optional = true } fuels-test-helpers = { workspace = true, optional = true } [features] -default = ["std", "fuels-test-helpers?/fuels-accounts", "coin-cache"] +default = ["std", "coin-cache"] coin-cache = ["fuels-accounts/coin-cache"] # The crates enabled via `dep:` below are not currently wasm compatible, as diff --git a/scripts/check-docs/Cargo.toml b/scripts/check-docs/Cargo.toml index 29ac54550..c3feae918 100644 --- a/scripts/check-docs/Cargo.toml +++ b/scripts/check-docs/Cargo.toml @@ -10,6 +10,6 @@ repository = { workspace = true } rust-version = { workspace = true } [dependencies] -anyhow = "1.0.75" +anyhow = { workspace = true, features = ["std"] } itertools = { workspace = true } -regex = { workspace = true } +regex = { workspace = true, features = ["std"] } diff --git a/wasm-tests/Cargo.toml b/wasm-tests/Cargo.toml index 4d13e5d1a..88936f1be 100644 --- a/wasm-tests/Cargo.toml +++ b/wasm-tests/Cargo.toml @@ -15,5 +15,5 @@ crate-type = ['cdylib'] [dev-dependencies] fuels = { workspace = true } fuels-core = { workspace = true } -getrandom = { version = "0.2.11", features = ["js"] } -wasm-bindgen-test = "0.3.39" +getrandom = { workspace = true, features = ["js"] } +wasm-bindgen-test = { workspace = true } From da324d1bb4458b24cf9e10e70e4374cf3cd9469a Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 17:06:48 +0200 Subject: [PATCH 07/70] use crate level std feature --- packages/fuels-accounts/Cargo.toml | 10 +++++++-- packages/fuels-accounts/src/lib.rs | 1 + packages/fuels-core/Cargo.toml | 23 +++++++++++-------- packages/fuels-core/src/types/errors.rs | 1 + packages/fuels-core/src/types/wrappers.rs | 1 + packages/fuels-programs/Cargo.toml | 4 ++-- packages/fuels-test-helpers/Cargo.toml | 27 +++++++++++++---------- packages/fuels-test-helpers/src/lib.rs | 23 +++++++++++++------ packages/fuels/src/lib.rs | 3 +-- 9 files changed, 59 insertions(+), 34 deletions(-) diff --git a/packages/fuels-accounts/Cargo.toml b/packages/fuels-accounts/Cargo.toml index 073494bfb..52a48e5fa 100644 --- a/packages/fuels-accounts/Cargo.toml +++ b/packages/fuels-accounts/Cargo.toml @@ -16,7 +16,7 @@ elliptic-curve = { workspace = true } eth-keystore = { workspace = true, optional = true } fuel-core-client = { workspace = true, optional = true } fuel-core-types = { workspace = true } -fuel-crypto = { workspace = true, features = ["std", "random"] } +fuel-crypto = { workspace = true } fuel-tx = { workspace = true } fuel-types = { workspace = true } fuels-core = { workspace = true } @@ -35,4 +35,10 @@ tokio = { workspace = true, features = ["test-util", "macros"] } [features] default = ["std"] coin-cache = ["tokio/time"] -std = ["fuels-core/std", "fuel-core-client/default", "dep:eth-keystore"] +std = [ + "fuels-core/std", + "fuel-core-client/default", + "dep:eth-keystore", + "fuel-crypto/std", + "fuel-crypto/random", +] diff --git a/packages/fuels-accounts/src/lib.rs b/packages/fuels-accounts/src/lib.rs index d023b56f8..2f621cb78 100644 --- a/packages/fuels-accounts/src/lib.rs +++ b/packages/fuels-accounts/src/lib.rs @@ -7,6 +7,7 @@ pub mod provider; #[cfg(feature = "std")] pub mod wallet; +#[cfg(feature = "std")] pub use account::*; #[cfg(feature = "coin-cache")] diff --git a/packages/fuels-core/Cargo.toml b/packages/fuels-core/Cargo.toml index 6e386ee8c..464087569 100644 --- a/packages/fuels-core/Cargo.toml +++ b/packages/fuels-core/Cargo.toml @@ -10,7 +10,7 @@ rust-version = { workspace = true } description = "Fuel Rust SDK core." [dependencies] -async-trait = { workspace = true, default-features = false } +async-trait = { workspace = true } bech32 = { workspace = true } chrono = { workspace = true } fuel-abi-types = { workspace = true } @@ -18,17 +18,17 @@ fuel-asm = { workspace = true } fuel-core-chain-config = { workspace = true } fuel-core-client = { workspace = true, optional = true } fuel-core-types = { workspace = true } -fuel-crypto = { workspace = true, features = ["std"] } +fuel-crypto = { workspace = true } fuel-tx = { workspace = true } -fuel-types = { workspace = true, features = ["default"] } +fuel-types = { workspace = true } fuel-vm = { workspace = true } fuels-macros = { workspace = true } -hex = { workspace = true, features = ["std"] } -itertools = { workspace = true, features = ["use_std"] } +hex = { workspace = true } +itertools = { workspace = true } serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true, default-features = true } -thiserror = { workspace = true, default-features = false } -uint = { workspace = true, default-features = false } +serde_json = { workspace = true } +thiserror = { workspace = true } +uint = { workspace = true } [dev-dependencies] fuel-tx = { workspace = true, features = ["test-helpers", "random"] } @@ -36,4 +36,9 @@ tokio = { workspace = true, features = ["test-util", "macros"] } [features] default = ["std"] -std = ["dep:fuel-core-client"] +std = [ + "dep:fuel-core-client", + "fuel-crypto/std", + "hex/std", + "itertools/use_std", +] diff --git a/packages/fuels-core/src/types/errors.rs b/packages/fuels-core/src/types/errors.rs index 34812a7d9..86dc59997 100644 --- a/packages/fuels-core/src/types/errors.rs +++ b/packages/fuels-core/src/types/errors.rs @@ -95,6 +95,7 @@ macro_rules! impl_error_from { impl_error_from!(Other, &'static str); impl_error_from!(Other, bech32::Error); +#[cfg(feature = "std")] impl_error_from!(Other, fuel_crypto::Error); impl_error_from!(Other, serde_json::Error); impl_error_from!(Other, FromHexError); diff --git a/packages/fuels-core/src/types/wrappers.rs b/packages/fuels-core/src/types/wrappers.rs index 90b98152c..152769a8a 100644 --- a/packages/fuels-core/src/types/wrappers.rs +++ b/packages/fuels-core/src/types/wrappers.rs @@ -7,6 +7,7 @@ pub mod input; pub mod message; pub mod message_proof; pub mod node_info; +#[cfg(feature = "std")] pub mod transaction; pub mod transaction_response; pub mod output { diff --git a/packages/fuels-programs/Cargo.toml b/packages/fuels-programs/Cargo.toml index 6ad2971ff..1396c3d3e 100644 --- a/packages/fuels-programs/Cargo.toml +++ b/packages/fuels-programs/Cargo.toml @@ -10,11 +10,11 @@ rust-version = { workspace = true } description = "Fuel Rust SDK contracts." [dependencies] -async-trait = { workspace = true, default-features = false } +async-trait = { workspace = true } fuel-abi-types = { workspace = true } fuel-asm = { workspace = true } fuel-tx = { workspace = true } -fuel-types = { workspace = true, features = ["default"] } +fuel-types = { workspace = true } fuels-accounts = { workspace = true } fuels-core = { workspace = true } itertools = { workspace = true } diff --git a/packages/fuels-test-helpers/Cargo.toml b/packages/fuels-test-helpers/Cargo.toml index 5372296b1..48c7887f0 100644 --- a/packages/fuels-test-helpers/Cargo.toml +++ b/packages/fuels-test-helpers/Cargo.toml @@ -11,26 +11,29 @@ description = "Fuel Rust SDK test helpers." [dependencies] fuel-core = { workspace = true, features = ["test-helpers"], optional = true } -fuel-core-chain-config = { workspace = true, features = [ - "test-helpers", - "std", -] } +fuel-core-chain-config = { workspace = true, features = ["test-helpers"] } fuel-core-client = { workspace = true } fuel-core-poa = { workspace = true } fuel-core-services = { workspace = true } fuel-crypto = { workspace = true } fuel-tx = { workspace = true } -fuel-types = { workspace = true, features = ["random"] } -fuels-accounts = { workspace = true, features = ["std"] } -fuels-core = { workspace = true, features = ["std"] } +fuel-types = { workspace = true } +fuels-accounts = { workspace = true } +fuels-core = { workspace = true } futures = { workspace = true } portpicker = { workspace = true } -rand = { workspace = true, default-features = false } -tempfile = { workspace = true, default-features = false } -tokio = { workspace = true, default-features = false } -which = { workspace = true, default-features = false } +rand = { workspace = true } +tempfile = { workspace = true } +tokio = { workspace = true } +which = { workspace = true } [features] default = ["std"] -std = ["fuels-accounts/std", "fuels-core/std", "fuel-core-chain-config/std"] +std = [ + "fuels-accounts/std", + "fuels-core/std", + "fuel-core-chain-config/std", + "fuel-types/random", + "fuel-core-chain-config/std", +] fuel-core-lib = ["dep:fuel-core"] diff --git a/packages/fuels-test-helpers/src/lib.rs b/packages/fuels-test-helpers/src/lib.rs index 88186f4d9..338864d7f 100644 --- a/packages/fuels-test-helpers/src/lib.rs +++ b/packages/fuels-test-helpers/src/lib.rs @@ -3,31 +3,36 @@ pub use accounts::*; use fuel_tx::{Bytes32, ConsensusParameters, ContractParameters, TxParameters, UtxoId}; use fuel_types::{AssetId, Nonce}; +#[cfg(feature = "std")] use fuels_accounts::provider::Provider; -use fuels_core::types::{ - bech32::Bech32Address, - coin::{Coin, CoinStatus}, - errors::Result, - message::{Message, MessageStatus}, -}; +#[cfg(feature = "std")] +use fuels_core::types::coin::{Coin, CoinStatus}; +#[cfg(feature = "std")] +use fuels_core::types::message::{Message, MessageStatus}; +use fuels_core::types::{bech32::Bech32Address, errors::Result}; pub use node_types::*; use rand::Fill; +#[cfg(feature = "std")] use utils::{into_coin_configs, into_message_configs}; pub use wallets_config::*; mod node_types; -#[cfg(not(feature = "fuel-core-lib"))] +#[cfg(all(not(feature = "fuel-core-lib"), feature = "std"))] pub(crate) mod fuel_bin_service; #[cfg(feature = "fuels-accounts")] mod accounts; +#[cfg(feature = "std")] pub use service::*; +#[cfg(feature = "std")] mod service; +#[cfg(feature = "std")] mod utils; mod wallets_config; +#[cfg(feature = "std")] /// Create a vector of `num_asset`*`coins_per_asset` UTXOs and a vector of the unique corresponding /// asset IDs. `AssetId`. Each UTXO (=coin) contains `amount_per_coin` amount of a random asset. The /// output of this function can be used with `setup_test_provider` to get a client with some @@ -60,6 +65,7 @@ pub fn setup_multiple_assets_coins( (coins, asset_ids) } +#[cfg(feature = "std")] /// Create a vector of UTXOs with the provided AssetIds, num_coins, and amount_per_coin pub fn setup_custom_assets_coins(owner: &Bech32Address, assets: &[AssetConfig]) -> Vec { let coins = assets @@ -71,6 +77,7 @@ pub fn setup_custom_assets_coins(owner: &Bech32Address, assets: &[AssetConfig]) coins } +#[cfg(feature = "std")] /// Create a vector of `num_coins` UTXOs containing `amount_per_coin` amount of asset `asset_id`. /// The output of this function can be used with `setup_test_provider` to get a client with some /// pre-existing coins, but with only one asset ID. @@ -103,6 +110,7 @@ pub fn setup_single_asset_coins( coins } +#[cfg(feature = "std")] pub fn setup_single_message( sender: &Bech32Address, recipient: &Bech32Address, @@ -121,6 +129,7 @@ pub fn setup_single_message( } } +#[cfg(feature = "std")] pub async fn setup_test_provider( coins: Vec, messages: Vec, diff --git a/packages/fuels/src/lib.rs b/packages/fuels/src/lib.rs index bffe9132d..f34eb1b1d 100644 --- a/packages/fuels/src/lib.rs +++ b/packages/fuels/src/lib.rs @@ -80,7 +80,7 @@ pub mod prelude { }, }, test_helpers::*, - types::transaction_builders::*, + types::{transaction::*, transaction_builders::*}, }; pub use super::{ core::constants::*, @@ -89,7 +89,6 @@ pub mod prelude { types::{ bech32::{Bech32Address, Bech32ContractId}, errors::{Error, Result}, - transaction::*, Address, AssetId, Bytes, ContractId, RawSlice, Salt, }, }; From dc2262fd4d9cdd324ebdfc7790527e4ba5da987b Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 19:25:39 +0200 Subject: [PATCH 08/70] lessen features --- examples/codec/Cargo.toml | 6 ++++-- examples/contracts/Cargo.toml | 8 ++++++-- examples/contracts/src/lib.rs | 2 +- examples/cookbook/Cargo.toml | 6 +++++- examples/debugging/Cargo.toml | 2 +- examples/macros/Cargo.toml | 2 +- examples/predicates/Cargo.toml | 6 +++++- examples/providers/Cargo.toml | 6 +++++- examples/rust_bindings/Cargo.toml | 4 +++- examples/rust_bindings/src/lib.rs | 2 -- examples/types/Cargo.toml | 4 ++-- examples/wallets/Cargo.toml | 8 ++++++-- packages/fuels-test-helpers/Cargo.toml | 3 +++ packages/fuels-test-helpers/src/lib.rs | 4 ++-- packages/fuels/Cargo.toml | 3 ++- packages/fuels/src/lib.rs | 5 +++-- 16 files changed, 49 insertions(+), 22 deletions(-) diff --git a/examples/codec/Cargo.toml b/examples/codec/Cargo.toml index a97f79f13..4d0cdd230 100644 --- a/examples/codec/Cargo.toml +++ b/examples/codec/Cargo.toml @@ -10,5 +10,7 @@ repository = { workspace = true } description = "Fuel Rust SDK codec examples." [dev-dependencies] -fuels = { workspace = true } -tokio = { workspace = true, features = ["full"] } +fuels = { workspace = true, features = [ + "std", +] } +tokio = { workspace = true, features = ["macros"] } diff --git a/examples/contracts/Cargo.toml b/examples/contracts/Cargo.toml index 0a02a9290..ac5c29cd4 100644 --- a/examples/contracts/Cargo.toml +++ b/examples/contracts/Cargo.toml @@ -10,9 +10,13 @@ repository = { workspace = true } description = "Fuel Rust SDK contract examples." [dev-dependencies] -fuels = { workspace = true } +fuels = { workspace = true, features = [ + "std", + "test-helpers", + "fuel-core-lib", +] } rand = { workspace = true } -tokio = { workspace = true, features = ["full"] } +tokio = { workspace = true, features = ["macros"] } [features] fuel-core-lib = ["fuels/fuel-core-lib"] diff --git a/examples/contracts/src/lib.rs b/examples/contracts/src/lib.rs index 6f71274ca..881959f14 100644 --- a/examples/contracts/src/lib.rs +++ b/examples/contracts/src/lib.rs @@ -36,7 +36,7 @@ mod tests { // ANCHOR: deploy_contract // This helper will launch a local node and provide a test wallet linked to it - let wallet = launch_provider_and_get_wallet().await?; + let wallet = fuels::test_helpers::launch_provider_and_get_wallet().await?; // This will load and deploy your contract binary to the chain so that its ID can // be used to initialize the instance diff --git a/examples/cookbook/Cargo.toml b/examples/cookbook/Cargo.toml index bdd360baf..d53cf3fb1 100644 --- a/examples/cookbook/Cargo.toml +++ b/examples/cookbook/Cargo.toml @@ -10,7 +10,11 @@ repository = { workspace = true } description = "Fuel Rust SDK cookbook examples." [dev-dependencies] -fuels = { workspace = true } +fuels = { workspace = true, features = [ + "std", + "test-helpers", + "fuel-core-lib", +] } rand = { workspace = true } tokio = { workspace = true, features = ["full"] } diff --git a/examples/debugging/Cargo.toml b/examples/debugging/Cargo.toml index 68d178083..0adbb35d0 100644 --- a/examples/debugging/Cargo.toml +++ b/examples/debugging/Cargo.toml @@ -11,7 +11,7 @@ description = "Fuel Rust SDK debugging examples." [dev-dependencies] fuel-abi-types = { workspace = true } -fuels = { workspace = true } +fuels = { workspace = true, features = ["std"] } rand = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true, features = ["full"] } diff --git a/examples/macros/Cargo.toml b/examples/macros/Cargo.toml index 6be83c5d0..d21e385b6 100644 --- a/examples/macros/Cargo.toml +++ b/examples/macros/Cargo.toml @@ -10,5 +10,5 @@ repository = { workspace = true } description = "Fuel Rust SDK macro examples." [dev-dependencies] -fuels = { workspace = true } +fuels = { workspace = true, features = ["std"] } tokio = { workspace = true, features = ["full"] } diff --git a/examples/predicates/Cargo.toml b/examples/predicates/Cargo.toml index 0785a218f..f104b8c2a 100644 --- a/examples/predicates/Cargo.toml +++ b/examples/predicates/Cargo.toml @@ -10,6 +10,10 @@ repository = { workspace = true } description = "Fuel Rust SDK predicate examples." [dev-dependencies] -fuels = { workspace = true } +fuels = { workspace = true, features = [ + "std", + "test-helpers", + "fuel-core-lib", +] } rand = { workspace = true } tokio = { workspace = true, features = ["full"] } diff --git a/examples/providers/Cargo.toml b/examples/providers/Cargo.toml index 08843ee8e..50eb174fb 100644 --- a/examples/providers/Cargo.toml +++ b/examples/providers/Cargo.toml @@ -10,6 +10,10 @@ repository = { workspace = true } description = "Fuel Rust SDK provider examples." [dev-dependencies] -fuels = { workspace = true } +fuels = { workspace = true, features = [ + "std", + "test-helpers", + "fuel-core-lib", +] } rand = { workspace = true } tokio = { workspace = true, features = ["full"] } diff --git a/examples/rust_bindings/Cargo.toml b/examples/rust_bindings/Cargo.toml index 5228d46b6..cbf03d217 100644 --- a/examples/rust_bindings/Cargo.toml +++ b/examples/rust_bindings/Cargo.toml @@ -10,7 +10,9 @@ repository = { workspace = true } description = "Fuel Rust SDK examples for Rust-native bindings" [dev-dependencies] -fuels = { workspace = true } +fuels = { workspace = true, features = [ + "std", +] } fuels-code-gen = { workspace = true } fuels-macros = { workspace = true } proc-macro2 = { workspace = true } diff --git a/examples/rust_bindings/src/lib.rs b/examples/rust_bindings/src/lib.rs index 4402e8ed8..47e1c0c87 100644 --- a/examples/rust_bindings/src/lib.rs +++ b/examples/rust_bindings/src/lib.rs @@ -5,8 +5,6 @@ mod tests { #[tokio::test] #[allow(unused_variables)] async fn transform_json_to_bindings() -> Result<()> { - use fuels::test_helpers::launch_provider_and_get_wallet; - let wallet = launch_provider_and_get_wallet().await?; { // ANCHOR: use_abigen use fuels::prelude::*; diff --git a/examples/types/Cargo.toml b/examples/types/Cargo.toml index 74c688adc..e6501343c 100644 --- a/examples/types/Cargo.toml +++ b/examples/types/Cargo.toml @@ -10,6 +10,6 @@ repository = { workspace = true } description = "Fuel Rust SDK types examples." [dev-dependencies] -fuels = { workspace = true } +fuels = { workspace = true, features = ["std"] } rand = { workspace = true } -tokio = { workspace = true, features = ["full"] } +tokio = { workspace = true, features = ["macros"] } diff --git a/examples/wallets/Cargo.toml b/examples/wallets/Cargo.toml index 5fa6ad736..1442c5fe3 100644 --- a/examples/wallets/Cargo.toml +++ b/examples/wallets/Cargo.toml @@ -10,6 +10,10 @@ repository = { workspace = true } description = "Fuel Rust SDK wallet examples." [dev-dependencies] -fuels = { workspace = true } +fuels = { workspace = true, features = [ + "std", + "test-helpers", + "fuel-core-lib", +] } rand = { workspace = true } -tokio = { workspace = true, features = ["full"] } +tokio = { workspace = true, features = ["macros"] } diff --git a/packages/fuels-test-helpers/Cargo.toml b/packages/fuels-test-helpers/Cargo.toml index 48c7887f0..bf84aa527 100644 --- a/packages/fuels-test-helpers/Cargo.toml +++ b/packages/fuels-test-helpers/Cargo.toml @@ -27,6 +27,9 @@ tempfile = { workspace = true } tokio = { workspace = true } which = { workspace = true } +[dev-dependencies] +fuels-test-helpers = { workspace = true, features = ["std"] } + [features] default = ["std"] std = [ diff --git a/packages/fuels-test-helpers/src/lib.rs b/packages/fuels-test-helpers/src/lib.rs index 338864d7f..cdf730c04 100644 --- a/packages/fuels-test-helpers/src/lib.rs +++ b/packages/fuels-test-helpers/src/lib.rs @@ -1,5 +1,5 @@ //! Testing helpers/utilities for Fuel SDK. -#[cfg(feature = "fuels-accounts")] +#[cfg(feature = "std")] pub use accounts::*; use fuel_tx::{Bytes32, ConsensusParameters, ContractParameters, TxParameters, UtxoId}; use fuel_types::{AssetId, Nonce}; @@ -20,7 +20,7 @@ mod node_types; #[cfg(all(not(feature = "fuel-core-lib"), feature = "std"))] pub(crate) mod fuel_bin_service; -#[cfg(feature = "fuels-accounts")] +#[cfg(feature = "std")] mod accounts; #[cfg(feature = "std")] diff --git a/packages/fuels/Cargo.toml b/packages/fuels/Cargo.toml index 26c739524..22237c6ac 100644 --- a/packages/fuels/Cargo.toml +++ b/packages/fuels/Cargo.toml @@ -36,9 +36,10 @@ std = [ "dep:fuels-programs", "dep:fuels-test-helpers", "fuels-accounts/std", - "fuels-programs?/std", + "fuels-programs/std", "fuels-core/std", "fuels-test-helpers?/std", ] fuel-core-lib = ["fuels-test-helpers?/fuel-core-lib", "dep:fuel-core"] +test-helpers = ["dep:fuels-test-helpers"] rocksdb = ["fuel-core?/rocksdb"] diff --git a/packages/fuels/src/lib.rs b/packages/fuels/src/lib.rs index f34eb1b1d..b84a1717f 100644 --- a/packages/fuels/src/lib.rs +++ b/packages/fuels/src/lib.rs @@ -53,13 +53,15 @@ pub mod types { pub use fuels_core::types::*; } -#[cfg(feature = "std")] +#[cfg(feature = "test-helpers")] pub mod test_helpers { pub use fuels_test_helpers::*; } #[doc(hidden)] pub mod prelude { + #[cfg(feature = "test-helpers")] + pub use super::test_helpers::*; #[cfg(feature = "std")] pub use super::{ accounts::{ @@ -79,7 +81,6 @@ pub mod prelude { SettableContract, StorageConfiguration, }, }, - test_helpers::*, types::{transaction::*, transaction_builders::*}, }; pub use super::{ From d2225d27cc4445e1893083b38bd18973f4300506 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 19:36:26 +0200 Subject: [PATCH 09/70] fuels accounts unused crate deps --- packages/fuels-accounts/Cargo.toml | 49 ++++++++++++++++++++---------- packages/fuels-accounts/src/lib.rs | 6 ++++ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/packages/fuels-accounts/Cargo.toml b/packages/fuels-accounts/Cargo.toml index 52a48e5fa..147ae50da 100644 --- a/packages/fuels-accounts/Cargo.toml +++ b/packages/fuels-accounts/Cargo.toml @@ -10,35 +10,52 @@ rust-version = { workspace = true } description = "Fuel Rust SDK accounts." [dependencies] -async-trait = { workspace = true } -chrono = { workspace = true } -elliptic-curve = { workspace = true } +async-trait = { workspace = true, optional = true } +chrono = { workspace = true, optional = true } +elliptic-curve = { workspace = true, optional = true } eth-keystore = { workspace = true, optional = true } fuel-core-client = { workspace = true, optional = true } -fuel-core-types = { workspace = true } -fuel-crypto = { workspace = true } -fuel-tx = { workspace = true } -fuel-types = { workspace = true } -fuels-core = { workspace = true } -rand = { workspace = true } -semver = { workspace = true } -tai64 = { workspace = true } -thiserror = { workspace = true } -tokio = { workspace = true } -zeroize = { workspace = true } +fuel-core-types = { workspace = true, optional = true } +fuel-crypto = { workspace = true, optional = true } +fuel-tx = { workspace = true, optional = true } +fuel-types = { workspace = true, optional = true } +fuels-core = { workspace = true, optional = true } +rand = { workspace = true, optional = true } +semver = { workspace = true, optional = true } +tai64 = { workspace = true, optional = true } +thiserror = { workspace = true, optional = true } +tokio = { workspace = true, optional = true } +zeroize = { workspace = true, optional = true } [dev-dependencies] fuel-tx = { workspace = true, features = ["test-helpers", "random"] } +fuels-accounts = { workspace = true, features = ["std", "coin-cache"] } tempfile = { workspace = true } tokio = { workspace = true, features = ["test-util", "macros"] } [features] default = ["std"] -coin-cache = ["tokio/time"] +coin-cache = ["tokio/time", "dep:fuels-core", "dep:fuel-types"] std = [ "fuels-core/std", "fuel-core-client/default", - "dep:eth-keystore", "fuel-crypto/std", "fuel-crypto/random", + "dep:eth-keystore", + "dep:chrono", + "dep:elliptic-curve", + "dep:eth-keystore", + "dep:fuel-core-client", + "dep:fuel-core-types", + "dep:fuel-crypto", + "dep:fuel-tx", + "dep:fuel-types", + "dep:fuels-core", + "dep:rand", + "dep:semver", + "dep:tai64", + "dep:thiserror", + "dep:tokio", + "dep:zeroize", + "dep:async-trait", ] diff --git a/packages/fuels-accounts/src/lib.rs b/packages/fuels-accounts/src/lib.rs index 2f621cb78..295873409 100644 --- a/packages/fuels-accounts/src/lib.rs +++ b/packages/fuels-accounts/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(unused_crate_dependencies)] #[cfg(feature = "std")] mod account; #[cfg(feature = "std")] @@ -15,3 +16,8 @@ mod coin_cache; #[cfg(feature = "std")] pub mod predicate; + +#[cfg(test)] +mod tests { + use fuels_accounts as _; +} From 9eab659a53282cdea4fe65d3a28c58312697993b Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 19:43:06 +0200 Subject: [PATCH 10/70] fuels core deps --- packages/fuels-code-gen/src/lib.rs | 1 + packages/fuels-core/Cargo.toml | 17 +++++++++++------ packages/fuels-core/src/lib.rs | 5 +++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/fuels-code-gen/src/lib.rs b/packages/fuels-code-gen/src/lib.rs index 3ccf6d728..5a9266859 100644 --- a/packages/fuels-code-gen/src/lib.rs +++ b/packages/fuels-code-gen/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(unused_crate_dependencies)] pub use program_bindings::*; pub mod error; diff --git a/packages/fuels-core/Cargo.toml b/packages/fuels-core/Cargo.toml index 464087569..f13d314d9 100644 --- a/packages/fuels-core/Cargo.toml +++ b/packages/fuels-core/Cargo.toml @@ -12,19 +12,19 @@ description = "Fuel Rust SDK core." [dependencies] async-trait = { workspace = true } bech32 = { workspace = true } -chrono = { workspace = true } +chrono = { workspace = true, optional = true } fuel-abi-types = { workspace = true } fuel-asm = { workspace = true } -fuel-core-chain-config = { workspace = true } +fuel-core-chain-config = { workspace = true, optional = true } fuel-core-client = { workspace = true, optional = true } -fuel-core-types = { workspace = true } +fuel-core-types = { workspace = true, optional = true } fuel-crypto = { workspace = true } -fuel-tx = { workspace = true } +fuel-tx = { workspace = true, features = ["alloc"] } fuel-types = { workspace = true } -fuel-vm = { workspace = true } +fuel-vm = { workspace = true, features = ["alloc"] } fuels-macros = { workspace = true } hex = { workspace = true } -itertools = { workspace = true } +itertools = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } thiserror = { workspace = true } @@ -32,6 +32,7 @@ uint = { workspace = true } [dev-dependencies] fuel-tx = { workspace = true, features = ["test-helpers", "random"] } +fuels-core = { workspace = true, features = ["std"] } tokio = { workspace = true, features = ["test-util", "macros"] } [features] @@ -41,4 +42,8 @@ std = [ "fuel-crypto/std", "hex/std", "itertools/use_std", + "dep:chrono", + "dep:fuel-core-chain-config", + "dep:fuel-core-types", + "dep:itertools", ] diff --git a/packages/fuels-core/src/lib.rs b/packages/fuels-core/src/lib.rs index 4fe809b03..6a6ec7970 100644 --- a/packages/fuels-core/src/lib.rs +++ b/packages/fuels-core/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(unused_crate_dependencies)] pub mod codec; pub mod traits; pub mod types; @@ -22,3 +23,7 @@ impl Configurables { } } } +#[cfg(test)] +mod tests { + use fuels_core as _; +} From 55ee802797dbb0058964dc34d94343a9328b4b9d Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 20:07:43 +0200 Subject: [PATCH 11/70] fuels programs unused deps --- packages/fuels-programs/Cargo.toml | 29 ++++++++++++++------- packages/fuels-programs/src/call_utils.rs | 8 +++--- packages/fuels-programs/src/lib.rs | 6 +++++ packages/fuels-programs/src/script_calls.rs | 19 +++++--------- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/packages/fuels-programs/Cargo.toml b/packages/fuels-programs/Cargo.toml index 1396c3d3e..ec81d2c82 100644 --- a/packages/fuels-programs/Cargo.toml +++ b/packages/fuels-programs/Cargo.toml @@ -10,22 +10,31 @@ rust-version = { workspace = true } description = "Fuel Rust SDK contracts." [dependencies] -async-trait = { workspace = true } -fuel-abi-types = { workspace = true } -fuel-asm = { workspace = true } +async-trait = { workspace = true, optional = true } +fuel-abi-types = { workspace = true, optional = true } +fuel-asm = { workspace = true, optional = true } fuel-tx = { workspace = true } -fuel-types = { workspace = true } -fuels-accounts = { workspace = true } +fuel-types = { workspace = true, optional = true } +fuels-accounts = { workspace = true, optional = true } fuels-core = { workspace = true } -itertools = { workspace = true } -rand = { workspace = true } -serde_json = { workspace = true } -tokio = { workspace = true } +itertools = { workspace = true, features = ["use_std"], optional = true } +serde_json = { workspace = true, optional = true } [dev-dependencies] +fuels-programs = { workspace = true, features = ["std"] } tempfile = { workspace = true } tokio = { workspace = true, features = ["macros", "test-util"] } +rand = { workspace = true } [features] default = ["std"] -std = ["fuels-core/std", "fuels-accounts/std"] +std = [ + "fuels-core/std", + "fuels-accounts/std", + "dep:itertools", + "dep:serde_json", + "dep:async-trait", + "dep:fuel-abi-types", + "dep:fuel-asm", + "dep:fuel-types", +] diff --git a/packages/fuels-programs/src/call_utils.rs b/packages/fuels-programs/src/call_utils.rs index b26576053..5d7e964be 100644 --- a/packages/fuels-programs/src/call_utils.rs +++ b/packages/fuels-programs/src/call_utils.rs @@ -455,13 +455,14 @@ fn generate_asset_change_outputs( .collect() } -pub(crate) fn generate_contract_outputs(num_of_contracts: usize) -> Vec { +pub(crate) fn generate_contract_outputs(num_of_contracts: usize) -> impl Iterator { (0..num_of_contracts) .map(|idx| Output::contract(idx as u16, Bytes32::zeroed(), Bytes32::zeroed())) - .collect() } -pub(crate) fn generate_contract_inputs(contract_ids: HashSet) -> Vec { +pub(crate) fn generate_contract_inputs( + contract_ids: HashSet, +) -> impl Iterator { contract_ids .into_iter() .enumerate() @@ -474,7 +475,6 @@ pub(crate) fn generate_contract_inputs(contract_ids: HashSet) -> Vec contract_id, ) }) - .collect() } fn extract_unique_contract_ids(calls: &[ContractCall]) -> HashSet { diff --git a/packages/fuels-programs/src/lib.rs b/packages/fuels-programs/src/lib.rs index 899358e94..f08f175a6 100644 --- a/packages/fuels-programs/src/lib.rs +++ b/packages/fuels-programs/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(unused_crate_dependencies)] pub mod call_response; #[cfg(feature = "std")] pub mod call_utils; @@ -8,3 +9,8 @@ pub mod receipt_parser; pub mod script_calls; #[cfg(feature = "std")] mod submit_response; + +#[cfg(test)] +mod tests { + use fuels_programs as _; +} diff --git a/packages/fuels-programs/src/script_calls.rs b/packages/fuels-programs/src/script_calls.rs index 735319125..a3966d84e 100644 --- a/packages/fuels-programs/src/script_calls.rs +++ b/packages/fuels-programs/src/script_calls.rs @@ -20,7 +20,6 @@ use fuels_core::{ tx_status::TxStatus, }, }; -use itertools::chain; use crate::{ call_response::FuelCallResponse, @@ -176,22 +175,18 @@ where .collect(); let num_of_contracts = contract_ids.len(); - let inputs = chain!( - generate_contract_inputs(contract_ids), - self.script_call.inputs.clone(), - ) - .collect(); + let inputs = generate_contract_inputs(contract_ids) + .chain(self.script_call.inputs.clone()) + .collect(); // Note the contract_outputs need to come first since the // contract_inputs are referencing them via `output_index`. The node // will, upon receiving our request, use `output_index` to index the // `inputs` array we've sent over. - let outputs = chain!( - generate_contract_outputs(num_of_contracts), - self.script_call.outputs.clone(), - self.script_call.variable_outputs.clone(), - ) - .collect(); + let outputs = generate_contract_outputs(num_of_contracts) + .chain(self.script_call.outputs.clone()) + .chain(self.script_call.variable_outputs.clone()) + .collect(); Ok((inputs, outputs)) } From 4b3b4219af75bb638f88a8e4b2071017b3f0acea Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 20:54:07 +0200 Subject: [PATCH 12/70] cleanup std flags --- packages/fuels-core/src/utils.rs | 10 +- packages/fuels-test-helpers/src/lib.rs | 178 ++--------------------- packages/fuels-test-helpers/src/utils.rs | 151 ++++++++++++++++++- 3 files changed, 170 insertions(+), 169 deletions(-) diff --git a/packages/fuels-core/src/utils.rs b/packages/fuels-core/src/utils.rs index 788293d32..b74f2492f 100644 --- a/packages/fuels-core/src/utils.rs +++ b/packages/fuels-core/src/utils.rs @@ -1,8 +1,7 @@ pub mod constants; pub mod offsets; -use constants::{WITNESS_STATIC_SIZE, WORD_SIZE}; -use fuel_tx::Witness; +use constants::WORD_SIZE; use crate::{error, types::errors::Result}; @@ -26,15 +25,18 @@ pub fn checked_round_up_to_word_alignment(bytes_len: usize) -> Result { ) }) } -pub(crate) fn calculate_witnesses_size<'a, I: IntoIterator>( + +#[cfg(feature = "std")] +pub(crate) fn calculate_witnesses_size<'a, I: IntoIterator>( witnesses: I, ) -> usize { witnesses .into_iter() - .map(|w| w.as_ref().len() + WITNESS_STATIC_SIZE) + .map(|w| w.as_ref().len() + constants::WITNESS_STATIC_SIZE) .sum() } +#[cfg(feature = "std")] pub(crate) mod sealed { pub trait Sealed {} } diff --git a/packages/fuels-test-helpers/src/lib.rs b/packages/fuels-test-helpers/src/lib.rs index cdf730c04..6ebcfea7e 100644 --- a/packages/fuels-test-helpers/src/lib.rs +++ b/packages/fuels-test-helpers/src/lib.rs @@ -1,185 +1,37 @@ //! Testing helpers/utilities for Fuel SDK. #[cfg(feature = "std")] pub use accounts::*; -use fuel_tx::{Bytes32, ConsensusParameters, ContractParameters, TxParameters, UtxoId}; -use fuel_types::{AssetId, Nonce}; -#[cfg(feature = "std")] -use fuels_accounts::provider::Provider; -#[cfg(feature = "std")] -use fuels_core::types::coin::{Coin, CoinStatus}; -#[cfg(feature = "std")] -use fuels_core::types::message::{Message, MessageStatus}; -use fuels_core::types::{bech32::Bech32Address, errors::Result}; pub use node_types::*; -use rand::Fill; #[cfg(feature = "std")] -use utils::{into_coin_configs, into_message_configs}; +pub use service::*; +#[cfg(feature = "std")] +pub use utils::*; pub use wallets_config::*; -mod node_types; - -#[cfg(all(not(feature = "fuel-core-lib"), feature = "std"))] -pub(crate) mod fuel_bin_service; #[cfg(feature = "std")] mod accounts; - -#[cfg(feature = "std")] -pub use service::*; +#[cfg(all(not(feature = "fuel-core-lib"), feature = "std"))] +pub(crate) mod fuel_bin_service; +mod node_types; #[cfg(feature = "std")] mod service; - #[cfg(feature = "std")] mod utils; mod wallets_config; -#[cfg(feature = "std")] -/// Create a vector of `num_asset`*`coins_per_asset` UTXOs and a vector of the unique corresponding -/// asset IDs. `AssetId`. Each UTXO (=coin) contains `amount_per_coin` amount of a random asset. The -/// output of this function can be used with `setup_test_provider` to get a client with some -/// pre-existing coins, with `num_asset` different asset ids. Note that one of the assets is the -/// base asset to pay for gas. -pub fn setup_multiple_assets_coins( - owner: &Bech32Address, - num_asset: u64, - coins_per_asset: u64, - amount_per_coin: u64, -) -> (Vec, Vec) { - let mut rng = rand::thread_rng(); - // Create `num_asset-1` asset ids so there is `num_asset` in total with the base asset - let asset_ids = (0..(num_asset - 1)) - .map(|_| { - let mut random_asset_id = AssetId::zeroed(); - random_asset_id - .try_fill(&mut rng) - .expect("failed to fill with random data"); - random_asset_id - }) - .chain([AssetId::zeroed()]) - .collect::>(); - - let coins = asset_ids - .iter() - .flat_map(|id| setup_single_asset_coins(owner, *id, coins_per_asset, amount_per_coin)) - .collect::>(); - - (coins, asset_ids) -} - -#[cfg(feature = "std")] -/// Create a vector of UTXOs with the provided AssetIds, num_coins, and amount_per_coin -pub fn setup_custom_assets_coins(owner: &Bech32Address, assets: &[AssetConfig]) -> Vec { - let coins = assets - .iter() - .flat_map(|asset| { - setup_single_asset_coins(owner, asset.id, asset.num_coins, asset.coin_amount) - }) - .collect::>(); - coins -} - -#[cfg(feature = "std")] -/// Create a vector of `num_coins` UTXOs containing `amount_per_coin` amount of asset `asset_id`. -/// The output of this function can be used with `setup_test_provider` to get a client with some -/// pre-existing coins, but with only one asset ID. -pub fn setup_single_asset_coins( - owner: &Bech32Address, - asset_id: AssetId, - num_coins: u64, - amount_per_coin: u64, -) -> Vec { - let mut rng = rand::thread_rng(); - - let coins: Vec = (1..=num_coins) - .map(|_i| { - let mut r = Bytes32::zeroed(); - r.try_fill(&mut rng) - .expect("failed to fill with random data"); - let utxo_id = UtxoId::new(r, 0); - - Coin { - owner: owner.clone(), - utxo_id, - amount: amount_per_coin, - asset_id, - status: CoinStatus::Unspent, - block_created: Default::default(), - } - }) - .collect(); - - coins -} - -#[cfg(feature = "std")] -pub fn setup_single_message( - sender: &Bech32Address, - recipient: &Bech32Address, - amount: u64, - nonce: Nonce, - data: Vec, -) -> Message { - Message { - sender: sender.clone(), - recipient: recipient.clone(), - nonce, - amount, - data, - da_height: 0, - status: MessageStatus::Unspent, - } -} - -#[cfg(feature = "std")] -pub async fn setup_test_provider( - coins: Vec, - messages: Vec, - node_config: Option, - chain_config: Option, -) -> Result { - let node_config = node_config.unwrap_or_default(); - let chain_config = chain_config.unwrap_or_else(testnet_chain_config); - - let coin_configs = into_coin_configs(coins); - let message_configs = into_message_configs(messages); - - let state_config = StateConfig { - coins: coin_configs, - messages: message_configs, - ..StateConfig::local_testnet() - }; - - let srv = FuelService::start(node_config, chain_config, state_config).await?; - - let address = srv.bound_address(); - - tokio::spawn(async move { - let _own_the_handle = srv; - let () = futures::future::pending().await; - }); - - Provider::from(address).await -} - -// Testnet ChainConfig with increased tx size and contract size limits -fn testnet_chain_config() -> ChainConfig { - let mut consensus_parameters = ConsensusParameters::default(); - let tx_params = TxParameters::default().with_max_size(10_000_000); - let contract_params = ContractParameters::default().with_contract_max_size(1_000_000); - consensus_parameters.set_tx_params(tx_params); - consensus_parameters.set_contract_params(contract_params); - - ChainConfig { - consensus_parameters, - ..ChainConfig::local_testnet() - } -} - #[cfg(test)] mod tests { use std::net::{Ipv4Addr, SocketAddr}; - use fuel_tx::{ConsensusParameters, ContractParameters, FeeParameters, TxParameters}; - use fuels_core::types::bech32::FUEL_BECH32_HRP; + use fuel_tx::{ + AssetId, Bytes32, ConsensusParameters, ContractParameters, FeeParameters, TxParameters, + }; + use fuels_core::types::{ + bech32::{Bech32Address, FUEL_BECH32_HRP}, + coin::Coin, + errors::Result, + }; + use rand::Fill; use super::*; diff --git a/packages/fuels-test-helpers/src/utils.rs b/packages/fuels-test-helpers/src/utils.rs index d459f6335..cc056e462 100644 --- a/packages/fuels-test-helpers/src/utils.rs +++ b/packages/fuels-test-helpers/src/utils.rs @@ -1,5 +1,15 @@ -use fuel_core_chain_config::{CoinConfig, MessageConfig}; -use fuels_core::types::{coin::Coin, message::Message}; +use fuel_core_chain_config::{ChainConfig, CoinConfig, MessageConfig, StateConfig}; +use fuel_tx::{AssetId, Bytes32, ConsensusParameters, ContractParameters, TxParameters, UtxoId}; +use fuel_types::Nonce; +use fuels_accounts::provider::Provider; +use fuels_core::types::{ + bech32::Bech32Address, + coin::{Coin, CoinStatus}, + message::{Message, MessageStatus}, +}; +use rand::Fill; + +use crate::{AssetConfig, FuelService, NodeConfig}; pub(crate) fn into_coin_configs(coins: Vec) -> Vec { coins @@ -14,3 +24,140 @@ pub(crate) fn into_message_configs(messages: Vec) -> Vec .map(Into::into) .collect::>() } + +/// Create a vector of `num_asset`*`coins_per_asset` UTXOs and a vector of the unique corresponding +/// asset IDs. `AssetId`. Each UTXO (=coin) contains `amount_per_coin` amount of a random asset. The +/// output of this function can be used with `setup_test_provider` to get a client with some +/// pre-existing coins, with `num_asset` different asset ids. Note that one of the assets is the +/// base asset to pay for gas. +pub fn setup_multiple_assets_coins( + owner: &Bech32Address, + num_asset: u64, + coins_per_asset: u64, + amount_per_coin: u64, +) -> (Vec, Vec) { + let mut rng = rand::thread_rng(); + // Create `num_asset-1` asset ids so there is `num_asset` in total with the base asset + let asset_ids = (0..(num_asset - 1)) + .map(|_| { + let mut random_asset_id = AssetId::zeroed(); + random_asset_id + .try_fill(&mut rng) + .expect("failed to fill with random data"); + random_asset_id + }) + .chain([AssetId::zeroed()]) + .collect::>(); + + let coins = asset_ids + .iter() + .flat_map(|id| setup_single_asset_coins(owner, *id, coins_per_asset, amount_per_coin)) + .collect::>(); + + (coins, asset_ids) +} + +/// Create a vector of UTXOs with the provided AssetIds, num_coins, and amount_per_coin +pub fn setup_custom_assets_coins(owner: &Bech32Address, assets: &[AssetConfig]) -> Vec { + let coins = assets + .iter() + .flat_map(|asset| { + setup_single_asset_coins(owner, asset.id, asset.num_coins, asset.coin_amount) + }) + .collect::>(); + coins +} + +/// Create a vector of `num_coins` UTXOs containing `amount_per_coin` amount of asset `asset_id`. +/// The output of this function can be used with `setup_test_provider` to get a client with some +/// pre-existing coins, but with only one asset ID. +pub fn setup_single_asset_coins( + owner: &Bech32Address, + asset_id: AssetId, + num_coins: u64, + amount_per_coin: u64, +) -> Vec { + let mut rng = rand::thread_rng(); + + let coins: Vec = (1..=num_coins) + .map(|_i| { + let mut r = Bytes32::zeroed(); + r.try_fill(&mut rng) + .expect("failed to fill with random data"); + let utxo_id = UtxoId::new(r, 0); + + Coin { + owner: owner.clone(), + utxo_id, + amount: amount_per_coin, + asset_id, + status: CoinStatus::Unspent, + block_created: Default::default(), + } + }) + .collect(); + + coins +} + +pub fn setup_single_message( + sender: &Bech32Address, + recipient: &Bech32Address, + amount: u64, + nonce: Nonce, + data: Vec, +) -> Message { + Message { + sender: sender.clone(), + recipient: recipient.clone(), + nonce, + amount, + data, + da_height: 0, + status: MessageStatus::Unspent, + } +} + +pub async fn setup_test_provider( + coins: Vec, + messages: Vec, + node_config: Option, + chain_config: Option, +) -> fuels_core::types::errors::Result { + let node_config = node_config.unwrap_or_default(); + let chain_config = chain_config.unwrap_or_else(testnet_chain_config); + + let coin_configs = into_coin_configs(coins); + let message_configs = into_message_configs(messages); + + let state_config = StateConfig { + coins: coin_configs, + messages: message_configs, + ..StateConfig::local_testnet() + }; + + let srv = FuelService::start(node_config, chain_config, state_config).await?; + + let address = srv.bound_address(); + + tokio::spawn(async move { + let _own_the_handle = srv; + let () = futures::future::pending().await; + }); + + Provider::from(address).await +} + +// Testnet ChainConfig with increased tx size and contract size limits +fn testnet_chain_config() -> ChainConfig { + let mut consensus_parameters = ConsensusParameters::default(); + let tx_params = TxParameters::default().with_max_size(10_000_000); + let contract_params = ContractParameters::default().with_contract_max_size(1_000_000); + consensus_parameters.set_tx_params(tx_params); + consensus_parameters.set_contract_params(contract_params); + + ChainConfig { + consensus_parameters, + ..ChainConfig::local_testnet() + } +} From 81e99d51d17e19534e98007418752976ee457b2d Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 11 May 2024 20:59:00 +0200 Subject: [PATCH 13/70] move back fuel-tx --- e2e/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index 797751e92..f2d54a08a 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -13,9 +13,9 @@ publish = false [dev-dependencies] # used in test assertions chrono = { workspace = true } -# TODO: [issue](https://github.com/FuelLabs/fuels-rs/issues/1375) needs to be removed, `ScriptTransaction` and `CreateTransaction` in `fuels` use `fuel_tx::Input` but don't reexport or convert it into a `fuels` owned type +# TODO: [issue](https://github.com/FuelLabs/fuels-rs/issues/1375) needs to be removed, `ScriptTransaction` and `CreateTransaction` in `fuels` use `fuel_tx::Input` but don't reexport or convert it into a `fuels` owned type fuel-tx = { workspace = true } fuel-tx = { workspace = true } -fuels = { workspace = true } +fuels = { workspace = true, features = ["test-helpers", "std"] } # TODO: [issue](https://github.com/FuelLabs/fuels-rs/issues/1376) because setup-program-test uses it but `fuels` did not reexport `rand` rand = { workspace = true } # used in test assertions From 88bbec3900f2212300c4875e1dd12dc331f68d9b Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 12 May 2024 09:18:19 +0200 Subject: [PATCH 14/70] checks tool wip --- Cargo.toml | 5 +++++ scripts/checks/Cargo.toml | 30 ++++++++++++++++++++++++++++++ scripts/checks/config/ci.yml | 10 ++++++++++ scripts/checks/config/max.yml | 0 scripts/checks/src/main.rs | 20 ++++++++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 scripts/checks/Cargo.toml create mode 100644 scripts/checks/config/ci.yml create mode 100644 scripts/checks/config/max.yml create mode 100644 scripts/checks/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 46750e824..3049bce24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ "packages/fuels-programs", "packages/fuels-test-helpers", "scripts/check-docs", + "scripts/checks", "scripts/versions-replacer", "wasm-tests", ] @@ -45,6 +46,7 @@ async-trait = { version = "0.1.74", default-features = false } bech32 = { version = "0.9.1", default-features = false } bytes = { version = "1.5.0", default-features = false } chrono = { version = "0.4.31", default-features = false } +clap = { version = "4.5", default-features = false } elliptic-curve = { version = "0.13.8", default-features = false } eth-keystore = { version = "0.5.0", default-features = false } fuel-abi-types = { version = "0.4.0", default-features = false } @@ -75,6 +77,9 @@ pretty_assertions = { version = "1.4.0", default-features = false } anyhow = { version = "1.0", default-features = false } getrandom = { version = "0.2", default-features = false } wasm-bindgen-test = { version = "0.3", default-features = false } +serde_yaml = { version = "0.9", default-features = false } +colored = { version = "2.1", default-features = false } +duct = { version = "0.13", default-features = false } # Dependencies from the `fuel-core` repository: fuel-core = { version = "0.26.0", default-features = false } diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml new file mode 100644 index 000000000..be1dbf372 --- /dev/null +++ b/scripts/checks/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "checks" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +readme.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true +version.workspace = true +publish = false + +[dependencies] +clap = { workspace = true, features = ["default", "derive"] } +tokio = { workspace = true, features = [ + "rt-multi-thread", + "process", + "macros", +] } +async-trait = { workspace = true } +which = { workspace = true } +anyhow = { workspace = true, features = ["std"] } +serde = { workspace = true, features = ["derive"] } +serde_yaml = { workspace = true } +itertools = { workspace = true, features = ["use_alloc"] } +colored = { workspace = true } +duct = { workspace = true } + +[dev-dependencies] +pretty_assertions = { workspace = true } diff --git a/scripts/checks/config/ci.yml b/scripts/checks/config/ci.yml new file mode 100644 index 000000000..5e977ade1 --- /dev/null +++ b/scripts/checks/config/ci.yml @@ -0,0 +1,10 @@ +crates: + - name: fuels + path: packages/fuels + fmt: true + check: + - features: ["fuel-core-lib"] + - features: ["default"] + - features: ["coin-cache"] + - features: ["std"] + diff --git a/scripts/checks/config/max.yml b/scripts/checks/config/max.yml new file mode 100644 index 000000000..e69de29bb diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs new file mode 100644 index 000000000..592e7b291 --- /dev/null +++ b/scripts/checks/src/main.rs @@ -0,0 +1,20 @@ +use std::io::IsTerminal; + +use clap::Parser; +mod cli; +mod config; +mod task; +mod util; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let cli = cli::Cli::parse(); + let verbose = cli.verbose; + let tasks = util::read_tasks_from_config(cli)?; + + let is_tty = std::io::stderr().is_terminal(); + + tasks.run(is_tty, verbose).await?; + + Ok(()) +} From 85a16234eae21a8d650fea896c7ab10a5536ad39 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 12 May 2024 21:39:36 +0200 Subject: [PATCH 15/70] prepare for doc check integration --- scripts/checks/Cargo.toml | 8 +- scripts/checks/config/ci.yml | 21 +- scripts/checks/src/cli.rs | 73 +++++++ scripts/checks/src/config.rs | 17 ++ scripts/checks/src/task.rs | 381 +++++++++++++++++++++++++++++++++++ scripts/checks/src/util.rs | 17 ++ 6 files changed, 500 insertions(+), 17 deletions(-) create mode 100644 scripts/checks/src/cli.rs create mode 100644 scripts/checks/src/config.rs create mode 100644 scripts/checks/src/task.rs create mode 100644 scripts/checks/src/util.rs diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index be1dbf372..501a579f5 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -12,13 +12,7 @@ publish = false [dependencies] clap = { workspace = true, features = ["default", "derive"] } -tokio = { workspace = true, features = [ - "rt-multi-thread", - "process", - "macros", -] } -async-trait = { workspace = true } -which = { workspace = true } +tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } anyhow = { workspace = true, features = ["std"] } serde = { workspace = true, features = ["derive"] } serde_yaml = { workspace = true } diff --git a/scripts/checks/config/ci.yml b/scripts/checks/config/ci.yml index 5e977ade1..fed665bb6 100644 --- a/scripts/checks/config/ci.yml +++ b/scripts/checks/config/ci.yml @@ -1,10 +1,11 @@ -crates: - - name: fuels - path: packages/fuels - fmt: true - check: - - features: ["fuel-core-lib"] - - features: ["default"] - - features: ["coin-cache"] - - features: ["std"] - +- working_dir: packages/fuels + name: "fuels" + commands: + - !Custom ["cargo", "check", "--features", "fuel-core-lib"] + - !Custom ["cargo", "check", "--features", "default"] + - !Custom ["cargo", "check", "--features", "coin-cache"] + - !Custom ["cargo", "check", "--features", "std"] + - !Custom ["cargo", "test", "--features", "fuel-core-lib"] + - !Custom ["cargo", "clippy", "--features", "fuel-core-lib"] + - !Custom ["cargo", "clippy", "--features", "default"] + - !Custom ["cargo", "hack", "--feature-powerset", "check"] diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs new file mode 100644 index 000000000..e94e552fb --- /dev/null +++ b/scripts/checks/src/cli.rs @@ -0,0 +1,73 @@ +use std::path::PathBuf; + +use clap::{arg, Parser, ValueEnum}; + +#[derive(Parser)] +#[command(about = "Runs pre-release checks deemed to heavy for CI.")] +pub struct Cli { + ///Comma separated list of crates to check. + #[arg( + short, + long, + value_delimiter = ',', + num_args = 0.. + + )] + pub crates: Vec, + #[arg(short, long, default_value = "ci")] + pub flavor: Flavor, + + /// Enable verbose output. + #[arg(short, long, default_value = "false")] + pub verbose: bool, + + #[arg(default_value = ".")] + pub workspace_root: PathBuf, +} + +#[derive(Debug, Copy, Clone, ValueEnum, PartialEq)] +pub enum Flavor { + Ci, + Max, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn crates_can_be_listed() { + // given + let cli = "foo --crates one,two"; + + // when + let cli = Cli::parse_from(cli.split_whitespace()); + + // then + assert_eq!(cli.crates, vec!["one", "two"]); + } + + #[test] + fn flavor_can_be_chosen() { + // given + let cli = "foo --flavor max"; + + // when + let cli = Cli::parse_from(cli.split_whitespace()); + + // then + assert_eq!(cli.flavor, Flavor::Max); + } + + #[test] + fn default_flavor_is_ci() { + // given + let cli = "foo"; + + // when + let cli = Cli::parse_from(cli.split_whitespace()); + + // then + assert_eq!(cli.flavor, Flavor::Ci); + } +} diff --git a/scripts/checks/src/config.rs b/scripts/checks/src/config.rs new file mode 100644 index 000000000..4fa0267b8 --- /dev/null +++ b/scripts/checks/src/config.rs @@ -0,0 +1,17 @@ +use std::path::PathBuf; + +#[derive(Debug, serde::Deserialize)] +pub struct Config(pub Vec); + +#[derive(Debug, serde::Deserialize)] +pub struct Group { + pub working_dir: PathBuf, + pub name: String, + pub commands: Vec, +} + +#[derive(Debug, serde::Deserialize)] +pub enum Command { + DocCheck, + Custom(Vec), +} diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs new file mode 100644 index 000000000..c95f40677 --- /dev/null +++ b/scripts/checks/src/task.rs @@ -0,0 +1,381 @@ +use std::{ + fmt::Display, + path::{Path, PathBuf}, +}; + +use colored::Colorize; +use duct::cmd; +use itertools::Itertools; +use tokio::task::JoinSet; + +use crate::config; + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct Task { + cwd: PathBuf, + name: String, + cmd: Command, +} + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub enum Command { + Custom { program: String, args: Vec }, + DocCheck, +} + +impl From for Command { + fn from(value: config::Command) -> Self { + match value { + config::Command::Custom(parts) => { + let program = parts.first().unwrap().to_string(); + let args = parts.into_iter().skip(1).map(|s| s.to_string()).collect(); + Self::Custom { program, args } + } + config::Command::DocCheck => Self::DocCheck, + } + } +} + +impl Display for Command { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Command::Custom { program, args } => { + let args = args.iter().join(" "); + write!(f, "{program} {args}") + } + Command::DocCheck => write!(f, "DocCheck"), + } + } +} + +impl Display for Task { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "({}) {}", self.name, self.cmd) + } +} + +#[derive(Debug, Clone)] +pub struct Execution { + pub cmd_desc: String, + pub status: ExecutionStatus, +} + +impl From for ExecutionStatus { + fn from(value: std::io::Error) -> Self { + Self::Failed { + reason: value.to_string(), + } + } +} + +#[derive(Debug, Clone)] +pub enum ExecutionStatus { + Success { out: String }, + Failed { reason: String }, +} + +impl Execution { + pub fn report(&self, tty: bool, verbose: bool) -> String { + let status = match &self.status { + ExecutionStatus::Failed { reason } => { + let err = if tty { "error".red() } else { "error".normal() }; + format!("{err}\n{reason}") + } + ExecutionStatus::Success { out } => { + let ok = if tty { "ok".green() } else { "ok".normal() }; + if verbose { + format!("{ok}\n{out}") + } else { + ok.to_string() + } + } + }; + + format!("{} ... {status}", self.cmd_desc) + } +} + +impl Task { + pub fn run(self) -> Execution { + match &self.cmd { + Command::Custom { program, args } => self.run_custom(program, args), + Command::DocCheck => self.run_doc_check(), + } + } + + fn run_doc_check(&self) -> Execution { + todo!() + } + + fn run_custom(&self, program: &String, args: &Vec) -> Execution { + let cmd = cmd(program, args) + .stderr_to_stdout() + .dir(&self.cwd) + .stdin_null() + .stdout_capture() + .unchecked(); + + let output = match cmd.run() { + Ok(output) => output, + Err(err) => return self.execution_report(err), + }; + + let decoded = String::from_utf8_lossy(&output.stdout).into_owned(); + let status = if output.status.success() { + ExecutionStatus::Success { out: decoded } + } else { + ExecutionStatus::Failed { reason: decoded } + }; + + self.execution_report(status) + } + + fn execution_report(&self, status: impl Into) -> Execution { + Execution { + cmd_desc: self.to_string(), + status: status.into(), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct Tasks { + pub tasks: Vec, +} + +impl Tasks { + pub fn from_config(config: config::Config, workspace_root: impl AsRef) -> Self { + let workspace_root = workspace_root.as_ref(); + let tasks = config + .0 + .into_iter() + .flat_map(|entry| { + let cwd = workspace_root.join(&entry.working_dir); + let name = entry.name; + entry + .commands + .into_iter() + .map(Command::from) + .map(move |cmd| Task { + cwd: cwd.clone(), + name: name.clone(), + cmd, + }) + }) + .collect(); + + Self { tasks } + } + + pub async fn run(self, tty: bool, verbose: bool) -> anyhow::Result<()> { + let mut set = JoinSet::new(); + for task in self.tasks { + set.spawn_blocking(|| task.run()); + } + + while let Some(result) = set.join_next().await { + let result = result?; + eprintln!("{}", result.report(tty, verbose)); + } + + Ok(()) + } + + pub fn retain(&mut self, crate_names: &[String]) { + self.tasks.retain(|task| crate_names.contains(&task.name)); + } +} + +#[cfg(test)] +mod tests { + use super::*; + use pretty_assertions::assert_eq; + + #[test] + fn tasks_correctly_generated() { + // given + let first = config::Group { + working_dir: PathBuf::from("some/foo"), + name: "foo".to_string(), + commands: vec![ + config::Command::Custom(vec!["cargo".to_string(), "check".to_string()]), + config::Command::Custom(vec!["cargo".to_string(), "check".to_string()]), + config::Command::Custom(vec!["cargo".to_string(), "fmt".to_string()]), + config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), + config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), + ], + }; + let second = config::Group { + working_dir: PathBuf::from("some/boo"), + name: "boo".to_string(), + commands: vec![ + config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), + config::Command::Custom(vec!["cargo".to_string(), "fmt".to_string()]), + ], + }; + + // when + let mut tasks = Tasks::from_config(config::Config(vec![first, second]), "."); + + // then + let crate1 = PathBuf::from("./some/foo"); + let crate2 = PathBuf::from("./some/boo"); + + tasks.tasks.sort(); + let mut expected = [ + Task { + name: "foo".to_string(), + cwd: crate1.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["check".to_string()], + }, + }, + Task { + name: "foo".to_string(), + cwd: crate1.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["check".to_string()], + }, + }, + Task { + name: "foo".to_string(), + cwd: crate1.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["fmt".to_string()], + }, + }, + Task { + name: "foo".to_string(), + cwd: crate1.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["test".to_string()], + }, + }, + Task { + name: "foo".to_string(), + cwd: crate1.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["test".to_string()], + }, + }, + Task { + name: "boo".to_string(), + cwd: crate2.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["fmt".to_string()], + }, + }, + Task { + name: "boo".to_string(), + cwd: crate2.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["test".to_string()], + }, + }, + ]; + + expected.sort(); + assert_eq!(tasks.tasks, expected); + } + + #[test] + fn selection_respected() { + // given + let config = config::Config(vec![ + config::Group { + working_dir: PathBuf::from("some/foo"), + name: "foo".to_string(), + commands: vec![ + config::Command::Custom(vec!["cargo".to_string(), "check".to_string()]), + config::Command::Custom(vec!["cargo".to_string(), "fmt".to_string()]), + config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), + ], + }, + config::Group { + working_dir: PathBuf::from("some/boo"), + name: "boo".to_string(), + commands: vec![ + config::Command::Custom(vec!["cargo".to_string(), "check".to_string()]), + config::Command::Custom(vec!["cargo".to_string(), "fmt".to_string()]), + config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), + ], + }, + ]); + + let mut tasks = Tasks::from_config(config, "."); + + // when + tasks.retain(&["foo".to_string()]); + + // then + let cwd = PathBuf::from("./some/foo"); + + let mut expected = [ + Task { + name: "foo".to_string(), + cwd: cwd.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["check".to_string()], + }, + }, + Task { + name: "foo".to_string(), + cwd: cwd.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["fmt".to_string()], + }, + }, + Task { + name: "foo".to_string(), + cwd: cwd.clone(), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["test".to_string()], + }, + }, + ]; + + tasks.tasks.sort(); + expected.sort(); + assert_eq!(tasks.tasks, expected); + } + + #[test] + fn workspace_root_respected() { + // given + let config = config::Config(vec![config::Group { + name: "foo".to_string(), + working_dir: PathBuf::from("some/foo"), + commands: vec![config::Command::Custom(vec![ + "cargo".to_string(), + "check".to_string(), + ])], + }]); + + // when + let mut tasks = Tasks::from_config(config, "workspace"); + + // then + let mut expected = [Task { + name: "foo".to_string(), + cwd: PathBuf::from("workspace/some/foo"), + cmd: Command::Custom { + program: "cargo".to_string(), + args: vec!["check".to_string()], + }, + }]; + + expected.sort(); + tasks.tasks.sort(); + assert_eq!(tasks.tasks, expected); + } +} diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs new file mode 100644 index 000000000..2ac984ffc --- /dev/null +++ b/scripts/checks/src/util.rs @@ -0,0 +1,17 @@ +use crate::{cli, config, task::Tasks}; + +pub fn read_tasks_from_config(cli: cli::Cli) -> anyhow::Result { + let yml = match cli.flavor { + cli::Flavor::Ci => include_str!("../config/ci.yml"), + cli::Flavor::Max => include_str!("../config/max.yml"), + }; + let config = serde_yaml::from_str::(yml)?; + + let mut tasks = Tasks::from_config(config, cli.workspace_root); + + if !cli.crates.is_empty() { + tasks.retain(&cli.crates); + } + + Ok(tasks) +} From bd870b578becaa29606b621c0b0a980765ab66d5 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Mon, 13 May 2024 13:50:41 +0200 Subject: [PATCH 16/70] wip --- Cargo.toml | 1 - scripts/check-docs/Cargo.toml | 15 - scripts/check-docs/src/lib.rs | 261 ----------- scripts/check-docs/src/main.rs | 37 -- scripts/check-docs/tests/harness.rs | 107 ----- scripts/checks/Cargo.toml | 3 +- scripts/checks/config/ci.yml | 6 + scripts/checks/src/config.rs | 2 +- scripts/checks/src/main.rs | 2 + scripts/checks/src/md_check.rs | 423 ++++++++++++++++++ scripts/checks/src/new_md_check.rs | 57 +++ scripts/checks/src/task.rs | 34 +- .../test_data/docs/src/SUMMARY.md | 0 .../test_data/docs/src/test-not-there.md | 0 .../test_data/docs/src/test.md | 0 .../test_data/test_anchor_data.rs | 0 .../test_data/test_include_data.md | 0 17 files changed, 518 insertions(+), 430 deletions(-) delete mode 100644 scripts/check-docs/Cargo.toml delete mode 100644 scripts/check-docs/src/lib.rs delete mode 100644 scripts/check-docs/src/main.rs delete mode 100644 scripts/check-docs/tests/harness.rs create mode 100644 scripts/checks/src/md_check.rs create mode 100644 scripts/checks/src/new_md_check.rs rename scripts/{check-docs/tests => checks}/test_data/docs/src/SUMMARY.md (100%) rename scripts/{check-docs/tests => checks}/test_data/docs/src/test-not-there.md (100%) rename scripts/{check-docs/tests => checks}/test_data/docs/src/test.md (100%) rename scripts/{check-docs/tests => checks}/test_data/test_anchor_data.rs (100%) rename scripts/{check-docs/tests => checks}/test_data/test_include_data.md (100%) diff --git a/Cargo.toml b/Cargo.toml index 3049bce24..53bed03c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ members = [ "packages/fuels-macros", "packages/fuels-programs", "packages/fuels-test-helpers", - "scripts/check-docs", "scripts/checks", "scripts/versions-replacer", "wasm-tests", diff --git a/scripts/check-docs/Cargo.toml b/scripts/check-docs/Cargo.toml deleted file mode 100644 index c3feae918..000000000 --- a/scripts/check-docs/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "check-docs" -version = { workspace = true } -authors = { workspace = true } -edition = { workspace = true } -homepage = { workspace = true } -license = { workspace = true } -publish = false -repository = { workspace = true } -rust-version = { workspace = true } - -[dependencies] -anyhow = { workspace = true, features = ["std"] } -itertools = { workspace = true } -regex = { workspace = true, features = ["std"] } diff --git a/scripts/check-docs/src/lib.rs b/scripts/check-docs/src/lib.rs deleted file mode 100644 index bcdd18e89..000000000 --- a/scripts/check-docs/src/lib.rs +++ /dev/null @@ -1,261 +0,0 @@ -use std::{ - collections::HashSet, - path::{Path, PathBuf}, -}; - -use anyhow::{anyhow, bail, Error}; -use itertools::{chain, Itertools}; -use regex::Regex; - -pub fn report_errors(error_type: &str, errors: &[Error]) { - if !errors.is_empty() { - eprintln!("\nInvalid {error_type} detected!\n"); - for error in errors { - eprintln!("{error}\n") - } - } -} - -pub fn report_warnings(warnings: &[Error]) { - if !warnings.is_empty() { - eprintln!("\nWarnings detected!\n"); - for warning in warnings { - eprintln!("{warning}\n") - } - } -} - -pub fn validate_includes( - includes: Vec, - valid_anchors: Vec, -) -> (Vec, Vec) { - let (pairs, errors): (Vec<_>, Vec<_>) = includes - .into_iter() - .filter(|include| !include.anchor_name.is_empty()) - .map(|include| { - let mut maybe_anchor = valid_anchors.iter().find(|anchor| { - anchor.file == include.anchor_file && anchor.name == include.anchor_name - }); - - match maybe_anchor.take() { - Some(anchor) => Ok(anchor.clone()), - None => Err(anyhow!( - "No anchor available to satisfy include {include:?}" - )), - } - }) - .partition_result(); - - let additional_warnings = valid_anchors - .iter() - .filter(|valid_anchor| { - let anchor_used_in_a_pair = pairs.iter().any(|anchor| anchor == *valid_anchor); - !anchor_used_in_a_pair - }) - .map(|unused_anchor| anyhow!("Anchor unused: {unused_anchor:?}!")) - .collect::>(); - - (errors, additional_warnings) -} - -#[allow(dead_code)] -#[derive(Debug, Clone)] -pub struct Include { - pub anchor_name: String, - pub anchor_file: PathBuf, - pub include_file: PathBuf, - pub line_no: usize, -} - -pub fn parse_includes(text_w_includes: String) -> (Vec, Vec) { - let apply_regex = |regex: Regex| { - let (includes, errors): (Vec<_>, Vec<_>) = text_w_includes - .lines() - .filter_map(|line| regex.captures(line)) - .map(|capture| { - let include_file = PathBuf::from(&capture[1]).canonicalize()?; - let line_no = capture[2].parse()?; - let anchor_file = PathBuf::from(&capture[3]); - let anchor_name = capture.get(4).map_or("", |m| m.as_str()).to_string(); - - let the_path = include_file.parent().unwrap().join(anchor_file); - - let anchor_file = the_path.canonicalize().map_err(|err| { - anyhow!( - "{the_path:?} when canonicalized gives error {err:?}\ninclude_file: {:?}", - include_file - ) - })?; - - Ok(Include { - anchor_name, - anchor_file, - include_file, - line_no, - }) - }) - .partition_result(); - (includes, errors) - }; - - apply_regex( - Regex::new(r"^(\S+):(\d+):\s*\{\{\s*#include\s*(\S+?)\s*(?::\s*(\S+)\s*)?\}\}") - .expect("could not construct regex"), - ) -} - -pub fn filter_valid_anchors(starts: Vec, ends: Vec) -> (Vec, Vec) { - let find_anchor_end_by_name = |anchor_name: &str, file: &Path| { - ends.iter() - .filter(|el| el.name == *anchor_name && el.file == file) - .collect::>() - }; - - let (pairs, errors):(Vec<_>, Vec<_>) = starts.into_iter().map(|start| { - let matches_by_name = find_anchor_end_by_name(&start.name, &start.file); - - let (begin, end) = match matches_by_name.as_slice() { - [single_match] => Ok((start, (*single_match).clone())), - [] => Err(anyhow!("Couldn't find a matching end anchor for {start:?}")), - multiple_ends => Err(anyhow!("Found too many matching anchor ends for anchor: {start:?}. The matching ends are: {multiple_ends:?}")), - }?; - - match check_validity_of_anchor_pair(&begin, &end) { - None => Ok((begin, end)), - Some(err) => { - let err_msg = err.to_string(); - Err(anyhow!("{err_msg}")) - } - } - }).partition_result(); - - let additional_errors = filter_unused_ends(&ends, &pairs) - .into_iter() - .map(|unused_end| anyhow!("Missing anchor start for {unused_end:?}")) - .collect::>(); - - let start_only = pairs.into_iter().map(|(begin, _)| begin).collect(); - - (start_only, chain!(errors, additional_errors).collect()) -} - -pub fn filter_unused_ends<'a>(ends: &'a [Anchor], pairs: &[(Anchor, Anchor)]) -> Vec<&'a Anchor> { - ends.iter() - .filter(|end| { - let end_used_in_pairs = pairs.iter().any(|(_, used_end)| *end == used_end); - !end_used_in_pairs - }) - .collect() -} - -pub fn check_validity_of_anchor_pair(begin: &Anchor, end: &Anchor) -> Option { - if begin.line_no > end.line_no { - Some(anyhow!("The end of the anchor appears before the beginning. End anchor: {end:?}. Begin anchor: {begin:?}")) - } else { - None - } -} - -#[derive(Debug, Clone, Hash, Eq, PartialEq)] -pub struct Anchor { - pub line_no: usize, - pub name: String, - pub file: PathBuf, -} - -pub fn extract_starts_and_ends( - text_w_anchors: &str, -) -> anyhow::Result<(Vec, Vec), Error> { - let apply_regex = |regex: Regex| { - text_w_anchors - .lines() - .filter_map(|line| regex.captures(line)) - .map(|capture| { - let file = PathBuf::from(&capture[1]).canonicalize()?; - let line_no = &capture[2]; - let anchor_name = &capture[3]; - - Ok(Anchor { - line_no: line_no.parse()?, - name: anchor_name.to_string(), - file, - }) - }) - .collect::, Error>>() - }; - - let begins = apply_regex(Regex::new( - r"^(.+):(\d+):\s*(?:/{2,}|/\*)\s*ANCHOR\s*:\s*([\w_-]+)\s*(?:\*/)?", - )?)?; - let ends = apply_regex(Regex::new( - r"^(.+):(\d+):\s*(?:/{2,}|/\*)\s*ANCHOR_END\s*:\s*([\w_-]+)\s*(?:\*/)?", - )?)?; - - Ok((begins, ends)) -} - -pub fn parse_md_files(text_w_files: String, path: &str) -> HashSet { - let regex = Regex::new(r"\((.*\.md)\)").expect("could not construct regex"); - - text_w_files - .lines() - .filter_map(|line| regex.captures(line)) - .map(|capture| { - PathBuf::from(path) - .join(&capture[1]) - .canonicalize() - .expect("could not canonicalize md path") - }) - .collect() -} - -pub fn validate_md_files( - md_files_summary: HashSet, - md_files_in_src: String, -) -> Vec { - md_files_in_src - .lines() - .filter_map(|file| { - let file = PathBuf::from(file) - .canonicalize() - .expect("could not canonicalize md path"); - - (!md_files_summary.contains(&file)) - .then(|| anyhow!("file `{}` not in SUMMARY.md", file.to_str().unwrap())) - }) - .collect() -} - -pub fn search_for_pattern(pattern: &str, location: &str) -> anyhow::Result { - let grep_project = std::process::Command::new("grep") - .arg("-H") // print filename - .arg("-n") // print line-number - .arg("-r") // search recursively - .arg("--binary-files=without-match") - .arg("--exclude-dir=check-docs") - .arg(pattern) - .arg(location) - .output() - .expect("failed grep command"); - - if !grep_project.status.success() { - bail!("Failed running `grep` command for pattern '{}'", pattern); - } - - Ok(String::from_utf8(grep_project.stdout)?) -} - -pub fn find_files(pattern: &str, location: &str, exclude: &str) -> anyhow::Result { - let find = std::process::Command::new("find") - .args([ - location, "-type", "f", "-name", pattern, "!", "-name", exclude, - ]) - .output() - .expect("Program `find` not in PATH"); - - if !find.status.success() { - bail!("Failed running `find` command for pattern {}", pattern); - } - - Ok(String::from_utf8(find.stdout)?) -} diff --git a/scripts/check-docs/src/main.rs b/scripts/check-docs/src/main.rs deleted file mode 100644 index 1badf4ba3..000000000 --- a/scripts/check-docs/src/main.rs +++ /dev/null @@ -1,37 +0,0 @@ -use anyhow::{bail, Error}; -use check_docs::{ - extract_starts_and_ends, filter_valid_anchors, find_files, parse_includes, parse_md_files, - report_errors, search_for_pattern, validate_includes, validate_md_files, -}; - -fn main() -> anyhow::Result<(), Error> { - let text_w_anchors = search_for_pattern("ANCHOR", ".")?; - let (starts, ends) = extract_starts_and_ends(&text_w_anchors)?; - let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); - - let text_mentioning_include = search_for_pattern("{{#include", ".")?; - let (includes, include_path_errors) = parse_includes(text_mentioning_include); - let (include_errors, additional_warnings) = validate_includes(includes, valid_anchors); - - let text_with_md_files = search_for_pattern(".md", "./docs/src/SUMMARY.md")?; - let md_files_in_summary = parse_md_files(text_with_md_files, "./docs/src/"); - let md_files_in_src = find_files("*.md", "./docs/src/", "SUMMARY.md")?; - let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); - - report_errors("warning", &additional_warnings); - report_errors("include paths", &include_path_errors); - report_errors("anchors", &anchor_errors); - report_errors("includes", &include_errors); - report_errors("md files", &md_files_errors); - - if !anchor_errors.is_empty() - || !include_errors.is_empty() - || !include_path_errors.is_empty() - || !additional_warnings.is_empty() - || !md_files_errors.is_empty() - { - bail!("Finished with errors"); - } - - Ok(()) -} diff --git a/scripts/check-docs/tests/harness.rs b/scripts/check-docs/tests/harness.rs deleted file mode 100644 index acda36099..000000000 --- a/scripts/check-docs/tests/harness.rs +++ /dev/null @@ -1,107 +0,0 @@ -use anyhow::Error; -use check_docs::{ - extract_starts_and_ends, filter_valid_anchors, find_files, parse_includes, parse_md_files, - search_for_pattern, validate_includes, validate_md_files, Anchor, Include, -}; - -enum TestEnum { - Anchor(Vec), - Include(Vec), - Errors(Vec), -} - -fn contains_any(vec: &TestEnum, str: &str) -> bool { - match vec { - TestEnum::Anchor(anchor_vec) => anchor_vec.iter().any(|anchor| anchor.name == str), - TestEnum::Include(include_vec) => { - include_vec.iter().any(|include| include.anchor_name == str) - } - TestEnum::Errors(err_vec) => err_vec.iter().any(|err| err.to_string().contains(str)), - } -} - -#[test] -fn test_anchors() -> anyhow::Result<()> { - let test_data = search_for_pattern("ANCHOR", ".")?; - - let (starts, ends) = extract_starts_and_ends(&test_data)?; - let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); - - let valid_vec = TestEnum::Anchor(valid_anchors.clone()); - let anchor_err_vec = TestEnum::Errors(anchor_errors); - - assert!(contains_any(&valid_vec, "test_anchor_line_comment")); - assert!(contains_any(&valid_vec, "test_anchor_block_comment")); - assert!(contains_any(&valid_vec, "test_with_more_forward_slashes")); - assert!(!contains_any(&valid_vec, "no_anchor_with_this_name")); - - assert!(contains_any( - &anchor_err_vec, - "Missing anchor start for Anchor { line_no: 10, name: \"test_no_anchor_beginning\"" - )); - assert!(contains_any(&anchor_err_vec, "Couldn't find a matching end anchor for Anchor { line_no: 12, name: \"test_no_anchor_end\"")); - assert!(contains_any(&anchor_err_vec, "The end of the anchor appears before the beginning. End anchor: Anchor { line_no: 14, name: \"test_end_before_beginning\"")); - - assert!(contains_any(&anchor_err_vec, "Found too many matching anchor ends for anchor: Anchor { line_no: 17, name: \"test_same_name_multiple_time\"")); - assert!(contains_any(&anchor_err_vec, "Found too many matching anchor ends for anchor: Anchor { line_no: 20, name: \"test_same_name_multiple_time\"")); - // Caused by too many matching anchors - assert!(contains_any( - &anchor_err_vec, - "Missing anchor start for Anchor { line_no: 18, name: \"test_same_name_multiple_time\"" - )); - assert!(contains_any( - &anchor_err_vec, - "Missing anchor start for Anchor { line_no: 21, name: \"test_same_name_multiple_time\"" - )); - - let text_mentioning_include = search_for_pattern("{{#include", ".")?; - - let (includes, include_path_errors) = parse_includes(text_mentioning_include); - - let includes_vec = TestEnum::Include(includes.clone()); - - assert!(contains_any(&includes_vec, "test_anchor_line_comment")); - assert!(contains_any(&includes_vec, "test_anchor_block_comment")); - assert!(contains_any( - &includes_vec, - "test_with_more_forward_slashes" - )); - assert!(contains_any(&includes_vec, "")); //Check the file include without anchor - - let include_path_errors = TestEnum::Errors(include_path_errors); - - assert!(contains_any( - &include_path_errors, - "test_anchor_data2.rs\" when canonicalized gives error Os { code: 2, kind: NotFound" - )); - - assert!(contains_any( - &include_path_errors, - "test_anchor_data3.rs\" when canonicalized gives error Os { code: 2, kind: NotFound" - )); - - let (include_errors, _) = validate_includes(includes, valid_anchors); - - let include_err_vec = TestEnum::Errors(include_errors); - - assert!(contains_any( - &include_err_vec, - "No anchor available to satisfy include Include { anchor_name: \"no_existing_anchor\"" - )); - - Ok(()) -} - -#[test] -fn test_unused_md() -> anyhow::Result<()> { - let text_with_md_files = search_for_pattern(".md", "./tests/test_data/docs/src/SUMMARY.md")?; - let md_files_in_summary = parse_md_files(text_with_md_files, "./tests/test_data/docs/src/"); - let md_files_in_src = find_files("*.md", "./tests/test_data/docs/src/", "SUMMARY.md")?; - let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); - - let error_msg = md_files_errors.first().unwrap().to_string(); - - assert!(error_msg.contains("test-not-there.md` not in SUMMARY.md")); - - Ok(()) -} diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index 501a579f5..2c3d9a45a 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -19,6 +19,7 @@ serde_yaml = { workspace = true } itertools = { workspace = true, features = ["use_alloc"] } colored = { workspace = true } duct = { workspace = true } +regex = { workspace = true, features = ["std", "unicode-perl"] } [dev-dependencies] -pretty_assertions = { workspace = true } +pretty_assertions = { workspace = true, features = ["std"] } diff --git a/scripts/checks/config/ci.yml b/scripts/checks/config/ci.yml index fed665bb6..7c8d3ef7b 100644 --- a/scripts/checks/config/ci.yml +++ b/scripts/checks/config/ci.yml @@ -9,3 +9,9 @@ - !Custom ["cargo", "clippy", "--features", "fuel-core-lib"] - !Custom ["cargo", "clippy", "--features", "default"] - !Custom ["cargo", "hack", "--feature-powerset", "check"] + +- working_dir: . + name: "workspace" + commands: + - !MdCheck + ignore: ["./scripts/checks/test_data"] diff --git a/scripts/checks/src/config.rs b/scripts/checks/src/config.rs index 4fa0267b8..64b9a6d3c 100644 --- a/scripts/checks/src/config.rs +++ b/scripts/checks/src/config.rs @@ -12,6 +12,6 @@ pub struct Group { #[derive(Debug, serde::Deserialize)] pub enum Command { - DocCheck, + MdCheck { ignore: Vec }, Custom(Vec), } diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index 592e7b291..b4e2f1259 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -3,6 +3,8 @@ use std::io::IsTerminal; use clap::Parser; mod cli; mod config; +mod md_check; +mod new_md_check; mod task; mod util; diff --git a/scripts/checks/src/md_check.rs b/scripts/checks/src/md_check.rs new file mode 100644 index 000000000..816c6547c --- /dev/null +++ b/scripts/checks/src/md_check.rs @@ -0,0 +1,423 @@ +use anyhow::anyhow; +use anyhow::{bail, Error}; +use duct::cmd; +use itertools::{chain, Itertools}; +use regex::Regex; +use std::{ + collections::HashSet, + path::{Path, PathBuf}, +}; + +pub fn run(dir: &Path, ignore: Vec) -> anyhow::Result<(), Error> { + eprintln!("Running md check..., ignore: {ignore:?}"); + let text_w_anchors = search_for_pattern("ANCHOR", dir, &ignore)?; + let (starts, ends) = extract_starts_and_ends(&text_w_anchors)?; + let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); + + let text_mentioning_include = search_for_pattern("{{#include", dir, &ignore)?; + let (includes, include_path_errors) = parse_includes(text_mentioning_include); + let (include_errors, additional_warnings) = validate_includes(includes, valid_anchors); + + let text_with_md_files = search_for_pattern(".md", dir.join("./docs/src/SUMMARY.md"), &ignore)?; + let md_files_in_summary = parse_md_files(text_with_md_files, dir.join("./docs/src/")); + let md_files_in_src = find_files("*.md", dir.join("./docs/src/"), "SUMMARY.md")?; + let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); + + report_errors("warning", &additional_warnings); + report_errors("include paths", &include_path_errors); + report_errors("anchors", &anchor_errors); + report_errors("includes", &include_errors); + report_errors("md files", &md_files_errors); + + if !anchor_errors.is_empty() + || !include_errors.is_empty() + || !include_path_errors.is_empty() + || !additional_warnings.is_empty() + || !md_files_errors.is_empty() + { + bail!("Finished with errors"); + } + + Ok(()) +} + +fn report_errors(error_type: &str, errors: &[Error]) { + if !errors.is_empty() { + eprintln!("\nInvalid {error_type} detected!\n"); + for error in errors { + eprintln!("{error}\n") + } + } +} + +pub fn report_warnings(warnings: &[Error]) { + if !warnings.is_empty() { + eprintln!("\nWarnings detected!\n"); + for warning in warnings { + eprintln!("{warning}\n") + } + } +} + +pub fn validate_includes( + includes: Vec, + valid_anchors: Vec, +) -> (Vec, Vec) { + let (pairs, errors): (Vec<_>, Vec<_>) = includes + .into_iter() + .filter(|include| !include.anchor_name.is_empty()) + .map(|include| { + let mut maybe_anchor = valid_anchors.iter().find(|anchor| { + anchor.file == include.anchor_file && anchor.name == include.anchor_name + }); + + match maybe_anchor.take() { + Some(anchor) => Ok(anchor.clone()), + None => Err(anyhow!( + "No anchor available to satisfy include {include:?}" + )), + } + }) + .partition_result(); + + let additional_warnings = valid_anchors + .iter() + .filter(|valid_anchor| { + let anchor_used_in_a_pair = pairs.iter().any(|anchor| anchor == *valid_anchor); + !anchor_used_in_a_pair + }) + .map(|unused_anchor| anyhow!("Anchor unused: {unused_anchor:?}!")) + .collect::>(); + + (errors, additional_warnings) +} + +#[allow(dead_code)] +#[derive(Debug, Clone)] +pub struct Include { + pub anchor_name: String, + pub anchor_file: PathBuf, + pub include_file: PathBuf, + pub line_no: usize, +} + +pub fn parse_includes(text_w_includes: String) -> (Vec, Vec) { + let apply_regex = |regex: Regex| { + let (includes, errors): (Vec<_>, Vec<_>) = text_w_includes + .lines() + .filter_map(|line| regex.captures(line)) + .map(|capture| { + let include_file = PathBuf::from(&capture[1]).canonicalize()?; + let line_no = capture[2].parse()?; + let anchor_file = PathBuf::from(&capture[3]); + let anchor_name = capture.get(4).map_or("", |m| m.as_str()).to_string(); + + let the_path = include_file.parent().unwrap().join(anchor_file); + + let anchor_file = the_path.canonicalize().map_err(|err| { + anyhow!( + "{the_path:?} when canonicalized gives error {err:?}\ninclude_file: {:?}", + include_file + ) + })?; + + Ok(Include { + anchor_name, + anchor_file, + include_file, + line_no, + }) + }) + .partition_result(); + (includes, errors) + }; + + apply_regex( + Regex::new(r"^(\S+):(\d+):\s*\{\{\s*#include\s*(\S+?)\s*(?::\s*(\S+)\s*)?\}\}") + .expect("could not construct regex"), + ) +} + +pub fn filter_valid_anchors(starts: Vec, ends: Vec) -> (Vec, Vec) { + let find_anchor_end_by_name = |anchor_name: &str, file: &Path| { + ends.iter() + .filter(|el| el.name == *anchor_name && el.file == file) + .collect::>() + }; + + let (pairs, errors):(Vec<_>, Vec<_>) = starts.into_iter().map(|start| { + let matches_by_name = find_anchor_end_by_name(&start.name, &start.file); + + let (begin, end) = match matches_by_name.as_slice() { + [single_match] => Ok((start, (*single_match).clone())), + [] => Err(anyhow!("Couldn't find a matching end anchor for {start:?}")), + multiple_ends => Err(anyhow!("Found too many matching anchor ends for anchor: {start:?}. The matching ends are: {multiple_ends:?}")), + }?; + + match check_validity_of_anchor_pair(&begin, &end) { + None => Ok((begin, end)), + Some(err) => { + let err_msg = err.to_string(); + Err(anyhow!("{err_msg}")) + } + } + }).partition_result(); + + let additional_errors = filter_unused_ends(&ends, &pairs) + .into_iter() + .map(|unused_end| anyhow!("Missing anchor start for {unused_end:?}")) + .collect::>(); + + let start_only = pairs.into_iter().map(|(begin, _)| begin).collect(); + + (start_only, chain!(errors, additional_errors).collect()) +} + +pub fn filter_unused_ends<'a>(ends: &'a [Anchor], pairs: &[(Anchor, Anchor)]) -> Vec<&'a Anchor> { + ends.iter() + .filter(|end| { + let end_used_in_pairs = pairs.iter().any(|(_, used_end)| *end == used_end); + !end_used_in_pairs + }) + .collect() +} + +pub fn check_validity_of_anchor_pair(begin: &Anchor, end: &Anchor) -> Option { + if begin.line_no > end.line_no { + Some(anyhow!("The end of the anchor appears before the beginning. End anchor: {end:?}. Begin anchor: {begin:?}")) + } else { + None + } +} + +#[derive(Debug, Clone, Hash, Eq, PartialEq)] +pub struct Anchor { + pub line_no: usize, + pub name: String, + pub file: PathBuf, +} + +pub fn extract_starts_and_ends( + text_w_anchors: &str, +) -> anyhow::Result<(Vec, Vec), Error> { + let apply_regex = |regex: Regex| { + text_w_anchors + .lines() + .filter_map(|line| regex.captures(line)) + .map(|capture| { + let file = PathBuf::from(&capture[1]).canonicalize()?; + let line_no = &capture[2]; + let anchor_name = &capture[3]; + + Ok(Anchor { + line_no: line_no.parse()?, + name: anchor_name.to_string(), + file, + }) + }) + .collect::, Error>>() + }; + + let begins = apply_regex(Regex::new( + r"^(.+):(\d+):\s*(?:/{2,}|/\*)\s*ANCHOR\s*:\s*([\w_-]+)\s*(?:\*/)?", + )?)?; + let ends = apply_regex(Regex::new( + r"^(.+):(\d+):\s*(?:/{2,}|/\*)\s*ANCHOR_END\s*:\s*([\w_-]+)\s*(?:\*/)?", + )?)?; + + Ok((begins, ends)) +} + +pub fn parse_md_files(text_w_files: String, path: impl AsRef) -> HashSet { + let regex = Regex::new(r"\((.*\.md)\)").expect("could not construct regex"); + + text_w_files + .lines() + .filter_map(|line| regex.captures(line)) + .map(|capture| { + PathBuf::from(path.as_ref()) + .join(&capture[1]) + .canonicalize() + .expect("could not canonicalize md path") + }) + .collect() +} + +pub fn validate_md_files( + md_files_summary: HashSet, + md_files_in_src: String, +) -> Vec { + md_files_in_src + .lines() + .filter_map(|file| { + let file = PathBuf::from(file) + .canonicalize() + .expect("could not canonicalize md path"); + + (!md_files_summary.contains(&file)) + .then(|| anyhow!("file `{}` not in SUMMARY.md", file.to_str().unwrap())) + }) + .collect() +} + +pub fn search_for_pattern( + pattern: &str, + location: impl AsRef, + ignore: &[PathBuf], +) -> anyhow::Result { + let ignored_files = ignore + .iter() + .flat_map(|path| ["--exclude-dir", path.to_str().unwrap()]); + let args = [ + "-H", + "-n", + "-r", + "--binary-files=without-match", + pattern, + location.as_ref().as_os_str().to_str().unwrap(), + ] + .into_iter() + .chain(ignored_files) + .collect_vec(); + + eprintln!("Running grep with args: {:?}", args); + + duct::cmd("grep", args) + .read() + .map_err(|err| anyhow!("Failed running `grep` command for pattern '{pattern}': {err}")) +} + +pub fn find_files( + pattern: &str, + location: impl AsRef, + exclude: &str, +) -> anyhow::Result { + Ok(cmd!( + "find", + location.as_ref().to_str().unwrap(), + "-type", + "f", + "-name", + pattern, + "!", + "-name", + exclude, + ) + .read()?) +} + +#[cfg(test)] +mod tests { + fn test_data_path(join: impl AsRef) -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("test_data") + .join(join.as_ref()) + } + + use super::*; + + use anyhow::Error; + + enum TestEnum { + Anchor(Vec), + Include(Vec), + Errors(Vec), + } + + fn contains_any(vec: &TestEnum, str: &str) -> bool { + match vec { + TestEnum::Anchor(anchor_vec) => anchor_vec.iter().any(|anchor| anchor.name == str), + TestEnum::Include(include_vec) => { + include_vec.iter().any(|include| include.anchor_name == str) + } + TestEnum::Errors(err_vec) => err_vec.iter().any(|err| err.to_string().contains(str)), + } + } + + #[test] + fn test_anchors() -> anyhow::Result<()> { + let data = search_for_pattern("ANCHOR", test_data_path("."), &[])?; + + let (starts, ends) = extract_starts_and_ends(&data)?; + let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); + + let valid_vec = TestEnum::Anchor(valid_anchors.clone()); + let anchor_err_vec = TestEnum::Errors(anchor_errors); + + assert!(contains_any(&valid_vec, "test_anchor_line_comment")); + assert!(contains_any(&valid_vec, "test_anchor_block_comment")); + assert!(contains_any(&valid_vec, "test_with_more_forward_slashes")); + assert!(!contains_any(&valid_vec, "no_anchor_with_this_name")); + + assert!(contains_any( + &anchor_err_vec, + "Missing anchor start for Anchor { line_no: 10, name: \"test_no_anchor_beginning\"" + )); + assert!(contains_any(&anchor_err_vec, "Couldn't find a matching end anchor for Anchor { line_no: 12, name: \"test_no_anchor_end\"")); + assert!(contains_any(&anchor_err_vec, "The end of the anchor appears before the beginning. End anchor: Anchor { line_no: 14, name: \"test_end_before_beginning\"")); + + assert!(contains_any(&anchor_err_vec, "Found too many matching anchor ends for anchor: Anchor { line_no: 17, name: \"test_same_name_multiple_time\"")); + assert!(contains_any(&anchor_err_vec, "Found too many matching anchor ends for anchor: Anchor { line_no: 20, name: \"test_same_name_multiple_time\"")); + // Caused by too many matching anchors + assert!(contains_any( + &anchor_err_vec, + "Missing anchor start for Anchor { line_no: 18, name: \"test_same_name_multiple_time\"" + )); + assert!(contains_any( + &anchor_err_vec, + "Missing anchor start for Anchor { line_no: 21, name: \"test_same_name_multiple_time\"" + )); + + let text_mentioning_include = search_for_pattern("{{#include", test_data_path("."), &[])?; + + let (includes, include_path_errors) = parse_includes(text_mentioning_include); + + let includes_vec = TestEnum::Include(includes.clone()); + + assert!(contains_any(&includes_vec, "test_anchor_line_comment")); + assert!(contains_any(&includes_vec, "test_anchor_block_comment")); + assert!(contains_any( + &includes_vec, + "test_with_more_forward_slashes" + )); + assert!(contains_any(&includes_vec, "")); //Check the file include without anchor + + let include_path_errors = TestEnum::Errors(include_path_errors); + + assert!(contains_any( + &include_path_errors, + "test_anchor_data2.rs\" when canonicalized gives error Os { code: 2, kind: NotFound" + )); + + assert!(contains_any( + &include_path_errors, + "test_anchor_data3.rs\" when canonicalized gives error Os { code: 2, kind: NotFound" + )); + + let (include_errors, _) = validate_includes(includes, valid_anchors); + + let include_err_vec = TestEnum::Errors(include_errors); + + assert!(contains_any( + &include_err_vec, + "No anchor available to satisfy include Include { anchor_name: \"no_existing_anchor\"" + )); + + Ok(()) + } + + #[test] + fn test_unused_md() -> anyhow::Result<()> { + let text_with_md_files = + search_for_pattern(".md", test_data_path("docs/src/SUMMARY.md"), &[])?; + let md_files_in_summary = parse_md_files(text_with_md_files, test_data_path("docs/src/")); + let md_files_in_src = find_files("*.md", test_data_path("docs/src/"), "SUMMARY.md")?; + let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); + + let error_msg = md_files_errors.first().unwrap().to_string(); + + assert!(error_msg.contains("test-not-there.md` not in SUMMARY.md")); + + Ok(()) + } +} diff --git a/scripts/checks/src/new_md_check.rs b/scripts/checks/src/new_md_check.rs new file mode 100644 index 000000000..7e36c1758 --- /dev/null +++ b/scripts/checks/src/new_md_check.rs @@ -0,0 +1,57 @@ +// Unused anchors +// include references non existent file +// include references non existent anchor +// anchor has no end +// anchor has multiple ends +// anchor has multiple beginnings +// md files not referenced in summary +// + +use std::path::{Path, PathBuf}; + +fn find_files_by_extension(dir: &Path) -> anyhow::Result> { + let mut files = vec![]; + for entry in dir.read_dir()? { + let path = entry?.path().canonicalize()?; + if path.is_file() { + files.push(path); + } else { + files.append(&mut find_files_by_extension(&path)?); + } + } + + Ok(files) +} + +trait FileFinder { + fn find_files(&self, extension: &str) -> anyhow::Result>; +} + +struct MdCheck { + ignore: Vec, +} + +impl MdCheck { + pub fn check(root: &Path) -> anyhow::Result<()> { + // find all rs and sw files + // load anchors text from them, check validity + // parse that into anchors, note errors + + // find all md files + // load includes from them + // check if files referenced in includes exist + // check if anchors referenced in includes exist + // check if all anchors are used + + // check if all files are referenced in summary + todo!() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_name() {} +} diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index c95f40677..03553ca43 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -8,7 +8,7 @@ use duct::cmd; use itertools::Itertools; use tokio::task::JoinSet; -use crate::config; +use crate::{config, md_check}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Task { @@ -20,7 +20,7 @@ pub struct Task { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum Command { Custom { program: String, args: Vec }, - DocCheck, + MdCheck { ignore: Vec }, } impl From for Command { @@ -31,7 +31,7 @@ impl From for Command { let args = parts.into_iter().skip(1).map(|s| s.to_string()).collect(); Self::Custom { program, args } } - config::Command::DocCheck => Self::DocCheck, + config::Command::MdCheck { ignore } => Self::MdCheck { ignore }, } } } @@ -43,7 +43,7 @@ impl Display for Command { let args = args.iter().join(" "); write!(f, "{program} {args}") } - Command::DocCheck => write!(f, "DocCheck"), + Command::MdCheck { .. } => write!(f, "MdCheck"), } } } @@ -68,6 +68,14 @@ impl From for ExecutionStatus { } } +impl From for ExecutionStatus { + fn from(value: anyhow::Error) -> Self { + Self::Failed { + reason: value.to_string(), + } + } +} + #[derive(Debug, Clone)] pub enum ExecutionStatus { Success { out: String }, @@ -99,12 +107,24 @@ impl Task { pub fn run(self) -> Execution { match &self.cmd { Command::Custom { program, args } => self.run_custom(program, args), - Command::DocCheck => self.run_doc_check(), + Command::MdCheck { ignore } => self.run_md_check(ignore), } } - fn run_doc_check(&self) -> Execution { - todo!() + fn run_md_check(&self, ignore: &[PathBuf]) -> Execution { + let ignore = ignore + .iter() + .map(|path| self.cwd.join(path)) + .collect::>(); + let status = if let Err(e) = md_check::run(&self.cwd, ignore) { + e.into() + } else { + ExecutionStatus::Success { + out: "".to_string(), + } + }; + + self.execution_report(status) } fn run_custom(&self, program: &String, args: &Vec) -> Execution { diff --git a/scripts/check-docs/tests/test_data/docs/src/SUMMARY.md b/scripts/checks/test_data/docs/src/SUMMARY.md similarity index 100% rename from scripts/check-docs/tests/test_data/docs/src/SUMMARY.md rename to scripts/checks/test_data/docs/src/SUMMARY.md diff --git a/scripts/check-docs/tests/test_data/docs/src/test-not-there.md b/scripts/checks/test_data/docs/src/test-not-there.md similarity index 100% rename from scripts/check-docs/tests/test_data/docs/src/test-not-there.md rename to scripts/checks/test_data/docs/src/test-not-there.md diff --git a/scripts/check-docs/tests/test_data/docs/src/test.md b/scripts/checks/test_data/docs/src/test.md similarity index 100% rename from scripts/check-docs/tests/test_data/docs/src/test.md rename to scripts/checks/test_data/docs/src/test.md diff --git a/scripts/check-docs/tests/test_data/test_anchor_data.rs b/scripts/checks/test_data/test_anchor_data.rs similarity index 100% rename from scripts/check-docs/tests/test_data/test_anchor_data.rs rename to scripts/checks/test_data/test_anchor_data.rs diff --git a/scripts/check-docs/tests/test_data/test_include_data.md b/scripts/checks/test_data/test_include_data.md similarity index 100% rename from scripts/check-docs/tests/test_data/test_include_data.md rename to scripts/checks/test_data/test_include_data.md From 942e1c8238695a2367ccb61c2428a67ba5e4c7a2 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Mon, 13 May 2024 15:20:31 +0200 Subject: [PATCH 17/70] fix unit tests --- scripts/checks/Cargo.toml | 1 + scripts/checks/config/ci.yml | 1 - scripts/checks/src/config.rs | 2 +- scripts/checks/src/main.rs | 1 - scripts/checks/src/md_check.rs | 169 ++++++++++++------ scripts/checks/src/new_md_check.rs | 57 ------ scripts/checks/src/task.rs | 14 +- scripts/checks/test_data/docs/src/SUMMARY.md | 1 - .../test_data/docs/src/test-not-there.md | 0 scripts/checks/test_data/docs/src/test.md | 0 scripts/checks/test_data/test_anchor_data.rs | 21 --- scripts/checks/test_data/test_include_data.md | 34 ---- 12 files changed, 124 insertions(+), 177 deletions(-) delete mode 100644 scripts/checks/src/new_md_check.rs delete mode 100644 scripts/checks/test_data/docs/src/SUMMARY.md delete mode 100644 scripts/checks/test_data/docs/src/test-not-there.md delete mode 100644 scripts/checks/test_data/docs/src/test.md delete mode 100644 scripts/checks/test_data/test_anchor_data.rs delete mode 100644 scripts/checks/test_data/test_include_data.md diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index 2c3d9a45a..90366ea1c 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -22,4 +22,5 @@ duct = { workspace = true } regex = { workspace = true, features = ["std", "unicode-perl"] } [dev-dependencies] +tempfile = { version = "3.10" } pretty_assertions = { workspace = true, features = ["std"] } diff --git a/scripts/checks/config/ci.yml b/scripts/checks/config/ci.yml index 7c8d3ef7b..2b6f6ceb5 100644 --- a/scripts/checks/config/ci.yml +++ b/scripts/checks/config/ci.yml @@ -14,4 +14,3 @@ name: "workspace" commands: - !MdCheck - ignore: ["./scripts/checks/test_data"] diff --git a/scripts/checks/src/config.rs b/scripts/checks/src/config.rs index 64b9a6d3c..97d231c1d 100644 --- a/scripts/checks/src/config.rs +++ b/scripts/checks/src/config.rs @@ -12,6 +12,6 @@ pub struct Group { #[derive(Debug, serde::Deserialize)] pub enum Command { - MdCheck { ignore: Vec }, + MdCheck, Custom(Vec), } diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index b4e2f1259..1de92aea6 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -4,7 +4,6 @@ use clap::Parser; mod cli; mod config; mod md_check; -mod new_md_check; mod task; mod util; diff --git a/scripts/checks/src/md_check.rs b/scripts/checks/src/md_check.rs index 816c6547c..1003ad757 100644 --- a/scripts/checks/src/md_check.rs +++ b/scripts/checks/src/md_check.rs @@ -8,17 +8,16 @@ use std::{ path::{Path, PathBuf}, }; -pub fn run(dir: &Path, ignore: Vec) -> anyhow::Result<(), Error> { - eprintln!("Running md check..., ignore: {ignore:?}"); - let text_w_anchors = search_for_pattern("ANCHOR", dir, &ignore)?; +pub fn run(dir: &Path) -> anyhow::Result<(), Error> { + let text_w_anchors = search_for_pattern("ANCHOR", dir)?; let (starts, ends) = extract_starts_and_ends(&text_w_anchors)?; let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); - let text_mentioning_include = search_for_pattern("{{#include", dir, &ignore)?; + let text_mentioning_include = search_for_pattern("{{#include", dir)?; let (includes, include_path_errors) = parse_includes(text_mentioning_include); let (include_errors, additional_warnings) = validate_includes(includes, valid_anchors); - let text_with_md_files = search_for_pattern(".md", dir.join("./docs/src/SUMMARY.md"), &ignore)?; + let text_with_md_files = search_for_pattern(".md", dir.join("./docs/src/SUMMARY.md"))?; let md_files_in_summary = parse_md_files(text_with_md_files, dir.join("./docs/src/")); let md_files_in_src = find_files("*.md", dir.join("./docs/src/"), "SUMMARY.md")?; let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); @@ -50,15 +49,6 @@ fn report_errors(error_type: &str, errors: &[Error]) { } } -pub fn report_warnings(warnings: &[Error]) { - if !warnings.is_empty() { - eprintln!("\nWarnings detected!\n"); - for warning in warnings { - eprintln!("{warning}\n") - } - } -} - pub fn validate_includes( includes: Vec, valid_anchors: Vec, @@ -260,31 +250,20 @@ pub fn validate_md_files( .collect() } -pub fn search_for_pattern( - pattern: &str, - location: impl AsRef, - ignore: &[PathBuf], -) -> anyhow::Result { - let ignored_files = ignore - .iter() - .flat_map(|path| ["--exclude-dir", path.to_str().unwrap()]); - let args = [ +pub fn search_for_pattern(pattern: &str, location: impl AsRef) -> anyhow::Result { + cmd!( + "grep", "-H", "-n", "-r", "--binary-files=without-match", pattern, - location.as_ref().as_os_str().to_str().unwrap(), - ] - .into_iter() - .chain(ignored_files) - .collect_vec(); - - eprintln!("Running grep with args: {:?}", args); - - duct::cmd("grep", args) - .read() - .map_err(|err| anyhow!("Failed running `grep` command for pattern '{pattern}': {err}")) + location.as_ref().to_str().unwrap() + ) + .stdin_null() + .stderr_null() + .read() + .map_err(|err| anyhow!("Failed running `grep` command for pattern '{pattern}': {err}")) } pub fn find_files( @@ -303,16 +282,13 @@ pub fn find_files( "-name", exclude, ) + .stdin_null() + .stderr_null() .read()?) } #[cfg(test)] mod tests { - fn test_data_path(join: impl AsRef) -> PathBuf { - PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("test_data") - .join(join.as_ref()) - } use super::*; @@ -336,7 +312,10 @@ mod tests { #[test] fn test_anchors() -> anyhow::Result<()> { - let data = search_for_pattern("ANCHOR", test_data_path("."), &[])?; + let test_data = generate_test_data()?; + let path = test_data.path(); + + let data = search_for_pattern("ANCHOR", path)?; let (starts, ends) = extract_starts_and_ends(&data)?; let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); @@ -351,24 +330,24 @@ mod tests { assert!(contains_any( &anchor_err_vec, - "Missing anchor start for Anchor { line_no: 10, name: \"test_no_anchor_beginning\"" + "Missing anchor start for Anchor { line_no: 11, name: \"test_no_anchor_beginning\"" )); - assert!(contains_any(&anchor_err_vec, "Couldn't find a matching end anchor for Anchor { line_no: 12, name: \"test_no_anchor_end\"")); - assert!(contains_any(&anchor_err_vec, "The end of the anchor appears before the beginning. End anchor: Anchor { line_no: 14, name: \"test_end_before_beginning\"")); + assert!(contains_any(&anchor_err_vec, "Couldn't find a matching end anchor for Anchor { line_no: 13, name: \"test_no_anchor_end\"")); + assert!(contains_any(&anchor_err_vec, "The end of the anchor appears before the beginning. End anchor: Anchor { line_no: 15, name: \"test_end_before_beginning\"")); - assert!(contains_any(&anchor_err_vec, "Found too many matching anchor ends for anchor: Anchor { line_no: 17, name: \"test_same_name_multiple_time\"")); - assert!(contains_any(&anchor_err_vec, "Found too many matching anchor ends for anchor: Anchor { line_no: 20, name: \"test_same_name_multiple_time\"")); + assert!(contains_any(&anchor_err_vec, "Found too many matching anchor ends for anchor: Anchor { line_no: 18, name: \"test_same_name_multiple_time\"")); + assert!(contains_any(&anchor_err_vec, "Found too many matching anchor ends for anchor: Anchor { line_no: 21, name: \"test_same_name_multiple_time\"")); // Caused by too many matching anchors assert!(contains_any( &anchor_err_vec, - "Missing anchor start for Anchor { line_no: 18, name: \"test_same_name_multiple_time\"" + "Missing anchor start for Anchor { line_no: 19, name: \"test_same_name_multiple_time\"" )); assert!(contains_any( &anchor_err_vec, - "Missing anchor start for Anchor { line_no: 21, name: \"test_same_name_multiple_time\"" + "Missing anchor start for Anchor { line_no: 22, name: \"test_same_name_multiple_time\"" )); - let text_mentioning_include = search_for_pattern("{{#include", test_data_path("."), &[])?; + let text_mentioning_include = search_for_pattern("{{#include", path)?; let (includes, include_path_errors) = parse_includes(text_mentioning_include); @@ -408,16 +387,102 @@ mod tests { #[test] fn test_unused_md() -> anyhow::Result<()> { - let text_with_md_files = - search_for_pattern(".md", test_data_path("docs/src/SUMMARY.md"), &[])?; - let md_files_in_summary = parse_md_files(text_with_md_files, test_data_path("docs/src/")); - let md_files_in_src = find_files("*.md", test_data_path("docs/src/"), "SUMMARY.md")?; + let test_data = generate_test_data()?; + let path = test_data.path(); + + let text_with_md_files = search_for_pattern(".md", path.join("docs/src/SUMMARY.md"))?; + let md_files_in_summary = parse_md_files(text_with_md_files, path.join("docs/src/")); + let md_files_in_src = find_files("*.md", path.join("docs/src/"), "SUMMARY.md")?; let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); let error_msg = md_files_errors.first().unwrap().to_string(); + eprintln!("{error_msg}"); assert!(error_msg.contains("test-not-there.md` not in SUMMARY.md")); Ok(()) } + + fn generate_test_data() -> anyhow::Result { + // Data is generated each time to avoid having the CI detect the errors in these test-only + // MDs. It was either that or rewrite the md_check to have an ignore list but that turned + // out to be problematic because grep excludes are finicky. The whole logic would have to + // be rewritten without grep for excludes to work reliably. + let temp_dir = tempfile::tempdir()?; + + let anchor_data = r#" +// ANCHOR: test_anchor_line_comment +///// ANCHOR_END: test_anchor_line_comment + +/* ANCHOR: test_anchor_block_comment */ +/* ANCHOR_END: test_anchor_block_comment */ + +// ANCHOR: test_with_more_forward_slashes +///// ANCHOR_END: test_with_more_forward_slashes + +// ANCHOR_END: test_no_anchor_beginning + +// ANCHOR: test_no_anchor_end + +// ANCHOR_END: test_end_before_beginning +// ANCHOR: test_end_before_beginning + +// ANCHOR: test_same_name_multiple_time +// ANCHOR_END: test_same_name_multiple_time + +// ANCHOR: test_same_name_multiple_time +// ANCHOR_END: test_same_name_multiple_time +"#; + let path = temp_dir.path(); + std::fs::write(path.join("test_anchor_data.rs"), anchor_data)?; + + let include_data = r#" +```rust,ignore +{{#include ./test_anchor_data.rs:test_anchor_line_comment}} +``` + +```rust,ignore +{{#include ./test_anchor_data.rs:test_anchor_block_comment}} +``` + +```rust,ignore +{{#include ./test_anchor_data.rs:test_with_more_forward_slashes}} +``` + +```rust,ignore +{{#include ./test_anchor_data.rs:no_existing_anchor}} +``` + +Include file with correct path + +```rust,ignore +{{#include ./test_anchor_data.rs}} +``` + +Include file with wrong path + +```rust,ignore +{{#include ./test_anchor_data2.rs}} +``` + +Another include file with wrong path + +```rust,ignore +{{#include ./test_anchor_data3.rs}} +``` +"#; + + std::fs::write(path.join("test_include_data.md"), include_data)?; + + let src = path.join("docs/src"); + std::fs::create_dir_all(&src)?; + + let summary = r#"- [Test](./test.md)"#; + std::fs::write(src.join("SUMMARY.md"), summary)?; + + std::fs::write(src.join("test.md"), "")?; + std::fs::write(src.join("test-not-there.md"), "")?; + + Ok(temp_dir) + } } diff --git a/scripts/checks/src/new_md_check.rs b/scripts/checks/src/new_md_check.rs deleted file mode 100644 index 7e36c1758..000000000 --- a/scripts/checks/src/new_md_check.rs +++ /dev/null @@ -1,57 +0,0 @@ -// Unused anchors -// include references non existent file -// include references non existent anchor -// anchor has no end -// anchor has multiple ends -// anchor has multiple beginnings -// md files not referenced in summary -// - -use std::path::{Path, PathBuf}; - -fn find_files_by_extension(dir: &Path) -> anyhow::Result> { - let mut files = vec![]; - for entry in dir.read_dir()? { - let path = entry?.path().canonicalize()?; - if path.is_file() { - files.push(path); - } else { - files.append(&mut find_files_by_extension(&path)?); - } - } - - Ok(files) -} - -trait FileFinder { - fn find_files(&self, extension: &str) -> anyhow::Result>; -} - -struct MdCheck { - ignore: Vec, -} - -impl MdCheck { - pub fn check(root: &Path) -> anyhow::Result<()> { - // find all rs and sw files - // load anchors text from them, check validity - // parse that into anchors, note errors - - // find all md files - // load includes from them - // check if files referenced in includes exist - // check if anchors referenced in includes exist - // check if all anchors are used - - // check if all files are referenced in summary - todo!() - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_name() {} -} diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index 03553ca43..0e027e013 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -20,7 +20,7 @@ pub struct Task { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum Command { Custom { program: String, args: Vec }, - MdCheck { ignore: Vec }, + MdCheck, } impl From for Command { @@ -31,7 +31,7 @@ impl From for Command { let args = parts.into_iter().skip(1).map(|s| s.to_string()).collect(); Self::Custom { program, args } } - config::Command::MdCheck { ignore } => Self::MdCheck { ignore }, + config::Command::MdCheck => Self::MdCheck, } } } @@ -107,16 +107,12 @@ impl Task { pub fn run(self) -> Execution { match &self.cmd { Command::Custom { program, args } => self.run_custom(program, args), - Command::MdCheck { ignore } => self.run_md_check(ignore), + Command::MdCheck => self.run_md_check(), } } - fn run_md_check(&self, ignore: &[PathBuf]) -> Execution { - let ignore = ignore - .iter() - .map(|path| self.cwd.join(path)) - .collect::>(); - let status = if let Err(e) = md_check::run(&self.cwd, ignore) { + fn run_md_check(&self) -> Execution { + let status = if let Err(e) = md_check::run(&self.cwd) { e.into() } else { ExecutionStatus::Success { diff --git a/scripts/checks/test_data/docs/src/SUMMARY.md b/scripts/checks/test_data/docs/src/SUMMARY.md deleted file mode 100644 index 556dad99a..000000000 --- a/scripts/checks/test_data/docs/src/SUMMARY.md +++ /dev/null @@ -1 +0,0 @@ -- [Test](./test.md) diff --git a/scripts/checks/test_data/docs/src/test-not-there.md b/scripts/checks/test_data/docs/src/test-not-there.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/scripts/checks/test_data/docs/src/test.md b/scripts/checks/test_data/docs/src/test.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/scripts/checks/test_data/test_anchor_data.rs b/scripts/checks/test_data/test_anchor_data.rs deleted file mode 100644 index 1cd26a039..000000000 --- a/scripts/checks/test_data/test_anchor_data.rs +++ /dev/null @@ -1,21 +0,0 @@ -// ANCHOR: test_anchor_line_comment -///// ANCHOR_END: test_anchor_line_comment - -/* ANCHOR: test_anchor_block_comment */ -/* ANCHOR_END: test_anchor_block_comment */ - -// ANCHOR: test_with_more_forward_slashes -///// ANCHOR_END: test_with_more_forward_slashes - -// ANCHOR_END: test_no_anchor_beginning - -// ANCHOR: test_no_anchor_end - -// ANCHOR_END: test_end_before_beginning -// ANCHOR: test_end_before_beginning - -// ANCHOR: test_same_name_multiple_time -// ANCHOR_END: test_same_name_multiple_time - -// ANCHOR: test_same_name_multiple_time -// ANCHOR_END: test_same_name_multiple_time diff --git a/scripts/checks/test_data/test_include_data.md b/scripts/checks/test_data/test_include_data.md deleted file mode 100644 index 53bb84642..000000000 --- a/scripts/checks/test_data/test_include_data.md +++ /dev/null @@ -1,34 +0,0 @@ - -```rust,ignore -{{#include ./test_anchor_data.rs:test_anchor_line_comment}} -``` - -```rust,ignore -{{#include ./test_anchor_data.rs:test_anchor_block_comment}} -``` - -```rust,ignore -{{#include ./test_anchor_data.rs:test_with_more_forward_slashes}} -``` - -```rust,ignore -{{#include ./test_anchor_data.rs:no_existing_anchor}} -``` - -Include file with correct path - -```rust,ignore -{{#include ./test_anchor_data.rs}} -``` - -Include file with wrong path - -```rust,ignore -{{#include ./test_anchor_data2.rs}} -``` - -Another include file with wrong path - -```rust,ignore -{{#include ./test_anchor_data3.rs}} -``` From 3cb0237e2f6a72a56ce91e1b6ddc5dc06ddc60d5 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 14 May 2024 11:51:09 +0200 Subject: [PATCH 18/70] wip --- Cargo.toml | 1 + scripts/checks/Cargo.toml | 4 +- scripts/checks/config/ci.yml | 9 +- scripts/checks/src/main.rs | 1 + scripts/checks/src/new_md_check.rs | 208 +++++++++++++++++++++++++++++ 5 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 scripts/checks/src/new_md_check.rs diff --git a/Cargo.toml b/Cargo.toml index 53bed03c4..5217554f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,6 +73,7 @@ uint = { version = "0.9.5", default-features = false } which = { version = "6.0.0", default-features = false } zeroize = { version = "1.7.0", default-features = false } pretty_assertions = { version = "1.4.0", default-features = false } +walkdir = { version = "2.5", default-features = false } anyhow = { version = "1.0", default-features = false } getrandom = { version = "0.2", default-features = false } wasm-bindgen-test = { version = "0.3", default-features = false } diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index 90366ea1c..f66f108af 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -20,7 +20,9 @@ itertools = { workspace = true, features = ["use_alloc"] } colored = { workspace = true } duct = { workspace = true } regex = { workspace = true, features = ["std", "unicode-perl"] } +walkdir = { workspace = true } [dev-dependencies] -tempfile = { version = "3.10" } +tempfile = { workspace = true } +thiserror = { workspace = true } pretty_assertions = { workspace = true, features = ["std"] } diff --git a/scripts/checks/config/ci.yml b/scripts/checks/config/ci.yml index 2b6f6ceb5..9dd5f2513 100644 --- a/scripts/checks/config/ci.yml +++ b/scripts/checks/config/ci.yml @@ -1,14 +1,7 @@ - working_dir: packages/fuels name: "fuels" commands: - - !Custom ["cargo", "check", "--features", "fuel-core-lib"] - - !Custom ["cargo", "check", "--features", "default"] - - !Custom ["cargo", "check", "--features", "coin-cache"] - - !Custom ["cargo", "check", "--features", "std"] - - !Custom ["cargo", "test", "--features", "fuel-core-lib"] - - !Custom ["cargo", "clippy", "--features", "fuel-core-lib"] - - !Custom ["cargo", "clippy", "--features", "default"] - - !Custom ["cargo", "hack", "--feature-powerset", "check"] + - !Custom ["cargo", "fmt", "--verbose", "--check"] - working_dir: . name: "workspace" diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index 1de92aea6..b4e2f1259 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -4,6 +4,7 @@ use clap::Parser; mod cli; mod config; mod md_check; +mod new_md_check; mod task; mod util; diff --git a/scripts/checks/src/new_md_check.rs b/scripts/checks/src/new_md_check.rs new file mode 100644 index 000000000..6eb34161f --- /dev/null +++ b/scripts/checks/src/new_md_check.rs @@ -0,0 +1,208 @@ +use std::path::{Path, PathBuf}; + +#[cfg(test)] +mod tests { + use std::{ + collections::{HashMap, HashSet}, + fs::File, + io::{BufRead, BufReader, Write}, + str::FromStr, + }; + + use itertools::Itertools; + use pretty_assertions::assert_eq; + use walkdir::WalkDir; + + use crate::md_check::Include; + + use super::*; + + #[derive(Debug, PartialEq)] + struct Anchor { + name: String, + start_line: u64, + end_line: u64, + } + + struct Anchors { + anchors: HashMap>, + } + + impl Anchors { + fn new() -> Self { + Anchors { + anchors: HashMap::new(), + } + } + + fn load(&mut self, file: &Path) -> Result<()> { + let lines = std::fs::read_to_string(&file)?.lines().collect_vec(); + + let mut start_anchors: Vec<(u64, String)> = vec![]; + let mut end_anchors: Vec<(u64, String)> = vec![]; + + for (i, line) in lines.iter().enumerate() { + if let Some(anchor) = line.strip_prefix("// ANCHOR: ") { + start_anchors.push((i as u64, anchor.to_string())); + } else if let Some(anchor) = line.strip_prefix("// ANCHOR_END: ") { + end_anchors.push((i as u64, anchor.to_string())); + } + } + + Ok(()) + } + } + + pub fn load_anchors(path: &[PathBuf]) -> Result { + todo!() + } + + #[test] + fn parses_anchors() { + // given + let temp_dir = tempfile::tempdir().unwrap(); + let file = temp_dir.path().join("file.rs"); + let lines = [ + "// ANCHOR: outer", + "// ANCHOR: inner", + "CONTENT", + "// ANCHOR_END: inner", + "// ANCHOR_END: outer", + ]; + + write_to_file(&file, &lines).unwrap(); + + let mut anchors = Anchors::new(); + + // when + anchors.load(&file).unwrap(); + + // then + assert_eq!( + load_anchors, + [ + Anchor { + name: "outer".to_string(), + start_line: 0, + end_line: 4, + }, + Anchor { + name: "inner".to_string(), + start_line: 1, + end_line: 3, + }, + ] + ) + } + + #[derive(thiserror::Error, Debug, PartialEq)] + enum Error { + #[error("Missing anchor. Needed in {usage}, expected in {expected_file} with name {name}")] + MissingAnchor { + usage: PathBuf, + expected_file: PathBuf, + name: String, + }, + #[error("{0}")] + Other(String), + } + + type Result = std::result::Result; + + impl From for Error { + fn from(err: walkdir::Error) -> Self { + Error::Other(err.to_string()) + } + } + impl From for Error { + fn from(err: anyhow::Error) -> Self { + Error::Other(err.to_string()) + } + } + + impl From for Error { + fn from(err: std::io::Error) -> Self { + Error::Other(err.to_string()) + } + } + + #[test] + fn missing_anchors_detected() { + // given + let temp_dir = tempfile::tempdir().unwrap(); + let path = temp_dir.path(); + + let anchors = path.join("includes.md"); + let lines = [r"{{#include ./test_anchor_data.rs:test_anchor_block_comment}}"].join("\n"); + std::fs::write(&anchors, lines); + + // when + let err = doit(&anchors).expect_err("Expected error"); + + // then + let expected = Error::MissingAnchor { + usage: path.join("includes.md"), + expected_file: path.join("test_anchor_data.rs"), + name: "test_anchor_block_comment".to_string(), + }; + + assert_eq!(err, expected); + } + + fn doit(dir: &Path, excludes: &[PathBuf]) -> Result<()> { + let code_files = find_files(dir, &["rs", "sw"], excludes)?; + let anchors = load_anchors(&code_files)?; + + let md_files = find_files(dir, &["md"], excludes)?; + let includes = extract_includes(&md_files)?; + + includes_valid(&includes, &anchors)?; + no_unused_anchors(&anchors, &includes)?; + + Ok(()) + } + + fn no_unused_anchors( + lookup: &HashMap>, + includes: &[Include], + ) -> Result<()> { + todo!() + } + + fn includes_valid(includes: &[Include], lookup: &HashMap>) -> Result<()> { + todo!() + } + + fn extract_includes(md_files: &[PathBuf]) -> Result> { + todo!() + } + + fn find_files(path: &Path, extensions: &[&str], excludes: &[PathBuf]) -> Result> { + let mut files = vec![]; + for entry in WalkDir::new(path) { + let path = entry?.path().to_owned(); + if excludes.contains(&path) || !path.is_file() { + continue; + } + + if let Some(ext) = path.extension() { + if extensions.contains(&ext.to_str().unwrap()) { + files.push(path); + } + } + } + Ok(files) + } + + fn write_to_file(path: &Path, lines: &[&str]) -> anyhow::Result<()> { + let mut file = File::create(path)?; + + for line in lines { + writeln!(&mut file, "{line}")?; + } + + file.sync_all()?; + + Ok(()) + } +} From d4e882e5ac9da34b2c827cd5336d0256a00dfc88 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 14 May 2024 11:59:28 +0200 Subject: [PATCH 19/70] remove target --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 65acc517a..f54a1239f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Generated by Cargo # will have compiled files and executables -/target/ +target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html @@ -17,5 +17,4 @@ docs/book/ # Don't add out/ files from test Sway projects. e2e/sway/**/out/ -e2e/sway/**/target/ e2e/sway/**/.gitignore From 792dd1855974f83c27cf3c20f4e57e4fef4238a4 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 14 May 2024 12:01:25 +0200 Subject: [PATCH 20/70] move forc --- Forc.toml | 113 -------------------------------------------------- e2e/Forc.toml | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 113 deletions(-) delete mode 100644 Forc.toml create mode 100644 e2e/Forc.toml diff --git a/Forc.toml b/Forc.toml deleted file mode 100644 index 0a99a5ade..000000000 --- a/Forc.toml +++ /dev/null @@ -1,113 +0,0 @@ -[workspace] -members = [ - 'e2e/sway/bindings/sharing_types/contract_a', - 'e2e/sway/bindings/sharing_types/contract_b', - 'e2e/sway/bindings/sharing_types/shared_lib', - 'e2e/sway/bindings/simple_contract', - 'e2e/sway/bindings/type_paths', - 'e2e/sway/contracts/asserts', - 'e2e/sway/contracts/auth_testing_abi', - 'e2e/sway/contracts/auth_testing_contract', - 'e2e/sway/contracts/block_timestamp', - 'e2e/sway/contracts/configurables', - 'e2e/sway/contracts/contract_test', - 'e2e/sway/contracts/large_return_data', - 'e2e/sway/contracts/lib_contract', - 'e2e/sway/contracts/lib_contract_abi', - 'e2e/sway/contracts/lib_contract_caller', - 'e2e/sway/contracts/library_test', - 'e2e/sway/contracts/liquidity_pool', - 'e2e/sway/contracts/low_level_caller', - 'e2e/sway/contracts/msg_methods', - 'e2e/sway/contracts/multiple_read_calls', - 'e2e/sway/contracts/needs_custom_decoder', - 'e2e/sway/contracts/payable_annotation', - 'e2e/sway/contracts/require', - 'e2e/sway/contracts/revert_transaction_error', - 'e2e/sway/contracts/storage', - 'e2e/sway/contracts/token_ops', - 'e2e/sway/contracts/transaction_block_height', - 'e2e/sway/logs/contract_logs', - 'e2e/sway/logs/contract_logs_abi', - 'e2e/sway/logs/contract_with_contract_logs', - 'e2e/sway/logs/script_heap_logs', - 'e2e/sway/logs/script_logs', - 'e2e/sway/logs/script_needs_custom_decoder_logging', - 'e2e/sway/logs/script_with_contract_logs', - 'e2e/sway/predicates/basic_predicate', - 'e2e/sway/predicates/predicate_configurables', - 'e2e/sway/predicates/predicate_witnesses', - 'e2e/sway/predicates/signatures', - 'e2e/sway/predicates/swap', - 'e2e/sway/scripts/arguments', - 'e2e/sway/scripts/basic_script', - 'e2e/sway/scripts/require_from_contract', - 'e2e/sway/scripts/script_array', - 'e2e/sway/scripts/script_asserts', - 'e2e/sway/scripts/script_configurables', - 'e2e/sway/scripts/script_enum', - 'e2e/sway/scripts/script_needs_custom_decoder', - 'e2e/sway/scripts/script_require', - 'e2e/sway/scripts/script_struct', - 'e2e/sway/scripts/transfer_script', - 'e2e/sway/types/contracts/b256', - 'e2e/sway/types/contracts/b512', - 'e2e/sway/types/contracts/bytes', - 'e2e/sway/types/contracts/call_empty_return', - 'e2e/sway/types/contracts/complex_types_contract', - 'e2e/sway/types/contracts/empty_arguments', - 'e2e/sway/types/contracts/enum_as_input', - 'e2e/sway/types/contracts/enum_encoding', - 'e2e/sway/types/contracts/enum_inside_struct', - 'e2e/sway/types/contracts/evm_address', - 'e2e/sway/types/contracts/generics', - 'e2e/sway/types/contracts/heap_type_in_enums', - 'e2e/sway/types/contracts/heap_types', - 'e2e/sway/types/contracts/identity', - 'e2e/sway/types/contracts/native_types', - 'e2e/sway/types/contracts/nested_structs', - 'e2e/sway/types/contracts/options', - 'e2e/sway/types/contracts/raw_slice', - 'e2e/sway/types/contracts/results', - 'e2e/sway/types/contracts/std_lib_string', - 'e2e/sway/types/contracts/str_in_array', - 'e2e/sway/types/contracts/string_slice', - 'e2e/sway/types/contracts/tuples', - 'e2e/sway/types/contracts/two_structs', - 'e2e/sway/types/contracts/type_inside_enum', - 'e2e/sway/types/contracts/u128', - 'e2e/sway/types/contracts/u256', - 'e2e/sway/types/contracts/vector_output', - 'e2e/sway/types/contracts/vectors', - 'e2e/sway/types/predicates/address', - 'e2e/sway/types/predicates/enums', - 'e2e/sway/types/predicates/predicate_b256', - 'e2e/sway/types/predicates/predicate_bytes', - 'e2e/sway/types/predicates/predicate_bytes_hash', - 'e2e/sway/types/predicates/predicate_generics', - 'e2e/sway/types/predicates/predicate_raw_slice', - 'e2e/sway/types/predicates/predicate_std_lib_string', - 'e2e/sway/types/predicates/predicate_tuples', - 'e2e/sway/types/predicates/predicate_u128', - 'e2e/sway/types/predicates/predicate_u256', - 'e2e/sway/types/predicates/predicate_vector', - 'e2e/sway/types/predicates/predicate_vectors', - 'e2e/sway/types/predicates/structs', - 'e2e/sway/types/predicates/u64', - 'e2e/sway/types/scripts/options_results', - 'e2e/sway/types/scripts/script_b256', - 'e2e/sway/types/scripts/script_bytes', - 'e2e/sway/types/scripts/script_generics', - 'e2e/sway/types/scripts/script_heap_types', - #TODO: Decide what to do with this test project once - # https://github.com/FuelLabs/sway/issues/5727 is resolved - # 'e2e/sway/types/scripts/script_raw_slice', - 'e2e/sway/types/scripts/script_std_lib_string', - 'e2e/sway/types/scripts/script_tuples', - 'e2e/sway/types/scripts/script_u128', - 'e2e/sway/types/scripts/script_u256', - 'e2e/sway/types/scripts/script_vectors', -] - -[patch.'https://github.com/fuellabs/sway'] -std = { git = "https://github.com/fuellabs/sway", branch = "xunilrj/new-encoding-configurables" } diff --git a/e2e/Forc.toml b/e2e/Forc.toml new file mode 100644 index 000000000..c96c62557 --- /dev/null +++ b/e2e/Forc.toml @@ -0,0 +1,113 @@ +[workspace] +members = [ + 'sway/bindings/sharing_types/contract_a', + 'sway/bindings/sharing_types/contract_b', + 'sway/bindings/sharing_types/shared_lib', + 'sway/bindings/simple_contract', + 'sway/bindings/type_paths', + 'sway/contracts/asserts', + 'sway/contracts/auth_testing_abi', + 'sway/contracts/auth_testing_contract', + 'sway/contracts/block_timestamp', + 'sway/contracts/configurables', + 'sway/contracts/contract_test', + 'sway/contracts/large_return_data', + 'sway/contracts/lib_contract', + 'sway/contracts/lib_contract_abi', + 'sway/contracts/lib_contract_caller', + 'sway/contracts/library_test', + 'sway/contracts/liquidity_pool', + 'sway/contracts/low_level_caller', + 'sway/contracts/msg_methods', + 'sway/contracts/multiple_read_calls', + 'sway/contracts/needs_custom_decoder', + 'sway/contracts/payable_annotation', + 'sway/contracts/require', + 'sway/contracts/revert_transaction_error', + 'sway/contracts/storage', + 'sway/contracts/token_ops', + 'sway/contracts/transaction_block_height', + 'sway/logs/contract_logs', + 'sway/logs/contract_logs_abi', + 'sway/logs/contract_with_contract_logs', + 'sway/logs/script_heap_logs', + 'sway/logs/script_logs', + 'sway/logs/script_needs_custom_decoder_logging', + 'sway/logs/script_with_contract_logs', + 'sway/predicates/basic_predicate', + 'sway/predicates/predicate_configurables', + 'sway/predicates/predicate_witnesses', + 'sway/predicates/signatures', + 'sway/predicates/swap', + 'sway/scripts/arguments', + 'sway/scripts/basic_script', + 'sway/scripts/require_from_contract', + 'sway/scripts/script_array', + 'sway/scripts/script_asserts', + 'sway/scripts/script_configurables', + 'sway/scripts/script_enum', + 'sway/scripts/script_needs_custom_decoder', + 'sway/scripts/script_require', + 'sway/scripts/script_struct', + 'sway/scripts/transfer_script', + 'sway/types/contracts/b256', + 'sway/types/contracts/b512', + 'sway/types/contracts/bytes', + 'sway/types/contracts/call_empty_return', + 'sway/types/contracts/complex_types_contract', + 'sway/types/contracts/empty_arguments', + 'sway/types/contracts/enum_as_input', + 'sway/types/contracts/enum_encoding', + 'sway/types/contracts/enum_inside_struct', + 'sway/types/contracts/evm_address', + 'sway/types/contracts/generics', + 'sway/types/contracts/heap_type_in_enums', + 'sway/types/contracts/heap_types', + 'sway/types/contracts/identity', + 'sway/types/contracts/native_types', + 'sway/types/contracts/nested_structs', + 'sway/types/contracts/options', + 'sway/types/contracts/raw_slice', + 'sway/types/contracts/results', + 'sway/types/contracts/std_lib_string', + 'sway/types/contracts/str_in_array', + 'sway/types/contracts/string_slice', + 'sway/types/contracts/tuples', + 'sway/types/contracts/two_structs', + 'sway/types/contracts/type_inside_enum', + 'sway/types/contracts/u128', + 'sway/types/contracts/u256', + 'sway/types/contracts/vector_output', + 'sway/types/contracts/vectors', + 'sway/types/predicates/address', + 'sway/types/predicates/enums', + 'sway/types/predicates/predicate_b256', + 'sway/types/predicates/predicate_bytes', + 'sway/types/predicates/predicate_bytes_hash', + 'sway/types/predicates/predicate_generics', + 'sway/types/predicates/predicate_raw_slice', + 'sway/types/predicates/predicate_std_lib_string', + 'sway/types/predicates/predicate_tuples', + 'sway/types/predicates/predicate_u128', + 'sway/types/predicates/predicate_u256', + 'sway/types/predicates/predicate_vector', + 'sway/types/predicates/predicate_vectors', + 'sway/types/predicates/structs', + 'sway/types/predicates/u64', + 'sway/types/scripts/options_results', + 'sway/types/scripts/script_b256', + 'sway/types/scripts/script_bytes', + 'sway/types/scripts/script_generics', + 'sway/types/scripts/script_heap_types', + #TODO: Decide what to do with this test project once + # https://github.com/FuelLabs/sway/issues/5727 is resolved + # 'sway/types/scripts/script_raw_slice', + 'sway/types/scripts/script_std_lib_string', + 'sway/types/scripts/script_tuples', + 'sway/types/scripts/script_u128', + 'sway/types/scripts/script_u256', + 'sway/types/scripts/script_vectors', +] + +[patch.'https://github.com/fuellabs/sway'] +std = { git = "https://github.com/fuellabs/sway", branch = "xunilrj/new-encoding-configurables" } From c6786458c66462b05339aeabd09a4620fe46be8c Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati <37515857+segfault-magnet@users.noreply.github.com> Date: Tue, 14 May 2024 12:01:35 +0200 Subject: [PATCH 21/70] Update packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs Co-authored-by: hal3e --- .../src/program_bindings/abigen/bindings/script.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs b/packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs index 0a81a72e7..49a1ad9b1 100644 --- a/packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs +++ b/packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs @@ -50,7 +50,7 @@ pub(crate) fn script_bindings( { pub fn new(account: T, binary_filepath: &str) -> Self { let binary = ::std::fs::read(binary_filepath) - .expect(&format!("Could not read binary {binary_filepath:?}")); + .expect(&format!("could not read script binary {binary_filepath:?}")); Self { account, binary, From d3fbb433f69946f882f607a734d2c8c9b78c764f Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 14 May 2024 12:04:27 +0200 Subject: [PATCH 22/70] propagate feature flags --- e2e/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index 797751e92..a485fe45e 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -24,6 +24,9 @@ tempfile = { workspace = true } tokio = { workspace = true } [features] +default = ["fuels/default"] fuel-core-lib = ["fuels/fuel-core-lib"] +rocksdb = ["fuels/rocksdb"] +coin-cache = ["fuels/coin-cache"] # TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked. test-type-paths = [] From d9511d0330f088cfd750a3b6691fc15163b23a2b Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 14 May 2024 12:30:23 +0200 Subject: [PATCH 23/70] fix coin cache usage of fuel core types --- e2e/Cargo.toml | 4 ++-- e2e/Forc.toml | 1 + e2e/sway/scripts/reverting/Forc.toml | 5 +++++ e2e/sway/scripts/reverting/src/main.sw | 5 +++++ e2e/tests/providers.rs | 8 ++------ 5 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 e2e/sway/scripts/reverting/Forc.toml create mode 100644 e2e/sway/scripts/reverting/src/main.sw diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index a485fe45e..8a2d180fe 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -21,10 +21,10 @@ rand = { workspace = true } # used in test assertions tai64 = { workspace = true } tempfile = { workspace = true } -tokio = { workspace = true } +tokio = { workspace = true, features = ["test-util"] } [features] -default = ["fuels/default"] +default = ["fuels/default", "coin-cache"] fuel-core-lib = ["fuels/fuel-core-lib"] rocksdb = ["fuels/rocksdb"] coin-cache = ["fuels/coin-cache"] diff --git a/e2e/Forc.toml b/e2e/Forc.toml index c96c62557..e6b21223f 100644 --- a/e2e/Forc.toml +++ b/e2e/Forc.toml @@ -42,6 +42,7 @@ members = [ 'sway/scripts/arguments', 'sway/scripts/basic_script', 'sway/scripts/require_from_contract', + 'sway/scripts/reverting', 'sway/scripts/script_array', 'sway/scripts/script_asserts', 'sway/scripts/script_configurables', diff --git a/e2e/sway/scripts/reverting/Forc.toml b/e2e/sway/scripts/reverting/Forc.toml new file mode 100644 index 000000000..5500daf4b --- /dev/null +++ b/e2e/sway/scripts/reverting/Forc.toml @@ -0,0 +1,5 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "reverting" diff --git a/e2e/sway/scripts/reverting/src/main.sw b/e2e/sway/scripts/reverting/src/main.sw new file mode 100644 index 000000000..b26952d90 --- /dev/null +++ b/e2e/sway/scripts/reverting/src/main.sw @@ -0,0 +1,5 @@ +script; + +fn main() { + assert(false) +} diff --git a/e2e/tests/providers.rs b/e2e/tests/providers.rs index b4764cd39..695dddcc9 100644 --- a/e2e/tests/providers.rs +++ b/e2e/tests/providers.rs @@ -765,8 +765,6 @@ async fn create_transfer( #[cfg(feature = "coin-cache")] #[tokio::test] async fn test_caching() -> Result<()> { - use fuels_core::types::tx_status::TxStatus; - let amount = 1000; let num_coins = 10; let mut wallets = launch_custom_provider_and_get_wallets( @@ -805,7 +803,7 @@ async fn test_caching() -> Result<()> { #[cfg(feature = "coin-cache")] async fn create_revert_tx(wallet: &WalletUnlocked) -> Result { - use fuel_core_types::fuel_asm::Opcode; + let script = std::fs::read("sway/scripts/reverting/out/release/reverting.bin")?; let amount = 1; let asset_id = AssetId::zeroed(); @@ -813,7 +811,7 @@ async fn create_revert_tx(wallet: &WalletUnlocked) -> Result let outputs = wallet.get_asset_outputs_for_amount(&Bech32Address::default(), asset_id, amount); let mut tb = ScriptTransactionBuilder::prepare_transfer(inputs, outputs, TxPolicies::default()) - .with_script(vec![Opcode::RVRT.into()]); + .with_script(script); tb.add_signer(wallet.clone())?; wallet.adjust_for_fee(&mut tb, amount).await?; @@ -824,8 +822,6 @@ async fn create_revert_tx(wallet: &WalletUnlocked) -> Result #[cfg(feature = "coin-cache")] #[tokio::test] async fn test_cache_invalidation_on_await() -> Result<()> { - use fuels_core::types::tx_status::TxStatus; - let block_time = 1u32; let provider_config = NodeConfig { block_production: Trigger::Interval { From 1b04bfb97219278dd174e0c9cbc8aa6d1f6607fd Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 14 May 2024 13:20:12 +0200 Subject: [PATCH 24/70] fix forc path --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10e518e67..0a03a0cdc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,10 +59,10 @@ jobs: fi - name: Check format of Sway test projects - run: forc fmt --check + run: forc fmt --check --path e2e - name: Build Sway test projects - run: forc build --release --terse --error-on-warnings + run: forc build --release --terse --error-on-warnings --path e2e - uses: actions/upload-artifact@v4 with: @@ -73,7 +73,7 @@ jobs: # TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked. - name: Build Sway test projects w type paths - run: forc build --release --terse --error-on-warnings --json-abi-with-callpaths + run: forc build --release --terse --error-on-warnings --json-abi-with-callpaths --path e2e - uses: actions/upload-artifact@v4 with: From 64b02d0a9cc84683e740efbbdc8f4ea9a4d5ad12 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 14 May 2024 23:08:36 +0200 Subject: [PATCH 25/70] wip again --- packages/fuels-accounts/Cargo.toml | 8 +- packages/fuels-accounts/src/lib.rs | 1 - packages/fuels-accounts/src/predicate.rs | 15 +- packages/fuels-test-helpers/src/accounts.rs | 4 +- scripts/checks/Cargo.toml | 1 - scripts/checks/config/ci.yml | 54 +++- scripts/checks/src/config.rs | 17 +- scripts/checks/src/main.rs | 1 - scripts/checks/src/md_check.rs | 74 ++--- scripts/checks/src/new_md_check.rs | 208 ------------- scripts/checks/src/task.rs | 311 +++++++++++++------- 11 files changed, 306 insertions(+), 388 deletions(-) delete mode 100644 scripts/checks/src/new_md_check.rs diff --git a/packages/fuels-accounts/Cargo.toml b/packages/fuels-accounts/Cargo.toml index 147ae50da..aa3a671f1 100644 --- a/packages/fuels-accounts/Cargo.toml +++ b/packages/fuels-accounts/Cargo.toml @@ -17,9 +17,9 @@ eth-keystore = { workspace = true, optional = true } fuel-core-client = { workspace = true, optional = true } fuel-core-types = { workspace = true, optional = true } fuel-crypto = { workspace = true, optional = true } -fuel-tx = { workspace = true, optional = true } +fuel-tx = { workspace = true } fuel-types = { workspace = true, optional = true } -fuels-core = { workspace = true, optional = true } +fuels-core = { workspace = true } rand = { workspace = true, optional = true } semver = { workspace = true, optional = true } tai64 = { workspace = true, optional = true } @@ -35,7 +35,7 @@ tokio = { workspace = true, features = ["test-util", "macros"] } [features] default = ["std"] -coin-cache = ["tokio/time", "dep:fuels-core", "dep:fuel-types"] +coin-cache = ["tokio/time", "dep:fuel-types"] std = [ "fuels-core/std", "fuel-core-client/default", @@ -48,9 +48,7 @@ std = [ "dep:fuel-core-client", "dep:fuel-core-types", "dep:fuel-crypto", - "dep:fuel-tx", "dep:fuel-types", - "dep:fuels-core", "dep:rand", "dep:semver", "dep:tai64", diff --git a/packages/fuels-accounts/src/lib.rs b/packages/fuels-accounts/src/lib.rs index 295873409..b219eb8e8 100644 --- a/packages/fuels-accounts/src/lib.rs +++ b/packages/fuels-accounts/src/lib.rs @@ -14,7 +14,6 @@ pub use account::*; #[cfg(feature = "coin-cache")] mod coin_cache; -#[cfg(feature = "std")] pub mod predicate; #[cfg(test)] diff --git a/packages/fuels-accounts/src/predicate.rs b/packages/fuels-accounts/src/predicate.rs index d27c7d18a..8a6675bb0 100644 --- a/packages/fuels-accounts/src/predicate.rs +++ b/packages/fuels-accounts/src/predicate.rs @@ -1,12 +1,8 @@ -use std::{fmt::Debug, fs}; +use std::fmt::Debug; #[cfg(feature = "std")] -use fuels_core::types::{input::Input, AssetId}; -use fuels_core::{ - error, - types::{bech32::Bech32Address, errors::Result}, - Configurables, -}; +use fuels_core::types::{errors::Result, input::Input, AssetId}; +use fuels_core::{types::bech32::Bech32Address, Configurables}; #[cfg(feature = "std")] use crate::accounts_utils::try_provider_error; @@ -39,9 +35,10 @@ impl Predicate { fuel_tx::Input::predicate_owner(code).into() } + #[cfg(feature = "std")] pub fn load_from(file_path: &str) -> Result { - let code = fs::read(file_path).map_err(|e| { - error!( + let code = std::fs::read(file_path).map_err(|e| { + fuels_core::error!( IO, "could not read predicate binary {file_path:?}. Reason: {e}" ) diff --git a/packages/fuels-test-helpers/src/accounts.rs b/packages/fuels-test-helpers/src/accounts.rs index 1dc9e99e6..716247fe4 100644 --- a/packages/fuels-test-helpers/src/accounts.rs +++ b/packages/fuels-test-helpers/src/accounts.rs @@ -14,7 +14,7 @@ use crate::{ /// The provider and the wallets are instantiated with the default configs. /// For more configurable options, see the `launch_custom_provider_and_get_wallets` function. /// # Examples -/// ``` +/// ```rust /// use fuels_test_helpers::launch_provider_and_get_wallet; /// /// async fn single_wallet() -> Result<(), Box> { @@ -34,7 +34,7 @@ pub async fn launch_provider_and_get_wallet() -> Result { /// Launches a custom node and provider, along with a configurable number of wallets. /// /// # Examples -/// ``` +/// ```rust /// use fuels_test_helpers::launch_custom_provider_and_get_wallets; /// use fuels_test_helpers::WalletsConfig; /// diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index f66f108af..14ef25b98 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -20,7 +20,6 @@ itertools = { workspace = true, features = ["use_alloc"] } colored = { workspace = true } duct = { workspace = true } regex = { workspace = true, features = ["std", "unicode-perl"] } -walkdir = { workspace = true } [dev-dependencies] tempfile = { workspace = true } diff --git a/scripts/checks/config/ci.yml b/scripts/checks/config/ci.yml index 9dd5f2513..997396526 100644 --- a/scripts/checks/config/ci.yml +++ b/scripts/checks/config/ci.yml @@ -1,9 +1,51 @@ -- working_dir: packages/fuels - name: "fuels" +- run_for_dirs: + - packages/fuels + - packages/fuels-accounts + - packages/fuels-code-gen + - packages/fuels-core + - packages/fuels-macros + - packages/fuels-programs + - packages/fuels-test-helpers + - e2e + - wasm-tests + - scripts/checks commands: - - !Custom ["cargo", "fmt", "--verbose", "--check"] + - !Custom + cmd: [cargo, fmt, --verbose, --check] + # - !Custom + # cmd: [cargo, clippy, --all-targets, --all-features, --no-deps] + # - !Custom + # # because those tests need to be run with wasm-pack + # ignore_if_cwd_ends_with: [wasm-tests] + # cmd: [cargo, nextest, run, --all-features] + - !Custom + # because these don't have libs + ignore_if_cwd_ends_with: [e2e, scripts/checks, wasm-tests] + cmd: [cargo, test, --doc] + - !Custom + # because these don't have libs + ignore_if_cwd_ends_with: [e2e, scripts/checks, wasm-tests] + cmd: [cargo, doc, --document-private-items] + env: + RUSTDOCFLAGS: "-D warnings" -- working_dir: . - name: "workspace" + + +- run_for_dirs: [wasm-tests] + commands: + - !Custom + cmd: [wasm-pack, test, --node] + +- run_for_dirs: [.] commands: - - !MdCheck + - !MdCheck + dont_search: [scripts/checks, target/] + - !Custom + cmd: [cargo, clippy, --workspace, --all-features] + # For some reason only works in the workspace dir + - !Custom + cmd: [cargo-machete, --skip-target-dir] + + +# - command: check_typos +# args: diff --git a/scripts/checks/src/config.rs b/scripts/checks/src/config.rs index 97d231c1d..26649b264 100644 --- a/scripts/checks/src/config.rs +++ b/scripts/checks/src/config.rs @@ -1,17 +1,22 @@ -use std::path::PathBuf; +use std::{collections::HashMap, path::PathBuf}; #[derive(Debug, serde::Deserialize)] pub struct Config(pub Vec); #[derive(Debug, serde::Deserialize)] pub struct Group { - pub working_dir: PathBuf, - pub name: String, + pub run_for_dirs: Vec, pub commands: Vec, } -#[derive(Debug, serde::Deserialize)] +#[derive(Debug, Clone, serde::Deserialize)] pub enum Command { - MdCheck, - Custom(Vec), + MdCheck { + ignore_if_in_dir: Option>, + }, + Custom { + ignore_if_cwd_ends_with: Option>, + cmd: Vec, + env: Option>, + }, } diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index b4e2f1259..1de92aea6 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -4,7 +4,6 @@ use clap::Parser; mod cli; mod config; mod md_check; -mod new_md_check; mod task; mod util; diff --git a/scripts/checks/src/md_check.rs b/scripts/checks/src/md_check.rs index 1003ad757..70b08b0ab 100644 --- a/scripts/checks/src/md_check.rs +++ b/scripts/checks/src/md_check.rs @@ -9,44 +9,35 @@ use std::{ }; pub fn run(dir: &Path) -> anyhow::Result<(), Error> { - let text_w_anchors = search_for_pattern("ANCHOR", dir)?; + let sources = ["packages", "e2e", "examples"].map(|source| dir.join(source)); + let text_w_anchors = search_for_pattern("ANCHOR", &sources)?; let (starts, ends) = extract_starts_and_ends(&text_w_anchors)?; let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); - let text_mentioning_include = search_for_pattern("{{#include", dir)?; + let text_mentioning_include = search_for_pattern("{{#include", &[dir.join("docs")])?; let (includes, include_path_errors) = parse_includes(text_mentioning_include); let (include_errors, additional_warnings) = validate_includes(includes, valid_anchors); - let text_with_md_files = search_for_pattern(".md", dir.join("./docs/src/SUMMARY.md"))?; + let text_with_md_files = search_for_pattern(".md", &[dir.join("./docs/src/SUMMARY.md")])?; let md_files_in_summary = parse_md_files(text_with_md_files, dir.join("./docs/src/")); let md_files_in_src = find_files("*.md", dir.join("./docs/src/"), "SUMMARY.md")?; let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); - report_errors("warning", &additional_warnings); - report_errors("include paths", &include_path_errors); - report_errors("anchors", &anchor_errors); - report_errors("includes", &include_errors); - report_errors("md files", &md_files_errors); - - if !anchor_errors.is_empty() - || !include_errors.is_empty() - || !include_path_errors.is_empty() - || !additional_warnings.is_empty() - || !md_files_errors.is_empty() - { - bail!("Finished with errors"); - } - - Ok(()) -} + let errors = chain!( + additional_warnings, + anchor_errors, + include_path_errors, + include_errors, + md_files_errors + ) + .collect_vec(); -fn report_errors(error_type: &str, errors: &[Error]) { if !errors.is_empty() { - eprintln!("\nInvalid {error_type} detected!\n"); - for error in errors { - eprintln!("{error}\n") - } + let err_str = errors.iter().map(|err| err.to_string()).join("\n"); + bail!("Errors: {err_str}") } + + Ok(()) } pub fn validate_includes( @@ -250,20 +241,15 @@ pub fn validate_md_files( .collect() } -pub fn search_for_pattern(pattern: &str, location: impl AsRef) -> anyhow::Result { - cmd!( - "grep", - "-H", - "-n", - "-r", - "--binary-files=without-match", - pattern, - location.as_ref().to_str().unwrap() - ) - .stdin_null() - .stderr_null() - .read() - .map_err(|err| anyhow!("Failed running `grep` command for pattern '{pattern}': {err}")) +pub fn search_for_pattern(pattern: &str, location: &[PathBuf]) -> anyhow::Result { + let mut args = vec!["-H", "-n", "-r", "--binary-files=without-match", pattern]; + args.extend(location.iter().map(|path| path.to_str().unwrap())); + + duct::cmd("grep", args) + .stdin_null() + .stderr_null() + .read() + .map_err(|err| anyhow!("Failed running `grep` command for pattern '{pattern}': {err}")) } pub fn find_files( @@ -315,7 +301,7 @@ mod tests { let test_data = generate_test_data()?; let path = test_data.path(); - let data = search_for_pattern("ANCHOR", path)?; + let data = search_for_pattern("ANCHOR", &[path.to_owned()])?; let (starts, ends) = extract_starts_and_ends(&data)?; let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); @@ -347,7 +333,7 @@ mod tests { "Missing anchor start for Anchor { line_no: 22, name: \"test_same_name_multiple_time\"" )); - let text_mentioning_include = search_for_pattern("{{#include", path)?; + let text_mentioning_include = search_for_pattern("{{#include", &[path.to_owned()])?; let (includes, include_path_errors) = parse_includes(text_mentioning_include); @@ -390,7 +376,7 @@ mod tests { let test_data = generate_test_data()?; let path = test_data.path(); - let text_with_md_files = search_for_pattern(".md", path.join("docs/src/SUMMARY.md"))?; + let text_with_md_files = search_for_pattern(".md", &[path.join("docs/src/SUMMARY.md")])?; let md_files_in_summary = parse_md_files(text_with_md_files, path.join("docs/src/")); let md_files_in_src = find_files("*.md", path.join("docs/src/"), "SUMMARY.md")?; let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); @@ -404,10 +390,6 @@ mod tests { } fn generate_test_data() -> anyhow::Result { - // Data is generated each time to avoid having the CI detect the errors in these test-only - // MDs. It was either that or rewrite the md_check to have an ignore list but that turned - // out to be problematic because grep excludes are finicky. The whole logic would have to - // be rewritten without grep for excludes to work reliably. let temp_dir = tempfile::tempdir()?; let anchor_data = r#" diff --git a/scripts/checks/src/new_md_check.rs b/scripts/checks/src/new_md_check.rs deleted file mode 100644 index 6eb34161f..000000000 --- a/scripts/checks/src/new_md_check.rs +++ /dev/null @@ -1,208 +0,0 @@ -use std::path::{Path, PathBuf}; - -#[cfg(test)] -mod tests { - use std::{ - collections::{HashMap, HashSet}, - fs::File, - io::{BufRead, BufReader, Write}, - str::FromStr, - }; - - use itertools::Itertools; - use pretty_assertions::assert_eq; - use walkdir::WalkDir; - - use crate::md_check::Include; - - use super::*; - - #[derive(Debug, PartialEq)] - struct Anchor { - name: String, - start_line: u64, - end_line: u64, - } - - struct Anchors { - anchors: HashMap>, - } - - impl Anchors { - fn new() -> Self { - Anchors { - anchors: HashMap::new(), - } - } - - fn load(&mut self, file: &Path) -> Result<()> { - let lines = std::fs::read_to_string(&file)?.lines().collect_vec(); - - let mut start_anchors: Vec<(u64, String)> = vec![]; - let mut end_anchors: Vec<(u64, String)> = vec![]; - - for (i, line) in lines.iter().enumerate() { - if let Some(anchor) = line.strip_prefix("// ANCHOR: ") { - start_anchors.push((i as u64, anchor.to_string())); - } else if let Some(anchor) = line.strip_prefix("// ANCHOR_END: ") { - end_anchors.push((i as u64, anchor.to_string())); - } - } - - Ok(()) - } - } - - pub fn load_anchors(path: &[PathBuf]) -> Result { - todo!() - } - - #[test] - fn parses_anchors() { - // given - let temp_dir = tempfile::tempdir().unwrap(); - let file = temp_dir.path().join("file.rs"); - let lines = [ - "// ANCHOR: outer", - "// ANCHOR: inner", - "CONTENT", - "// ANCHOR_END: inner", - "// ANCHOR_END: outer", - ]; - - write_to_file(&file, &lines).unwrap(); - - let mut anchors = Anchors::new(); - - // when - anchors.load(&file).unwrap(); - - // then - assert_eq!( - load_anchors, - [ - Anchor { - name: "outer".to_string(), - start_line: 0, - end_line: 4, - }, - Anchor { - name: "inner".to_string(), - start_line: 1, - end_line: 3, - }, - ] - ) - } - - #[derive(thiserror::Error, Debug, PartialEq)] - enum Error { - #[error("Missing anchor. Needed in {usage}, expected in {expected_file} with name {name}")] - MissingAnchor { - usage: PathBuf, - expected_file: PathBuf, - name: String, - }, - #[error("{0}")] - Other(String), - } - - type Result = std::result::Result; - - impl From for Error { - fn from(err: walkdir::Error) -> Self { - Error::Other(err.to_string()) - } - } - impl From for Error { - fn from(err: anyhow::Error) -> Self { - Error::Other(err.to_string()) - } - } - - impl From for Error { - fn from(err: std::io::Error) -> Self { - Error::Other(err.to_string()) - } - } - - #[test] - fn missing_anchors_detected() { - // given - let temp_dir = tempfile::tempdir().unwrap(); - let path = temp_dir.path(); - - let anchors = path.join("includes.md"); - let lines = [r"{{#include ./test_anchor_data.rs:test_anchor_block_comment}}"].join("\n"); - std::fs::write(&anchors, lines); - - // when - let err = doit(&anchors).expect_err("Expected error"); - - // then - let expected = Error::MissingAnchor { - usage: path.join("includes.md"), - expected_file: path.join("test_anchor_data.rs"), - name: "test_anchor_block_comment".to_string(), - }; - - assert_eq!(err, expected); - } - - fn doit(dir: &Path, excludes: &[PathBuf]) -> Result<()> { - let code_files = find_files(dir, &["rs", "sw"], excludes)?; - let anchors = load_anchors(&code_files)?; - - let md_files = find_files(dir, &["md"], excludes)?; - let includes = extract_includes(&md_files)?; - - includes_valid(&includes, &anchors)?; - no_unused_anchors(&anchors, &includes)?; - - Ok(()) - } - - fn no_unused_anchors( - lookup: &HashMap>, - includes: &[Include], - ) -> Result<()> { - todo!() - } - - fn includes_valid(includes: &[Include], lookup: &HashMap>) -> Result<()> { - todo!() - } - - fn extract_includes(md_files: &[PathBuf]) -> Result> { - todo!() - } - - fn find_files(path: &Path, extensions: &[&str], excludes: &[PathBuf]) -> Result> { - let mut files = vec![]; - for entry in WalkDir::new(path) { - let path = entry?.path().to_owned(); - if excludes.contains(&path) || !path.is_file() { - continue; - } - - if let Some(ext) = path.extension() { - if extensions.contains(&ext.to_str().unwrap()) { - files.push(path); - } - } - } - Ok(files) - } - - fn write_to_file(path: &Path, lines: &[&str]) -> anyhow::Result<()> { - let mut file = File::create(path)?; - - for line in lines { - writeln!(&mut file, "{line}")?; - } - - file.sync_all()?; - - Ok(()) - } -} diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index 0e027e013..ad6aeb174 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -13,44 +13,74 @@ use crate::{config, md_check}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Task { cwd: PathBuf, - name: String, - cmd: Command, + cmd: Action, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] -pub enum Command { - Custom { program: String, args: Vec }, +pub enum Action { + Custom { + program: String, + args: Vec, + env: Vec<(String, String)>, + }, MdCheck, } +pub struct Command { + ignore_if_cwd_ends_with: Vec, + action: Action, +} + impl From for Command { fn from(value: config::Command) -> Self { match value { - config::Command::Custom(parts) => { + config::Command::Custom { + cmd: parts, + ignore_if_cwd_ends_with, + env, + } => { let program = parts.first().unwrap().to_string(); let args = parts.into_iter().skip(1).map(|s| s.to_string()).collect(); - Self::Custom { program, args } + Self { + ignore_if_cwd_ends_with: ignore_if_cwd_ends_with.unwrap_or_default(), + action: Action::Custom { + program, + args, + env: env.unwrap_or_default().into_iter().collect(), + }, + } } - config::Command::MdCheck => Self::MdCheck, + config::Command::MdCheck { ignore_if_in_dir } => Self { + ignore_if_cwd_ends_with: ignore_if_in_dir.unwrap_or_default(), + action: Action::MdCheck, + }, } } } -impl Display for Command { +impl Display for Action { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Command::Custom { program, args } => { + Action::Custom { program, args, env } => { let args = args.iter().join(" "); - write!(f, "{program} {args}") + if env.is_empty() { + write!(f, "{program} {args}") + } else { + let env = env + .iter() + .map(|(key, value)| format!("{key}='{value}'")) + .join(" "); + write!(f, "{env} {program} {args}") + } } - Command::MdCheck { .. } => write!(f, "MdCheck"), + Action::MdCheck { .. } => write!(f, "MdCheck"), } } } impl Display for Task { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "({}) {}", self.name, self.cmd) + write!(f, "({:?}) {}", self.cwd, self.cmd) } } @@ -106,8 +136,10 @@ impl Execution { impl Task { pub fn run(self) -> Execution { match &self.cmd { - Command::Custom { program, args } => self.run_custom(program, args), - Command::MdCheck => self.run_md_check(), + Action::Custom { program, args, env } => { + self.run_custom(program, args.iter().map(|e| e.as_str()), env) + } + Action::MdCheck => self.run_md_check(), } } @@ -123,14 +155,21 @@ impl Task { self.execution_report(status) } - fn run_custom(&self, program: &String, args: &Vec) -> Execution { - let cmd = cmd(program, args) + fn run_custom<'a, F>(&self, program: &str, args: F, env: &[(String, String)]) -> Execution + where + F: IntoIterator, + { + let mut cmd = cmd(program, args) .stderr_to_stdout() .dir(&self.cwd) .stdin_null() .stdout_capture() .unchecked(); + for (key, value) in env { + cmd = cmd.env(key, value); + } + let output = match cmd.run() { Ok(output) => output, Err(err) => return self.execution_report(err), @@ -166,17 +205,24 @@ impl Tasks { .0 .into_iter() .flat_map(|entry| { - let cwd = workspace_root.join(&entry.working_dir); - let name = entry.name; - entry - .commands - .into_iter() - .map(Command::from) - .map(move |cmd| Task { - cwd: cwd.clone(), - name: name.clone(), - cmd, - }) + entry.run_for_dirs.into_iter().flat_map(move |dir| { + let cwd = workspace_root.join(dir); + entry + .commands + .iter() + .cloned() + .map(Command::from) + .filter(|cmd| { + cmd.ignore_if_cwd_ends_with + .iter() + .all(|ignored_dir| !cwd.ends_with(ignored_dir)) + }) + .map(|cmd| Task { + cwd: cwd.clone(), + cmd: cmd.action, + }) + .collect_vec() + }) }) .collect(); @@ -189,21 +235,42 @@ impl Tasks { set.spawn_blocking(|| task.run()); } + let mut errors = false; while let Some(result) = set.join_next().await { - let result = result?; - eprintln!("{}", result.report(tty, verbose)); + let execution = result?; + if let ExecutionStatus::Success { .. } = execution.status { + errors = true; + } + + let report = execution.report(tty, verbose); + eprintln!("{report}"); + } + + if errors { + anyhow::bail!("Some checks failed"); } Ok(()) } - pub fn retain(&mut self, crate_names: &[String]) { - self.tasks.retain(|task| crate_names.contains(&task.name)); + pub fn retain(&mut self, dir_names: &[String]) { + self.tasks.retain(|task| { + let var = &task + .cwd + .file_name() + .unwrap_or_default() + .to_string_lossy() + .into_owned(); + dir_names.contains(var) + }); } } #[cfg(test)] mod tests { + + use std::collections::HashMap; + use super::*; use pretty_assertions::assert_eq; @@ -211,22 +278,34 @@ mod tests { fn tasks_correctly_generated() { // given let first = config::Group { - working_dir: PathBuf::from("some/foo"), - name: "foo".to_string(), + run_for_dirs: vec![PathBuf::from("some/foo1"), PathBuf::from("some/foo2")], commands: vec![ - config::Command::Custom(vec!["cargo".to_string(), "check".to_string()]), - config::Command::Custom(vec!["cargo".to_string(), "check".to_string()]), - config::Command::Custom(vec!["cargo".to_string(), "fmt".to_string()]), - config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), - config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), + config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "check".to_string()], + env: Some(HashMap::from_iter(vec![( + "FOO".to_string(), + "BAR".to_string(), + )])), + }, + config::Command::MdCheck { + ignore_if_in_dir: None, + }, ], }; let second = config::Group { - working_dir: PathBuf::from("some/boo"), - name: "boo".to_string(), + run_for_dirs: vec![PathBuf::from("some/boo")], commands: vec![ - config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), - config::Command::Custom(vec!["cargo".to_string(), "fmt".to_string()]), + config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "test".to_string()], + env: None, + }, + config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "fmt".to_string()], + env: None, + }, ], }; @@ -234,65 +313,50 @@ mod tests { let mut tasks = Tasks::from_config(config::Config(vec![first, second]), "."); // then - let crate1 = PathBuf::from("./some/foo"); - let crate2 = PathBuf::from("./some/boo"); + let group1_path1 = PathBuf::from("./some/foo1"); + let group1_path2 = PathBuf::from("./some/foo2"); + let group2_path1 = PathBuf::from("./some/boo"); tasks.tasks.sort(); let mut expected = [ Task { - name: "foo".to_string(), - cwd: crate1.clone(), - cmd: Command::Custom { - program: "cargo".to_string(), - args: vec!["check".to_string()], - }, - }, - Task { - name: "foo".to_string(), - cwd: crate1.clone(), - cmd: Command::Custom { + cwd: group1_path1.clone(), + cmd: Action::Custom { program: "cargo".to_string(), args: vec!["check".to_string()], + env: vec![("FOO".to_string(), "BAR".to_string())], }, }, Task { - name: "foo".to_string(), - cwd: crate1.clone(), - cmd: Command::Custom { - program: "cargo".to_string(), - args: vec!["fmt".to_string()], - }, + cwd: group1_path1.clone(), + cmd: Action::MdCheck, }, Task { - name: "foo".to_string(), - cwd: crate1.clone(), - cmd: Command::Custom { + cwd: group1_path2.clone(), + cmd: Action::Custom { program: "cargo".to_string(), - args: vec!["test".to_string()], + args: vec!["check".to_string()], + env: vec![("FOO".to_string(), "BAR".to_string())], }, }, Task { - name: "foo".to_string(), - cwd: crate1.clone(), - cmd: Command::Custom { - program: "cargo".to_string(), - args: vec!["test".to_string()], - }, + cwd: group1_path2.clone(), + cmd: Action::MdCheck, }, Task { - name: "boo".to_string(), - cwd: crate2.clone(), - cmd: Command::Custom { + cwd: group2_path1.clone(), + cmd: Action::Custom { program: "cargo".to_string(), args: vec!["fmt".to_string()], + env: vec![], }, }, Task { - name: "boo".to_string(), - cwd: crate2.clone(), - cmd: Command::Custom { + cwd: group2_path1.clone(), + cmd: Action::Custom { program: "cargo".to_string(), args: vec!["test".to_string()], + env: vec![], }, }, ]; @@ -306,21 +370,43 @@ mod tests { // given let config = config::Config(vec![ config::Group { - working_dir: PathBuf::from("some/foo"), - name: "foo".to_string(), + run_for_dirs: vec![PathBuf::from("some/foo"), PathBuf::from("other/zoo")], commands: vec![ - config::Command::Custom(vec!["cargo".to_string(), "check".to_string()]), - config::Command::Custom(vec!["cargo".to_string(), "fmt".to_string()]), - config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), + config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "check".to_string()], + env: None, + }, + config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "fmt".to_string()], + env: None, + }, + config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "test".to_string()], + env: None, + }, ], }, config::Group { - working_dir: PathBuf::from("some/boo"), - name: "boo".to_string(), + run_for_dirs: vec![PathBuf::from("some/boo")], commands: vec![ - config::Command::Custom(vec!["cargo".to_string(), "check".to_string()]), - config::Command::Custom(vec!["cargo".to_string(), "fmt".to_string()]), - config::Command::Custom(vec!["cargo".to_string(), "test".to_string()]), + config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "check".to_string()], + env: None, + }, + config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "fmt".to_string()], + env: None, + }, + config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "test".to_string()], + env: None, + }, ], }, ]); @@ -328,34 +414,34 @@ mod tests { let mut tasks = Tasks::from_config(config, "."); // when - tasks.retain(&["foo".to_string()]); + tasks.retain(&["zoo".to_string()]); // then - let cwd = PathBuf::from("./some/foo"); + let cwd = PathBuf::from("./other/zoo"); let mut expected = [ Task { - name: "foo".to_string(), cwd: cwd.clone(), - cmd: Command::Custom { + cmd: Action::Custom { program: "cargo".to_string(), args: vec!["check".to_string()], + env: vec![], }, }, Task { - name: "foo".to_string(), cwd: cwd.clone(), - cmd: Command::Custom { + cmd: Action::Custom { program: "cargo".to_string(), args: vec!["fmt".to_string()], + env: vec![], }, }, Task { - name: "foo".to_string(), cwd: cwd.clone(), - cmd: Command::Custom { + cmd: Action::Custom { program: "cargo".to_string(), args: vec!["test".to_string()], + env: vec![], }, }, ]; @@ -369,12 +455,12 @@ mod tests { fn workspace_root_respected() { // given let config = config::Config(vec![config::Group { - name: "foo".to_string(), - working_dir: PathBuf::from("some/foo"), - commands: vec![config::Command::Custom(vec![ - "cargo".to_string(), - "check".to_string(), - ])], + run_for_dirs: vec![PathBuf::from("some/foo")], + commands: vec![config::Command::Custom { + ignore_if_cwd_ends_with: None, + cmd: vec!["cargo".to_string(), "check".to_string()], + env: None, + }], }]); // when @@ -382,11 +468,11 @@ mod tests { // then let mut expected = [Task { - name: "foo".to_string(), cwd: PathBuf::from("workspace/some/foo"), - cmd: Command::Custom { + cmd: Action::Custom { program: "cargo".to_string(), args: vec!["check".to_string()], + env: vec![], }, }]; @@ -394,4 +480,23 @@ mod tests { tasks.tasks.sort(); assert_eq!(tasks.tasks, expected); } + + #[test] + fn ignore_if_in_dir_respected() { + // given + let config = config::Config(vec![config::Group { + run_for_dirs: vec![PathBuf::from("boom/some/foo")], + commands: vec![config::Command::Custom { + ignore_if_cwd_ends_with: Some(vec!["some/foo".to_string()]), + cmd: vec!["cargo".to_string(), "check".to_string()], + env: None, + }], + }]); + + // when + let tasks = Tasks::from_config(config, "."); + + // then + assert_eq!(tasks.tasks, []); + } } From 76656baab9ee8075a2bafd4785f13c1b00ec1b65 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 14 May 2024 23:12:05 +0200 Subject: [PATCH 26/70] add typos --- scripts/checks/config/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/checks/config/ci.yml b/scripts/checks/config/ci.yml index 997396526..d5397e2bb 100644 --- a/scripts/checks/config/ci.yml +++ b/scripts/checks/config/ci.yml @@ -12,6 +12,8 @@ commands: - !Custom cmd: [cargo, fmt, --verbose, --check] + - !Custom + cmd: [typos] # - !Custom # cmd: [cargo, clippy, --all-targets, --all-features, --no-deps] # - !Custom From ca8c7e980525db866afaae033b776b83d42e9d5d Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Thu, 16 May 2024 18:53:54 +0200 Subject: [PATCH 27/70] move config to rust based --- Cargo.toml | 1 + scripts/checks/Cargo.toml | 7 +- scripts/checks/config/ci.yml | 53 ----------- scripts/checks/config/max.yml | 0 scripts/checks/src/cli.rs | 64 +++++++++++-- scripts/checks/src/config.rs | 31 ++++-- scripts/checks/src/config/ci.rs | 148 ++++++++++++++++++++++++++++ scripts/checks/src/main.rs | 23 ++++- scripts/checks/src/task.rs | 164 +++++++++++++++++++++----------- scripts/checks/src/util.rs | 28 ++++-- 10 files changed, 383 insertions(+), 136 deletions(-) delete mode 100644 scripts/checks/config/ci.yml delete mode 100644 scripts/checks/config/max.yml create mode 100644 scripts/checks/src/config/ci.rs diff --git a/Cargo.toml b/Cargo.toml index 5217554f2..98a0d8c60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,7 @@ which = { version = "6.0.0", default-features = false } zeroize = { version = "1.7.0", default-features = false } pretty_assertions = { version = "1.4.0", default-features = false } walkdir = { version = "2.5", default-features = false } +tokio-util = { version = "0.7", default-features = false } anyhow = { version = "1.0", default-features = false } getrandom = { version = "0.2", default-features = false } wasm-bindgen-test = { version = "0.3", default-features = false } diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index 14ef25b98..a42376ab0 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -15,11 +15,14 @@ clap = { workspace = true, features = ["default", "derive"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } anyhow = { workspace = true, features = ["std"] } serde = { workspace = true, features = ["derive"] } -serde_yaml = { workspace = true } -itertools = { workspace = true, features = ["use_alloc"] } +serde_json = { workspace = true, features = ["std"] } +itertools = { workspace = true, features = ["use_std"] } +tokio-util = { workspace = true } colored = { workspace = true } duct = { workspace = true } regex = { workspace = true, features = ["std", "unicode-perl"] } +sha2 = { workspace = true, features = ["std"] } +hex = { workspace = true, features = ["std"] } [dev-dependencies] tempfile = { workspace = true } diff --git a/scripts/checks/config/ci.yml b/scripts/checks/config/ci.yml deleted file mode 100644 index d5397e2bb..000000000 --- a/scripts/checks/config/ci.yml +++ /dev/null @@ -1,53 +0,0 @@ -- run_for_dirs: - - packages/fuels - - packages/fuels-accounts - - packages/fuels-code-gen - - packages/fuels-core - - packages/fuels-macros - - packages/fuels-programs - - packages/fuels-test-helpers - - e2e - - wasm-tests - - scripts/checks - commands: - - !Custom - cmd: [cargo, fmt, --verbose, --check] - - !Custom - cmd: [typos] - # - !Custom - # cmd: [cargo, clippy, --all-targets, --all-features, --no-deps] - # - !Custom - # # because those tests need to be run with wasm-pack - # ignore_if_cwd_ends_with: [wasm-tests] - # cmd: [cargo, nextest, run, --all-features] - - !Custom - # because these don't have libs - ignore_if_cwd_ends_with: [e2e, scripts/checks, wasm-tests] - cmd: [cargo, test, --doc] - - !Custom - # because these don't have libs - ignore_if_cwd_ends_with: [e2e, scripts/checks, wasm-tests] - cmd: [cargo, doc, --document-private-items] - env: - RUSTDOCFLAGS: "-D warnings" - - - -- run_for_dirs: [wasm-tests] - commands: - - !Custom - cmd: [wasm-pack, test, --node] - -- run_for_dirs: [.] - commands: - - !MdCheck - dont_search: [scripts/checks, target/] - - !Custom - cmd: [cargo, clippy, --workspace, --all-features] - # For some reason only works in the workspace dir - - !Custom - cmd: [cargo-machete, --skip-target-dir] - - -# - command: check_typos -# args: diff --git a/scripts/checks/config/max.yml b/scripts/checks/config/max.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index e94e552fb..bad0a0563 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -5,7 +5,7 @@ use clap::{arg, Parser, ValueEnum}; #[derive(Parser)] #[command(about = "Runs pre-release checks deemed to heavy for CI.")] pub struct Cli { - ///Comma separated list of crates to check. + ///Comma separated list of tasks to run #[arg( short, long, @@ -13,16 +13,54 @@ pub struct Cli { num_args = 0.. )] - pub crates: Vec, + pub only_tasks_with_ids: Vec, + + /// Prints out all tasks available (depends on what `flavor` is enabled) + #[arg(short, long, action)] + pub list_tasks: bool, + + /// List directories that are used by the tasks in JSON format. + #[arg(long)] + pub list_used_dirs: bool, + + /// Only run tasks in the given directory + #[arg( + long, + value_delimiter = ',', + num_args = 0.. + + )] + pub only_tasks_in_dir: Vec, + + /// Used to enable/disable tests that take too long/are too resource intense. #[arg(short, long, default_value = "ci")] pub flavor: Flavor, + /// Sway project compiled with type path support + #[arg(short, long, action)] + pub sway_with_type_paths: bool, + /// Enable verbose output. #[arg(short, long, default_value = "false")] pub verbose: bool, - #[arg(default_value = ".")] - pub workspace_root: PathBuf, + /// If ran as a binary from elsewhere the workspace_root needs to be pointed to where the + /// project workspace root is + #[arg(default_value_t = default_workspace_root())] + pub workspace_root: String, +} + +fn default_workspace_root() -> String { + // This will bake in the current path of the project as the default workspace_root. Makes it so that the checks can be run from anywhere in the project. + // Would usually be a bad idea, but in this case it's fine since it's utility code. + PathBuf::from(file!()) + .parent() + .unwrap() + .join("../../../") + .canonicalize() + .unwrap() + .to_string_lossy() + .to_string() } #[derive(Debug, Copy, Clone, ValueEnum, PartialEq)] @@ -36,15 +74,27 @@ mod tests { use super::*; #[test] - fn crates_can_be_listed() { + fn tasks_can_be_selected() { + // given + let cli = "foo --tasks one,two"; + + // when + let cli = Cli::parse_from(cli.split_whitespace()); + + // then + assert_eq!(cli.only_tasks_with_ids, vec!["one", "two"]); + } + + #[test] + fn tasks_can_be_listed() { // given - let cli = "foo --crates one,two"; + let cli = "foo --list-tasks"; // when let cli = Cli::parse_from(cli.split_whitespace()); // then - assert_eq!(cli.crates, vec!["one", "two"]); + assert!(cli.list_tasks); } #[test] diff --git a/scripts/checks/src/config.rs b/scripts/checks/src/config.rs index 26649b264..d1a98e0f3 100644 --- a/scripts/checks/src/config.rs +++ b/scripts/checks/src/config.rs @@ -1,22 +1,39 @@ -use std::{collections::HashMap, path::PathBuf}; +pub mod ci; -#[derive(Debug, serde::Deserialize)] -pub struct Config(pub Vec); +use std::{ + collections::HashMap, + path::{Path, PathBuf}, +}; -#[derive(Debug, serde::Deserialize)] -pub struct Group { +#[derive(Debug, Clone, serde::Deserialize)] +pub struct TasksDescription { pub run_for_dirs: Vec, pub commands: Vec, } +#[derive(Debug, Clone, serde::Deserialize)] +pub enum RunIf { + CwdDoesntEndWith(Vec), +} + +impl RunIf { + pub fn should_run(&self, cwd: &Path) -> bool { + match self { + RunIf::CwdDoesntEndWith(suffixes) => { + !suffixes.iter().any(|suffix| cwd.ends_with(suffix)) + } + } + } +} + #[derive(Debug, Clone, serde::Deserialize)] pub enum Command { MdCheck { - ignore_if_in_dir: Option>, + run_if: Option, }, Custom { - ignore_if_cwd_ends_with: Option>, cmd: Vec, env: Option>, + run_if: Option, }, } diff --git a/scripts/checks/src/config/ci.rs b/scripts/checks/src/config/ci.rs new file mode 100644 index 000000000..f8b5638cf --- /dev/null +++ b/scripts/checks/src/config/ci.rs @@ -0,0 +1,148 @@ +use std::path::PathBuf; + +use crate::config::RunIf; +use crate::config::TasksDescription; + +use super::Command; + +pub fn ci_config(sway_type_paths: bool) -> Vec { + vec![ + common(), + e2e_specific(sway_type_paths), + wasm_specific(), + workspace_level(), + ] +} + +fn paths(paths: &[&str]) -> Vec { + let workspace = PathBuf::from(file!()) + .parent() + .unwrap() + .join("../../../../"); + + paths + .iter() + .map(|path| workspace.join(path).canonicalize().unwrap()) + .collect() +} + +fn split(string: &str) -> Vec { + string + .split_whitespace() + .map(|word| word.to_owned()) + .collect() +} + +macro_rules! custom { + ($cmd: literal) => { + crate::config::Command::Custom { + cmd: self::split($cmd), + env: None, + run_if: None, + } + }; + ($cmd: literal, $run_if: expr) => { + crate::config::Command::Custom { + cmd: self::split($cmd), + env: None, + run_if: Some($run_if), + } + }; + ($cmd: literal, $env: literal) => { + crate::config::Command::Custom { + cmd: self::split($cmd), + env: Some($env), + run_if: None, + } + }; + ($cmd: literal , $run_if: expr, $($env_key:literal = $env_value:literal),*) => { + crate::config::Command::Custom { + cmd: self::split($cmd), + env: Some( + std::collections::HashMap::from_iter([ + $(($env_key.to_owned(), $env_value.to_owned()),)* + ])), + run_if: Some($run_if), + } + }; +} + +fn cwd_doesnt_end_with(suffixes: &[&str]) -> RunIf { + RunIf::CwdDoesntEndWith(suffixes.iter().map(|s| s.to_string()).collect()) +} + +fn common() -> TasksDescription { + TasksDescription { + run_for_dirs: paths(&[ + "packages/fuels", + "packages/fuels-accounts", + "packages/fuels-code-gen", + "packages/fuels-core", + "packages/fuels-macros", + "packages/fuels-programs", + "packages/fuels-test-helpers", + "e2e", + "wasm-tests", + "scripts/checks", + ]), + commands: vec![ + custom!("cargo fmt --verbose --check"), + custom!("typos"), + custom!("cargo clippy --all-targets --all-features --no-deps"), + custom!( + "cargo nextest run --all-features", + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + // wasm ignored because wasm tests need to be run with wasm-pack + cwd_doesnt_end_with(&["wasm-tests", "e2e"]) + ), + custom!( + "cargo test --doc", + // because these don't have libs + cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), + "RUSTDOCFLAGS" = "-D warnings" + ), + custom!( + "cargo doc --document-private-items", + // because these don't have libs + cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), + "RUSTDOCFLAGS" = "-D warnings" + ), + ], + } +} + +fn e2e_specific(sway_type_paths: bool) -> TasksDescription { + let commands = if sway_type_paths { + vec![custom!( + "cargo nextest run --features default,fuel-core-lib,test-type-paths" + )] + } else { + vec![ + custom!("cargo nextest run --features default,fuel-core-lib"), + custom!("cargo nextest run --features default"), + ] + }; + TasksDescription { + run_for_dirs: paths(&["e2e"]), + commands, + } +} + +fn wasm_specific() -> TasksDescription { + TasksDescription { + run_for_dirs: paths(&["wasm-tests"]), + commands: vec![custom!("wasm-pack test --node")], + } +} + +fn workspace_level() -> TasksDescription { + TasksDescription { + run_for_dirs: paths(&["."]), + commands: vec![ + Command::MdCheck { run_if: None }, + custom!("cargo machete --skip-target-dir"), + custom!("cargo clippy --workspace --all-features"), + custom!("typos"), + ], + } +} diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index 1de92aea6..aac024b12 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -10,12 +10,29 @@ mod util; #[tokio::main] async fn main() -> anyhow::Result<()> { let cli = cli::Cli::parse(); - let verbose = cli.verbose; - let tasks = util::read_tasks_from_config(cli)?; + + let tasks = util::read_tasks_from_config(&cli); + + if cli.list_tasks { + for task in &tasks.tasks { + println!("{task}"); + } + return Ok(()); + } + + if cli.list_used_dirs { + let dirs = tasks.used_dirs(); + // Json used because the CI needs it as such + println!("{}", serde_json::json!({ "dirs": dirs })); + return Ok(()); + } let is_tty = std::io::stderr().is_terminal(); - tasks.run(is_tty, verbose).await?; + let cancel_token = tokio_util::sync::CancellationToken::new(); + util::watch_for_cancel(cancel_token.clone()); + + tasks.run(is_tty, cli.verbose, cancel_token).await?; Ok(()) } diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index ad6aeb174..31c1f1c5f 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -6,17 +6,22 @@ use std::{ use colored::Colorize; use duct::cmd; use itertools::Itertools; +use sha2::Digest; use tokio::task::JoinSet; +use tokio_util::sync::CancellationToken; -use crate::{config, md_check}; +use crate::{ + config::{self, RunIf, TasksDescription}, + md_check, +}; -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Task { - cwd: PathBuf, - cmd: Action, + pub cwd: PathBuf, + pub cmd: Action, } -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Action { Custom { program: String, @@ -27,7 +32,7 @@ pub enum Action { } pub struct Command { - ignore_if_cwd_ends_with: Vec, + run_if: Option, action: Action, } @@ -36,13 +41,13 @@ impl From for Command { match value { config::Command::Custom { cmd: parts, - ignore_if_cwd_ends_with, env, + run_if, } => { let program = parts.first().unwrap().to_string(); let args = parts.into_iter().skip(1).map(|s| s.to_string()).collect(); Self { - ignore_if_cwd_ends_with: ignore_if_cwd_ends_with.unwrap_or_default(), + run_if, action: Action::Custom { program, args, @@ -50,9 +55,9 @@ impl From for Command { }, } } - config::Command::MdCheck { ignore_if_in_dir } => Self { - ignore_if_cwd_ends_with: ignore_if_in_dir.unwrap_or_default(), + config::Command::MdCheck { run_if } => Self { action: Action::MdCheck, + run_if, }, } } @@ -80,7 +85,7 @@ impl Display for Action { impl Display for Task { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "({:?}) {}", self.cwd, self.cmd) + write!(f, "Task {}, dir: {:?}, {}", self.id(), self.cwd, self.cmd) } } @@ -134,6 +139,12 @@ impl Execution { } impl Task { + pub fn id(&self) -> String { + let mut hasher = sha2::Sha256::default(); + hasher.update(format!("{:?}", self).as_bytes()); + hex::encode(&hasher.finalize()[..8]) + } + pub fn run(self) -> Execution { match &self.cmd { Action::Custom { program, args, env } => { @@ -199,10 +210,34 @@ pub struct Tasks { } impl Tasks { - pub fn from_config(config: config::Config, workspace_root: impl AsRef) -> Self { + pub fn used_dirs(&self) -> Vec { + self.tasks + .iter() + .map(|task| &task.cwd) + .unique() + .cloned() + .collect() + } + pub fn verify_no_duplicates(&self) -> anyhow::Result<()> { + let duplicates = self + .tasks + .iter() + .duplicates_by(|task| task.id()) + .collect_vec(); + + if !duplicates.is_empty() { + anyhow::bail!("Found duplicate tasks: {:#?}", duplicates); + } + + Ok(()) + } + + pub fn from_task_descriptions( + groups: Vec, + workspace_root: impl AsRef, + ) -> Self { let workspace_root = workspace_root.as_ref(); - let tasks = config - .0 + let tasks = groups .into_iter() .flat_map(|entry| { entry.run_for_dirs.into_iter().flat_map(move |dir| { @@ -213,9 +248,11 @@ impl Tasks { .cloned() .map(Command::from) .filter(|cmd| { - cmd.ignore_if_cwd_ends_with - .iter() - .all(|ignored_dir| !cwd.ends_with(ignored_dir)) + if let Some(condition) = &cmd.run_if { + condition.should_run(&cwd) + } else { + true + } }) .map(|cmd| Task { cwd: cwd.clone(), @@ -229,13 +266,27 @@ impl Tasks { Self { tasks } } - pub async fn run(self, tty: bool, verbose: bool) -> anyhow::Result<()> { + pub async fn run( + self, + tty: bool, + verbose: bool, + cancel_token: CancellationToken, + ) -> anyhow::Result<()> { + self.verify_no_duplicates()?; let mut set = JoinSet::new(); for task in self.tasks { set.spawn_blocking(|| task.run()); } let mut errors = false; + tokio::select! { + _ = cancel_token.cancelled() => { + return Ok(()); + } + else => { + + } + } while let Some(result) = set.join_next().await { let execution = result?; if let ExecutionStatus::Success { .. } = execution.status { @@ -253,15 +304,20 @@ impl Tasks { Ok(()) } - pub fn retain(&mut self, dir_names: &[String]) { + pub fn retain_with_ids(&mut self, ids: &[String]) { + self.tasks.retain(|task| ids.contains(&task.id())); + } + + pub fn retain_with_dirs(&mut self, dirs: &[String]) { self.tasks.retain(|task| { - let var = &task - .cwd - .file_name() - .unwrap_or_default() - .to_string_lossy() - .into_owned(); - dir_names.contains(var) + dirs.contains( + &task + .cwd + .canonicalize() + .unwrap() + .to_string_lossy() + .to_string(), + ) }); } } @@ -277,40 +333,38 @@ mod tests { #[test] fn tasks_correctly_generated() { // given - let first = config::Group { + let first = config::TasksDescription { run_for_dirs: vec![PathBuf::from("some/foo1"), PathBuf::from("some/foo2")], commands: vec![ config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "check".to_string()], env: Some(HashMap::from_iter(vec![( "FOO".to_string(), "BAR".to_string(), )])), + run_if: None, }, - config::Command::MdCheck { - ignore_if_in_dir: None, - }, + config::Command::MdCheck { run_if: None }, ], }; - let second = config::Group { + let second = config::TasksDescription { run_for_dirs: vec![PathBuf::from("some/boo")], commands: vec![ config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "test".to_string()], env: None, + run_if: None, }, config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "fmt".to_string()], env: None, + run_if: None, }, ], }; // when - let mut tasks = Tasks::from_config(config::Config(vec![first, second]), "."); + let mut tasks = Tasks::from_task_descriptions(vec![first, second], "."); // then let group1_path1 = PathBuf::from("./some/foo1"); @@ -368,53 +422,53 @@ mod tests { #[test] fn selection_respected() { // given - let config = config::Config(vec![ - config::Group { + let config = vec![ + config::TasksDescription { run_for_dirs: vec![PathBuf::from("some/foo"), PathBuf::from("other/zoo")], commands: vec![ config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "check".to_string()], env: None, + run_if: None, }, config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "fmt".to_string()], env: None, + run_if: None, }, config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "test".to_string()], env: None, + run_if: None, }, ], }, - config::Group { + config::TasksDescription { run_for_dirs: vec![PathBuf::from("some/boo")], commands: vec![ config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "check".to_string()], env: None, + run_if: None, }, config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "fmt".to_string()], env: None, + run_if: None, }, config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "test".to_string()], env: None, + run_if: None, }, ], }, - ]); + ]; - let mut tasks = Tasks::from_config(config, "."); + let mut tasks = Tasks::from_task_descriptions(config, "."); // when - tasks.retain(&["zoo".to_string()]); + tasks.retain_with_ids(&["zoo".to_string()]); // then let cwd = PathBuf::from("./other/zoo"); @@ -454,17 +508,17 @@ mod tests { #[test] fn workspace_root_respected() { // given - let config = config::Config(vec![config::Group { + let config = vec![config::TasksDescription { run_for_dirs: vec![PathBuf::from("some/foo")], commands: vec![config::Command::Custom { - ignore_if_cwd_ends_with: None, cmd: vec!["cargo".to_string(), "check".to_string()], env: None, + run_if: None, }], - }]); + }]; // when - let mut tasks = Tasks::from_config(config, "workspace"); + let mut tasks = Tasks::from_task_descriptions(config, "workspace"); // then let mut expected = [Task { @@ -484,17 +538,17 @@ mod tests { #[test] fn ignore_if_in_dir_respected() { // given - let config = config::Config(vec![config::Group { + let config = vec![config::TasksDescription { run_for_dirs: vec![PathBuf::from("boom/some/foo")], commands: vec![config::Command::Custom { - ignore_if_cwd_ends_with: Some(vec!["some/foo".to_string()]), cmd: vec!["cargo".to_string(), "check".to_string()], env: None, + run_if: Some(RunIf::CwdDoesntEndWith(vec!["some/foo".to_string()])), }], - }]); + }]; // when - let tasks = Tasks::from_config(config, "."); + let tasks = Tasks::from_task_descriptions(config, "."); // then assert_eq!(tasks.tasks, []); diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 2ac984ffc..c5d334469 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -1,17 +1,27 @@ use crate::{cli, config, task::Tasks}; -pub fn read_tasks_from_config(cli: cli::Cli) -> anyhow::Result { - let yml = match cli.flavor { - cli::Flavor::Ci => include_str!("../config/ci.yml"), - cli::Flavor::Max => include_str!("../config/max.yml"), +pub fn read_tasks_from_config(cli: &cli::Cli) -> Tasks { + let config = match cli.flavor { + cli::Flavor::Ci => config::ci::ci_config(cli.sway_with_type_paths), + cli::Flavor::Max => todo!(), }; - let config = serde_yaml::from_str::(yml)?; - let mut tasks = Tasks::from_config(config, cli.workspace_root); + let mut tasks = Tasks::from_task_descriptions(config, cli.workspace_root.clone()); - if !cli.crates.is_empty() { - tasks.retain(&cli.crates); + if !cli.only_tasks_with_ids.is_empty() { + tasks.retain_with_ids(&cli.only_tasks_with_ids); } - Ok(tasks) + if !cli.only_tasks_in_dir.is_empty() { + tasks.retain_with_dirs(&cli.only_tasks_in_dir); + } + + tasks +} + +pub fn watch_for_cancel(cancel_token: tokio_util::sync::CancellationToken) { + tokio::task::spawn(async move { + tokio::signal::ctrl_c().await.unwrap(); + cancel_token.cancel(); + }); } From 6bd0805f466d914329593f2e95b063cf197d18fe Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Thu, 16 May 2024 19:52:00 +0200 Subject: [PATCH 28/70] graceful shutdown --- Cargo.toml | 1 + scripts/checks/Cargo.toml | 4 +- scripts/checks/src/cli.rs | 33 +++++---------- scripts/checks/src/config/ci.rs | 67 ++++++++++++++++--------------- scripts/checks/src/main.rs | 1 + scripts/checks/src/task.rs | 71 ++++++++++++++------------------- scripts/checks/src/util.rs | 14 ++++++- 7 files changed, 91 insertions(+), 100 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 98a0d8c60..a0d20de01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,6 +75,7 @@ zeroize = { version = "1.7.0", default-features = false } pretty_assertions = { version = "1.4.0", default-features = false } walkdir = { version = "2.5", default-features = false } tokio-util = { version = "0.7", default-features = false } +nix = { version = "0.28", default-features = false } anyhow = { version = "1.0", default-features = false } getrandom = { version = "0.2", default-features = false } wasm-bindgen-test = { version = "0.3", default-features = false } diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index a42376ab0..dc8af707a 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -12,12 +12,13 @@ publish = false [dependencies] clap = { workspace = true, features = ["default", "derive"] } -tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } +tokio = { workspace = true, features = ["rt-multi-thread", "macros", "signal"] } anyhow = { workspace = true, features = ["std"] } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["std"] } itertools = { workspace = true, features = ["use_std"] } tokio-util = { workspace = true } +nix = { workspace = true, features = ["process", "signal"] } colored = { workspace = true } duct = { workspace = true } regex = { workspace = true, features = ["std", "unicode-perl"] } @@ -25,6 +26,7 @@ sha2 = { workspace = true, features = ["std"] } hex = { workspace = true, features = ["std"] } [dev-dependencies] +rand = { workspace = true, features = ["std", "std_rng"] } tempfile = { workspace = true } thiserror = { workspace = true } pretty_assertions = { workspace = true, features = ["std"] } diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index bad0a0563..ff744e781 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -46,21 +46,8 @@ pub struct Cli { /// If ran as a binary from elsewhere the workspace_root needs to be pointed to where the /// project workspace root is - #[arg(default_value_t = default_workspace_root())] - pub workspace_root: String, -} - -fn default_workspace_root() -> String { - // This will bake in the current path of the project as the default workspace_root. Makes it so that the checks can be run from anywhere in the project. - // Would usually be a bad idea, but in this case it's fine since it's utility code. - PathBuf::from(file!()) - .parent() - .unwrap() - .join("../../../") - .canonicalize() - .unwrap() - .to_string_lossy() - .to_string() + #[arg(short, long = "root", required = true)] + pub root: PathBuf, } #[derive(Debug, Copy, Clone, ValueEnum, PartialEq)] @@ -76,10 +63,10 @@ mod tests { #[test] fn tasks_can_be_selected() { // given - let cli = "foo --tasks one,two"; + let cli = "foo --only-tasks-with-ids one,two -r ."; // when - let cli = Cli::parse_from(cli.split_whitespace()); + let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then assert_eq!(cli.only_tasks_with_ids, vec!["one", "two"]); @@ -88,10 +75,10 @@ mod tests { #[test] fn tasks_can_be_listed() { // given - let cli = "foo --list-tasks"; + let cli = "foo --list-tasks -r ."; // when - let cli = Cli::parse_from(cli.split_whitespace()); + let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then assert!(cli.list_tasks); @@ -100,10 +87,10 @@ mod tests { #[test] fn flavor_can_be_chosen() { // given - let cli = "foo --flavor max"; + let cli = "foo --flavor max -r ."; // when - let cli = Cli::parse_from(cli.split_whitespace()); + let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then assert_eq!(cli.flavor, Flavor::Max); @@ -112,10 +99,10 @@ mod tests { #[test] fn default_flavor_is_ci() { // given - let cli = "foo"; + let cli = "foo -r ."; // when - let cli = Cli::parse_from(cli.split_whitespace()); + let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then assert_eq!(cli.flavor, Flavor::Ci); diff --git a/scripts/checks/src/config/ci.rs b/scripts/checks/src/config/ci.rs index f8b5638cf..e4d6bafba 100644 --- a/scripts/checks/src/config/ci.rs +++ b/scripts/checks/src/config/ci.rs @@ -1,3 +1,4 @@ +use std::path::Path; use std::path::PathBuf; use crate::config::RunIf; @@ -5,24 +6,23 @@ use crate::config::TasksDescription; use super::Command; -pub fn ci_config(sway_type_paths: bool) -> Vec { +pub fn ci_config(workspace: &Path, sway_type_paths: bool) -> Vec { vec![ - common(), - e2e_specific(sway_type_paths), - wasm_specific(), - workspace_level(), + common(workspace), + e2e_specific(workspace, sway_type_paths), + wasm_specific(workspace), + workspace_level(workspace), ] } -fn paths(paths: &[&str]) -> Vec { - let workspace = PathBuf::from(file!()) - .parent() - .unwrap() - .join("../../../../"); - +fn paths(workspace: &Path, paths: &[&str]) -> Vec { paths .iter() - .map(|path| workspace.join(path).canonicalize().unwrap()) + .map(|path| { + let path = workspace.join(path); + path.canonicalize() + .unwrap_or_else(|_| panic!("Path not found: {:?}", path)) + }) .collect() } @@ -71,20 +71,23 @@ fn cwd_doesnt_end_with(suffixes: &[&str]) -> RunIf { RunIf::CwdDoesntEndWith(suffixes.iter().map(|s| s.to_string()).collect()) } -fn common() -> TasksDescription { +fn common(workspace: &Path) -> TasksDescription { TasksDescription { - run_for_dirs: paths(&[ - "packages/fuels", - "packages/fuels-accounts", - "packages/fuels-code-gen", - "packages/fuels-core", - "packages/fuels-macros", - "packages/fuels-programs", - "packages/fuels-test-helpers", - "e2e", - "wasm-tests", - "scripts/checks", - ]), + run_for_dirs: paths( + workspace, + &[ + "packages/fuels", + "packages/fuels-accounts", + "packages/fuels-code-gen", + "packages/fuels-core", + "packages/fuels-macros", + "packages/fuels-programs", + "packages/fuels-test-helpers", + "e2e", + "wasm-tests", + "scripts/checks", + ], + ), commands: vec![ custom!("cargo fmt --verbose --check"), custom!("typos"), @@ -111,7 +114,7 @@ fn common() -> TasksDescription { } } -fn e2e_specific(sway_type_paths: bool) -> TasksDescription { +fn e2e_specific(workspace: &Path, sway_type_paths: bool) -> TasksDescription { let commands = if sway_type_paths { vec![custom!( "cargo nextest run --features default,fuel-core-lib,test-type-paths" @@ -123,24 +126,24 @@ fn e2e_specific(sway_type_paths: bool) -> TasksDescription { ] }; TasksDescription { - run_for_dirs: paths(&["e2e"]), + run_for_dirs: paths(workspace, &["e2e"]), commands, } } -fn wasm_specific() -> TasksDescription { +fn wasm_specific(workspace: &Path) -> TasksDescription { TasksDescription { - run_for_dirs: paths(&["wasm-tests"]), + run_for_dirs: paths(workspace, &["wasm-tests"]), commands: vec![custom!("wasm-pack test --node")], } } -fn workspace_level() -> TasksDescription { +fn workspace_level(workspace: &Path) -> TasksDescription { TasksDescription { - run_for_dirs: paths(&["."]), + run_for_dirs: paths(workspace, &["."]), commands: vec![ Command::MdCheck { run_if: None }, - custom!("cargo machete --skip-target-dir"), + custom!("cargo-machete --skip-target-dir"), custom!("cargo clippy --workspace --all-features"), custom!("typos"), ], diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index aac024b12..ecf48feaa 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -10,6 +10,7 @@ mod util; #[tokio::main] async fn main() -> anyhow::Result<()> { let cli = cli::Cli::parse(); + util::configure_child_process_cleanup()?; let tasks = util::read_tasks_from_config(&cli); diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index 31c1f1c5f..615289b77 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -6,6 +6,7 @@ use std::{ use colored::Colorize; use duct::cmd; use itertools::Itertools; +use nix::{sys::signal::Signal, unistd::Pid}; use sha2::Digest; use tokio::task::JoinSet; use tokio_util::sync::CancellationToken; @@ -279,22 +280,36 @@ impl Tasks { } let mut errors = false; - tokio::select! { - _ = cancel_token.cancelled() => { - return Ok(()); - } - else => { - } - } - while let Some(result) = set.join_next().await { - let execution = result?; + let mut handle_task_response = |execution: Execution| { if let ExecutionStatus::Success { .. } = execution.status { errors = true; } let report = execution.report(tty, verbose); eprintln!("{report}"); + anyhow::Ok(()) + }; + + let kill_processes = || { + // All spawned processes are in the same process group created in main. + nix::sys::signal::killpg(Pid::from_raw(0), Signal::SIGINT) + }; + + loop { + tokio::select! { + _ = cancel_token.cancelled() => { + kill_processes()?; + return Ok(()); + } + task_response = set.join_next() => { + if let Some(result) = task_response { + handle_task_response(result?)?; + } else { + break; + } + } + } } if errors { @@ -467,42 +482,14 @@ mod tests { let mut tasks = Tasks::from_task_descriptions(config, "."); + use rand::seq::SliceRandom; + let random_task = tasks.tasks.choose(&mut rand::thread_rng()).unwrap().clone(); + // when - tasks.retain_with_ids(&["zoo".to_string()]); + tasks.retain_with_ids(&[random_task.id()]); // then - let cwd = PathBuf::from("./other/zoo"); - - let mut expected = [ - Task { - cwd: cwd.clone(), - cmd: Action::Custom { - program: "cargo".to_string(), - args: vec!["check".to_string()], - env: vec![], - }, - }, - Task { - cwd: cwd.clone(), - cmd: Action::Custom { - program: "cargo".to_string(), - args: vec!["fmt".to_string()], - env: vec![], - }, - }, - Task { - cwd: cwd.clone(), - cmd: Action::Custom { - program: "cargo".to_string(), - args: vec!["test".to_string()], - env: vec![], - }, - }, - ]; - - tasks.tasks.sort(); - expected.sort(); - assert_eq!(tasks.tasks, expected); + assert_eq!(tasks.tasks, [random_task]); } #[test] diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index c5d334469..309c049ae 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -1,12 +1,16 @@ +use std::path::Path; + +use nix::unistd::Pid; + use crate::{cli, config, task::Tasks}; pub fn read_tasks_from_config(cli: &cli::Cli) -> Tasks { let config = match cli.flavor { - cli::Flavor::Ci => config::ci::ci_config(cli.sway_with_type_paths), + cli::Flavor::Ci => config::ci::ci_config(Path::new(&cli.root), cli.sway_with_type_paths), cli::Flavor::Max => todo!(), }; - let mut tasks = Tasks::from_task_descriptions(config, cli.workspace_root.clone()); + let mut tasks = Tasks::from_task_descriptions(config, cli.root.clone()); if !cli.only_tasks_with_ids.is_empty() { tasks.retain_with_ids(&cli.only_tasks_with_ids); @@ -25,3 +29,9 @@ pub fn watch_for_cancel(cancel_token: tokio_util::sync::CancellationToken) { cancel_token.cancel(); }); } + +pub fn configure_child_process_cleanup() -> anyhow::Result<()> { + // This process is moved into its own process group so that it's easier to kill any of its children. + nix::unistd::setpgid(Pid::from_raw(0), Pid::from_raw(0))?; + Ok(()) +} From 12779936cddcafc3cc087ab19eeb9d3fc70528bb Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Thu, 16 May 2024 20:36:07 +0200 Subject: [PATCH 29/70] normal checks passing --- .../program_bindings/abigen/bindings/contract.rs | 3 --- packages/fuels-programs/src/call_utils.rs | 4 ++-- packages/fuels-programs/src/contract.rs | 4 ++-- packages/fuels-programs/src/submit_response.rs | 2 -- scripts/checks/src/config/ci.rs | 14 ++++++++++---- scripts/checks/src/task.rs | 2 +- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/fuels-code-gen/src/program_bindings/abigen/bindings/contract.rs b/packages/fuels-code-gen/src/program_bindings/abigen/bindings/contract.rs index 77b4481ab..8367832d2 100644 --- a/packages/fuels-code-gen/src/program_bindings/abigen/bindings/contract.rs +++ b/packages/fuels-code-gen/src/program_bindings/abigen/bindings/contract.rs @@ -148,9 +148,6 @@ fn expand_functions(functions: &[FullABIFunction]) -> Result { /// Transforms a function defined in [`FullABIFunction`] into a [`TokenStream`] /// that represents that same function signature as a Rust-native function /// declaration. -/// -/// The generated function prepares the necessary data and proceeds to call -/// [::fuels_contract::contract::method_hash] for the actual call. pub(crate) fn expand_fn(abi_fun: &FullABIFunction) -> Result { let mut generator = FunctionGenerator::new(abi_fun)?; diff --git a/packages/fuels-programs/src/call_utils.rs b/packages/fuels-programs/src/call_utils.rs index 5d7e964be..dba483f8d 100644 --- a/packages/fuels-programs/src/call_utils.rs +++ b/packages/fuels-programs/src/call_utils.rs @@ -144,7 +144,7 @@ pub(crate) async fn transaction_builder_from_contract_calls( .with_outputs(outputs)) } -/// Creates a [`ScriptTransaction`] from contract calls. The internal [Transaction] is +/// Creates a [`ScriptTransaction`] from contract calls. The internal [`fuel_tx::Transaction`] is /// initialized with the actual script instructions, script data needed to perform the call and /// transaction inputs/outputs consisting of assets and contracts. pub(crate) async fn build_tx_from_contract_calls( @@ -320,7 +320,7 @@ pub(crate) fn build_script_data_from_contract_calls( } /// Returns the VM instructions for calling a contract method -/// We use the [`Opcode`] to call a contract: [`CALL`](Opcode::CALL) +/// We use the [`fuel_asm::Opcode`] to call a contract: [`CALL`](fuel_asm::Opcode::CALL) /// pointing at the following registers: /// /// 0x10 Script data offset diff --git a/packages/fuels-programs/src/contract.rs b/packages/fuels-programs/src/contract.rs index e49cb62e6..3be7da775 100644 --- a/packages/fuels-programs/src/contract.rs +++ b/packages/fuels-programs/src/contract.rs @@ -135,7 +135,7 @@ impl StorageConfiguration { self.autoload_storage } - /// Slots added via [`add_slot_overrides`] will override any + /// Slots added via [`Self::add_slot_overrides`] will override any /// existing slots with matching keys. pub fn add_slot_overrides( mut self, @@ -145,7 +145,7 @@ impl StorageConfiguration { self } - /// Slots added via [`add_slot_overrides_from_file`] will override any + /// Slots added via [`Self::add_slot_overrides_from_file`] will override any /// existing slots with matching keys. /// /// `path` - path to a JSON file containing the storage slots. diff --git a/packages/fuels-programs/src/submit_response.rs b/packages/fuels-programs/src/submit_response.rs index 13d0b332b..61e971363 100644 --- a/packages/fuels-programs/src/submit_response.rs +++ b/packages/fuels-programs/src/submit_response.rs @@ -30,8 +30,6 @@ use crate::{ /// - `retry_config`: The retry configuration for the transaction. /// - `tx_id`: The optional transaction ID of the submitted transaction. /// - `call_handler`: The call handler that manages the type of call. -/// -/// ``` #[derive(Debug)] pub struct SubmitResponse { tx_id: Bytes32, diff --git a/scripts/checks/src/config/ci.rs b/scripts/checks/src/config/ci.rs index e4d6bafba..c50ac4cf1 100644 --- a/scripts/checks/src/config/ci.rs +++ b/scripts/checks/src/config/ci.rs @@ -91,7 +91,11 @@ fn common(workspace: &Path) -> TasksDescription { commands: vec![ custom!("cargo fmt --verbose --check"), custom!("typos"), - custom!("cargo clippy --all-targets --all-features --no-deps"), + custom!( + "cargo clippy --all-targets --all-features --no-deps", + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + cwd_doesnt_end_with(&["e2e"]) + ), custom!( "cargo nextest run --all-features", // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) @@ -116,13 +120,15 @@ fn common(workspace: &Path) -> TasksDescription { fn e2e_specific(workspace: &Path, sway_type_paths: bool) -> TasksDescription { let commands = if sway_type_paths { - vec![custom!( - "cargo nextest run --features default,fuel-core-lib,test-type-paths" - )] + vec![ + custom!("cargo nextest run --features default,fuel-core-lib,test-type-paths"), + custom!("cargo clippy --all-features --all-targets --no-deps"), + ] } else { vec![ custom!("cargo nextest run --features default,fuel-core-lib"), custom!("cargo nextest run --features default"), + custom!("cargo clippy --features default,fuel-core-lib --all-targets --no-deps"), ] }; TasksDescription { diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index 615289b77..72ebd7f4f 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -282,7 +282,7 @@ impl Tasks { let mut errors = false; let mut handle_task_response = |execution: Execution| { - if let ExecutionStatus::Success { .. } = execution.status { + if let ExecutionStatus::Failed { .. } = execution.status { errors = true; } From bd30cf91da6950afa198dccb3f071196b04af64b Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Thu, 16 May 2024 21:29:04 +0200 Subject: [PATCH 30/70] move parsing of cargo to a build script --- Cargo.toml | 5 +++ scripts/checks/Cargo.toml | 7 +++ scripts/checks/build.rs | 44 +++++++++++++++++++ scripts/checks/src/config.rs | 2 +- .../src/config/{ci.rs => description.rs} | 30 ++++++------- scripts/checks/src/util.rs | 4 +- scripts/versions-replacer/Cargo.toml | 12 ++--- 7 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 scripts/checks/build.rs rename scripts/checks/src/config/{ci.rs => description.rs} (89%) diff --git a/Cargo.toml b/Cargo.toml index a0d20de01..c254e5bf8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,6 +82,11 @@ wasm-bindgen-test = { version = "0.3", default-features = false } serde_yaml = { version = "0.9", default-features = false } colored = { version = "2.1", default-features = false } duct = { version = "0.13", default-features = false } +toml = { version = "0.8", default-features = false } +once_cell = { version = "1.19", default-features = false } +color-eyre = { version = "0.6", default-features = false } +cargo_metadata = { version = "0.18", default-features = false } +argh = { version = "0.1", default-features = false } # Dependencies from the `fuel-core` repository: fuel-core = { version = "0.26.0", default-features = false } diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index dc8af707a..9c6c5961d 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -10,6 +10,8 @@ rust-version.workspace = true version.workspace = true publish = false +build = "build.rs" + [dependencies] clap = { workspace = true, features = ["default", "derive"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros", "signal"] } @@ -30,3 +32,8 @@ rand = { workspace = true, features = ["std", "std_rng"] } tempfile = { workspace = true } thiserror = { workspace = true } pretty_assertions = { workspace = true, features = ["std"] } + +[build-dependencies] +toml = { workspace = true, features = ["parse"] } +serde = { workspace = true, features = ["derive"] } +itertools = { workspace = true, features = ["use_alloc"] } diff --git a/scripts/checks/build.rs b/scripts/checks/build.rs new file mode 100644 index 000000000..82e583265 --- /dev/null +++ b/scripts/checks/build.rs @@ -0,0 +1,44 @@ +use itertools::Itertools; +use std::path::Path; + +fn main() { + let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../Cargo.toml"); + + let path = path + .canonicalize() + .unwrap_or_else(|_| panic!("Path not found: {:?}", path)); + + let members = workspace_members(&path); + + generate_rust_code(members); + + println!("cargo:rerun-if-changed={}", path.display()); +} + +fn workspace_members(cargo: &Path) -> Vec { + #[derive(Debug, Clone, serde::Deserialize)] + struct Workspace { + members: Vec, + } + #[derive(Debug, Clone, serde::Deserialize)] + struct Cargo { + workspace: Workspace, + } + + let data = std::fs::read_to_string(cargo).unwrap(); + let cargo_toml: Cargo = toml::from_str(&data).unwrap(); + cargo_toml.workspace.members +} + +fn generate_rust_code(members: Vec) { + let members = members + .iter() + .map(|member| format!("{:?}", member)) + .join(",\n"); + + let code = format!("static WORKSPACE_MEMBERS: &[&str] = &[{members}];"); + + let out_dir = std::env::var("OUT_DIR").unwrap(); + let dest_path = Path::new(&out_dir).join("workspace_members.rs"); + std::fs::write(dest_path, code).unwrap(); +} diff --git a/scripts/checks/src/config.rs b/scripts/checks/src/config.rs index d1a98e0f3..d1686f2d8 100644 --- a/scripts/checks/src/config.rs +++ b/scripts/checks/src/config.rs @@ -1,4 +1,4 @@ -pub mod ci; +pub mod description; use std::{ collections::HashMap, diff --git a/scripts/checks/src/config/ci.rs b/scripts/checks/src/config/description.rs similarity index 89% rename from scripts/checks/src/config/ci.rs rename to scripts/checks/src/config/description.rs index c50ac4cf1..b0a3e8b21 100644 --- a/scripts/checks/src/config/ci.rs +++ b/scripts/checks/src/config/description.rs @@ -15,6 +15,11 @@ pub fn ci_config(workspace: &Path, sway_type_paths: bool) -> Vec Vec { + let ci = ci_config(workspace, sway_type_paths); + todo!() +} + fn paths(workspace: &Path, paths: &[&str]) -> Vec { paths .iter() @@ -73,21 +78,7 @@ fn cwd_doesnt_end_with(suffixes: &[&str]) -> RunIf { fn common(workspace: &Path) -> TasksDescription { TasksDescription { - run_for_dirs: paths( - workspace, - &[ - "packages/fuels", - "packages/fuels-accounts", - "packages/fuels-code-gen", - "packages/fuels-core", - "packages/fuels-macros", - "packages/fuels-programs", - "packages/fuels-test-helpers", - "e2e", - "wasm-tests", - "scripts/checks", - ], - ), + run_for_dirs: all_workspace_paths(workspace), commands: vec![ custom!("cargo fmt --verbose --check"), custom!("typos"), @@ -106,7 +97,6 @@ fn common(workspace: &Path) -> TasksDescription { "cargo test --doc", // because these don't have libs cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), - "RUSTDOCFLAGS" = "-D warnings" ), custom!( "cargo doc --document-private-items", @@ -118,6 +108,14 @@ fn common(workspace: &Path) -> TasksDescription { } } +include!(concat!(env!("OUT_DIR"), "/workspace_members.rs")); +fn all_workspace_paths(workspace: &Path) -> Vec { + self::WORKSPACE_MEMBERS + .iter() + .map(|member| workspace.join(member).canonicalize().unwrap()) + .collect() +} + fn e2e_specific(workspace: &Path, sway_type_paths: bool) -> TasksDescription { let commands = if sway_type_paths { vec![ diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 309c049ae..714d4e447 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -6,7 +6,9 @@ use crate::{cli, config, task::Tasks}; pub fn read_tasks_from_config(cli: &cli::Cli) -> Tasks { let config = match cli.flavor { - cli::Flavor::Ci => config::ci::ci_config(Path::new(&cli.root), cli.sway_with_type_paths), + cli::Flavor::Ci => { + config::description::ci_config(Path::new(&cli.root), cli.sway_with_type_paths) + } cli::Flavor::Max => todo!(), }; diff --git a/scripts/versions-replacer/Cargo.toml b/scripts/versions-replacer/Cargo.toml index 5e875ae41..8ca5b83f2 100644 --- a/scripts/versions-replacer/Cargo.toml +++ b/scripts/versions-replacer/Cargo.toml @@ -10,10 +10,10 @@ repository = { workspace = true } rust-version = { workspace = true } [dependencies] -argh = "0.1.12" -cargo_metadata = "0.18.1" -color-eyre = "0.6.2" -once_cell = "1.18.0" -regex = { workspace = true } +argh = { workspace = true } +cargo_metadata = { workspace = true } +color-eyre = { workspace = true } +once_cell = { workspace = true } +regex = { workspace = true, features = ["unicode-perl"] } serde = { workspace = true, features = ["derive"] } -walkdir = "2.4.0" +walkdir = { workspace = true } From 7d01bbb61eaf50afcd608ac4688b3924ff3d54c5 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Thu, 16 May 2024 23:16:09 +0200 Subject: [PATCH 31/70] wip --- scripts/checks/src/cli.rs | 6 +- scripts/checks/src/config/description.rs | 301 ++++++++++++++--------- scripts/checks/src/util.rs | 9 +- 3 files changed, 188 insertions(+), 128 deletions(-) diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index ff744e781..587140557 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -53,7 +53,7 @@ pub struct Cli { #[derive(Debug, Copy, Clone, ValueEnum, PartialEq)] pub enum Flavor { Ci, - Max, + Other, } #[cfg(test)] @@ -87,13 +87,13 @@ mod tests { #[test] fn flavor_can_be_chosen() { // given - let cli = "foo --flavor max -r ."; + let cli = "foo --flavor other -r ."; // when let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then - assert_eq!(cli.flavor, Flavor::Max); + assert_eq!(cli.flavor, Flavor::Other); } #[test] diff --git a/scripts/checks/src/config/description.rs b/scripts/checks/src/config/description.rs index b0a3e8b21..9f7ea0a96 100644 --- a/scripts/checks/src/config/description.rs +++ b/scripts/checks/src/config/description.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; @@ -6,150 +7,210 @@ use crate::config::TasksDescription; use super::Command; -pub fn ci_config(workspace: &Path, sway_type_paths: bool) -> Vec { +pub fn ci(workspace: PathBuf, sway_type_paths: bool) -> Vec { + let desc = TaskDescriptionBuilder::new(workspace, sway_type_paths, &["-Dwarnings"]); vec![ - common(workspace), - e2e_specific(workspace, sway_type_paths), - wasm_specific(workspace), - workspace_level(workspace), + desc.common(), + desc.e2e_specific(), + desc.wasm_specific(), + desc.workspace_level(), ] } -pub fn max(workspace: &Path, sway_type_paths: bool) -> Vec { - let ci = ci_config(workspace, sway_type_paths); - todo!() +pub fn other(workspace: PathBuf, sway_type_paths: bool) -> Vec { + let desc = TaskDescriptionBuilder::new(workspace, sway_type_paths, &["-Dwarnings"]); + vec![desc.hack_common(), desc.hack_e2e()] } -fn paths(workspace: &Path, paths: &[&str]) -> Vec { - paths - .iter() - .map(|path| { - let path = workspace.join(path); - path.canonicalize() - .unwrap_or_else(|_| panic!("Path not found: {:?}", path)) - }) - .collect() +struct TaskDescriptionBuilder { + workspace: PathBuf, + sway_type_paths: bool, + rust_flags: Vec, } -fn split(string: &str) -> Vec { - string - .split_whitespace() - .map(|word| word.to_owned()) - .collect() -} +impl TaskDescriptionBuilder { + fn new(workspace: PathBuf, sway_type_paths: bool, rust_flags: &[&str]) -> Self { + Self { + workspace, + sway_type_paths, + rust_flags: rust_flags.iter().map(|s| s.to_string()).collect(), + } + } -macro_rules! custom { - ($cmd: literal) => { - crate::config::Command::Custom { - cmd: self::split($cmd), - env: None, - run_if: None, + fn workspace_path(&self, paths: &[&str]) -> Vec { + paths + .iter() + .map(|path| { + let path = self.workspace.join(path); + path.canonicalize() + .unwrap_or_else(|_| panic!("Path not found: {:?}", path)) + }) + .collect() + } + + fn hack_common(&self) -> TasksDescription { + TasksDescription { + run_for_dirs: all_workspace_members(&self.workspace), + commands: vec![ + self.cargo_if( + "hack --feature-powerset check", + cwd_doesnt_end_with(&["e2e"]), + ), + self.cargo_if( + "hack --feature-powerset check --tests", + cwd_doesnt_end_with(&["e2e"]), + ), + ], } - }; - ($cmd: literal, $run_if: expr) => { - crate::config::Command::Custom { - cmd: self::split($cmd), - env: None, - run_if: Some($run_if), + } + + fn hack_e2e(&self) -> TasksDescription { + let exclude_features = if self.sway_type_paths { + "--exclude-features test-type-paths" + } else { + "" + }; + TasksDescription { + run_for_dirs: self.workspace_path(&["e2e"]), + commands: vec![ + self.cargo(format!("hack --feature-powerset {exclude_features} check ")), + self.cargo("hack --feature-powerset {exclude-features} check --tests"), + ], } - }; - ($cmd: literal, $env: literal) => { - crate::config::Command::Custom { - cmd: self::split($cmd), - env: Some($env), + } + + fn cargo_if(&self, cmd: impl Into, run_if: Option) -> Command { + let flags = self.rust_flags.join(","); + let env = HashMap::from_iter([("RUSTFLAGS".to_owned(), flags)]); + Command::Custom { + cmd: parse_cmd("cargo", &cmd.into()), + env: Some(env), + run_if, + } + } + + fn cargo_env( + &self, + cmd: impl Into, + env: (impl Into, impl Into), + ) -> Command { + Command::Custom { + cmd: parse_cmd("cargo", &cmd.into()), + env: Some(env), run_if: None, } - }; - ($cmd: literal , $run_if: expr, $($env_key:literal = $env_value:literal),*) => { - crate::config::Command::Custom { - cmd: self::split($cmd), - env: Some( - std::collections::HashMap::from_iter([ - $(($env_key.to_owned(), $env_value.to_owned()),)* - ])), - run_if: Some($run_if), + } + + fn cargo(&self, cmd: impl Into) -> Command { + self.cargo_if(cmd, None) + } + + fn custom(&self, cmd: &str, env: Option<(&str, &str)>, run_if: Option) -> Command { + let env = if let Some((key, value)) = env { + Some(std::collections::HashMap::from_iter(vec![( + key.to_owned(), + value.to_owned(), + )])) + } else { + None + }; + + Command::Custom { + cmd: parse_cmd("", cmd), + env, + run_if, } - }; + } + + fn e2e_specific(&self) -> TasksDescription { + let commands = if self.sway_type_paths { + vec![ + self.cargo("nextest run --features default,fuel-core-lib,test-type-paths"), + self.cargo("clippy --all-features --all-targets --no-deps"), + ] + } else { + vec![ + self.cargo("nextest run --features default"), + self.cargo("clippy --features default,fuel-core-lib --all-targets --no-deps"), + ] + }; + TasksDescription { + run_for_dirs: self.workspace_path(&["e2e"]), + commands, + } + } + + fn wasm_specific(&self) -> TasksDescription { + TasksDescription { + run_for_dirs: self.workspace_path(&["wasm-tests"]), + commands: vec![self.custom("wasm-pack test --node", None, None)], + } + } + + fn workspace_level(&self) -> TasksDescription { + TasksDescription { + run_for_dirs: self.workspace_path(&["."]), + commands: vec![ + Command::MdCheck { run_if: None }, + self.custom("cargo-machete --skip-target-dir", None, None), + self.cargo("clippy --workspace --all-features"), + self.custom("typos", None, None), + ], + } + } + + fn common(&self) -> TasksDescription { + let workspace = &self.workspace; + TasksDescription { + run_for_dirs: all_workspace_members(workspace), + commands: vec![ + self.cargo("fmt --verbose --check"), + self.custom("typos", None, None), + self.cargo_if( + "clippy --all-targets --all-features --no-deps", + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + cwd_doesnt_end_with(&["e2e"]), + ), + self.cargo_if( + "nextest run --all-features", + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + // wasm ignored because wasm tests need to be run with wasm-pack + cwd_doesnt_end_with(&["wasm-tests", "e2e"]), + ), + self.cargo_if( + "test --doc", + // because these don't have libs + cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), + ), + self.cargo_if( + "doc --document-private-items", + // because these don't have libs + cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), + ), + ], + } + } } -fn cwd_doesnt_end_with(suffixes: &[&str]) -> RunIf { - RunIf::CwdDoesntEndWith(suffixes.iter().map(|s| s.to_string()).collect()) +fn cwd_doesnt_end_with(suffixes: &[&str]) -> Option { + Some(RunIf::CwdDoesntEndWith( + suffixes.iter().map(|s| s.to_string()).collect(), + )) } -fn common(workspace: &Path) -> TasksDescription { - TasksDescription { - run_for_dirs: all_workspace_paths(workspace), - commands: vec![ - custom!("cargo fmt --verbose --check"), - custom!("typos"), - custom!( - "cargo clippy --all-targets --all-features --no-deps", - // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) - cwd_doesnt_end_with(&["e2e"]) - ), - custom!( - "cargo nextest run --all-features", - // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) - // wasm ignored because wasm tests need to be run with wasm-pack - cwd_doesnt_end_with(&["wasm-tests", "e2e"]) - ), - custom!( - "cargo test --doc", - // because these don't have libs - cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), - ), - custom!( - "cargo doc --document-private-items", - // because these don't have libs - cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), - "RUSTDOCFLAGS" = "-D warnings" - ), - ], +fn parse_cmd(prepend: &str, string: &str) -> Vec { + let parts = string.split_whitespace().map(|s| s.to_string()).collect(); + if prepend.is_empty() { + parts + } else { + [vec![prepend.to_owned()], parts].concat() } } include!(concat!(env!("OUT_DIR"), "/workspace_members.rs")); -fn all_workspace_paths(workspace: &Path) -> Vec { +fn all_workspace_members(workspace: &Path) -> Vec { self::WORKSPACE_MEMBERS .iter() .map(|member| workspace.join(member).canonicalize().unwrap()) .collect() } - -fn e2e_specific(workspace: &Path, sway_type_paths: bool) -> TasksDescription { - let commands = if sway_type_paths { - vec![ - custom!("cargo nextest run --features default,fuel-core-lib,test-type-paths"), - custom!("cargo clippy --all-features --all-targets --no-deps"), - ] - } else { - vec![ - custom!("cargo nextest run --features default,fuel-core-lib"), - custom!("cargo nextest run --features default"), - custom!("cargo clippy --features default,fuel-core-lib --all-targets --no-deps"), - ] - }; - TasksDescription { - run_for_dirs: paths(workspace, &["e2e"]), - commands, - } -} - -fn wasm_specific(workspace: &Path) -> TasksDescription { - TasksDescription { - run_for_dirs: paths(workspace, &["wasm-tests"]), - commands: vec![custom!("wasm-pack test --node")], - } -} - -fn workspace_level(workspace: &Path) -> TasksDescription { - TasksDescription { - run_for_dirs: paths(workspace, &["."]), - commands: vec![ - Command::MdCheck { run_if: None }, - custom!("cargo-machete --skip-target-dir"), - custom!("cargo clippy --workspace --all-features"), - custom!("typos"), - ], - } -} diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 714d4e447..c2890d0e4 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -5,12 +5,11 @@ use nix::unistd::Pid; use crate::{cli, config, task::Tasks}; pub fn read_tasks_from_config(cli: &cli::Cli) -> Tasks { - let config = match cli.flavor { - cli::Flavor::Ci => { - config::description::ci_config(Path::new(&cli.root), cli.sway_with_type_paths) - } - cli::Flavor::Max => todo!(), + let config_fn = match cli.flavor { + cli::Flavor::Ci => config::description::ci, + cli::Flavor::Other => config::description::other, }; + let config = config_fn(cli.root.clone(), cli.sway_with_type_paths); let mut tasks = Tasks::from_task_descriptions(config, cli.root.clone()); From e19a773949de58bb8bf7422a75c68d2532119b8f Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Thu, 16 May 2024 23:40:59 +0200 Subject: [PATCH 32/70] fix cargodoc flag --- scripts/checks/src/config/description.rs | 59 ++++++++++++------------ scripts/checks/src/util.rs | 2 - 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/scripts/checks/src/config/description.rs b/scripts/checks/src/config/description.rs index 9f7ea0a96..c239fefee 100644 --- a/scripts/checks/src/config/description.rs +++ b/scripts/checks/src/config/description.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; @@ -79,46 +80,43 @@ impl TaskDescriptionBuilder { } } + fn cargo(&self, cmd: impl Into) -> Command { + self.cargo_full(cmd, None, None) + } + fn cargo_if(&self, cmd: impl Into, run_if: Option) -> Command { - let flags = self.rust_flags.join(","); - let env = HashMap::from_iter([("RUSTFLAGS".to_owned(), flags)]); - Command::Custom { - cmd: parse_cmd("cargo", &cmd.into()), - env: Some(env), - run_if, - } + self.cargo_full(cmd, None, run_if) } - fn cargo_env( + fn cargo_full( &self, cmd: impl Into, - env: (impl Into, impl Into), + env: Option<(&str, &str)>, + run_if: Option, ) -> Command { + let mut envs = self.rust_flags_env(); + + if let Some(env) = env { + envs.insert(env.0.into(), env.1.into()); + } + Command::Custom { cmd: parse_cmd("cargo", &cmd.into()), - env: Some(env), - run_if: None, + env: Some(envs), + run_if, } } - fn cargo(&self, cmd: impl Into) -> Command { - self.cargo_if(cmd, None) + fn rust_flags_env(&self) -> HashMap { + let value = self.rust_flags.iter().join(","); + HashMap::from_iter(vec![("RUSTFLAGS".to_owned(), value)]) } - fn custom(&self, cmd: &str, env: Option<(&str, &str)>, run_if: Option) -> Command { - let env = if let Some((key, value)) = env { - Some(std::collections::HashMap::from_iter(vec![( - key.to_owned(), - value.to_owned(), - )])) - } else { - None - }; - + fn custom(&self, cmd: &str) -> Command { Command::Custom { cmd: parse_cmd("", cmd), - env, - run_if, + env: None, + run_if: None, } } @@ -143,7 +141,7 @@ impl TaskDescriptionBuilder { fn wasm_specific(&self) -> TasksDescription { TasksDescription { run_for_dirs: self.workspace_path(&["wasm-tests"]), - commands: vec![self.custom("wasm-pack test --node", None, None)], + commands: vec![self.custom("wasm-pack test --node")], } } @@ -152,9 +150,9 @@ impl TaskDescriptionBuilder { run_for_dirs: self.workspace_path(&["."]), commands: vec![ Command::MdCheck { run_if: None }, - self.custom("cargo-machete --skip-target-dir", None, None), + self.custom("cargo-machete --skip-target-dir"), self.cargo("clippy --workspace --all-features"), - self.custom("typos", None, None), + self.custom("typos"), ], } } @@ -165,7 +163,7 @@ impl TaskDescriptionBuilder { run_for_dirs: all_workspace_members(workspace), commands: vec![ self.cargo("fmt --verbose --check"), - self.custom("typos", None, None), + self.custom("typos"), self.cargo_if( "clippy --all-targets --all-features --no-deps", // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) @@ -182,8 +180,9 @@ impl TaskDescriptionBuilder { // because these don't have libs cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), ), - self.cargo_if( + self.cargo_full( "doc --document-private-items", + Some(("RUSTDOCFLAGS", "-Dwarnings")), // because these don't have libs cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), ), diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index c2890d0e4..155615e25 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -1,5 +1,3 @@ -use std::path::Path; - use nix::unistd::Pid; use crate::{cli, config, task::Tasks}; From 5ec656b533040196a800715bf7999614a291a8d5 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Fri, 17 May 2024 00:01:15 +0200 Subject: [PATCH 33/70] cargo hack passed --- packages/fuels-accounts/src/lib.rs | 8 +------- scripts/checks/src/config/description.rs | 8 +++++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/fuels-accounts/src/lib.rs b/packages/fuels-accounts/src/lib.rs index b219eb8e8..1acc234a4 100644 --- a/packages/fuels-accounts/src/lib.rs +++ b/packages/fuels-accounts/src/lib.rs @@ -1,4 +1,3 @@ -#![deny(unused_crate_dependencies)] #[cfg(feature = "std")] mod account; #[cfg(feature = "std")] @@ -11,12 +10,7 @@ pub mod wallet; #[cfg(feature = "std")] pub use account::*; -#[cfg(feature = "coin-cache")] +#[cfg(all(feature = "std", feature = "coin-cache"))] mod coin_cache; pub mod predicate; - -#[cfg(test)] -mod tests { - use fuels_accounts as _; -} diff --git a/scripts/checks/src/config/description.rs b/scripts/checks/src/config/description.rs index c239fefee..9302c95a2 100644 --- a/scripts/checks/src/config/description.rs +++ b/scripts/checks/src/config/description.rs @@ -67,15 +67,17 @@ impl TaskDescriptionBuilder { fn hack_e2e(&self) -> TasksDescription { let exclude_features = if self.sway_type_paths { - "--exclude-features test-type-paths" - } else { "" + } else { + "--exclude-features test-type-paths" }; TasksDescription { run_for_dirs: self.workspace_path(&["e2e"]), commands: vec![ self.cargo(format!("hack --feature-powerset {exclude_features} check ")), - self.cargo("hack --feature-powerset {exclude-features} check --tests"), + self.cargo(format!( + "hack --feature-powerset {exclude_features} check --tests" + )), ], } } From 2a4494391d2467f373dfae6de8c26f8f088e9512 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Fri, 17 May 2024 00:31:11 +0200 Subject: [PATCH 34/70] deny unused crate deps --- scripts/checks/src/config/description.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/checks/src/config/description.rs b/scripts/checks/src/config/description.rs index 9302c95a2..be4544853 100644 --- a/scripts/checks/src/config/description.rs +++ b/scripts/checks/src/config/description.rs @@ -19,7 +19,11 @@ pub fn ci(workspace: PathBuf, sway_type_paths: bool) -> Vec { } pub fn other(workspace: PathBuf, sway_type_paths: bool) -> Vec { - let desc = TaskDescriptionBuilder::new(workspace, sway_type_paths, &["-Dwarnings"]); + let desc = TaskDescriptionBuilder::new( + workspace, + sway_type_paths, + &["-Dwarnings", "-Dunused_crate_dependencies"], + ); vec![desc.hack_common(), desc.hack_e2e()] } From 2b006757bf5f85d4be4824bf97b3166a74c01f23 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Fri, 17 May 2024 16:30:15 +0200 Subject: [PATCH 35/70] split off udeps check --- e2e/Cargo.toml | 2 +- examples/contracts/src/lib.rs | 2 +- examples/rust_bindings/Cargo.toml | 5 +-- packages/fuels-accounts/Cargo.toml | 3 ++ packages/fuels-code-gen/src/lib.rs | 1 - packages/fuels-core/src/lib.rs | 1 - packages/fuels-macros/Cargo.toml | 2 -- packages/fuels-programs/src/lib.rs | 1 - packages/fuels-test-helpers/Cargo.toml | 4 +-- scripts/checks/Cargo.toml | 1 - scripts/checks/src/cli.rs | 7 +++-- scripts/checks/src/config/description.rs | 40 ++++++++++++++++++------ scripts/checks/src/util.rs | 3 +- 13 files changed, 44 insertions(+), 28 deletions(-) diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index 9957e4470..c3f51ede1 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -13,7 +13,7 @@ publish = false [dev-dependencies] # used in test assertions chrono = { workspace = true } -# TODO: [issue](https://github.com/FuelLabs/fuels-rs/issues/1375) needs to be removed, `ScriptTransaction` and `CreateTransaction` in `fuels` use `fuel_tx::Input` but don't reexport or convert it into a `fuels` owned type fuel-tx = { workspace = true } +# TODO: [issue](https://github.com/FuelLabs/fuels-rs/issues/1375) needs to be removed, `ScriptTransaction` and `CreateTransaction` in `fuels` use `fuel_tx::Input` but don't reexport or convert it into a `fuels` owned type fuel-tx = { workspace = true } fuels = { workspace = true, features = ["test-helpers", "std"] } # TODO: [issue](https://github.com/FuelLabs/fuels-rs/issues/1376) because setup-program-test uses it but `fuels` did not reexport `rand` diff --git a/examples/contracts/src/lib.rs b/examples/contracts/src/lib.rs index 881959f14..6f71274ca 100644 --- a/examples/contracts/src/lib.rs +++ b/examples/contracts/src/lib.rs @@ -36,7 +36,7 @@ mod tests { // ANCHOR: deploy_contract // This helper will launch a local node and provide a test wallet linked to it - let wallet = fuels::test_helpers::launch_provider_and_get_wallet().await?; + let wallet = launch_provider_and_get_wallet().await?; // This will load and deploy your contract binary to the chain so that its ID can // be used to initialize the instance diff --git a/examples/rust_bindings/Cargo.toml b/examples/rust_bindings/Cargo.toml index cbf03d217..1a826f539 100644 --- a/examples/rust_bindings/Cargo.toml +++ b/examples/rust_bindings/Cargo.toml @@ -10,10 +10,7 @@ repository = { workspace = true } description = "Fuel Rust SDK examples for Rust-native bindings" [dev-dependencies] -fuels = { workspace = true, features = [ - "std", -] } -fuels-code-gen = { workspace = true } +fuels = { workspace = true, features = ["std"] } fuels-macros = { workspace = true } proc-macro2 = { workspace = true } rand = { workspace = true } diff --git a/packages/fuels-accounts/Cargo.toml b/packages/fuels-accounts/Cargo.toml index aa3a671f1..917731b47 100644 --- a/packages/fuels-accounts/Cargo.toml +++ b/packages/fuels-accounts/Cargo.toml @@ -9,6 +9,9 @@ repository = { workspace = true } rust-version = { workspace = true } description = "Fuel Rust SDK accounts." +[package.metadata.cargo-udeps.ignore] +development = ["fuels-accounts", "tokio"] + [dependencies] async-trait = { workspace = true, optional = true } chrono = { workspace = true, optional = true } diff --git a/packages/fuels-code-gen/src/lib.rs b/packages/fuels-code-gen/src/lib.rs index 5a9266859..3ccf6d728 100644 --- a/packages/fuels-code-gen/src/lib.rs +++ b/packages/fuels-code-gen/src/lib.rs @@ -1,4 +1,3 @@ -#![deny(unused_crate_dependencies)] pub use program_bindings::*; pub mod error; diff --git a/packages/fuels-core/src/lib.rs b/packages/fuels-core/src/lib.rs index 6a6ec7970..4563e8695 100644 --- a/packages/fuels-core/src/lib.rs +++ b/packages/fuels-core/src/lib.rs @@ -1,4 +1,3 @@ -#![deny(unused_crate_dependencies)] pub mod codec; pub mod traits; pub mod types; diff --git a/packages/fuels-macros/Cargo.toml b/packages/fuels-macros/Cargo.toml index 1df44598d..8160ef5c7 100644 --- a/packages/fuels-macros/Cargo.toml +++ b/packages/fuels-macros/Cargo.toml @@ -17,9 +17,7 @@ fuels-code-gen = { workspace = true } itertools = { workspace = true } proc-macro2 = { workspace = true } quote = { workspace = true } -rand = { workspace = true } syn = { workspace = true, features = ["extra-traits"] } [dev-dependencies] trybuild = { workspace = true } - diff --git a/packages/fuels-programs/src/lib.rs b/packages/fuels-programs/src/lib.rs index f08f175a6..ce48e6eca 100644 --- a/packages/fuels-programs/src/lib.rs +++ b/packages/fuels-programs/src/lib.rs @@ -1,4 +1,3 @@ -#![deny(unused_crate_dependencies)] pub mod call_response; #[cfg(feature = "std")] pub mod call_utils; diff --git a/packages/fuels-test-helpers/Cargo.toml b/packages/fuels-test-helpers/Cargo.toml index bf84aa527..d06ee5cd0 100644 --- a/packages/fuels-test-helpers/Cargo.toml +++ b/packages/fuels-test-helpers/Cargo.toml @@ -13,7 +13,7 @@ description = "Fuel Rust SDK test helpers." fuel-core = { workspace = true, features = ["test-helpers"], optional = true } fuel-core-chain-config = { workspace = true, features = ["test-helpers"] } fuel-core-client = { workspace = true } -fuel-core-poa = { workspace = true } +fuel-core-poa = { workspace = true, optional = true } fuel-core-services = { workspace = true } fuel-crypto = { workspace = true } fuel-tx = { workspace = true } @@ -39,4 +39,4 @@ std = [ "fuel-types/random", "fuel-core-chain-config/std", ] -fuel-core-lib = ["dep:fuel-core"] +fuel-core-lib = ["dep:fuel-core", "dep:fuel-core-poa"] diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index 9c6c5961d..465beb90e 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -30,7 +30,6 @@ hex = { workspace = true, features = ["std"] } [dev-dependencies] rand = { workspace = true, features = ["std", "std_rng"] } tempfile = { workspace = true } -thiserror = { workspace = true } pretty_assertions = { workspace = true, features = ["std"] } [build-dependencies] diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index 587140557..02a080a70 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -53,7 +53,8 @@ pub struct Cli { #[derive(Debug, Copy, Clone, ValueEnum, PartialEq)] pub enum Flavor { Ci, - Other, + HackFeatures, + HackDeps, } #[cfg(test)] @@ -87,13 +88,13 @@ mod tests { #[test] fn flavor_can_be_chosen() { // given - let cli = "foo --flavor other -r ."; + let cli = "foo --flavor hack-features -r ."; // when let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then - assert_eq!(cli.flavor, Flavor::Other); + assert_eq!(cli.flavor, Flavor::HackFeatures); } #[test] diff --git a/scripts/checks/src/config/description.rs b/scripts/checks/src/config/description.rs index be4544853..a9a3c8575 100644 --- a/scripts/checks/src/config/description.rs +++ b/scripts/checks/src/config/description.rs @@ -18,13 +18,14 @@ pub fn ci(workspace: PathBuf, sway_type_paths: bool) -> Vec { ] } -pub fn other(workspace: PathBuf, sway_type_paths: bool) -> Vec { - let desc = TaskDescriptionBuilder::new( - workspace, - sway_type_paths, - &["-Dwarnings", "-Dunused_crate_dependencies"], - ); - vec![desc.hack_common(), desc.hack_e2e()] +pub fn hack_features(workspace: PathBuf, sway_type_paths: bool) -> Vec { + let desc = TaskDescriptionBuilder::new(workspace, sway_type_paths, &["-Dwarnings"]); + vec![desc.hack_features_common(), desc.hack_features_e2e()] +} + +pub fn hack_deps(workspace: PathBuf, sway_type_paths: bool) -> Vec { + let desc = TaskDescriptionBuilder::new(workspace, sway_type_paths, &["-Dwarnings"]); + vec![desc.hack_deps_common()] } struct TaskDescriptionBuilder { @@ -53,7 +54,7 @@ impl TaskDescriptionBuilder { .collect() } - fn hack_common(&self) -> TasksDescription { + fn hack_features_common(&self) -> TasksDescription { TasksDescription { run_for_dirs: all_workspace_members(&self.workspace), commands: vec![ @@ -69,7 +70,20 @@ impl TaskDescriptionBuilder { } } - fn hack_e2e(&self) -> TasksDescription { + fn hack_deps_common(&self) -> TasksDescription { + TasksDescription { + run_for_dirs: all_workspace_members(&self.workspace), + commands: vec![ + self.cargo_if("+nightly hack --deps udeps", cwd_doesnt_end_with(&["e2e"])), + self.cargo_if( + "+nightly hack --deps udeps --tests", + cwd_doesnt_end_with(&["e2e"]), + ), + ], + } + } + + fn hack_features_e2e(&self) -> TasksDescription { let exclude_features = if self.sway_type_paths { "" } else { @@ -82,6 +96,12 @@ impl TaskDescriptionBuilder { self.cargo(format!( "hack --feature-powerset {exclude_features} check --tests" )), + self.cargo(format!( + "+nightly hack --feature-powerset {exclude_features} udeps" + )), + self.cargo(format!( + "+nightly hack --feature-powerset {exclude_features} udeps --tests" + )), ], } } @@ -114,7 +134,7 @@ impl TaskDescriptionBuilder { } fn rust_flags_env(&self) -> HashMap { - let value = self.rust_flags.iter().join(","); + let value = self.rust_flags.iter().join(" "); HashMap::from_iter(vec![("RUSTFLAGS".to_owned(), value)]) } diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 155615e25..824ba9005 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -5,7 +5,8 @@ use crate::{cli, config, task::Tasks}; pub fn read_tasks_from_config(cli: &cli::Cli) -> Tasks { let config_fn = match cli.flavor { cli::Flavor::Ci => config::description::ci, - cli::Flavor::Other => config::description::other, + cli::Flavor::HackFeatures => config::description::hack_features, + cli::Flavor::HackDeps => config::description::hack_deps, }; let config = config_fn(cli.root.clone(), cli.sway_with_type_paths); From e6d060f0875d3870a7d43fcb26131f8f8213bc2e Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sat, 18 May 2024 15:29:50 +0200 Subject: [PATCH 36/70] simplify --- .github/workflows/ci.yml | 65 +-- scripts/checks/src/cli.rs | 6 +- scripts/checks/src/config.rs | 39 -- scripts/checks/src/config/description.rs | 241 ----------- scripts/checks/src/description.rs | 318 ++++++++++++++ scripts/checks/src/main.rs | 11 +- scripts/checks/src/task.rs | 512 ++++++++++------------- scripts/checks/src/util.rs | 20 +- 8 files changed, 576 insertions(+), 636 deletions(-) delete mode 100644 scripts/checks/src/config.rs delete mode 100644 scripts/checks/src/config/description.rs create mode 100644 scripts/checks/src/description.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85280bf78..a9da2f9f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,38 +137,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - cargo_command: [check] - args: [--all-features] - package: ${{fromJSON(needs.get-workspace-members.outputs.members)}} - include: - - cargo_command: fmt - args: --all --verbose -- --check - - cargo_command: clippy - args: --all-targets - download_sway_artifacts: sway-examples - - cargo_command: clippy - args: --all-targets --features "default fuel-core-lib test-type-paths" - download_sway_artifacts: sway-examples-w-type-paths - - cargo_command: nextest - args: run --all-targets --features "default fuel-core-lib test-type-paths coin-cache" --workspace --cargo-quiet - download_sway_artifacts: sway-examples-w-type-paths - install_fuel_core: true - - cargo_command: nextest - args: run --all-targets --workspace --cargo-quiet - download_sway_artifacts: sway-examples - install_fuel_core: true - - cargo_command: test - args: --doc --workspace - - cargo_command: machete - args: --skip-target-dir - - command: test_wasm - args: - - command: check_doc_anchors_valid - args: - - command: check_doc_unresolved_links - args: - - command: check_typos - args: + dir: ${{fromJSON(needs.get-workspace-members.outputs.members)}} steps: - name: Checkout repository uses: actions/checkout@v3 @@ -178,13 +147,12 @@ jobs: with: toolchain: ${{ env.RUST_VERSION }} components: clippy,rustfmt - # selecting a toolchain either by action or manual `rustup` calls should happen # before the cache plugin, as it uses the current rustc version as its cache key - uses: Swatinem/rust-cache@v2.0.1 continue-on-error: true with: - key: "${{ matrix.cargo_command }} ${{ matrix.args }} ${{ matrix.package }}" + key: "${{ matrix.dir }}" - name: Install Fuel Core if: ${{ matrix.install_fuel_core }} @@ -214,40 +182,19 @@ jobs: if: ${{ matrix.cargo_command == 'machete' }} uses: taiki-e/install-action@cargo-machete - - name: Cargo (workspace-level) - if: ${{ matrix.cargo_command && !matrix.package }} - run: cargo ${{ matrix.cargo_command }} ${{ matrix.args }} - - - name: Cargo (package-level) - if: ${{ matrix.cargo_command && matrix.package }} - run: cargo ${{ matrix.cargo_command }} -p ${{ matrix.package }} ${{ matrix.args }} - - name: Install NodeJS for WASM testing - if: ${{ matrix.command == 'test_wasm' }} uses: actions/setup-node@v3 with: node-version: 18 - - name: Test WASM - if: ${{ matrix.command == 'test_wasm' }} + - name: Install typos tool + uses: crate-ci/typos@v1.20.3 + + - name: Install wasm toolchain run: | rustup target add wasm32-unknown-unknown curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - cd wasm-tests - wasm-pack test --node - - name: Check for invalid documentation anchors - if: ${{ matrix.command == 'check_doc_anchors_valid' }} - run: cargo run --bin check-docs - - - name: Check for unresolved documentation links - if: ${{ matrix.command == 'check_doc_unresolved_links' }} - run: | - ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" - - - name: Check for typos - if: ${{ matrix.command == 'check_typos' }} - uses: crate-ci/typos@v1.20.3 publish: needs: diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index 02a080a70..02f52495d 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -19,9 +19,9 @@ pub struct Cli { #[arg(short, long, action)] pub list_tasks: bool, - /// List directories that are used by the tasks in JSON format. + /// Print json job description to be used for the CI #[arg(long)] - pub list_used_dirs: bool, + pub print_ci_jobs_desc: bool, /// Only run tasks in the given directory #[arg( @@ -36,7 +36,7 @@ pub struct Cli { #[arg(short, long, default_value = "ci")] pub flavor: Flavor, - /// Sway project compiled with type path support + /// Run only tasks that require sway type paths #[arg(short, long, action)] pub sway_with_type_paths: bool, diff --git a/scripts/checks/src/config.rs b/scripts/checks/src/config.rs deleted file mode 100644 index d1686f2d8..000000000 --- a/scripts/checks/src/config.rs +++ /dev/null @@ -1,39 +0,0 @@ -pub mod description; - -use std::{ - collections::HashMap, - path::{Path, PathBuf}, -}; - -#[derive(Debug, Clone, serde::Deserialize)] -pub struct TasksDescription { - pub run_for_dirs: Vec, - pub commands: Vec, -} - -#[derive(Debug, Clone, serde::Deserialize)] -pub enum RunIf { - CwdDoesntEndWith(Vec), -} - -impl RunIf { - pub fn should_run(&self, cwd: &Path) -> bool { - match self { - RunIf::CwdDoesntEndWith(suffixes) => { - !suffixes.iter().any(|suffix| cwd.ends_with(suffix)) - } - } - } -} - -#[derive(Debug, Clone, serde::Deserialize)] -pub enum Command { - MdCheck { - run_if: Option, - }, - Custom { - cmd: Vec, - env: Option>, - run_if: Option, - }, -} diff --git a/scripts/checks/src/config/description.rs b/scripts/checks/src/config/description.rs deleted file mode 100644 index a9a3c8575..000000000 --- a/scripts/checks/src/config/description.rs +++ /dev/null @@ -1,241 +0,0 @@ -use itertools::Itertools; -use std::collections::HashMap; -use std::path::Path; -use std::path::PathBuf; - -use crate::config::RunIf; -use crate::config::TasksDescription; - -use super::Command; - -pub fn ci(workspace: PathBuf, sway_type_paths: bool) -> Vec { - let desc = TaskDescriptionBuilder::new(workspace, sway_type_paths, &["-Dwarnings"]); - vec![ - desc.common(), - desc.e2e_specific(), - desc.wasm_specific(), - desc.workspace_level(), - ] -} - -pub fn hack_features(workspace: PathBuf, sway_type_paths: bool) -> Vec { - let desc = TaskDescriptionBuilder::new(workspace, sway_type_paths, &["-Dwarnings"]); - vec![desc.hack_features_common(), desc.hack_features_e2e()] -} - -pub fn hack_deps(workspace: PathBuf, sway_type_paths: bool) -> Vec { - let desc = TaskDescriptionBuilder::new(workspace, sway_type_paths, &["-Dwarnings"]); - vec![desc.hack_deps_common()] -} - -struct TaskDescriptionBuilder { - workspace: PathBuf, - sway_type_paths: bool, - rust_flags: Vec, -} - -impl TaskDescriptionBuilder { - fn new(workspace: PathBuf, sway_type_paths: bool, rust_flags: &[&str]) -> Self { - Self { - workspace, - sway_type_paths, - rust_flags: rust_flags.iter().map(|s| s.to_string()).collect(), - } - } - - fn workspace_path(&self, paths: &[&str]) -> Vec { - paths - .iter() - .map(|path| { - let path = self.workspace.join(path); - path.canonicalize() - .unwrap_or_else(|_| panic!("Path not found: {:?}", path)) - }) - .collect() - } - - fn hack_features_common(&self) -> TasksDescription { - TasksDescription { - run_for_dirs: all_workspace_members(&self.workspace), - commands: vec![ - self.cargo_if( - "hack --feature-powerset check", - cwd_doesnt_end_with(&["e2e"]), - ), - self.cargo_if( - "hack --feature-powerset check --tests", - cwd_doesnt_end_with(&["e2e"]), - ), - ], - } - } - - fn hack_deps_common(&self) -> TasksDescription { - TasksDescription { - run_for_dirs: all_workspace_members(&self.workspace), - commands: vec![ - self.cargo_if("+nightly hack --deps udeps", cwd_doesnt_end_with(&["e2e"])), - self.cargo_if( - "+nightly hack --deps udeps --tests", - cwd_doesnt_end_with(&["e2e"]), - ), - ], - } - } - - fn hack_features_e2e(&self) -> TasksDescription { - let exclude_features = if self.sway_type_paths { - "" - } else { - "--exclude-features test-type-paths" - }; - TasksDescription { - run_for_dirs: self.workspace_path(&["e2e"]), - commands: vec![ - self.cargo(format!("hack --feature-powerset {exclude_features} check ")), - self.cargo(format!( - "hack --feature-powerset {exclude_features} check --tests" - )), - self.cargo(format!( - "+nightly hack --feature-powerset {exclude_features} udeps" - )), - self.cargo(format!( - "+nightly hack --feature-powerset {exclude_features} udeps --tests" - )), - ], - } - } - - fn cargo(&self, cmd: impl Into) -> Command { - self.cargo_full(cmd, None, None) - } - - fn cargo_if(&self, cmd: impl Into, run_if: Option) -> Command { - self.cargo_full(cmd, None, run_if) - } - - fn cargo_full( - &self, - cmd: impl Into, - env: Option<(&str, &str)>, - run_if: Option, - ) -> Command { - let mut envs = self.rust_flags_env(); - - if let Some(env) = env { - envs.insert(env.0.into(), env.1.into()); - } - - Command::Custom { - cmd: parse_cmd("cargo", &cmd.into()), - env: Some(envs), - run_if, - } - } - - fn rust_flags_env(&self) -> HashMap { - let value = self.rust_flags.iter().join(" "); - HashMap::from_iter(vec![("RUSTFLAGS".to_owned(), value)]) - } - - fn custom(&self, cmd: &str) -> Command { - Command::Custom { - cmd: parse_cmd("", cmd), - env: None, - run_if: None, - } - } - - fn e2e_specific(&self) -> TasksDescription { - let commands = if self.sway_type_paths { - vec![ - self.cargo("nextest run --features default,fuel-core-lib,test-type-paths"), - self.cargo("clippy --all-features --all-targets --no-deps"), - ] - } else { - vec![ - self.cargo("nextest run --features default"), - self.cargo("clippy --features default,fuel-core-lib --all-targets --no-deps"), - ] - }; - TasksDescription { - run_for_dirs: self.workspace_path(&["e2e"]), - commands, - } - } - - fn wasm_specific(&self) -> TasksDescription { - TasksDescription { - run_for_dirs: self.workspace_path(&["wasm-tests"]), - commands: vec![self.custom("wasm-pack test --node")], - } - } - - fn workspace_level(&self) -> TasksDescription { - TasksDescription { - run_for_dirs: self.workspace_path(&["."]), - commands: vec![ - Command::MdCheck { run_if: None }, - self.custom("cargo-machete --skip-target-dir"), - self.cargo("clippy --workspace --all-features"), - self.custom("typos"), - ], - } - } - - fn common(&self) -> TasksDescription { - let workspace = &self.workspace; - TasksDescription { - run_for_dirs: all_workspace_members(workspace), - commands: vec![ - self.cargo("fmt --verbose --check"), - self.custom("typos"), - self.cargo_if( - "clippy --all-targets --all-features --no-deps", - // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) - cwd_doesnt_end_with(&["e2e"]), - ), - self.cargo_if( - "nextest run --all-features", - // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) - // wasm ignored because wasm tests need to be run with wasm-pack - cwd_doesnt_end_with(&["wasm-tests", "e2e"]), - ), - self.cargo_if( - "test --doc", - // because these don't have libs - cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), - ), - self.cargo_full( - "doc --document-private-items", - Some(("RUSTDOCFLAGS", "-Dwarnings")), - // because these don't have libs - cwd_doesnt_end_with(&["e2e", "scripts/checks", "wasm-tests"]), - ), - ], - } - } -} - -fn cwd_doesnt_end_with(suffixes: &[&str]) -> Option { - Some(RunIf::CwdDoesntEndWith( - suffixes.iter().map(|s| s.to_string()).collect(), - )) -} - -fn parse_cmd(prepend: &str, string: &str) -> Vec { - let parts = string.split_whitespace().map(|s| s.to_string()).collect(); - if prepend.is_empty() { - parts - } else { - [vec![prepend.to_owned()], parts].concat() - } -} - -include!(concat!(env!("OUT_DIR"), "/workspace_members.rs")); -fn all_workspace_members(workspace: &Path) -> Vec { - self::WORKSPACE_MEMBERS - .iter() - .map(|member| workspace.join(member).canonicalize().unwrap()) - .collect() -} diff --git a/scripts/checks/src/description.rs b/scripts/checks/src/description.rs new file mode 100644 index 000000000..668b30bef --- /dev/null +++ b/scripts/checks/src/description.rs @@ -0,0 +1,318 @@ +use itertools::chain; +use itertools::Itertools; +use std::collections::HashSet; +use std::path::PathBuf; + +use crate::task::Command; +use crate::task::Dependency; +use crate::task::Task; + +pub fn ci(workspace: PathBuf, sway_type_paths: bool) -> HashSet { + generate_tasks(workspace, sway_type_paths, |tb| tb.ci()) +} + +pub fn hack_features(workspace: PathBuf, sway_type_paths: bool) -> HashSet { + generate_tasks(workspace, sway_type_paths, |tb| tb.hack_features()) +} + +pub fn hack_deps(workspace: PathBuf, sway_type_paths: bool) -> HashSet { + generate_tasks(workspace, sway_type_paths, |tb| tb.hack_deps()) +} + +fn generate_tasks(workspace: PathBuf, sway_type_paths: bool, task_fn: F) -> HashSet +where + F: FnOnce(TasksBuilder) -> HashSet + Copy, +{ + let wo_type_paths = task_fn(TasksBuilder::new(workspace.clone(), false, &["-Dwarnings"])); + + if sway_type_paths { + let w_type_paths = task_fn(TasksBuilder::new(workspace, true, &["-Dwarnings"])); + w_type_paths.difference(&wo_type_paths).cloned().collect() + } else { + wo_type_paths + } +} + +struct TasksBuilder { + workspace: PathBuf, + sway_type_paths: bool, + rust_flags: Vec, +} + +impl TasksBuilder { + fn new(workspace: PathBuf, sway_type_paths: bool, rust_flags: &[&str]) -> Self { + Self { + workspace, + sway_type_paths, + rust_flags: rust_flags.iter().map(|s| s.to_string()).collect(), + } + } + + pub fn ci(&self) -> HashSet { + chain!( + self.common(), + self.e2e_specific(), + self.wasm_specific(), + self.workspace_level(), + ) + .collect() + } + + pub fn hack_features(&self) -> HashSet { + chain!(self.hack_features_common(), self.hack_features_e2e()).collect() + } + + pub fn hack_deps(&self) -> HashSet { + self.hack_deps_common().collect() + } + + fn workspace_path(&self, path: &str) -> PathBuf { + let path = self.workspace.join(path); + path.canonicalize() + .unwrap_or_else(|_| panic!("Path not found: {:?}", path)) + } + + fn hack_features_common(&self) -> Vec { + self.all_workspace_members() + .into_iter() + .flat_map(|member| { + let commands = if !member.ends_with("e2e") { + let deps = [Dependency::RustStable, Dependency::CargoHack]; + vec![ + self.cargo("hack --feature-powerset check", &deps), + self.cargo("hack --feature-powerset check --tests", &deps), + ] + } else { + vec![] + }; + + commands.into_iter().map(move |cmd| Task { + cwd: member.clone(), + cmd, + }) + }) + .collect() + } + + fn hack_deps_common(&self) -> impl Iterator + '_ { + self.all_workspace_members().into_iter().flat_map(|member| { + let commands = if !member.ends_with("e2e") { + let deps = [Dependency::RustNightly, Dependency::CargoHack]; + vec![ + self.cargo("+nightly hack --deps udeps", &deps), + self.cargo("+nightly hack --deps udeps --tests", &deps), + ] + } else { + vec![] + }; + commands.into_iter().map(move |cmd| Task { + cwd: member.clone(), + cmd, + }) + }) + } + + fn hack_features_e2e(&self) -> Vec { + let exclude_features = if self.sway_type_paths { + "" + } else { + "--exclude-features test-type-paths" + }; + + let deps = [Dependency::RustStable, Dependency::CargoHack]; + [ + self.cargo( + format!("hack --feature-powerset {exclude_features} check"), + &deps, + ), + self.cargo( + format!("hack --feature-powerset {exclude_features} check --tests"), + &deps, + ), + ] + .map(|cmd| Task { + cwd: self.workspace_path("e2e"), + cmd, + }) + .to_vec() + } + + fn cargo(&self, cmd: impl Into, deps: &[Dependency]) -> Command { + self.cargo_full(cmd, None, deps) + } + + fn cargo_full( + &self, + cmd: impl Into, + env: Option<(&str, &str)>, + deps: &[Dependency], + ) -> Command { + let mut envs = self.rust_flags_env(); + + if let Some(env) = env { + envs.push((env.0.into(), env.1.into())); + } + + Command::Custom { + program: "cargo".to_string(), + args: parse_cmd("", &cmd.into()), + env: envs, + deps: deps.to_vec(), + } + } + + fn rust_flags_env(&self) -> Vec<(String, String)> { + let value = self.rust_flags.iter().join(" "); + vec![("RUSTFLAGS".to_owned(), value)] + } + + fn custom(&self, program: &str, args: &str, deps: &[Dependency]) -> Command { + Command::Custom { + program: program.to_owned(), + args: parse_cmd("", args), + env: vec![], + deps: deps.to_vec(), + } + } + + fn e2e_specific(&self) -> impl Iterator + '_ { + let type_paths_feat = if self.sway_type_paths { + ",test-type-paths" + } else { + "" + }; + + let sway_artifacts_dep = Dependency::SwayArtifacts { + type_paths: self.sway_type_paths, + }; + let test_deps = [ + Dependency::RustStable, + Dependency::Nextest, + sway_artifacts_dep, + ]; + let clippy_deps = [ + Dependency::RustStable, + Dependency::Clippy, + sway_artifacts_dep, + ]; + [ + self.cargo( + format!("nextest run --features default,fuel-core-lib{type_paths_feat}"), + &test_deps, + ), + self.cargo( + format!("nextest run --features default,{type_paths_feat}"), + &[test_deps.to_vec(), vec![Dependency::FuelCoreBinary]].concat(), + ), + self.cargo( + format!("clippy --all-targets --no-deps --features default,{type_paths_feat}"), + &clippy_deps, + ), + ] + .map(|cmd| Task { + cwd: self.workspace_path("e2e"), + cmd, + }) + .into_iter() + } + + fn wasm_specific(&self) -> impl Iterator { + std::iter::once(Task { + cwd: self.workspace_path("wasm-tests"), + cmd: self.custom( + "wasm-pack test --node", + "", + &[Dependency::Wasm, Dependency::RustStable], + ), + }) + } + + fn workspace_level(&self) -> impl Iterator { + [ + Command::MdCheck, + self.custom( + "cargo-machete --skip-target-dir", + "", + &[Dependency::CargoMachete], + ), + self.cargo( + "clippy --workspace --all-features", + &[Dependency::RustStable, Dependency::Clippy], + ), + self.custom("typos", "", &[Dependency::TyposCli]), + ] + .map(|cmd| Task { + cwd: self.workspace_path("."), + cmd, + }) + .into_iter() + } + + fn common(&self) -> impl Iterator + '_ { + self.all_workspace_members().into_iter().flat_map(|member| { + let mut commands = vec![ + self.cargo( + "fmt --verbose --check", + &[Dependency::RustStable, Dependency::RustFmt], + ), + self.custom("typos", "", &[Dependency::TyposCli]), + ]; + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + if !member.ends_with("e2e") { + let cmd = self.cargo( + "clippy --all-targets --all-features --no-deps", + &[Dependency::RustStable, Dependency::Clippy], + ); + commands.push(cmd); + } + + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + // wasm ignored because wasm tests need to be run with wasm-pack + if !member.ends_with("wasm-tests") && !member.ends_with("e2e") { + let cmd = self.cargo( + "nextest run --all-features", + &[Dependency::RustStable, Dependency::Nextest], + ); + commands.push(cmd); + } + + // because these don't have libs + if !member.ends_with("e2e") + && !member.ends_with("scripts/checks") + && !member.ends_with("wasm-tests") + { + let cmd = self.cargo("test --doc", &[Dependency::RustStable]); + commands.push(cmd); + + let cmd = self.cargo_full( + "doc --document-private-items", + Some(("RUSTDOCFLAGS", "-Dwarnings")), + &[Dependency::RustStable], + ); + commands.push(cmd); + } + commands.into_iter().map(move |cmd| Task { + cwd: member.clone(), + cmd, + }) + }) + } + + fn all_workspace_members(&self) -> Vec { + self::WORKSPACE_MEMBERS + .iter() + .map(|member| self.workspace_path(member)) + .collect() + } +} + +fn parse_cmd(prepend: &str, string: &str) -> Vec { + let parts = string.split_whitespace().map(|s| s.to_string()).collect(); + if prepend.is_empty() { + parts + } else { + [vec![prepend.to_owned()], parts].concat() + } +} + +include!(concat!(env!("OUT_DIR"), "/workspace_members.rs")); diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index ecf48feaa..77cc0bf0b 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -2,7 +2,7 @@ use std::io::IsTerminal; use clap::Parser; mod cli; -mod config; +mod description; mod md_check; mod task; mod util; @@ -12,7 +12,7 @@ async fn main() -> anyhow::Result<()> { let cli = cli::Cli::parse(); util::configure_child_process_cleanup()?; - let tasks = util::read_tasks_from_config(&cli); + let tasks = util::generate_tasks(&cli); if cli.list_tasks { for task in &tasks.tasks { @@ -21,10 +21,11 @@ async fn main() -> anyhow::Result<()> { return Ok(()); } - if cli.list_used_dirs { - let dirs = tasks.used_dirs(); + if cli.print_ci_jobs_desc { + let desc = tasks.ci_jobs(); // Json used because the CI needs it as such - println!("{}", serde_json::json!({ "dirs": dirs })); + let jsonified = serde_json::to_string_pretty(&desc)?; + println!("{jsonified}"); return Ok(()); } diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index 72ebd7f4f..132d70e7d 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -1,4 +1,5 @@ use std::{ + collections::{BTreeSet, HashMap, HashSet}, fmt::Display, path::{Path, PathBuf}, }; @@ -11,63 +12,130 @@ use sha2::Digest; use tokio::task::JoinSet; use tokio_util::sync::CancellationToken; -use crate::{ - config::{self, RunIf, TasksDescription}, - md_check, -}; +use crate::md_check; + +#[derive(Debug, Clone, serde::Serialize, Copy)] +pub enum SwayProjectDep { + TypePaths, + Normal, +} + +#[derive(Debug, Clone, serde::Serialize)] +pub struct CiDeps { + fuel_core_binary: bool, + #[serde(skip_serializing_if = "Option::is_none")] + rust_toolchain_components: Option, + wasm: bool, + cargo_hack: bool, + nextest: bool, + cargo_machete: bool, + typos_cli: bool, + #[serde(skip_serializing_if = "Option::is_none")] + sway_project_artifacts: Option, +} + +#[derive(Debug, Clone, serde::Serialize)] +pub struct CiJob { + dir: PathBuf, + deps: CiDeps, +} + +impl CiDeps { + pub fn from_deps(deps: &HashSet) -> Self { + let fuel_core_binary = deps.contains(&Dependency::FuelCoreBinary); + let wasm = deps.contains(&Dependency::Wasm); + let cargo_hack = deps.contains(&Dependency::CargoHack); + let nextest = deps.contains(&Dependency::Nextest); + let cargo_machete = deps.contains(&Dependency::CargoMachete); + let typos_cli = deps.contains(&Dependency::TyposCli); + + let sway_project_artifacts = deps.iter().find_map(|dep| match dep { + Dependency::SwayArtifacts { type_paths } if *type_paths => { + Some(SwayProjectDep::TypePaths) + } + Dependency::SwayArtifacts { .. } => Some(SwayProjectDep::Normal), + _ => None, + }); + + let mut components = String::new(); + if deps.contains(&Dependency::Clippy) { + components.push_str("clippy"); + } + if deps.contains(&Dependency::RustFmt) { + if !components.is_empty() { + components.push(','); + } + components.push_str("rustfmt"); + } + + let rust_toolchain_components = if components.is_empty() { + None + } else { + Some(components) + }; + + Self { + fuel_core_binary, + rust_toolchain_components, + wasm, + cargo_hack, + nextest, + cargo_machete, + typos_cli, + sway_project_artifacts, + } + } +} #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Task { pub cwd: PathBuf, - pub cmd: Action, + pub cmd: Command, +} + +#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub enum Dependency { + FuelCoreBinary, + Clippy, + CargoHack, + RustFmt, + RustStable, + RustNightly, + SwayArtifacts { type_paths: bool }, + Nextest, + CargoMachete, + Wasm, + TyposCli, + Grep, + Find, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum Action { +pub enum Command { Custom { program: String, args: Vec, env: Vec<(String, String)>, + deps: Vec, }, MdCheck, } -pub struct Command { - run_if: Option, - action: Action, -} - -impl From for Command { - fn from(value: config::Command) -> Self { - match value { - config::Command::Custom { - cmd: parts, - env, - run_if, - } => { - let program = parts.first().unwrap().to_string(); - let args = parts.into_iter().skip(1).map(|s| s.to_string()).collect(); - Self { - run_if, - action: Action::Custom { - program, - args, - env: env.unwrap_or_default().into_iter().collect(), - }, - } - } - config::Command::MdCheck { run_if } => Self { - action: Action::MdCheck, - run_if, - }, +impl Command { + pub fn deps(&self) -> HashSet { + match self { + Command::Custom { deps, .. } => HashSet::from_iter(deps.iter().copied()), + Command::MdCheck => HashSet::from_iter([Dependency::Grep, Dependency::Find]), } } } -impl Display for Action { +impl Display for Command { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Action::Custom { program, args, env } => { + Command::Custom { + program, args, env, .. + } => { let args = args.iter().join(" "); if env.is_empty() { write!(f, "{program} {args}") @@ -79,7 +147,7 @@ impl Display for Action { write!(f, "{env} {program} {args}") } } - Action::MdCheck { .. } => write!(f, "MdCheck"), + Command::MdCheck { .. } => write!(f, "MdCheck"), } } } @@ -148,10 +216,10 @@ impl Task { pub fn run(self) -> Execution { match &self.cmd { - Action::Custom { program, args, env } => { - self.run_custom(program, args.iter().map(|e| e.as_str()), env) - } - Action::MdCheck => self.run_md_check(), + Command::Custom { + program, args, env, .. + } => self.run_custom(program, args.iter().map(|e| e.as_str()), env), + Command::MdCheck => self.run_md_check(), } } @@ -211,14 +279,21 @@ pub struct Tasks { } impl Tasks { - pub fn used_dirs(&self) -> Vec { + pub fn ci_jobs(&self) -> Vec { self.tasks .iter() - .map(|task| &task.cwd) - .unique() - .cloned() + .group_by(|task| &task.cwd) + .into_iter() + .map(|(cwd, tasks)| { + let deps = tasks.flat_map(|task| task.cmd.deps()).collect(); + CiJob { + dir: cwd.clone(), + deps: CiDeps::from_deps(&deps), + } + }) .collect() } + pub fn verify_no_duplicates(&self) -> anyhow::Result<()> { let duplicates = self .tasks @@ -233,40 +308,6 @@ impl Tasks { Ok(()) } - pub fn from_task_descriptions( - groups: Vec, - workspace_root: impl AsRef, - ) -> Self { - let workspace_root = workspace_root.as_ref(); - let tasks = groups - .into_iter() - .flat_map(|entry| { - entry.run_for_dirs.into_iter().flat_map(move |dir| { - let cwd = workspace_root.join(dir); - entry - .commands - .iter() - .cloned() - .map(Command::from) - .filter(|cmd| { - if let Some(condition) = &cmd.run_if { - condition.should_run(&cwd) - } else { - true - } - }) - .map(|cmd| Task { - cwd: cwd.clone(), - cmd: cmd.action, - }) - .collect_vec() - }) - }) - .collect(); - - Self { tasks } - } - pub async fn run( self, tty: bool, @@ -339,205 +380,116 @@ impl Tasks { #[cfg(test)] mod tests { - - use std::collections::HashMap; - - use super::*; - use pretty_assertions::assert_eq; - - #[test] - fn tasks_correctly_generated() { - // given - let first = config::TasksDescription { - run_for_dirs: vec![PathBuf::from("some/foo1"), PathBuf::from("some/foo2")], - commands: vec![ - config::Command::Custom { - cmd: vec!["cargo".to_string(), "check".to_string()], - env: Some(HashMap::from_iter(vec![( - "FOO".to_string(), - "BAR".to_string(), - )])), - run_if: None, - }, - config::Command::MdCheck { run_if: None }, - ], - }; - let second = config::TasksDescription { - run_for_dirs: vec![PathBuf::from("some/boo")], - commands: vec![ - config::Command::Custom { - cmd: vec!["cargo".to_string(), "test".to_string()], - env: None, - run_if: None, - }, - config::Command::Custom { - cmd: vec!["cargo".to_string(), "fmt".to_string()], - env: None, - run_if: None, - }, - ], - }; - - // when - let mut tasks = Tasks::from_task_descriptions(vec![first, second], "."); - - // then - let group1_path1 = PathBuf::from("./some/foo1"); - let group1_path2 = PathBuf::from("./some/foo2"); - let group2_path1 = PathBuf::from("./some/boo"); - - tasks.tasks.sort(); - let mut expected = [ - Task { - cwd: group1_path1.clone(), - cmd: Action::Custom { - program: "cargo".to_string(), - args: vec!["check".to_string()], - env: vec![("FOO".to_string(), "BAR".to_string())], - }, - }, - Task { - cwd: group1_path1.clone(), - cmd: Action::MdCheck, - }, - Task { - cwd: group1_path2.clone(), - cmd: Action::Custom { - program: "cargo".to_string(), - args: vec!["check".to_string()], - env: vec![("FOO".to_string(), "BAR".to_string())], - }, - }, - Task { - cwd: group1_path2.clone(), - cmd: Action::MdCheck, - }, - Task { - cwd: group2_path1.clone(), - cmd: Action::Custom { - program: "cargo".to_string(), - args: vec!["fmt".to_string()], - env: vec![], - }, - }, - Task { - cwd: group2_path1.clone(), - cmd: Action::Custom { - program: "cargo".to_string(), - args: vec!["test".to_string()], - env: vec![], - }, - }, - ]; - - expected.sort(); - assert_eq!(tasks.tasks, expected); - } - - #[test] - fn selection_respected() { - // given - let config = vec![ - config::TasksDescription { - run_for_dirs: vec![PathBuf::from("some/foo"), PathBuf::from("other/zoo")], - commands: vec![ - config::Command::Custom { - cmd: vec!["cargo".to_string(), "check".to_string()], - env: None, - run_if: None, - }, - config::Command::Custom { - cmd: vec!["cargo".to_string(), "fmt".to_string()], - env: None, - run_if: None, - }, - config::Command::Custom { - cmd: vec!["cargo".to_string(), "test".to_string()], - env: None, - run_if: None, - }, - ], - }, - config::TasksDescription { - run_for_dirs: vec![PathBuf::from("some/boo")], - commands: vec![ - config::Command::Custom { - cmd: vec!["cargo".to_string(), "check".to_string()], - env: None, - run_if: None, - }, - config::Command::Custom { - cmd: vec!["cargo".to_string(), "fmt".to_string()], - env: None, - run_if: None, - }, - config::Command::Custom { - cmd: vec!["cargo".to_string(), "test".to_string()], - env: None, - run_if: None, - }, - ], - }, - ]; - - let mut tasks = Tasks::from_task_descriptions(config, "."); - - use rand::seq::SliceRandom; - let random_task = tasks.tasks.choose(&mut rand::thread_rng()).unwrap().clone(); - - // when - tasks.retain_with_ids(&[random_task.id()]); - - // then - assert_eq!(tasks.tasks, [random_task]); - } - - #[test] - fn workspace_root_respected() { - // given - let config = vec![config::TasksDescription { - run_for_dirs: vec![PathBuf::from("some/foo")], - commands: vec![config::Command::Custom { - cmd: vec!["cargo".to_string(), "check".to_string()], - env: None, - run_if: None, - }], - }]; - - // when - let mut tasks = Tasks::from_task_descriptions(config, "workspace"); - - // then - let mut expected = [Task { - cwd: PathBuf::from("workspace/some/foo"), - cmd: Action::Custom { - program: "cargo".to_string(), - args: vec!["check".to_string()], - env: vec![], - }, - }]; - - expected.sort(); - tasks.tasks.sort(); - assert_eq!(tasks.tasks, expected); - } - - #[test] - fn ignore_if_in_dir_respected() { - // given - let config = vec![config::TasksDescription { - run_for_dirs: vec![PathBuf::from("boom/some/foo")], - commands: vec![config::Command::Custom { - cmd: vec!["cargo".to_string(), "check".to_string()], - env: None, - run_if: Some(RunIf::CwdDoesntEndWith(vec!["some/foo".to_string()])), - }], - }]; - - // when - let tasks = Tasks::from_task_descriptions(config, "."); - - // then - assert_eq!(tasks.tasks, []); - } + // + // use std::collections::HashMap; + // + // use super::*; + // use pretty_assertions::assert_eq; + // + // #[test] + // fn selection_respected() { + // // given + // let config = vec![ + // config::TasksDescription { + // run_for_dirs: vec![PathBuf::from("some/foo"), PathBuf::from("other/zoo")], + // commands: vec![ + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "check".to_string()], + // env: None, + // run_if: None, + // }, + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "fmt".to_string()], + // env: None, + // run_if: None, + // }, + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "test".to_string()], + // env: None, + // run_if: None, + // }, + // ], + // }, + // config::TasksDescription { + // run_for_dirs: vec![PathBuf::from("some/boo")], + // commands: vec![ + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "check".to_string()], + // env: None, + // run_if: None, + // }, + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "fmt".to_string()], + // env: None, + // run_if: None, + // }, + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "test".to_string()], + // env: None, + // run_if: None, + // }, + // ], + // }, + // ]; + // + // let mut tasks = Tasks::from_task_descriptions(config, "."); + // + // use rand::seq::SliceRandom; + // let random_task = tasks.tasks.choose(&mut rand::thread_rng()).unwrap().clone(); + // + // // when + // tasks.retain_with_ids(&[random_task.id()]); + // + // // then + // assert_eq!(tasks.tasks, [random_task]); + // } + // + // #[test] + // fn workspace_root_respected() { + // // given + // let config = vec![config::TasksDescription { + // run_for_dirs: vec![PathBuf::from("some/foo")], + // commands: vec![config::Command::Custom { + // cmd: vec!["cargo".to_string(), "check".to_string()], + // env: None, + // run_if: None, + // }], + // }]; + // + // // when + // let mut tasks = Tasks::from_task_descriptions(config, "workspace"); + // + // // then + // let mut expected = [Task { + // cwd: PathBuf::from("workspace/some/foo"), + // cmd: Command::Custom { + // program: "cargo".to_string(), + // args: vec!["check".to_string()], + // env: vec![], + // }, + // }]; + // + // expected.sort(); + // tasks.tasks.sort(); + // assert_eq!(tasks.tasks, expected); + // } + // + // #[test] + // fn ignore_if_in_dir_respected() { + // // given + // let config = vec![config::TasksDescription { + // run_for_dirs: vec![PathBuf::from("boom/some/foo")], + // commands: vec![config::Command::Custom { + // cmd: vec!["cargo".to_string(), "check".to_string()], + // env: None, + // run_if: Some(RunIf::CwdDoesntEndWith(vec!["some/foo".to_string()])), + // }], + // }]; + // + // // when + // let tasks = Tasks::from_task_descriptions(config, "."); + // + // // then + // assert_eq!(tasks.tasks, []); + // } } diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 824ba9005..51ac1330f 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -1,16 +1,18 @@ use nix::unistd::Pid; -use crate::{cli, config, task::Tasks}; +use crate::{cli, task::Tasks}; -pub fn read_tasks_from_config(cli: &cli::Cli) -> Tasks { - let config_fn = match cli.flavor { - cli::Flavor::Ci => config::description::ci, - cli::Flavor::HackFeatures => config::description::hack_features, - cli::Flavor::HackDeps => config::description::hack_deps, +pub fn generate_tasks(cli: &cli::Cli) -> Tasks { + let tasks_gen = match cli.flavor { + cli::Flavor::Ci => crate::description::ci, + cli::Flavor::HackFeatures => crate::description::hack_features, + cli::Flavor::HackDeps => crate::description::hack_deps, + }; + let mut tasks = Tasks { + tasks: tasks_gen(cli.root.clone(), cli.sway_with_type_paths) + .into_iter() + .collect(), }; - let config = config_fn(cli.root.clone(), cli.sway_with_type_paths); - - let mut tasks = Tasks::from_task_descriptions(config, cli.root.clone()); if !cli.only_tasks_with_ids.is_empty() { tasks.retain_with_ids(&cli.only_tasks_with_ids); From 615dd5b8147c16e71d3752ae5ba8cfb343db0ca8 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 13:25:21 +0200 Subject: [PATCH 37/70] fix ci jobs gen --- .github/workflows/ci.yml | 49 ++-- scripts/checks/src/cli.rs | 15 +- scripts/checks/src/description.rs | 407 ++++++++++++++++++------------ scripts/checks/src/main.rs | 17 +- scripts/checks/src/task.rs | 237 ++++++++++------- scripts/checks/src/util.rs | 23 +- 6 files changed, 448 insertions(+), 300 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9da2f9f5..f96306b94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,20 +82,37 @@ jobs: path: | e2e/sway/**/out/* - get-workspace-members: - runs-on: ubuntu-latest - outputs: - members: ${{ steps.set-members.outputs.members }} - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - id: set-members - run: | - # install dasel - curl -sSLf "$DASEL_VERSION" -L -o dasel && chmod +x dasel - mv ./dasel /usr/local/bin/dasel - members=$(cat Cargo.toml | dasel -r toml -w json 'workspace.members' | jq -r ".[]" | xargs -I '{}' dasel -f {}/Cargo.toml 'package.name' | jq -R '[.]' | jq -s -c 'add') - echo "members=$members" >> $GITHUB_OUTPUT + build-checks-binary: + runs-on: ubuntu-latest + outputs: + config: ${{ steps.generate-config.outputs.config }} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + + - uses: Swatinem/rust-cache@v2 + with: + prefix-key: "v1-rust" + + - name: Build checks binary + run: cargo build --release --package checks --bin checks + + - name: Upload checks binary + uses: actions/upload-artifact@v4 + with: + name: checks-binary + path: target/release/checks + + - name: Generate config + id: generate-config + run: | + ./target/release/checks generate-config > config.json + echo "::set-output name=config::$(cat config.json)" verify-rust-version: runs-on: ubuntu-latest @@ -132,12 +149,12 @@ jobs: needs: - setup-test-projects - verify-rust-version - - get-workspace-members + - generate-job-config - publish-crates-check runs-on: ubuntu-latest strategy: matrix: - dir: ${{fromJSON(needs.get-workspace-members.outputs.members)}} + config: ${{fromJSON(needs.generate-job-config.outputs.config)}} steps: - name: Checkout repository uses: actions/checkout@v3 diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index 02f52495d..c55ada4c6 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -13,7 +13,7 @@ pub struct Cli { num_args = 0.. )] - pub only_tasks_with_ids: Vec, + pub only_tasks_with_ids: Option>, /// Prints out all tasks available (depends on what `flavor` is enabled) #[arg(short, long, action)] @@ -23,22 +23,23 @@ pub struct Cli { #[arg(long)] pub print_ci_jobs_desc: bool, - /// Only run tasks in the given directory + /// Only run tasks in the given directories #[arg( long, value_delimiter = ',', num_args = 0.. )] - pub only_tasks_in_dir: Vec, + pub only_tasks_in_dir: Option>, /// Used to enable/disable tests that take too long/are too resource intense. - #[arg(short, long, default_value = "ci")] + #[arg(short, long, default_value = "normal")] pub flavor: Flavor, - /// Run only tasks that require sway type paths + /// Enables some tests that need the sway artifacts to be built with the type paths enabled. + /// Has no effect for CI job generation since, in Ci, we can download the correct artifacts as needed. #[arg(short, long, action)] - pub sway_with_type_paths: bool, + pub sway_compiled_with_type_paths: bool, /// Enable verbose output. #[arg(short, long, default_value = "false")] @@ -52,7 +53,7 @@ pub struct Cli { #[derive(Debug, Copy, Clone, ValueEnum, PartialEq)] pub enum Flavor { - Ci, + Normal, HackFeatures, HackDeps, } diff --git a/scripts/checks/src/description.rs b/scripts/checks/src/description.rs index 668b30bef..7b187a6d6 100644 --- a/scripts/checks/src/description.rs +++ b/scripts/checks/src/description.rs @@ -1,54 +1,53 @@ use itertools::chain; use itertools::Itertools; -use std::collections::HashSet; +use std::collections::BTreeSet; +use std::path::Path; use std::path::PathBuf; +use crate::task::CargoDeps; +use crate::task::CiDeps; use crate::task::Command; -use crate::task::Dependency; +use crate::task::RustDeps; +use crate::task::SwayArtifacts; use crate::task::Task; +use crate::task::Tasks; -pub fn ci(workspace: PathBuf, sway_type_paths: bool) -> HashSet { - generate_tasks(workspace, sway_type_paths, |tb| tb.ci()) +pub fn normal(workspace: PathBuf) -> Tasks { + let builder = TasksBuilder::new(workspace.clone(), &["-Dwarnings"]); + Tasks { + tasks: builder.local(), + } } -pub fn hack_features(workspace: PathBuf, sway_type_paths: bool) -> HashSet { - generate_tasks(workspace, sway_type_paths, |tb| tb.hack_features()) -} +pub fn hack_features(workspace: PathBuf) -> Tasks { + let builder = TasksBuilder::new(workspace.clone(), &["-Dwarnings"]); -pub fn hack_deps(workspace: PathBuf, sway_type_paths: bool) -> HashSet { - generate_tasks(workspace, sway_type_paths, |tb| tb.hack_deps()) + Tasks { + tasks: builder.hack_features(), + } } -fn generate_tasks(workspace: PathBuf, sway_type_paths: bool, task_fn: F) -> HashSet -where - F: FnOnce(TasksBuilder) -> HashSet + Copy, -{ - let wo_type_paths = task_fn(TasksBuilder::new(workspace.clone(), false, &["-Dwarnings"])); - - if sway_type_paths { - let w_type_paths = task_fn(TasksBuilder::new(workspace, true, &["-Dwarnings"])); - w_type_paths.difference(&wo_type_paths).cloned().collect() - } else { - wo_type_paths +pub fn hack_deps(workspace: PathBuf) -> Tasks { + let builder = TasksBuilder::new(workspace.clone(), &["-Dwarnings"]); + Tasks { + tasks: builder.hack_deps(), } } struct TasksBuilder { workspace: PathBuf, - sway_type_paths: bool, rust_flags: Vec, } impl TasksBuilder { - fn new(workspace: PathBuf, sway_type_paths: bool, rust_flags: &[&str]) -> Self { + fn new(workspace: PathBuf, rust_flags: &[&str]) -> Self { Self { workspace, - sway_type_paths, rust_flags: rust_flags.iter().map(|s| s.to_string()).collect(), } } - pub fn ci(&self) -> HashSet { + pub fn local(&self) -> BTreeSet { chain!( self.common(), self.e2e_specific(), @@ -58,11 +57,11 @@ impl TasksBuilder { .collect() } - pub fn hack_features(&self) -> HashSet { + pub fn hack_features(&self) -> BTreeSet { chain!(self.hack_features_common(), self.hack_features_e2e()).collect() } - pub fn hack_deps(&self) -> HashSet { + pub fn hack_deps(&self) -> BTreeSet { self.hack_deps_common().collect() } @@ -73,20 +72,16 @@ impl TasksBuilder { } fn hack_features_common(&self) -> Vec { - self.all_workspace_members() + let ignore = self.workspace_path("e2e"); + self.all_workspace_members(Some(&ignore)) .into_iter() .flat_map(|member| { - let commands = if !member.ends_with("e2e") { - let deps = [Dependency::RustStable, Dependency::CargoHack]; - vec![ - self.cargo("hack --feature-powerset check", &deps), - self.cargo("hack --feature-powerset check --tests", &deps), - ] - } else { - vec![] - }; - - commands.into_iter().map(move |cmd| Task { + [ + self.cargo_hack("--feature-powerset check", CiDeps::default()), + self.cargo_hack("--feature-powerset check --tests", CiDeps::default()), + ] + .into_iter() + .map(move |cmd| Task { cwd: member.clone(), cmd, }) @@ -95,39 +90,48 @@ impl TasksBuilder { } fn hack_deps_common(&self) -> impl Iterator + '_ { - self.all_workspace_members().into_iter().flat_map(|member| { - let commands = if !member.ends_with("e2e") { - let deps = [Dependency::RustNightly, Dependency::CargoHack]; - vec![ - self.cargo("+nightly hack --deps udeps", &deps), - self.cargo("+nightly hack --deps udeps --tests", &deps), + let ignore = self.workspace_path("e2e"); + self.all_workspace_members(Some(&ignore)) + .into_iter() + .flat_map(|member| { + let deps = CiDeps { + cargo: CargoDeps { + udeps: true, + ..Default::default() + }, + rust: Some(RustDeps { + nightly: true, + ..Default::default() + }), + ..Default::default() + }; + [ + self.cargo_hack("udeps", deps.clone()), + self.cargo_hack("udeps --tests", deps), ] - } else { - vec![] - }; - commands.into_iter().map(move |cmd| Task { - cwd: member.clone(), - cmd, + .into_iter() + .map(move |cmd| Task { + cwd: member.clone(), + cmd, + }) }) - }) } fn hack_features_e2e(&self) -> Vec { - let exclude_features = if self.sway_type_paths { - "" - } else { - "--exclude-features test-type-paths" - }; - - let deps = [Dependency::RustStable, Dependency::CargoHack]; [ - self.cargo( - format!("hack --feature-powerset {exclude_features} check"), - &deps, + self.cargo_hack( + "--feature-powerset check --tests", + CiDeps { + sway_artifacts: Some(SwayArtifacts::TypePaths), + ..Default::default() + }, ), - self.cargo( - format!("hack --feature-powerset {exclude_features} check --tests"), - &deps, + self.cargo_hack( + "--feature-powerset --exclude-features test-type-paths check --tests", + CiDeps { + sway_artifacts: Some(SwayArtifacts::Normal), + ..Default::default() + }, ), ] .map(|cmd| Task { @@ -137,76 +141,124 @@ impl TasksBuilder { .to_vec() } - fn cargo(&self, cmd: impl Into, deps: &[Dependency]) -> Command { - self.cargo_full(cmd, None, deps) + fn cargo_fmt(&self, cmd: impl Into, mut deps: CiDeps) -> Command { + deps += CiDeps { + rust: Some(RustDeps { + components: BTreeSet::from_iter(["rustfmt".to_string()]), + ..Default::default() + }), + ..Default::default() + }; + + let cmd = format!("fmt {}", cmd.into()); + + self.cargo(cmd, None, deps) } - fn cargo_full( - &self, - cmd: impl Into, - env: Option<(&str, &str)>, - deps: &[Dependency], - ) -> Command { - let mut envs = self.rust_flags_env(); + fn cargo_clippy(&self, cmd: impl Into, mut deps: CiDeps) -> Command { + deps += CiDeps { + rust: Some(RustDeps { + components: BTreeSet::from_iter(["clippy".to_string()]), + ..Default::default() + }), + ..Default::default() + }; - if let Some(env) = env { - envs.push((env.0.into(), env.1.into())); - } + let cmd = format!("clippy {}", cmd.into()); + self.cargo(cmd, None, deps) + } + + fn cargo_hack(&self, cmd: impl Into, mut deps: CiDeps) -> Command { + deps += CiDeps { + cargo: CargoDeps { + hack: true, + ..Default::default() + }, + ..Default::default() + }; + + let cmd = format!("hack {}", cmd.into()); + self.cargo(cmd, None, deps) + } + + fn cargo_nextest(&self, cmd: impl Into, mut deps: CiDeps) -> Command { + deps += CiDeps { + cargo: CargoDeps { + nextest: true, + ..Default::default() + }, + ..Default::default() + }; + + let cmd = format!("nextest {}", cmd.into()); + + self.cargo(cmd, None, deps) + } + + fn cargo(&self, cmd: impl Into, env: Option<(&str, &str)>, deps: CiDeps) -> Command { + let envs = { + let flags = self.rust_flags.iter().join(" "); + let mut envs = vec![("RUSTFLAGS".to_owned(), flags)]; + + if let Some(env) = env { + envs.push((env.0.into(), env.1.into())); + } + envs + }; + + let nightly = if deps.rust.as_ref().is_some_and(|r| r.nightly) { + "+nightly" + } else { + "" + }; Command::Custom { program: "cargo".to_string(), - args: parse_cmd("", &cmd.into()), + args: parse_cmd(nightly, &cmd.into()), env: envs, - deps: deps.to_vec(), + deps: deps.clone(), } } - fn rust_flags_env(&self) -> Vec<(String, String)> { - let value = self.rust_flags.iter().join(" "); - vec![("RUSTFLAGS".to_owned(), value)] - } - - fn custom(&self, program: &str, args: &str, deps: &[Dependency]) -> Command { + fn custom(&self, program: &str, args: &str, deps: &CiDeps) -> Command { Command::Custom { program: program.to_owned(), args: parse_cmd("", args), env: vec![], - deps: deps.to_vec(), + deps: deps.clone(), } } fn e2e_specific(&self) -> impl Iterator + '_ { - let type_paths_feat = if self.sway_type_paths { - ",test-type-paths" - } else { - "" - }; - - let sway_artifacts_dep = Dependency::SwayArtifacts { - type_paths: self.sway_type_paths, - }; - let test_deps = [ - Dependency::RustStable, - Dependency::Nextest, - sway_artifacts_dep, - ]; - let clippy_deps = [ - Dependency::RustStable, - Dependency::Clippy, - sway_artifacts_dep, - ]; [ - self.cargo( - format!("nextest run --features default,fuel-core-lib{type_paths_feat}"), - &test_deps, + self.cargo_nextest( + "run --features default,fuel-core-lib,test-type-paths", + CiDeps { + sway_artifacts: Some(SwayArtifacts::TypePaths), + ..Default::default() + }, ), - self.cargo( - format!("nextest run --features default,{type_paths_feat}"), - &[test_deps.to_vec(), vec![Dependency::FuelCoreBinary]].concat(), + self.cargo_nextest( + "run --features default,fuel-core-lib", + CiDeps { + sway_artifacts: Some(SwayArtifacts::Normal), + ..Default::default() + }, ), - self.cargo( - format!("clippy --all-targets --no-deps --features default,{type_paths_feat}"), - &clippy_deps, + self.cargo_nextest( + "run --features default,test-type-paths", + CiDeps { + fuel_core_binary: true, + sway_artifacts: Some(SwayArtifacts::Normal), + ..Default::default() + }, + ), + self.cargo_clippy( + "--all-targets --no-deps --features default,test-type-paths", + CiDeps { + sway_artifacts: Some(SwayArtifacts::TypePaths), + ..Default::default() + }, ), ] .map(|cmd| Task { @@ -222,7 +274,10 @@ impl TasksBuilder { cmd: self.custom( "wasm-pack test --node", "", - &[Dependency::Wasm, Dependency::RustStable], + &CiDeps { + wasm: true, + ..Default::default() + }, ), }) } @@ -233,13 +288,29 @@ impl TasksBuilder { self.custom( "cargo-machete --skip-target-dir", "", - &[Dependency::CargoMachete], + &CiDeps { + cargo: CargoDeps { + machete: true, + ..Default::default() + }, + ..Default::default() + }, + ), + self.cargo_clippy( + "--workspace --all-features", + CiDeps { + sway_artifacts: Some(SwayArtifacts::Normal), + ..Default::default() + }, ), - self.cargo( - "clippy --workspace --all-features", - &[Dependency::RustStable, Dependency::Clippy], + self.custom( + "typos", + "", + &CiDeps { + typos_cli: true, + ..Default::default() + }, ), - self.custom("typos", "", &[Dependency::TyposCli]), ] .map(|cmd| Task { cwd: self.workspace_path("."), @@ -249,59 +320,63 @@ impl TasksBuilder { } fn common(&self) -> impl Iterator + '_ { - self.all_workspace_members().into_iter().flat_map(|member| { - let mut commands = vec![ - self.cargo( - "fmt --verbose --check", - &[Dependency::RustStable, Dependency::RustFmt], - ), - self.custom("typos", "", &[Dependency::TyposCli]), - ]; - // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) - if !member.ends_with("e2e") { - let cmd = self.cargo( - "clippy --all-targets --all-features --no-deps", - &[Dependency::RustStable, Dependency::Clippy], - ); - commands.push(cmd); - } - - // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) - // wasm ignored because wasm tests need to be run with wasm-pack - if !member.ends_with("wasm-tests") && !member.ends_with("e2e") { - let cmd = self.cargo( - "nextest run --all-features", - &[Dependency::RustStable, Dependency::Nextest], - ); - commands.push(cmd); - } - - // because these don't have libs - if !member.ends_with("e2e") - && !member.ends_with("scripts/checks") - && !member.ends_with("wasm-tests") - { - let cmd = self.cargo("test --doc", &[Dependency::RustStable]); - commands.push(cmd); - - let cmd = self.cargo_full( - "doc --document-private-items", - Some(("RUSTDOCFLAGS", "-Dwarnings")), - &[Dependency::RustStable], - ); - commands.push(cmd); - } - commands.into_iter().map(move |cmd| Task { - cwd: member.clone(), - cmd, + self.all_workspace_members(None) + .into_iter() + .flat_map(|member| { + let mut commands = vec![ + self.cargo_fmt("--verbose --check", Default::default()), + self.custom( + "typos", + "", + &CiDeps { + typos_cli: true, + ..Default::default() + }, + ), + ]; + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + if member != self.workspace_path("e2e") { + let cmd = self + .cargo_clippy("--all-targets --all-features --no-deps", Default::default()); + commands.push(cmd); + } + + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + // wasm ignored because wasm tests need to be run with wasm-pack + if member != self.workspace_path("wasm-tests") + && member != self.workspace_path("e2e") + { + let cmd = self.cargo_nextest("run --all-features", Default::default()); + commands.push(cmd); + } + + // because these don't have libs + if member != self.workspace_path("e2e") + && member != self.workspace_path("wasm-tests") + && member != self.workspace_path("scripts/checks") + { + let cmd = self.cargo("test --doc", None, CiDeps::default()); + commands.push(cmd); + + let cmd = self.cargo( + "doc --document-private-items", + Some(("RUSTDOCFLAGS", "-Dwarnings")), + CiDeps::default(), + ); + commands.push(cmd); + } + commands.into_iter().map(move |cmd| Task { + cwd: member.clone(), + cmd, + }) }) - }) } - fn all_workspace_members(&self) -> Vec { + fn all_workspace_members(&self, ignore: Option<&Path>) -> Vec { self::WORKSPACE_MEMBERS .iter() .map(|member| self.workspace_path(member)) + .filter(|member| ignore.map_or(true, |ignore| !member.starts_with(ignore))) .collect() } } diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index 77cc0bf0b..333e07c91 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -12,6 +12,15 @@ async fn main() -> anyhow::Result<()> { let cli = cli::Cli::parse(); util::configure_child_process_cleanup()?; + if cli.print_ci_jobs_desc { + let tasks = description::normal(cli.root.clone()); + let jobs = tasks.ci_jobs(); + // Json used because the CI needs it as such + let jsonified = serde_json::to_string_pretty(&jobs)?; + println!("{jsonified}"); + return Ok(()); + } + let tasks = util::generate_tasks(&cli); if cli.list_tasks { @@ -21,14 +30,6 @@ async fn main() -> anyhow::Result<()> { return Ok(()); } - if cli.print_ci_jobs_desc { - let desc = tasks.ci_jobs(); - // Json used because the CI needs it as such - let jsonified = serde_json::to_string_pretty(&desc)?; - println!("{jsonified}"); - return Ok(()); - } - let is_tty = std::io::stderr().is_terminal(); let cancel_token = tokio_util::sync::CancellationToken::new(); diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index 132d70e7d..23f0c2ab8 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -1,131 +1,159 @@ -use std::{ - collections::{BTreeSet, HashMap, HashSet}, - fmt::Display, - path::{Path, PathBuf}, -}; +use std::{collections::BTreeSet, fmt::Display, path::PathBuf}; use colored::Colorize; use duct::cmd; use itertools::Itertools; use nix::{sys::signal::Signal, unistd::Pid}; +use serde::{Serialize, Serializer}; use sha2::Digest; use tokio::task::JoinSet; use tokio_util::sync::CancellationToken; use crate::md_check; -#[derive(Debug, Clone, serde::Serialize, Copy)] -pub enum SwayProjectDep { +#[derive(Debug, Clone, serde::Serialize, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum SwayArtifacts { TypePaths, Normal, } -#[derive(Debug, Clone, serde::Serialize)] +#[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct RustDeps { + pub nightly: bool, + #[serde(serialize_with = "comma_separated")] + pub components: BTreeSet, +} + +fn comma_separated(components: &BTreeSet, serializer: S) -> Result +where + S: Serializer, +{ + let components = components.iter().join(","); + components.serialize(serializer) +} + +#[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct CargoDeps { + pub hack: bool, + pub nextest: bool, + pub machete: bool, + pub udeps: bool, +} + +impl std::ops::Add for CargoDeps { + type Output = Self; + fn add(mut self, other: Self) -> Self { + self += other; + self + } +} + +impl std::ops::AddAssign for CargoDeps { + fn add_assign(&mut self, other: Self) { + self.hack |= other.hack; + self.nextest |= other.nextest; + self.machete |= other.machete; + } +} + +#[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CiDeps { - fuel_core_binary: bool, + pub fuel_core_binary: bool, #[serde(skip_serializing_if = "Option::is_none")] - rust_toolchain_components: Option, - wasm: bool, - cargo_hack: bool, - nextest: bool, - cargo_machete: bool, - typos_cli: bool, + pub rust: Option, + pub wasm: bool, + pub cargo: CargoDeps, + pub typos_cli: bool, #[serde(skip_serializing_if = "Option::is_none")] - sway_project_artifacts: Option, + pub sway_artifacts: Option, } -#[derive(Debug, Clone, serde::Serialize)] -pub struct CiJob { - dir: PathBuf, - deps: CiDeps, +impl std::ops::Add for CiDeps { + type Output = Self; + fn add(mut self, other: Self) -> Self { + self += other; + self + } } -impl CiDeps { - pub fn from_deps(deps: &HashSet) -> Self { - let fuel_core_binary = deps.contains(&Dependency::FuelCoreBinary); - let wasm = deps.contains(&Dependency::Wasm); - let cargo_hack = deps.contains(&Dependency::CargoHack); - let nextest = deps.contains(&Dependency::Nextest); - let cargo_machete = deps.contains(&Dependency::CargoMachete); - let typos_cli = deps.contains(&Dependency::TyposCli); - - let sway_project_artifacts = deps.iter().find_map(|dep| match dep { - Dependency::SwayArtifacts { type_paths } if *type_paths => { - Some(SwayProjectDep::TypePaths) +impl std::ops::AddAssign for CiDeps { + fn add_assign(&mut self, other: Self) { + self.fuel_core_binary |= other.fuel_core_binary; + + let rust = match (self.rust.take(), other.rust) { + (Some(mut self_rust), Some(other_rust)) => { + self_rust.nightly |= other_rust.nightly; + self_rust.components = self_rust + .components + .union(&other_rust.components) + .cloned() + .collect(); + Some(self_rust) } - Dependency::SwayArtifacts { .. } => Some(SwayProjectDep::Normal), - _ => None, - }); - - let mut components = String::new(); - if deps.contains(&Dependency::Clippy) { - components.push_str("clippy"); - } - if deps.contains(&Dependency::RustFmt) { - if !components.is_empty() { - components.push(','); + (Some(self_rust), None) => Some(self_rust), + (None, Some(other_rust)) => Some(other_rust), + (None, None) => None, + }; + self.rust = rust; + + self.wasm |= other.wasm; + self.cargo += other.cargo; + self.typos_cli |= other.typos_cli; + + let sway_artifacts = match (self.sway_artifacts, other.sway_artifacts) { + (Some(self_sway), Some(other_sway)) => { + if self_sway != other_sway { + panic!( + "Deps cannot be unified. Cannot have type paths and normal artifacts at once! {self_sway:?} != {other_sway:?}", + ); + } + Some(self_sway) } - components.push_str("rustfmt"); - } - - let rust_toolchain_components = if components.is_empty() { - None - } else { - Some(components) + (Some(self_sway), None) => Some(self_sway), + (None, Some(other_sway)) => Some(other_sway), + (None, None) => None, }; - - Self { - fuel_core_binary, - rust_toolchain_components, - wasm, - cargo_hack, - nextest, - cargo_machete, - typos_cli, - sway_project_artifacts, - } + self.sway_artifacts = sway_artifacts; } } +#[derive(Debug, Clone, serde::Serialize)] +pub struct CiJob { + deps: CiDeps, + #[serde(serialize_with = "serialize_as_ids")] + tasks: Vec, +} + +fn serialize_as_ids(tasks: &[Task], serializer: S) -> Result +where + S: Serializer, +{ + let ids = tasks.iter().map(|task| task.id()).join(","); + ids.serialize(serializer) +} + #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Task { pub cwd: PathBuf, pub cmd: Command, } -#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -pub enum Dependency { - FuelCoreBinary, - Clippy, - CargoHack, - RustFmt, - RustStable, - RustNightly, - SwayArtifacts { type_paths: bool }, - Nextest, - CargoMachete, - Wasm, - TyposCli, - Grep, - Find, -} - #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Command { Custom { program: String, args: Vec, env: Vec<(String, String)>, - deps: Vec, + deps: CiDeps, }, MdCheck, } impl Command { - pub fn deps(&self) -> HashSet { + pub fn deps(&self) -> CiDeps { match self { - Command::Custom { deps, .. } => HashSet::from_iter(deps.iter().copied()), - Command::MdCheck => HashSet::from_iter([Dependency::Grep, Dependency::Find]), + Command::Custom { deps, .. } => deps.clone(), + Command::MdCheck => CiDeps::default(), } } } @@ -275,21 +303,52 @@ impl Task { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Tasks { - pub tasks: Vec, + pub tasks: BTreeSet, } impl Tasks { pub fn ci_jobs(&self) -> Vec { self.tasks .iter() - .group_by(|task| &task.cwd) + .sorted_by_key(|task| task.cwd.clone()) + .group_by(|task| task.cwd.clone()) .into_iter() - .map(|(cwd, tasks)| { - let deps = tasks.flat_map(|task| task.cmd.deps()).collect(); - CiJob { - dir: cwd.clone(), - deps: CiDeps::from_deps(&deps), + .flat_map(|(_, tasks)| { + let (tasks_requiring_type_paths, normal_tasks): (Vec<_>, Vec<_>) = + tasks.into_iter().partition(|task| { + task.cmd + .deps() + .sway_artifacts + .is_some_and(|dep| matches!(dep, SwayArtifacts::TypePaths)) + }); + + let type_paths_deps = tasks_requiring_type_paths + .iter() + .map(|ty| ty.cmd.deps()) + .reduce(|acc, next| acc + next); + + let normal_deps = normal_tasks + .iter() + .map(|ty| ty.cmd.deps()) + .reduce(|acc, next| acc + next); + + let mut jobs = vec![]; + + if let Some(deps) = type_paths_deps { + jobs.push(CiJob { + deps, + tasks: tasks_requiring_type_paths.into_iter().cloned().collect(), + }); + } + + if let Some(deps) = normal_deps { + jobs.push(CiJob { + deps, + tasks: normal_tasks.into_iter().cloned().collect(), + }); } + + jobs }) .collect() } diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 51ac1330f..2e24b2ed2 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -1,25 +1,20 @@ use nix::unistd::Pid; -use crate::{cli, task::Tasks}; +use crate::{cli, description, task::Tasks}; pub fn generate_tasks(cli: &cli::Cli) -> Tasks { - let tasks_gen = match cli.flavor { - cli::Flavor::Ci => crate::description::ci, - cli::Flavor::HackFeatures => crate::description::hack_features, - cli::Flavor::HackDeps => crate::description::hack_deps, - }; - let mut tasks = Tasks { - tasks: tasks_gen(cli.root.clone(), cli.sway_with_type_paths) - .into_iter() - .collect(), + let mut tasks = match cli.flavor { + cli::Flavor::Normal => description::normal(cli.root.clone()), + cli::Flavor::HackFeatures => description::hack_features(cli.root.clone()), + cli::Flavor::HackDeps => description::hack_deps(cli.root.clone()), }; - if !cli.only_tasks_with_ids.is_empty() { - tasks.retain_with_ids(&cli.only_tasks_with_ids); + if let Some(ids) = &cli.only_tasks_with_ids { + tasks.retain_with_ids(ids); } - if !cli.only_tasks_in_dir.is_empty() { - tasks.retain_with_dirs(&cli.only_tasks_in_dir); + if let Some(dirs) = &cli.only_tasks_in_dir { + tasks.retain_with_dirs(dirs); } tasks From 463f0b579864a7b9e7726fdfe8eeaee622d1b633 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 14:11:40 +0200 Subject: [PATCH 38/70] fix type paths flag --- scripts/checks/src/cli.rs | 11 +- scripts/checks/src/description.rs | 338 +++++++++++++++--------------- scripts/checks/src/task.rs | 23 +- scripts/checks/src/util.rs | 4 + 4 files changed, 195 insertions(+), 181 deletions(-) diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index c55ada4c6..29d810f8e 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -30,7 +30,7 @@ pub struct Cli { num_args = 0.. )] - pub only_tasks_in_dir: Option>, + pub only_tasks_in_dir: Option>, /// Used to enable/disable tests that take too long/are too resource intense. #[arg(short, long, default_value = "normal")] @@ -71,7 +71,10 @@ mod tests { let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then - assert_eq!(cli.only_tasks_with_ids, vec!["one", "two"]); + assert_eq!( + cli.only_tasks_with_ids, + Some(vec!["one".to_string(), "two".to_string()]) + ); } #[test] @@ -99,7 +102,7 @@ mod tests { } #[test] - fn default_flavor_is_ci() { + fn default_flavor_is_normal() { // given let cli = "foo -r ."; @@ -107,6 +110,6 @@ mod tests { let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then - assert_eq!(cli.flavor, Flavor::Ci); + assert_eq!(cli.flavor, Flavor::Normal); } } diff --git a/scripts/checks/src/description.rs b/scripts/checks/src/description.rs index 7b187a6d6..5437b2591 100644 --- a/scripts/checks/src/description.rs +++ b/scripts/checks/src/description.rs @@ -65,10 +65,147 @@ impl TasksBuilder { self.hack_deps_common().collect() } - fn workspace_path(&self, path: &str) -> PathBuf { - let path = self.workspace.join(path); - path.canonicalize() - .unwrap_or_else(|_| panic!("Path not found: {:?}", path)) + fn common(&self) -> impl Iterator + '_ { + self.all_workspace_members(None) + .into_iter() + .flat_map(|member| { + let mut commands = vec![ + self.cargo_fmt("--verbose --check", Default::default()), + self.custom( + "typos", + "", + &CiDeps { + typos_cli: true, + ..Default::default() + }, + ), + ]; + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + if member != self.workspace_path("e2e") { + let cmd = self + .cargo_clippy("--all-targets --all-features --no-deps", Default::default()); + commands.push(cmd); + } + + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) + // wasm ignored because wasm tests need to be run with wasm-pack + if member != self.workspace_path("wasm-tests") + && member != self.workspace_path("e2e") + { + let cmd = self.cargo_nextest("run --all-features", Default::default()); + commands.push(cmd); + } + + // because these don't have libs + if member != self.workspace_path("e2e") + && member != self.workspace_path("wasm-tests") + && member != self.workspace_path("scripts/checks") + { + let cmd = self.cargo("test --doc", None, CiDeps::default()); + commands.push(cmd); + + let cmd = self.cargo( + "doc --document-private-items", + Some(("RUSTDOCFLAGS", "-Dwarnings")), + CiDeps::default(), + ); + commands.push(cmd); + } + commands.into_iter().map(move |cmd| Task { + cwd: member.clone(), + cmd, + }) + }) + } + + fn e2e_specific(&self) -> impl Iterator + '_ { + [ + self.cargo_nextest( + "run --features default,fuel-core-lib,test-type-paths", + CiDeps { + sway_artifacts: Some(SwayArtifacts::TypePaths), + ..Default::default() + }, + ), + self.cargo_nextest( + "run --features default,fuel-core-lib", + CiDeps { + sway_artifacts: Some(SwayArtifacts::Normal), + ..Default::default() + }, + ), + self.cargo_nextest( + "run --features default,test-type-paths", + CiDeps { + fuel_core_binary: true, + sway_artifacts: Some(SwayArtifacts::Normal), + ..Default::default() + }, + ), + self.cargo_clippy( + "--all-targets --no-deps --features default,test-type-paths", + CiDeps { + sway_artifacts: Some(SwayArtifacts::TypePaths), + ..Default::default() + }, + ), + ] + .map(|cmd| Task { + cwd: self.workspace_path("e2e"), + cmd, + }) + .into_iter() + } + + fn wasm_specific(&self) -> impl Iterator { + std::iter::once(Task { + cwd: self.workspace_path("wasm-tests"), + cmd: self.custom( + "wasm-pack", + "test --node", + &CiDeps { + wasm: true, + ..Default::default() + }, + ), + }) + } + + fn workspace_level(&self) -> impl Iterator { + [ + Command::MdCheck, + self.custom( + "cargo-machete", + "--skip-target-dir", + &CiDeps { + cargo: CargoDeps { + machete: true, + ..Default::default() + }, + ..Default::default() + }, + ), + self.cargo_clippy( + "--workspace --all-features", + CiDeps { + sway_artifacts: Some(SwayArtifacts::Normal), + ..Default::default() + }, + ), + self.custom( + "typos", + "", + &CiDeps { + typos_cli: true, + ..Default::default() + }, + ), + ] + .map(|cmd| Task { + cwd: self.workspace_path("."), + cmd, + }) + .into_iter() } fn hack_features_common(&self) -> Vec { @@ -89,6 +226,30 @@ impl TasksBuilder { .collect() } + fn hack_features_e2e(&self) -> Vec { + [ + self.cargo_hack( + "--feature-powerset check --tests", + CiDeps { + sway_artifacts: Some(SwayArtifacts::TypePaths), + ..Default::default() + }, + ), + self.cargo_hack( + "--feature-powerset --exclude-features test-type-paths check --tests", + CiDeps { + sway_artifacts: Some(SwayArtifacts::Normal), + ..Default::default() + }, + ), + ] + .map(|cmd| Task { + cwd: self.workspace_path("e2e"), + cmd, + }) + .to_vec() + } + fn hack_deps_common(&self) -> impl Iterator + '_ { let ignore = self.workspace_path("e2e"); self.all_workspace_members(Some(&ignore)) @@ -117,30 +278,6 @@ impl TasksBuilder { }) } - fn hack_features_e2e(&self) -> Vec { - [ - self.cargo_hack( - "--feature-powerset check --tests", - CiDeps { - sway_artifacts: Some(SwayArtifacts::TypePaths), - ..Default::default() - }, - ), - self.cargo_hack( - "--feature-powerset --exclude-features test-type-paths check --tests", - CiDeps { - sway_artifacts: Some(SwayArtifacts::Normal), - ..Default::default() - }, - ), - ] - .map(|cmd| Task { - cwd: self.workspace_path("e2e"), - cmd, - }) - .to_vec() - } - fn cargo_fmt(&self, cmd: impl Into, mut deps: CiDeps) -> Command { deps += CiDeps { rust: Some(RustDeps { @@ -229,147 +366,10 @@ impl TasksBuilder { } } - fn e2e_specific(&self) -> impl Iterator + '_ { - [ - self.cargo_nextest( - "run --features default,fuel-core-lib,test-type-paths", - CiDeps { - sway_artifacts: Some(SwayArtifacts::TypePaths), - ..Default::default() - }, - ), - self.cargo_nextest( - "run --features default,fuel-core-lib", - CiDeps { - sway_artifacts: Some(SwayArtifacts::Normal), - ..Default::default() - }, - ), - self.cargo_nextest( - "run --features default,test-type-paths", - CiDeps { - fuel_core_binary: true, - sway_artifacts: Some(SwayArtifacts::Normal), - ..Default::default() - }, - ), - self.cargo_clippy( - "--all-targets --no-deps --features default,test-type-paths", - CiDeps { - sway_artifacts: Some(SwayArtifacts::TypePaths), - ..Default::default() - }, - ), - ] - .map(|cmd| Task { - cwd: self.workspace_path("e2e"), - cmd, - }) - .into_iter() - } - - fn wasm_specific(&self) -> impl Iterator { - std::iter::once(Task { - cwd: self.workspace_path("wasm-tests"), - cmd: self.custom( - "wasm-pack test --node", - "", - &CiDeps { - wasm: true, - ..Default::default() - }, - ), - }) - } - - fn workspace_level(&self) -> impl Iterator { - [ - Command::MdCheck, - self.custom( - "cargo-machete --skip-target-dir", - "", - &CiDeps { - cargo: CargoDeps { - machete: true, - ..Default::default() - }, - ..Default::default() - }, - ), - self.cargo_clippy( - "--workspace --all-features", - CiDeps { - sway_artifacts: Some(SwayArtifacts::Normal), - ..Default::default() - }, - ), - self.custom( - "typos", - "", - &CiDeps { - typos_cli: true, - ..Default::default() - }, - ), - ] - .map(|cmd| Task { - cwd: self.workspace_path("."), - cmd, - }) - .into_iter() - } - - fn common(&self) -> impl Iterator + '_ { - self.all_workspace_members(None) - .into_iter() - .flat_map(|member| { - let mut commands = vec![ - self.cargo_fmt("--verbose --check", Default::default()), - self.custom( - "typos", - "", - &CiDeps { - typos_cli: true, - ..Default::default() - }, - ), - ]; - // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) - if member != self.workspace_path("e2e") { - let cmd = self - .cargo_clippy("--all-targets --all-features --no-deps", Default::default()); - commands.push(cmd); - } - - // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) - // wasm ignored because wasm tests need to be run with wasm-pack - if member != self.workspace_path("wasm-tests") - && member != self.workspace_path("e2e") - { - let cmd = self.cargo_nextest("run --all-features", Default::default()); - commands.push(cmd); - } - - // because these don't have libs - if member != self.workspace_path("e2e") - && member != self.workspace_path("wasm-tests") - && member != self.workspace_path("scripts/checks") - { - let cmd = self.cargo("test --doc", None, CiDeps::default()); - commands.push(cmd); - - let cmd = self.cargo( - "doc --document-private-items", - Some(("RUSTDOCFLAGS", "-Dwarnings")), - CiDeps::default(), - ); - commands.push(cmd); - } - commands.into_iter().map(move |cmd| Task { - cwd: member.clone(), - cmd, - }) - }) + fn workspace_path(&self, path: &str) -> PathBuf { + let path = self.workspace.join(path); + path.canonicalize() + .unwrap_or_else(|_| panic!("Path not found: {:?}", path)) } fn all_workspace_members(&self, ignore: Option<&Path>) -> Vec { diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index 23f0c2ab8..e5c49cfb4 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -423,15 +423,22 @@ impl Tasks { self.tasks.retain(|task| ids.contains(&task.id())); } - pub fn retain_with_dirs(&mut self, dirs: &[String]) { + pub fn retain_with_dirs(&mut self, dirs: &[PathBuf]) { + let dirs = dirs + .iter() + .map(|dir| { + dir.canonicalize() + .unwrap_or_else(|_| panic!("unable to canonicalize path {dir:?}")) + }) + .collect_vec(); + self.tasks.retain(|task| dirs.contains(&task.cwd)); + } + + pub fn retain_without_type_paths(&mut self) { self.tasks.retain(|task| { - dirs.contains( - &task - .cwd - .canonicalize() - .unwrap() - .to_string_lossy() - .to_string(), + matches!( + task.cmd.deps().sway_artifacts, + Some(SwayArtifacts::Normal) | None ) }); } diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 2e24b2ed2..03fcddf02 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -17,6 +17,10 @@ pub fn generate_tasks(cli: &cli::Cli) -> Tasks { tasks.retain_with_dirs(dirs); } + if !cli.sway_compiled_with_type_paths { + tasks.retain_without_type_paths(); + } + tasks } From e7cfeb5348ded5fd674a7634a488531f58beef2b Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 14:53:50 +0200 Subject: [PATCH 39/70] fix ci --- .github/workflows/ci.yml | 67 +++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f96306b94..db2c06d1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ env: NEXTEST_STATUS_LEVEL: "fail" jobs: - setup-test-projects: + compile_sway_projects: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -147,32 +147,43 @@ jobs: cargo-verifications: needs: - - setup-test-projects + - compile_sway_projects - verify-rust-version - - generate-job-config + - build-checks-binary - publish-crates-check runs-on: ubuntu-latest strategy: matrix: - config: ${{fromJSON(needs.generate-job-config.outputs.config)}} + config: ${{fromJSON(needs.build-checks-binary.outputs.config)}} steps: - name: Checkout repository uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - - uses: dtolnay/rust-toolchain@master + + - name: Install Rust toolchain + if: ${{ matrix.config.deps.rust && matrix.config.deps.rust.nightly == false }} + uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.RUST_VERSION }} - components: clippy,rustfmt - # selecting a toolchain either by action or manual `rustup` calls should happen - # before the cache plugin, as it uses the current rustc version as its cache key + components: ${{ matrix.config.deps.rust.components || '' }} + + - name: Install Rust nightly toolchain + if: ${{ matrix.config.deps.rust && matrix.config.deps.rust.nightly == true }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + components: ${{ matrix.config.deps.rust.components || '' }} + + # selecting a toolchain either by action or manual `rustup` calls should happen + # before the cache plugin, as it uses the current rustc version as its cache key - uses: Swatinem/rust-cache@v2.0.1 continue-on-error: true with: - key: "${{ matrix.dir }}" + key: "${{ matrix.config.tasks }}" - name: Install Fuel Core - if: ${{ matrix.install_fuel_core }} + if: ${{ matrix.config.deps.fuel_core_binary }} run: | if [[ -n $FUEL_CORE_PATCH_BRANCH ]]; then cargo install --locked fuel-core-bin --git https://github.com/FuelLabs/fuel-core --branch "$FUEL_CORE_PATCH_BRANCH" @@ -183,35 +194,55 @@ jobs: mv fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core fi - - name: Download sway example artifacts - if: ${{ matrix.download_sway_artifacts }} + - name: Download sway example artifacts (Normal) + if: ${{ matrix.config.deps.sway_artifacts == 'Normal' }} + uses: actions/download-artifact@v4 + with: + name: sway-examples + # Needed because `upload-artifact` will remove 'e2e/sway' because it is shared between all matched files + path: e2e/sway/ + + - name: Download sway example artifacts (TypePaths) + if: ${{ matrix.config.deps.sway_artifacts == 'TypePaths' }} uses: actions/download-artifact@v4 with: - name: ${{ matrix.download_sway_artifacts }} + name: sway-examples-w-type-paths # Needed because `upload-artifact` will remove 'e2e/sway' because it is shared between all matched files path: e2e/sway/ - name: Install nextest - if: ${{ matrix.cargo_command == 'nextest' }} + if: ${{ matrix.config.deps.cargo.nextest }} uses: taiki-e/install-action@nextest - name: Install cargo-machete - if: ${{ matrix.cargo_command == 'machete' }} + if: ${{ matrix.config.deps.cargo.machete }} uses: taiki-e/install-action@cargo-machete - name: Install NodeJS for WASM testing + if: ${{ matrix.config.deps.wasm }} uses: actions/setup-node@v3 with: node-version: 18 - - name: Install typos tool - uses: crate-ci/typos@v1.20.3 - - name: Install wasm toolchain + if: ${{ matrix.config.deps.wasm }} run: | rustup target add wasm32-unknown-unknown curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - name: Install typos tool + if: ${{ matrix.config.deps.typos_cli }} + uses: crate-ci/typos@v1.20.3 + + - name: Download checks binary + uses: actions/download-artifact@v4 + with: + name: checks-binary + path: target/release/checks + + - name: Run checks + run: ./target/release/checks --only-tasks-with-ids ${{ matrix.config.tasks }} + publish: needs: From 8cd77ead8ec0fefebe2bb180122444736f3ae074 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 14:55:38 +0200 Subject: [PATCH 40/70] fix checks generation stage --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db2c06d1f..8f2ff0ad8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,7 +100,7 @@ jobs: prefix-key: "v1-rust" - name: Build checks binary - run: cargo build --release --package checks --bin checks + run: cargo build --package checks --bin checks - name: Upload checks binary uses: actions/upload-artifact@v4 @@ -111,7 +111,7 @@ jobs: - name: Generate config id: generate-config run: | - ./target/release/checks generate-config > config.json + ./target/release/checks -r . --print-ci-jobs-desc > config.json echo "::set-output name=config::$(cat config.json)" verify-rust-version: From 9eedae9988d6122b2147e9b8cd769cc0995d35dc Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 14:57:10 +0200 Subject: [PATCH 41/70] use debug checks --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f2ff0ad8..7fd2ef83e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,12 +106,12 @@ jobs: uses: actions/upload-artifact@v4 with: name: checks-binary - path: target/release/checks + path: target/debug/checks - name: Generate config id: generate-config run: | - ./target/release/checks -r . --print-ci-jobs-desc > config.json + ./target/debug/checks -r . --print-ci-jobs-desc > config.json echo "::set-output name=config::$(cat config.json)" verify-rust-version: @@ -238,10 +238,10 @@ jobs: uses: actions/download-artifact@v4 with: name: checks-binary - path: target/release/checks + path: target/debug/checks - name: Run checks - run: ./target/release/checks --only-tasks-with-ids ${{ matrix.config.tasks }} + run: ./target/debug/checks --only-tasks-with-ids ${{ matrix.config.tasks }} publish: From 63f81f138e7da037448766b414630dd5b0d14fcb Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 15:07:39 +0200 Subject: [PATCH 42/70] change how output is generated --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fd2ef83e..6d89b1c4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -111,8 +111,7 @@ jobs: - name: Generate config id: generate-config run: | - ./target/debug/checks -r . --print-ci-jobs-desc > config.json - echo "::set-output name=config::$(cat config.json)" + ./target/debug/checks -r . --print-ci-jobs-desc >> "$GITHUB_OUTPUT" verify-rust-version: runs-on: ubuntu-latest From 01f49040717434032215b66b443c46777a195e63 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 15:12:42 +0200 Subject: [PATCH 43/70] fix output gen again --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d89b1c4e..829f23b99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -111,7 +111,10 @@ jobs: - name: Generate config id: generate-config run: | + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + echo "config<<$EOF" >> "$GITHUB_OUTPUT" ./target/debug/checks -r . --print-ci-jobs-desc >> "$GITHUB_OUTPUT" + echo "$EOF" >> "$GITHUB_OUTPUT" verify-rust-version: runs-on: ubuntu-latest From 8b440e889810723cd84da36da0c9f3f235a7ec98 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 15:18:19 +0200 Subject: [PATCH 44/70] fix path --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 829f23b99..f221e2b86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -240,11 +240,10 @@ jobs: uses: actions/download-artifact@v4 with: name: checks-binary - path: target/debug/checks + path: ./checks - name: Run checks - run: ./target/debug/checks --only-tasks-with-ids ${{ matrix.config.tasks }} - + run: ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} publish: needs: From 8b79b0c6bc1939a7ccea3b32dc742c3238214490 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 15:21:53 +0200 Subject: [PATCH 45/70] wrong path --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f221e2b86..3f4cd998f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -240,7 +240,6 @@ jobs: uses: actions/download-artifact@v4 with: name: checks-binary - path: ./checks - name: Run checks run: ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} From 5a1cccf92573e3dcac3a60eff9f95d8524c9ee53 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 15:24:19 +0200 Subject: [PATCH 46/70] make checks executable --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f4cd998f..ade0d18ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -242,7 +242,9 @@ jobs: name: checks-binary - name: Run checks - run: ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} + run: | + chmod +x checks + ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} publish: needs: From f11e7c101718d1755aac7f15bf1faf5ca773a006 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 15:26:27 +0200 Subject: [PATCH 47/70] add mandatory root parameter --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ade0d18ba..ad0c15e1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -244,7 +244,7 @@ jobs: - name: Run checks run: | chmod +x checks - ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} + ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} --root . publish: needs: From 918c89289149d410a2ace34a35388df24e4f8325 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 15:42:33 +0200 Subject: [PATCH 48/70] typos download --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad0c15e1a..6985fe5f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -234,7 +234,11 @@ jobs: - name: Install typos tool if: ${{ matrix.config.deps.typos_cli }} - uses: crate-ci/typos@v1.20.3 + run: | + curl -sSLf 'https://github.com/crate-ci/typos/releases/download/v1.21.0/typos-v1.21.0-x86_64-unknown-linux-musl.tar.gz' > typos.tar.gz + tar -xzf typos.tar.gz + chmod +x typos + mv typos /usr/local/bin/typos - name: Download checks binary uses: actions/download-artifact@v4 From 7c19d44d636d94e975acf94c3f3217ee3292f76d Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 15:48:46 +0200 Subject: [PATCH 49/70] fix typos extracting --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6985fe5f1..9c3a71d27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -236,7 +236,7 @@ jobs: if: ${{ matrix.config.deps.typos_cli }} run: | curl -sSLf 'https://github.com/crate-ci/typos/releases/download/v1.21.0/typos-v1.21.0-x86_64-unknown-linux-musl.tar.gz' > typos.tar.gz - tar -xzf typos.tar.gz + tar xf typos.tar.gz --wildcards "./typos" && rm typos.tar.gz chmod +x typos mv typos /usr/local/bin/typos From f15bc42b4ddbfc19719f07b0322d9c58dd07673a Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 16:13:20 +0200 Subject: [PATCH 50/70] add name to matrix tasks --- .github/workflows/ci.yml | 1 + scripts/checks/src/description.rs | 24 ++++++++-------------- scripts/checks/src/main.rs | 4 +--- scripts/checks/src/task.rs | 34 +++++++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c3a71d27..ab5185ab0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -157,6 +157,7 @@ jobs: strategy: matrix: config: ${{fromJSON(needs.build-checks-binary.outputs.config)}} + name: Cargo Verification [${{ matrix.config.name }}] steps: - name: Checkout repository uses: actions/checkout@v3 diff --git a/scripts/checks/src/description.rs b/scripts/checks/src/description.rs index 5437b2591..764c5063a 100644 --- a/scripts/checks/src/description.rs +++ b/scripts/checks/src/description.rs @@ -12,26 +12,20 @@ use crate::task::SwayArtifacts; use crate::task::Task; use crate::task::Tasks; -pub fn normal(workspace: PathBuf) -> Tasks { - let builder = TasksBuilder::new(workspace.clone(), &["-Dwarnings"]); - Tasks { - tasks: builder.local(), - } +pub fn normal(workspace_root: PathBuf) -> Tasks { + let builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); + Tasks::new(builder.local(), workspace_root) } -pub fn hack_features(workspace: PathBuf) -> Tasks { - let builder = TasksBuilder::new(workspace.clone(), &["-Dwarnings"]); +pub fn hack_features(workspace_root: PathBuf) -> Tasks { + let builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); - Tasks { - tasks: builder.hack_features(), - } + Tasks::new(builder.hack_features(), workspace_root) } -pub fn hack_deps(workspace: PathBuf) -> Tasks { - let builder = TasksBuilder::new(workspace.clone(), &["-Dwarnings"]); - Tasks { - tasks: builder.hack_deps(), - } +pub fn hack_deps(workspace_root: PathBuf) -> Tasks { + let builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); + Tasks::new(builder.hack_deps(), workspace_root) } struct TasksBuilder { diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index 333e07c91..dd228b40b 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -24,9 +24,7 @@ async fn main() -> anyhow::Result<()> { let tasks = util::generate_tasks(&cli); if cli.list_tasks { - for task in &tasks.tasks { - println!("{task}"); - } + println!("{tasks}"); return Ok(()); } diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index e5c49cfb4..bb9e55f7c 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -122,6 +122,7 @@ pub struct CiJob { deps: CiDeps, #[serde(serialize_with = "serialize_as_ids")] tasks: Vec, + name: String, } fn serialize_as_ids(tasks: &[Task], serializer: S) -> Result @@ -303,17 +304,34 @@ impl Task { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Tasks { - pub tasks: BTreeSet, + tasks: BTreeSet, + workspace_root: PathBuf, +} + +impl Display for Tasks { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for task in &self.tasks { + writeln!(f, "{}", task)?; + } + Ok(()) + } } impl Tasks { + pub fn new(tasks: BTreeSet, workspace_root: PathBuf) -> Self { + Self { + tasks, + workspace_root: workspace_root.canonicalize().unwrap(), + } + } + pub fn ci_jobs(&self) -> Vec { self.tasks .iter() .sorted_by_key(|task| task.cwd.clone()) .group_by(|task| task.cwd.clone()) .into_iter() - .flat_map(|(_, tasks)| { + .flat_map(|(cwd, tasks)| { let (tasks_requiring_type_paths, normal_tasks): (Vec<_>, Vec<_>) = tasks.into_iter().partition(|task| { task.cmd @@ -334,8 +352,19 @@ impl Tasks { let mut jobs = vec![]; + let name = format!( + "{}", + cwd.strip_prefix(&self.workspace_root) + .unwrap_or_else(|_| panic!( + "{cwd:?} is a prefix of {}", + self.workspace_root.display() + )) + .display() + ); + if let Some(deps) = type_paths_deps { jobs.push(CiJob { + name: name.clone(), deps, tasks: tasks_requiring_type_paths.into_iter().cloned().collect(), }); @@ -343,6 +372,7 @@ impl Tasks { if let Some(deps) = normal_deps { jobs.push(CiJob { + name, deps, tasks: normal_tasks.into_iter().cloned().collect(), }); From 05cf1b33dc38d44f25ce43d9f12367a98cf0b99e Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 16:17:34 +0200 Subject: [PATCH 51/70] fix names --- .github/workflows/ci.yml | 2 +- scripts/checks/src/task.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab5185ab0..424fafeaa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -157,7 +157,7 @@ jobs: strategy: matrix: config: ${{fromJSON(needs.build-checks-binary.outputs.config)}} - name: Cargo Verification [${{ matrix.config.name }}] + name: ${{ matrix.config.name }} steps: - name: Checkout repository uses: actions/checkout@v3 diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index bb9e55f7c..0bcfdaec1 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -3,7 +3,7 @@ use std::{collections::BTreeSet, fmt::Display, path::PathBuf}; use colored::Colorize; use duct::cmd; use itertools::Itertools; -use nix::{sys::signal::Signal, unistd::Pid}; +use nix::{sys::signal::Signal, unistd::Pid, NixPath}; use serde::{Serialize, Serializer}; use sha2::Digest; use tokio::task::JoinSet; @@ -352,15 +352,15 @@ impl Tasks { let mut jobs = vec![]; - let name = format!( - "{}", - cwd.strip_prefix(&self.workspace_root) - .unwrap_or_else(|_| panic!( - "{cwd:?} is a prefix of {}", - self.workspace_root.display() - )) - .display() - ); + let relative_path = cwd.strip_prefix(&self.workspace_root).unwrap_or_else(|_| { + panic!("{cwd:?} is a prefix of {}", self.workspace_root.display()) + }); + + let name = if relative_path.is_empty() { + "workspace".to_string() + } else { + format!("{}", relative_path.display()) + }; if let Some(deps) = type_paths_deps { jobs.push(CiJob { From ad82288839a6832997cb2c5dc8216218971c428f Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 16:26:12 +0200 Subject: [PATCH 52/70] add examples dep --- scripts/checks/src/description.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/scripts/checks/src/description.rs b/scripts/checks/src/description.rs index 764c5063a..1a5e6e610 100644 --- a/scripts/checks/src/description.rs +++ b/scripts/checks/src/description.rs @@ -63,21 +63,33 @@ impl TasksBuilder { self.all_workspace_members(None) .into_iter() .flat_map(|member| { + let deps = { + // Some examples run abigen! on sway projects in e2e + let sway_artifacts = member + .starts_with(self.workspace_path("examples")) + .then_some(SwayArtifacts::Normal); + + CiDeps { + sway_artifacts, + ..Default::default() + } + }; + let mut commands = vec![ - self.cargo_fmt("--verbose --check", Default::default()), + self.cargo_fmt("--verbose --check", deps.clone()), self.custom( "typos", "", &CiDeps { typos_cli: true, - ..Default::default() + ..deps.clone() }, ), ]; // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) if member != self.workspace_path("e2e") { - let cmd = self - .cargo_clippy("--all-targets --all-features --no-deps", Default::default()); + let cmd = + self.cargo_clippy("--all-targets --all-features --no-deps", deps.clone()); commands.push(cmd); } @@ -86,7 +98,7 @@ impl TasksBuilder { if member != self.workspace_path("wasm-tests") && member != self.workspace_path("e2e") { - let cmd = self.cargo_nextest("run --all-features", Default::default()); + let cmd = self.cargo_nextest("run --all-features", deps.clone()); commands.push(cmd); } @@ -95,16 +107,17 @@ impl TasksBuilder { && member != self.workspace_path("wasm-tests") && member != self.workspace_path("scripts/checks") { - let cmd = self.cargo("test --doc", None, CiDeps::default()); + let cmd = self.cargo("test --doc", None, deps.clone()); commands.push(cmd); let cmd = self.cargo( "doc --document-private-items", Some(("RUSTDOCFLAGS", "-Dwarnings")), - CiDeps::default(), + deps.clone(), ); commands.push(cmd); } + commands.into_iter().map(move |cmd| Task { cwd: member.clone(), cmd, From 54ebde32ddfd696467a9a6cac26a371111fdf86f Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 16:38:48 +0200 Subject: [PATCH 53/70] debug --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 424fafeaa..bccfef6d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,6 +163,9 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} + - name: Debug config + run: | + echo ${{ matrix.config }} - name: Install Rust toolchain if: ${{ matrix.config.deps.rust && matrix.config.deps.rust.nightly == false }} From 8d342708e54c85acb23f4c3b1d6132d5fbb61f32 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 16:54:54 +0200 Subject: [PATCH 54/70] fix cache --- .github/workflows/ci.yml | 2 +- scripts/checks/src/task.rs | 44 ++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bccfef6d0..a9429ea32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -186,7 +186,7 @@ jobs: - uses: Swatinem/rust-cache@v2.0.1 continue-on-error: true with: - key: "${{ matrix.config.tasks }}" + key: "${{ matrix.config.cache_key }}" - name: Install Fuel Core if: ${{ matrix.config.deps.fuel_core_binary }} diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs index 0bcfdaec1..deaf95717 100644 --- a/scripts/checks/src/task.rs +++ b/scripts/checks/src/task.rs @@ -120,17 +120,23 @@ impl std::ops::AddAssign for CiDeps { #[derive(Debug, Clone, serde::Serialize)] pub struct CiJob { deps: CiDeps, - #[serde(serialize_with = "serialize_as_ids")] - tasks: Vec, + // Comma separated task ids + task_ids: String, name: String, + // Must not contain commas, rust-cache complains + cache_key: String, } -fn serialize_as_ids(tasks: &[Task], serializer: S) -> Result -where - S: Serializer, -{ - let ids = tasks.iter().map(|task| task.id()).join(","); - ids.serialize(serializer) +impl CiJob { + pub fn new(deps: CiDeps, tasks: &[&Task], name: String) -> Self { + let ids = tasks.iter().map(|t| t.id()).join(","); + Self { + deps, + cache_key: short_sha256(&ids), + task_ids: ids, + name, + } + } } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -236,11 +242,15 @@ impl Execution { } } +fn short_sha256(input: &str) -> String { + let mut hasher = sha2::Sha256::default(); + hasher.update(input.as_bytes()); + hex::encode(&hasher.finalize()[..8]) +} + impl Task { pub fn id(&self) -> String { - let mut hasher = sha2::Sha256::default(); - hasher.update(format!("{:?}", self).as_bytes()); - hex::encode(&hasher.finalize()[..8]) + short_sha256(&format!("{:?}", self)) } pub fn run(self) -> Execution { @@ -363,19 +373,11 @@ impl Tasks { }; if let Some(deps) = type_paths_deps { - jobs.push(CiJob { - name: name.clone(), - deps, - tasks: tasks_requiring_type_paths.into_iter().cloned().collect(), - }); + jobs.push(CiJob::new(deps, &tasks_requiring_type_paths, name.clone())); } if let Some(deps) = normal_deps { - jobs.push(CiJob { - name, - deps, - tasks: normal_tasks.into_iter().cloned().collect(), - }); + jobs.push(CiJob::new(deps, &normal_tasks, name)); } jobs From 7c5f030cd77de0124c919842321e112b015887ca Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 16:57:37 +0200 Subject: [PATCH 55/70] fix type paths dep --- scripts/checks/src/description.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checks/src/description.rs b/scripts/checks/src/description.rs index 1a5e6e610..ab9794111 100644 --- a/scripts/checks/src/description.rs +++ b/scripts/checks/src/description.rs @@ -145,7 +145,7 @@ impl TasksBuilder { "run --features default,test-type-paths", CiDeps { fuel_core_binary: true, - sway_artifacts: Some(SwayArtifacts::Normal), + sway_artifacts: Some(SwayArtifacts::TypePaths), ..Default::default() }, ), From ded67cbae646fe6897240e997a32837b48481c83 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 17:05:08 +0200 Subject: [PATCH 56/70] missing tests --- .github/workflows/ci.yml | 2 +- scripts/checks/src/cli.rs | 8 ++++---- scripts/checks/src/util.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9429ea32..16dcdb51b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -252,7 +252,7 @@ jobs: - name: Run checks run: | chmod +x checks - ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} --root . + ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} --root . --disable-type-paths=false publish: needs: diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index 29d810f8e..05df34432 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -36,10 +36,10 @@ pub struct Cli { #[arg(short, long, default_value = "normal")] pub flavor: Flavor, - /// Enables some tests that need the sway artifacts to be built with the type paths enabled. - /// Has no effect for CI job generation since, in Ci, we can download the correct artifacts as needed. - #[arg(short, long, action)] - pub sway_compiled_with_type_paths: bool, + /// Disables tests that need the sway artifacts to be built with the type paths enabled. + /// Enabled by default. + #[arg(short, long, default_value_t = true)] + pub disable_type_paths: bool, /// Enable verbose output. #[arg(short, long, default_value = "false")] diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 03fcddf02..e4c97e115 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -17,7 +17,7 @@ pub fn generate_tasks(cli: &cli::Cli) -> Tasks { tasks.retain_with_dirs(dirs); } - if !cli.sway_compiled_with_type_paths { + if cli.disable_type_paths { tasks.retain_without_type_paths(); } From 17a10593021173e9f6b3d1a2a0aeaf7333875fc3 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 17:20:37 +0200 Subject: [PATCH 57/70] fix type paths --- .github/workflows/ci.yml | 2 +- scripts/checks/src/cli.rs | 7 +++---- scripts/checks/src/util.rs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16dcdb51b..e5d411488 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -252,7 +252,7 @@ jobs: - name: Run checks run: | chmod +x checks - ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} --root . --disable-type-paths=false + ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} --root . --sway-type-paths publish: needs: diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index 05df34432..ea868c82c 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -36,10 +36,9 @@ pub struct Cli { #[arg(short, long, default_value = "normal")] pub flavor: Flavor, - /// Disables tests that need the sway artifacts to be built with the type paths enabled. - /// Enabled by default. - #[arg(short, long, default_value_t = true)] - pub disable_type_paths: bool, + /// Enables tests that need the sway artifacts to be built with the type paths enabled. + #[arg(short, long, action)] + pub sway_type_paths: bool, /// Enable verbose output. #[arg(short, long, default_value = "false")] diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index e4c97e115..0655d14aa 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -17,7 +17,7 @@ pub fn generate_tasks(cli: &cli::Cli) -> Tasks { tasks.retain_with_dirs(dirs); } - if cli.disable_type_paths { + if !cli.sway_type_paths { tasks.retain_without_type_paths(); } From 7dfbae49173d62c8f17f2c9e0c7a4829d2f71d80 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Sun, 19 May 2024 17:25:15 +0200 Subject: [PATCH 58/70] fix task ids --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5d411488..5ea98eda1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -252,7 +252,7 @@ jobs: - name: Run checks run: | chmod +x checks - ./checks --only-tasks-with-ids ${{ matrix.config.tasks }} --root . --sway-type-paths + ./checks --only-tasks-with-ids ${{ matrix.config.task_ids }} --root . --sway-type-paths publish: needs: From a050f6319c5f9a60f1d98382bd1a98ba38856196 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Mon, 20 May 2024 12:18:55 +0200 Subject: [PATCH 59/70] reorg --- .../checks/src/{description.rs => config.rs} | 41 +- scripts/checks/src/main.rs | 6 +- scripts/checks/src/task.rs | 593 ------------------ scripts/checks/src/tasks.rs | 289 +++++++++ scripts/checks/src/tasks/command.rs | 45 ++ scripts/checks/src/tasks/deps.rs | 140 +++++ scripts/checks/src/tasks/report.rs | 50 ++ scripts/checks/src/tasks/task.rs | 90 +++ scripts/checks/src/util.rs | 8 +- 9 files changed, 641 insertions(+), 621 deletions(-) rename scripts/checks/src/{description.rs => config.rs} (92%) delete mode 100644 scripts/checks/src/task.rs create mode 100644 scripts/checks/src/tasks.rs create mode 100644 scripts/checks/src/tasks/command.rs create mode 100644 scripts/checks/src/tasks/deps.rs create mode 100644 scripts/checks/src/tasks/report.rs create mode 100644 scripts/checks/src/tasks/task.rs diff --git a/scripts/checks/src/description.rs b/scripts/checks/src/config.rs similarity index 92% rename from scripts/checks/src/description.rs rename to scripts/checks/src/config.rs index ab9794111..f084ac24a 100644 --- a/scripts/checks/src/description.rs +++ b/scripts/checks/src/config.rs @@ -4,13 +4,12 @@ use std::collections::BTreeSet; use std::path::Path; use std::path::PathBuf; -use crate::task::CargoDeps; -use crate::task::CiDeps; -use crate::task::Command; -use crate::task::RustDeps; -use crate::task::SwayArtifacts; -use crate::task::Task; -use crate::task::Tasks; +use crate::tasks::command::Command; +use crate::tasks::deps; +use crate::tasks::deps::CiDeps; +use crate::tasks::deps::SwayArtifacts; +use crate::tasks::task::Task; +use crate::tasks::Tasks; pub fn normal(workspace_root: PathBuf) -> Tasks { let builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); @@ -130,14 +129,14 @@ impl TasksBuilder { self.cargo_nextest( "run --features default,fuel-core-lib,test-type-paths", CiDeps { - sway_artifacts: Some(SwayArtifacts::TypePaths), + sway_artifacts: Some(deps::SwayArtifacts::TypePaths), ..Default::default() }, ), self.cargo_nextest( "run --features default,fuel-core-lib", CiDeps { - sway_artifacts: Some(SwayArtifacts::Normal), + sway_artifacts: Some(deps::SwayArtifacts::Normal), ..Default::default() }, ), @@ -145,14 +144,14 @@ impl TasksBuilder { "run --features default,test-type-paths", CiDeps { fuel_core_binary: true, - sway_artifacts: Some(SwayArtifacts::TypePaths), + sway_artifacts: Some(deps::SwayArtifacts::TypePaths), ..Default::default() }, ), self.cargo_clippy( "--all-targets --no-deps --features default,test-type-paths", CiDeps { - sway_artifacts: Some(SwayArtifacts::TypePaths), + sway_artifacts: Some(deps::SwayArtifacts::TypePaths), ..Default::default() }, ), @@ -185,7 +184,7 @@ impl TasksBuilder { "cargo-machete", "--skip-target-dir", &CiDeps { - cargo: CargoDeps { + cargo: deps::CargoDeps { machete: true, ..Default::default() }, @@ -195,7 +194,7 @@ impl TasksBuilder { self.cargo_clippy( "--workspace --all-features", CiDeps { - sway_artifacts: Some(SwayArtifacts::Normal), + sway_artifacts: Some(deps::SwayArtifacts::Normal), ..Default::default() }, ), @@ -238,14 +237,14 @@ impl TasksBuilder { self.cargo_hack( "--feature-powerset check --tests", CiDeps { - sway_artifacts: Some(SwayArtifacts::TypePaths), + sway_artifacts: Some(deps::SwayArtifacts::TypePaths), ..Default::default() }, ), self.cargo_hack( "--feature-powerset --exclude-features test-type-paths check --tests", CiDeps { - sway_artifacts: Some(SwayArtifacts::Normal), + sway_artifacts: Some(deps::SwayArtifacts::Normal), ..Default::default() }, ), @@ -263,11 +262,11 @@ impl TasksBuilder { .into_iter() .flat_map(|member| { let deps = CiDeps { - cargo: CargoDeps { + cargo: deps::CargoDeps { udeps: true, ..Default::default() }, - rust: Some(RustDeps { + rust: Some(deps::RustDeps { nightly: true, ..Default::default() }), @@ -287,7 +286,7 @@ impl TasksBuilder { fn cargo_fmt(&self, cmd: impl Into, mut deps: CiDeps) -> Command { deps += CiDeps { - rust: Some(RustDeps { + rust: Some(deps::RustDeps { components: BTreeSet::from_iter(["rustfmt".to_string()]), ..Default::default() }), @@ -301,7 +300,7 @@ impl TasksBuilder { fn cargo_clippy(&self, cmd: impl Into, mut deps: CiDeps) -> Command { deps += CiDeps { - rust: Some(RustDeps { + rust: Some(deps::RustDeps { components: BTreeSet::from_iter(["clippy".to_string()]), ..Default::default() }), @@ -314,7 +313,7 @@ impl TasksBuilder { fn cargo_hack(&self, cmd: impl Into, mut deps: CiDeps) -> Command { deps += CiDeps { - cargo: CargoDeps { + cargo: deps::CargoDeps { hack: true, ..Default::default() }, @@ -327,7 +326,7 @@ impl TasksBuilder { fn cargo_nextest(&self, cmd: impl Into, mut deps: CiDeps) -> Command { deps += CiDeps { - cargo: CargoDeps { + cargo: deps::CargoDeps { nextest: true, ..Default::default() }, diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index dd228b40b..b7c95af9d 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -2,9 +2,9 @@ use std::io::IsTerminal; use clap::Parser; mod cli; -mod description; +mod config; mod md_check; -mod task; +mod tasks; mod util; #[tokio::main] @@ -13,7 +13,7 @@ async fn main() -> anyhow::Result<()> { util::configure_child_process_cleanup()?; if cli.print_ci_jobs_desc { - let tasks = description::normal(cli.root.clone()); + let tasks = config::normal(cli.root.clone()); let jobs = tasks.ci_jobs(); // Json used because the CI needs it as such let jsonified = serde_json::to_string_pretty(&jobs)?; diff --git a/scripts/checks/src/task.rs b/scripts/checks/src/task.rs deleted file mode 100644 index deaf95717..000000000 --- a/scripts/checks/src/task.rs +++ /dev/null @@ -1,593 +0,0 @@ -use std::{collections::BTreeSet, fmt::Display, path::PathBuf}; - -use colored::Colorize; -use duct::cmd; -use itertools::Itertools; -use nix::{sys::signal::Signal, unistd::Pid, NixPath}; -use serde::{Serialize, Serializer}; -use sha2::Digest; -use tokio::task::JoinSet; -use tokio_util::sync::CancellationToken; - -use crate::md_check; - -#[derive(Debug, Clone, serde::Serialize, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum SwayArtifacts { - TypePaths, - Normal, -} - -#[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct RustDeps { - pub nightly: bool, - #[serde(serialize_with = "comma_separated")] - pub components: BTreeSet, -} - -fn comma_separated(components: &BTreeSet, serializer: S) -> Result -where - S: Serializer, -{ - let components = components.iter().join(","); - components.serialize(serializer) -} - -#[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct CargoDeps { - pub hack: bool, - pub nextest: bool, - pub machete: bool, - pub udeps: bool, -} - -impl std::ops::Add for CargoDeps { - type Output = Self; - fn add(mut self, other: Self) -> Self { - self += other; - self - } -} - -impl std::ops::AddAssign for CargoDeps { - fn add_assign(&mut self, other: Self) { - self.hack |= other.hack; - self.nextest |= other.nextest; - self.machete |= other.machete; - } -} - -#[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct CiDeps { - pub fuel_core_binary: bool, - #[serde(skip_serializing_if = "Option::is_none")] - pub rust: Option, - pub wasm: bool, - pub cargo: CargoDeps, - pub typos_cli: bool, - #[serde(skip_serializing_if = "Option::is_none")] - pub sway_artifacts: Option, -} - -impl std::ops::Add for CiDeps { - type Output = Self; - fn add(mut self, other: Self) -> Self { - self += other; - self - } -} - -impl std::ops::AddAssign for CiDeps { - fn add_assign(&mut self, other: Self) { - self.fuel_core_binary |= other.fuel_core_binary; - - let rust = match (self.rust.take(), other.rust) { - (Some(mut self_rust), Some(other_rust)) => { - self_rust.nightly |= other_rust.nightly; - self_rust.components = self_rust - .components - .union(&other_rust.components) - .cloned() - .collect(); - Some(self_rust) - } - (Some(self_rust), None) => Some(self_rust), - (None, Some(other_rust)) => Some(other_rust), - (None, None) => None, - }; - self.rust = rust; - - self.wasm |= other.wasm; - self.cargo += other.cargo; - self.typos_cli |= other.typos_cli; - - let sway_artifacts = match (self.sway_artifacts, other.sway_artifacts) { - (Some(self_sway), Some(other_sway)) => { - if self_sway != other_sway { - panic!( - "Deps cannot be unified. Cannot have type paths and normal artifacts at once! {self_sway:?} != {other_sway:?}", - ); - } - Some(self_sway) - } - (Some(self_sway), None) => Some(self_sway), - (None, Some(other_sway)) => Some(other_sway), - (None, None) => None, - }; - self.sway_artifacts = sway_artifacts; - } -} - -#[derive(Debug, Clone, serde::Serialize)] -pub struct CiJob { - deps: CiDeps, - // Comma separated task ids - task_ids: String, - name: String, - // Must not contain commas, rust-cache complains - cache_key: String, -} - -impl CiJob { - pub fn new(deps: CiDeps, tasks: &[&Task], name: String) -> Self { - let ids = tasks.iter().map(|t| t.id()).join(","); - Self { - deps, - cache_key: short_sha256(&ids), - task_ids: ids, - name, - } - } -} - -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct Task { - pub cwd: PathBuf, - pub cmd: Command, -} - -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum Command { - Custom { - program: String, - args: Vec, - env: Vec<(String, String)>, - deps: CiDeps, - }, - MdCheck, -} - -impl Command { - pub fn deps(&self) -> CiDeps { - match self { - Command::Custom { deps, .. } => deps.clone(), - Command::MdCheck => CiDeps::default(), - } - } -} - -impl Display for Command { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Command::Custom { - program, args, env, .. - } => { - let args = args.iter().join(" "); - if env.is_empty() { - write!(f, "{program} {args}") - } else { - let env = env - .iter() - .map(|(key, value)| format!("{key}='{value}'")) - .join(" "); - write!(f, "{env} {program} {args}") - } - } - Command::MdCheck { .. } => write!(f, "MdCheck"), - } - } -} - -impl Display for Task { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Task {}, dir: {:?}, {}", self.id(), self.cwd, self.cmd) - } -} - -#[derive(Debug, Clone)] -pub struct Execution { - pub cmd_desc: String, - pub status: ExecutionStatus, -} - -impl From for ExecutionStatus { - fn from(value: std::io::Error) -> Self { - Self::Failed { - reason: value.to_string(), - } - } -} - -impl From for ExecutionStatus { - fn from(value: anyhow::Error) -> Self { - Self::Failed { - reason: value.to_string(), - } - } -} - -#[derive(Debug, Clone)] -pub enum ExecutionStatus { - Success { out: String }, - Failed { reason: String }, -} - -impl Execution { - pub fn report(&self, tty: bool, verbose: bool) -> String { - let status = match &self.status { - ExecutionStatus::Failed { reason } => { - let err = if tty { "error".red() } else { "error".normal() }; - format!("{err}\n{reason}") - } - ExecutionStatus::Success { out } => { - let ok = if tty { "ok".green() } else { "ok".normal() }; - if verbose { - format!("{ok}\n{out}") - } else { - ok.to_string() - } - } - }; - - format!("{} ... {status}", self.cmd_desc) - } -} - -fn short_sha256(input: &str) -> String { - let mut hasher = sha2::Sha256::default(); - hasher.update(input.as_bytes()); - hex::encode(&hasher.finalize()[..8]) -} - -impl Task { - pub fn id(&self) -> String { - short_sha256(&format!("{:?}", self)) - } - - pub fn run(self) -> Execution { - match &self.cmd { - Command::Custom { - program, args, env, .. - } => self.run_custom(program, args.iter().map(|e| e.as_str()), env), - Command::MdCheck => self.run_md_check(), - } - } - - fn run_md_check(&self) -> Execution { - let status = if let Err(e) = md_check::run(&self.cwd) { - e.into() - } else { - ExecutionStatus::Success { - out: "".to_string(), - } - }; - - self.execution_report(status) - } - - fn run_custom<'a, F>(&self, program: &str, args: F, env: &[(String, String)]) -> Execution - where - F: IntoIterator, - { - let mut cmd = cmd(program, args) - .stderr_to_stdout() - .dir(&self.cwd) - .stdin_null() - .stdout_capture() - .unchecked(); - - for (key, value) in env { - cmd = cmd.env(key, value); - } - - let output = match cmd.run() { - Ok(output) => output, - Err(err) => return self.execution_report(err), - }; - - let decoded = String::from_utf8_lossy(&output.stdout).into_owned(); - let status = if output.status.success() { - ExecutionStatus::Success { out: decoded } - } else { - ExecutionStatus::Failed { reason: decoded } - }; - - self.execution_report(status) - } - - fn execution_report(&self, status: impl Into) -> Execution { - Execution { - cmd_desc: self.to_string(), - status: status.into(), - } - } -} - -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] -pub struct Tasks { - tasks: BTreeSet, - workspace_root: PathBuf, -} - -impl Display for Tasks { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - for task in &self.tasks { - writeln!(f, "{}", task)?; - } - Ok(()) - } -} - -impl Tasks { - pub fn new(tasks: BTreeSet, workspace_root: PathBuf) -> Self { - Self { - tasks, - workspace_root: workspace_root.canonicalize().unwrap(), - } - } - - pub fn ci_jobs(&self) -> Vec { - self.tasks - .iter() - .sorted_by_key(|task| task.cwd.clone()) - .group_by(|task| task.cwd.clone()) - .into_iter() - .flat_map(|(cwd, tasks)| { - let (tasks_requiring_type_paths, normal_tasks): (Vec<_>, Vec<_>) = - tasks.into_iter().partition(|task| { - task.cmd - .deps() - .sway_artifacts - .is_some_and(|dep| matches!(dep, SwayArtifacts::TypePaths)) - }); - - let type_paths_deps = tasks_requiring_type_paths - .iter() - .map(|ty| ty.cmd.deps()) - .reduce(|acc, next| acc + next); - - let normal_deps = normal_tasks - .iter() - .map(|ty| ty.cmd.deps()) - .reduce(|acc, next| acc + next); - - let mut jobs = vec![]; - - let relative_path = cwd.strip_prefix(&self.workspace_root).unwrap_or_else(|_| { - panic!("{cwd:?} is a prefix of {}", self.workspace_root.display()) - }); - - let name = if relative_path.is_empty() { - "workspace".to_string() - } else { - format!("{}", relative_path.display()) - }; - - if let Some(deps) = type_paths_deps { - jobs.push(CiJob::new(deps, &tasks_requiring_type_paths, name.clone())); - } - - if let Some(deps) = normal_deps { - jobs.push(CiJob::new(deps, &normal_tasks, name)); - } - - jobs - }) - .collect() - } - - pub fn verify_no_duplicates(&self) -> anyhow::Result<()> { - let duplicates = self - .tasks - .iter() - .duplicates_by(|task| task.id()) - .collect_vec(); - - if !duplicates.is_empty() { - anyhow::bail!("Found duplicate tasks: {:#?}", duplicates); - } - - Ok(()) - } - - pub async fn run( - self, - tty: bool, - verbose: bool, - cancel_token: CancellationToken, - ) -> anyhow::Result<()> { - self.verify_no_duplicates()?; - let mut set = JoinSet::new(); - for task in self.tasks { - set.spawn_blocking(|| task.run()); - } - - let mut errors = false; - - let mut handle_task_response = |execution: Execution| { - if let ExecutionStatus::Failed { .. } = execution.status { - errors = true; - } - - let report = execution.report(tty, verbose); - eprintln!("{report}"); - anyhow::Ok(()) - }; - - let kill_processes = || { - // All spawned processes are in the same process group created in main. - nix::sys::signal::killpg(Pid::from_raw(0), Signal::SIGINT) - }; - - loop { - tokio::select! { - _ = cancel_token.cancelled() => { - kill_processes()?; - return Ok(()); - } - task_response = set.join_next() => { - if let Some(result) = task_response { - handle_task_response(result?)?; - } else { - break; - } - } - } - } - - if errors { - anyhow::bail!("Some checks failed"); - } - - Ok(()) - } - - pub fn retain_with_ids(&mut self, ids: &[String]) { - self.tasks.retain(|task| ids.contains(&task.id())); - } - - pub fn retain_with_dirs(&mut self, dirs: &[PathBuf]) { - let dirs = dirs - .iter() - .map(|dir| { - dir.canonicalize() - .unwrap_or_else(|_| panic!("unable to canonicalize path {dir:?}")) - }) - .collect_vec(); - self.tasks.retain(|task| dirs.contains(&task.cwd)); - } - - pub fn retain_without_type_paths(&mut self) { - self.tasks.retain(|task| { - matches!( - task.cmd.deps().sway_artifacts, - Some(SwayArtifacts::Normal) | None - ) - }); - } -} - -#[cfg(test)] -mod tests { - // - // use std::collections::HashMap; - // - // use super::*; - // use pretty_assertions::assert_eq; - // - // #[test] - // fn selection_respected() { - // // given - // let config = vec![ - // config::TasksDescription { - // run_for_dirs: vec![PathBuf::from("some/foo"), PathBuf::from("other/zoo")], - // commands: vec![ - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "check".to_string()], - // env: None, - // run_if: None, - // }, - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "fmt".to_string()], - // env: None, - // run_if: None, - // }, - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "test".to_string()], - // env: None, - // run_if: None, - // }, - // ], - // }, - // config::TasksDescription { - // run_for_dirs: vec![PathBuf::from("some/boo")], - // commands: vec![ - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "check".to_string()], - // env: None, - // run_if: None, - // }, - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "fmt".to_string()], - // env: None, - // run_if: None, - // }, - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "test".to_string()], - // env: None, - // run_if: None, - // }, - // ], - // }, - // ]; - // - // let mut tasks = Tasks::from_task_descriptions(config, "."); - // - // use rand::seq::SliceRandom; - // let random_task = tasks.tasks.choose(&mut rand::thread_rng()).unwrap().clone(); - // - // // when - // tasks.retain_with_ids(&[random_task.id()]); - // - // // then - // assert_eq!(tasks.tasks, [random_task]); - // } - // - // #[test] - // fn workspace_root_respected() { - // // given - // let config = vec![config::TasksDescription { - // run_for_dirs: vec![PathBuf::from("some/foo")], - // commands: vec![config::Command::Custom { - // cmd: vec!["cargo".to_string(), "check".to_string()], - // env: None, - // run_if: None, - // }], - // }]; - // - // // when - // let mut tasks = Tasks::from_task_descriptions(config, "workspace"); - // - // // then - // let mut expected = [Task { - // cwd: PathBuf::from("workspace/some/foo"), - // cmd: Command::Custom { - // program: "cargo".to_string(), - // args: vec!["check".to_string()], - // env: vec![], - // }, - // }]; - // - // expected.sort(); - // tasks.tasks.sort(); - // assert_eq!(tasks.tasks, expected); - // } - // - // #[test] - // fn ignore_if_in_dir_respected() { - // // given - // let config = vec![config::TasksDescription { - // run_for_dirs: vec![PathBuf::from("boom/some/foo")], - // commands: vec![config::Command::Custom { - // cmd: vec!["cargo".to_string(), "check".to_string()], - // env: None, - // run_if: Some(RunIf::CwdDoesntEndWith(vec!["some/foo".to_string()])), - // }], - // }]; - // - // // when - // let tasks = Tasks::from_task_descriptions(config, "."); - // - // // then - // assert_eq!(tasks.tasks, []); - // } -} diff --git a/scripts/checks/src/tasks.rs b/scripts/checks/src/tasks.rs new file mode 100644 index 000000000..abceb01b8 --- /dev/null +++ b/scripts/checks/src/tasks.rs @@ -0,0 +1,289 @@ +use std::{collections::BTreeSet, fmt::Display, path::PathBuf}; + +use itertools::Itertools; +use nix::{sys::signal::Signal, unistd::Pid, NixPath}; +use sha2::Digest; +use tokio::task::JoinSet; +use tokio_util::sync::CancellationToken; + +pub mod command; +pub mod deps; +pub mod report; +pub mod task; + +use self::deps::SwayArtifacts; + +fn short_sha256(input: &str) -> String { + let mut hasher = sha2::Sha256::default(); + hasher.update(input.as_bytes()); + hex::encode(&hasher.finalize()[..8]) +} + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct Tasks { + tasks: BTreeSet, + workspace_root: PathBuf, +} + +impl Display for Tasks { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for task in &self.tasks { + writeln!(f, "{}", task)?; + } + Ok(()) + } +} + +impl Tasks { + pub fn new(tasks: BTreeSet, workspace_root: PathBuf) -> Self { + Self { + tasks, + workspace_root: workspace_root.canonicalize().unwrap(), + } + } + + pub fn ci_jobs(&self) -> Vec { + self.tasks + .iter() + .sorted_by_key(|task| task.cwd.clone()) + .group_by(|task| task.cwd.clone()) + .into_iter() + .flat_map(|(cwd, tasks)| { + let (tasks_requiring_type_paths, normal_tasks): (Vec<_>, Vec<_>) = + tasks.into_iter().partition(|task| { + task.cmd + .deps() + .sway_artifacts + .is_some_and(|dep| matches!(dep, SwayArtifacts::TypePaths)) + }); + + let type_paths_deps = tasks_requiring_type_paths + .iter() + .map(|ty| ty.cmd.deps()) + .reduce(|acc, next| acc + next); + + let normal_deps = normal_tasks + .iter() + .map(|ty| ty.cmd.deps()) + .reduce(|acc, next| acc + next); + + let mut jobs = vec![]; + + let relative_path = cwd.strip_prefix(&self.workspace_root).unwrap_or_else(|_| { + panic!("{cwd:?} is a prefix of {}", self.workspace_root.display()) + }); + + let name = if relative_path.is_empty() { + "workspace".to_string() + } else { + format!("{}", relative_path.display()) + }; + + if let Some(deps) = type_paths_deps { + jobs.push(deps::CiJob::new( + deps, + &tasks_requiring_type_paths, + name.clone(), + )); + } + + if let Some(deps) = normal_deps { + jobs.push(deps::CiJob::new(deps, &normal_tasks, name)); + } + + jobs + }) + .collect() + } + + pub async fn run( + self, + tty: bool, + verbose: bool, + cancel_token: CancellationToken, + ) -> anyhow::Result<()> { + let mut set = JoinSet::new(); + for task in self.tasks { + set.spawn_blocking(|| task.run()); + } + + let mut errors = false; + + let mut handle_task_response = |execution: report::Report| { + if let report::Status::Failed { .. } = execution.status { + errors = true; + } + + let report = execution.report(tty, verbose); + eprintln!("{report}"); + anyhow::Ok(()) + }; + + let kill_processes = || { + // All spawned processes are in the same process group created in main. + nix::sys::signal::killpg(Pid::from_raw(0), Signal::SIGINT) + }; + + loop { + tokio::select! { + _ = cancel_token.cancelled() => { + kill_processes()?; + return Ok(()); + } + task_response = set.join_next() => { + if let Some(result) = task_response { + handle_task_response(result?)?; + } else { + break; + } + } + } + } + + if errors { + anyhow::bail!("Some checks failed"); + } + + Ok(()) + } + + pub fn retain_with_ids(&mut self, ids: &[String]) { + self.tasks.retain(|task| ids.contains(&task.id())); + } + + pub fn retain_with_dirs(&mut self, dirs: &[PathBuf]) { + let dirs = dirs + .iter() + .map(|dir| { + dir.canonicalize() + .unwrap_or_else(|_| panic!("unable to canonicalize path {dir:?}")) + }) + .collect_vec(); + self.tasks.retain(|task| dirs.contains(&task.cwd)); + } + + pub fn retain_without_type_paths(&mut self) { + self.tasks.retain(|task| { + matches!( + task.cmd.deps().sway_artifacts, + Some(SwayArtifacts::Normal) | None + ) + }); + } +} + +#[cfg(test)] +mod tests { + // + // use std::collections::HashMap; + // + // use super::*; + // use pretty_assertions::assert_eq; + // + // #[test] + // fn selection_respected() { + // // given + // let config = vec![ + // config::TasksDescription { + // run_for_dirs: vec![PathBuf::from("some/foo"), PathBuf::from("other/zoo")], + // commands: vec![ + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "check".to_string()], + // env: None, + // run_if: None, + // }, + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "fmt".to_string()], + // env: None, + // run_if: None, + // }, + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "test".to_string()], + // env: None, + // run_if: None, + // }, + // ], + // }, + // config::TasksDescription { + // run_for_dirs: vec![PathBuf::from("some/boo")], + // commands: vec![ + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "check".to_string()], + // env: None, + // run_if: None, + // }, + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "fmt".to_string()], + // env: None, + // run_if: None, + // }, + // config::Command::Custom { + // cmd: vec!["cargo".to_string(), "test".to_string()], + // env: None, + // run_if: None, + // }, + // ], + // }, + // ]; + // + // let mut tasks = Tasks::from_task_descriptions(config, "."); + // + // use rand::seq::SliceRandom; + // let random_task = tasks.tasks.choose(&mut rand::thread_rng()).unwrap().clone(); + // + // // when + // tasks.retain_with_ids(&[random_task.id()]); + // + // // then + // assert_eq!(tasks.tasks, [random_task]); + // } + // + // #[test] + // fn workspace_root_respected() { + // // given + // let config = vec![config::TasksDescription { + // run_for_dirs: vec![PathBuf::from("some/foo")], + // commands: vec![config::Command::Custom { + // cmd: vec!["cargo".to_string(), "check".to_string()], + // env: None, + // run_if: None, + // }], + // }]; + // + // // when + // let mut tasks = Tasks::from_task_descriptions(config, "workspace"); + // + // // then + // let mut expected = [Task { + // cwd: PathBuf::from("workspace/some/foo"), + // cmd: Command::Custom { + // program: "cargo".to_string(), + // args: vec!["check".to_string()], + // env: vec![], + // }, + // }]; + // + // expected.sort(); + // tasks.tasks.sort(); + // assert_eq!(tasks.tasks, expected); + // } + // + // #[test] + // fn ignore_if_in_dir_respected() { + // // given + // let config = vec![config::TasksDescription { + // run_for_dirs: vec![PathBuf::from("boom/some/foo")], + // commands: vec![config::Command::Custom { + // cmd: vec!["cargo".to_string(), "check".to_string()], + // env: None, + // run_if: Some(RunIf::CwdDoesntEndWith(vec!["some/foo".to_string()])), + // }], + // }]; + // + // // when + // let tasks = Tasks::from_task_descriptions(config, "."); + // + // // then + // assert_eq!(tasks.tasks, []); + // } +} diff --git a/scripts/checks/src/tasks/command.rs b/scripts/checks/src/tasks/command.rs new file mode 100644 index 000000000..af3179ad7 --- /dev/null +++ b/scripts/checks/src/tasks/command.rs @@ -0,0 +1,45 @@ +use super::deps::CiDeps; +use itertools::Itertools; +use std::fmt::Display; + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum Command { + Custom { + program: String, + args: Vec, + env: Vec<(String, String)>, + deps: CiDeps, + }, + MdCheck, +} + +impl Command { + pub fn deps(&self) -> CiDeps { + match self { + Command::Custom { deps, .. } => deps.clone(), + Command::MdCheck => CiDeps::default(), + } + } +} + +impl Display for Command { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Command::Custom { + program, args, env, .. + } => { + let args = args.iter().join(" "); + if env.is_empty() { + write!(f, "{program} {args}") + } else { + let env = env + .iter() + .map(|(key, value)| format!("{key}='{value}'")) + .join(" "); + write!(f, "{env} {program} {args}") + } + } + Command::MdCheck { .. } => write!(f, "MdCheck"), + } + } +} diff --git a/scripts/checks/src/tasks/deps.rs b/scripts/checks/src/tasks/deps.rs new file mode 100644 index 000000000..eff06f32c --- /dev/null +++ b/scripts/checks/src/tasks/deps.rs @@ -0,0 +1,140 @@ +use std::collections::BTreeSet; + +use super::short_sha256; + +use super::task::Task; + +use itertools::Itertools; +use serde::Serialize; +use serde::Serializer; + +#[derive(Debug, Clone, serde::Serialize, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum SwayArtifacts { + TypePaths, + Normal, +} + +#[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct RustDeps { + pub nightly: bool, + #[serde(serialize_with = "comma_separated")] + pub components: BTreeSet, +} + +pub(crate) fn comma_separated( + components: &BTreeSet, + serializer: S, +) -> Result +where + S: Serializer, +{ + let components = components.iter().join(","); + components.serialize(serializer) +} + +#[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct CargoDeps { + pub hack: bool, + pub nextest: bool, + pub machete: bool, + pub udeps: bool, +} + +impl std::ops::Add for CargoDeps { + type Output = Self; + fn add(mut self, other: Self) -> Self { + self += other; + self + } +} + +impl std::ops::AddAssign for CargoDeps { + fn add_assign(&mut self, other: Self) { + self.hack |= other.hack; + self.nextest |= other.nextest; + self.machete |= other.machete; + } +} + +#[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct CiDeps { + pub fuel_core_binary: bool, + #[serde(skip_serializing_if = "Option::is_none")] + pub rust: Option, + pub wasm: bool, + pub cargo: CargoDeps, + pub typos_cli: bool, + #[serde(skip_serializing_if = "Option::is_none")] + pub sway_artifacts: Option, +} + +impl std::ops::Add for CiDeps { + type Output = Self; + fn add(mut self, other: Self) -> Self { + self += other; + self + } +} + +impl std::ops::AddAssign for CiDeps { + fn add_assign(&mut self, other: Self) { + self.fuel_core_binary |= other.fuel_core_binary; + + let rust = match (self.rust.take(), other.rust) { + (Some(mut self_rust), Some(other_rust)) => { + self_rust.nightly |= other_rust.nightly; + self_rust.components = self_rust + .components + .union(&other_rust.components) + .cloned() + .collect(); + Some(self_rust) + } + (Some(self_rust), None) => Some(self_rust), + (None, Some(other_rust)) => Some(other_rust), + (None, None) => None, + }; + self.rust = rust; + + self.wasm |= other.wasm; + self.cargo += other.cargo; + self.typos_cli |= other.typos_cli; + + let sway_artifacts = match (self.sway_artifacts, other.sway_artifacts) { + (Some(self_sway), Some(other_sway)) => { + if self_sway != other_sway { + panic!( + "Deps cannot be unified. Cannot have type paths and normal artifacts at once! {self_sway:?} != {other_sway:?}", + ); + } + Some(self_sway) + } + (Some(self_sway), None) => Some(self_sway), + (None, Some(other_sway)) => Some(other_sway), + (None, None) => None, + }; + self.sway_artifacts = sway_artifacts; + } +} + +#[derive(Debug, Clone, serde::Serialize)] +pub struct CiJob { + pub(crate) deps: CiDeps, + // Comma separated task ids + pub(crate) task_ids: String, + pub(crate) name: String, + // Must not contain commas, rust-cache complains + pub(crate) cache_key: String, +} + +impl CiJob { + pub fn new(deps: CiDeps, tasks: &[&Task], name: String) -> Self { + let ids = tasks.iter().map(|t| t.id()).join(","); + Self { + deps, + cache_key: short_sha256(&ids), + task_ids: ids, + name, + } + } +} diff --git a/scripts/checks/src/tasks/report.rs b/scripts/checks/src/tasks/report.rs new file mode 100644 index 000000000..e7a1596da --- /dev/null +++ b/scripts/checks/src/tasks/report.rs @@ -0,0 +1,50 @@ +use colored::Colorize; + +#[derive(Debug, Clone)] +pub struct Report { + pub cmd_desc: String, + pub status: Status, +} + +impl From for Status { + fn from(value: std::io::Error) -> Self { + Self::Failed { + reason: value.to_string(), + } + } +} + +impl From for Status { + fn from(value: anyhow::Error) -> Self { + Self::Failed { + reason: value.to_string(), + } + } +} + +#[derive(Debug, Clone)] +pub enum Status { + Success { out: String }, + Failed { reason: String }, +} + +impl Report { + pub fn report(&self, tty: bool, verbose: bool) -> String { + let status = match &self.status { + Status::Failed { reason } => { + let err = if tty { "error".red() } else { "error".normal() }; + format!("{err}\n{reason}") + } + Status::Success { out } => { + let ok = if tty { "ok".green() } else { "ok".normal() }; + if verbose { + format!("{ok}\n{out}") + } else { + ok.to_string() + } + } + }; + + format!("{} ... {status}", self.cmd_desc) + } +} diff --git a/scripts/checks/src/tasks/task.rs b/scripts/checks/src/tasks/task.rs new file mode 100644 index 000000000..ea07a1b05 --- /dev/null +++ b/scripts/checks/src/tasks/task.rs @@ -0,0 +1,90 @@ +use crate::md_check; + +use super::command::Command; +use super::report::{Report, Status}; +use super::short_sha256; + +use std::fmt::Display; + +use std::path::PathBuf; + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Task { + pub cwd: PathBuf, + pub cmd: Command, +} + +impl Display for Task { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Task {}, dir: {:?}, {}", self.id(), self.cwd, self.cmd) + } +} + +impl Task { + pub fn id(&self) -> String { + short_sha256(&format!("{:?}", self)) + } + + pub fn run(self) -> Report { + match &self.cmd { + Command::Custom { + program, args, env, .. + } => self.run_custom(program, args.iter().map(|e| e.as_str()), env), + Command::MdCheck => self.run_md_check(), + } + } + + pub(crate) fn run_md_check(&self) -> Report { + let status = if let Err(e) = md_check::run(&self.cwd) { + e.into() + } else { + Status::Success { + out: "".to_string(), + } + }; + + self.report(status) + } + + pub(crate) fn run_custom<'a, F>( + &self, + program: &str, + args: F, + env: &[(String, String)], + ) -> Report + where + F: IntoIterator, + { + let mut cmd = duct::cmd(program, args) + .stderr_to_stdout() + .dir(&self.cwd) + .stdin_null() + .stdout_capture() + .unchecked(); + + for (key, value) in env { + cmd = cmd.env(key, value); + } + + let output = match cmd.run() { + Ok(output) => output, + Err(err) => return self.report(err), + }; + + let decoded = String::from_utf8_lossy(&output.stdout).into_owned(); + let status = if output.status.success() { + Status::Success { out: decoded } + } else { + Status::Failed { reason: decoded } + }; + + self.report(status) + } + + pub(crate) fn report(&self, status: impl Into) -> Report { + Report { + cmd_desc: self.to_string(), + status: status.into(), + } + } +} diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 0655d14aa..9d5acb126 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -1,12 +1,12 @@ use nix::unistd::Pid; -use crate::{cli, description, task::Tasks}; +use crate::{cli, config, tasks::Tasks}; pub fn generate_tasks(cli: &cli::Cli) -> Tasks { let mut tasks = match cli.flavor { - cli::Flavor::Normal => description::normal(cli.root.clone()), - cli::Flavor::HackFeatures => description::hack_features(cli.root.clone()), - cli::Flavor::HackDeps => description::hack_deps(cli.root.clone()), + cli::Flavor::Normal => config::normal(cli.root.clone()), + cli::Flavor::HackFeatures => config::hack_features(cli.root.clone()), + cli::Flavor::HackDeps => config::hack_deps(cli.root.clone()), }; if let Some(ids) = &cli.only_tasks_with_ids { From 156286fb62ea80399d38406bb084d6576942c97a Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Mon, 20 May 2024 12:40:32 +0200 Subject: [PATCH 60/70] reorg --- scripts/checks/src/customize.rs | 59 +++++++++ scripts/checks/src/main.rs | 7 +- scripts/checks/src/tasks.rs | 121 +----------------- .../src/{config.rs => tasks/builder.rs} | 105 +++++++-------- scripts/checks/src/util.rs | 24 ---- 5 files changed, 111 insertions(+), 205 deletions(-) create mode 100644 scripts/checks/src/customize.rs rename scripts/checks/src/{config.rs => tasks/builder.rs} (85%) diff --git a/scripts/checks/src/customize.rs b/scripts/checks/src/customize.rs new file mode 100644 index 000000000..d5950edf9 --- /dev/null +++ b/scripts/checks/src/customize.rs @@ -0,0 +1,59 @@ +use crate::tasks::builder::TasksBuilder; +use crate::tasks::deps::CiJob; +use crate::{cli, tasks::Tasks}; +use std::path::PathBuf; + +pub fn ci_jobs(workspace_root: PathBuf) -> Vec { + let tasks = normal(workspace_root); + tasks.ci_jobs() +} + +pub fn choose_tasks(cli: &cli::Cli) -> Tasks { + let mut tasks = match cli.flavor { + cli::Flavor::Normal => normal(cli.root.clone()), + cli::Flavor::HackFeatures => hack_features(cli.root.clone()), + cli::Flavor::HackDeps => hack_deps(cli.root.clone()), + }; + + if let Some(ids) = &cli.only_tasks_with_ids { + tasks.retain_with_ids(ids); + } + + if let Some(dirs) = &cli.only_tasks_in_dir { + tasks.retain_with_dirs(dirs); + } + + if !cli.sway_type_paths { + tasks.retain_without_type_paths(); + } + + tasks +} + +fn normal(workspace_root: PathBuf) -> Tasks { + let mut builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); + + builder.common(); + builder.e2e_specific(); + builder.wasm_specific(); + builder.workspace_level(); + + builder.build() +} + +fn hack_features(workspace_root: PathBuf) -> Tasks { + let mut builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); + + builder.hack_features_common(); + builder.hack_features_e2e(); + + builder.build() +} + +fn hack_deps(workspace_root: PathBuf) -> Tasks { + let mut builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); + + builder.hack_deps_common(); + + builder.build() +} diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index b7c95af9d..10d44d976 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -2,7 +2,7 @@ use std::io::IsTerminal; use clap::Parser; mod cli; -mod config; +mod customize; mod md_check; mod tasks; mod util; @@ -13,15 +13,14 @@ async fn main() -> anyhow::Result<()> { util::configure_child_process_cleanup()?; if cli.print_ci_jobs_desc { - let tasks = config::normal(cli.root.clone()); - let jobs = tasks.ci_jobs(); + let jobs = customize::ci_jobs(cli.root.clone()); // Json used because the CI needs it as such let jsonified = serde_json::to_string_pretty(&jobs)?; println!("{jsonified}"); return Ok(()); } - let tasks = util::generate_tasks(&cli); + let tasks = customize::choose_tasks(&cli); if cli.list_tasks { println!("{tasks}"); diff --git a/scripts/checks/src/tasks.rs b/scripts/checks/src/tasks.rs index abceb01b8..9fd808b5f 100644 --- a/scripts/checks/src/tasks.rs +++ b/scripts/checks/src/tasks.rs @@ -6,6 +6,7 @@ use sha2::Digest; use tokio::task::JoinSet; use tokio_util::sync::CancellationToken; +pub mod builder; pub mod command; pub mod deps; pub mod report; @@ -35,9 +36,9 @@ impl Display for Tasks { } impl Tasks { - pub fn new(tasks: BTreeSet, workspace_root: PathBuf) -> Self { + pub fn new(tasks: impl IntoIterator, workspace_root: PathBuf) -> Self { Self { - tasks, + tasks: BTreeSet::from_iter(tasks), workspace_root: workspace_root.canonicalize().unwrap(), } } @@ -171,119 +172,3 @@ impl Tasks { }); } } - -#[cfg(test)] -mod tests { - // - // use std::collections::HashMap; - // - // use super::*; - // use pretty_assertions::assert_eq; - // - // #[test] - // fn selection_respected() { - // // given - // let config = vec![ - // config::TasksDescription { - // run_for_dirs: vec![PathBuf::from("some/foo"), PathBuf::from("other/zoo")], - // commands: vec![ - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "check".to_string()], - // env: None, - // run_if: None, - // }, - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "fmt".to_string()], - // env: None, - // run_if: None, - // }, - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "test".to_string()], - // env: None, - // run_if: None, - // }, - // ], - // }, - // config::TasksDescription { - // run_for_dirs: vec![PathBuf::from("some/boo")], - // commands: vec![ - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "check".to_string()], - // env: None, - // run_if: None, - // }, - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "fmt".to_string()], - // env: None, - // run_if: None, - // }, - // config::Command::Custom { - // cmd: vec!["cargo".to_string(), "test".to_string()], - // env: None, - // run_if: None, - // }, - // ], - // }, - // ]; - // - // let mut tasks = Tasks::from_task_descriptions(config, "."); - // - // use rand::seq::SliceRandom; - // let random_task = tasks.tasks.choose(&mut rand::thread_rng()).unwrap().clone(); - // - // // when - // tasks.retain_with_ids(&[random_task.id()]); - // - // // then - // assert_eq!(tasks.tasks, [random_task]); - // } - // - // #[test] - // fn workspace_root_respected() { - // // given - // let config = vec![config::TasksDescription { - // run_for_dirs: vec![PathBuf::from("some/foo")], - // commands: vec![config::Command::Custom { - // cmd: vec!["cargo".to_string(), "check".to_string()], - // env: None, - // run_if: None, - // }], - // }]; - // - // // when - // let mut tasks = Tasks::from_task_descriptions(config, "workspace"); - // - // // then - // let mut expected = [Task { - // cwd: PathBuf::from("workspace/some/foo"), - // cmd: Command::Custom { - // program: "cargo".to_string(), - // args: vec!["check".to_string()], - // env: vec![], - // }, - // }]; - // - // expected.sort(); - // tasks.tasks.sort(); - // assert_eq!(tasks.tasks, expected); - // } - // - // #[test] - // fn ignore_if_in_dir_respected() { - // // given - // let config = vec![config::TasksDescription { - // run_for_dirs: vec![PathBuf::from("boom/some/foo")], - // commands: vec![config::Command::Custom { - // cmd: vec!["cargo".to_string(), "check".to_string()], - // env: None, - // run_if: Some(RunIf::CwdDoesntEndWith(vec!["some/foo".to_string()])), - // }], - // }]; - // - // // when - // let tasks = Tasks::from_task_descriptions(config, "."); - // - // // then - // assert_eq!(tasks.tasks, []); - // } -} diff --git a/scripts/checks/src/config.rs b/scripts/checks/src/tasks/builder.rs similarity index 85% rename from scripts/checks/src/config.rs rename to scripts/checks/src/tasks/builder.rs index f084ac24a..4822cb9c1 100644 --- a/scripts/checks/src/config.rs +++ b/scripts/checks/src/tasks/builder.rs @@ -1,4 +1,3 @@ -use itertools::chain; use itertools::Itertools; use std::collections::BTreeSet; use std::path::Path; @@ -10,56 +9,24 @@ use crate::tasks::deps::CiDeps; use crate::tasks::deps::SwayArtifacts; use crate::tasks::task::Task; use crate::tasks::Tasks; - -pub fn normal(workspace_root: PathBuf) -> Tasks { - let builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); - Tasks::new(builder.local(), workspace_root) -} - -pub fn hack_features(workspace_root: PathBuf) -> Tasks { - let builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); - - Tasks::new(builder.hack_features(), workspace_root) -} - -pub fn hack_deps(workspace_root: PathBuf) -> Tasks { - let builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); - Tasks::new(builder.hack_deps(), workspace_root) -} - -struct TasksBuilder { +pub struct TasksBuilder { workspace: PathBuf, rust_flags: Vec, + tasks: Vec, } impl TasksBuilder { - fn new(workspace: PathBuf, rust_flags: &[&str]) -> Self { + pub fn new(workspace: PathBuf, rust_flags: &[&str]) -> Self { Self { workspace, rust_flags: rust_flags.iter().map(|s| s.to_string()).collect(), + tasks: vec![], } } - pub fn local(&self) -> BTreeSet { - chain!( - self.common(), - self.e2e_specific(), - self.wasm_specific(), - self.workspace_level(), - ) - .collect() - } - - pub fn hack_features(&self) -> BTreeSet { - chain!(self.hack_features_common(), self.hack_features_e2e()).collect() - } - - pub fn hack_deps(&self) -> BTreeSet { - self.hack_deps_common().collect() - } - - fn common(&self) -> impl Iterator + '_ { - self.all_workspace_members(None) + pub fn common(&mut self) { + let tasks = self + .all_workspace_members(None) .into_iter() .flat_map(|member| { let deps = { @@ -85,6 +52,7 @@ impl TasksBuilder { }, ), ]; + // e2e ignored because we have to control the features carefully (e.g. rocksdb, test-type-paths, etc) if member != self.workspace_path("e2e") { let cmd = @@ -122,10 +90,13 @@ impl TasksBuilder { cmd, }) }) + .collect_vec(); + + self.tasks.extend(tasks); } - fn e2e_specific(&self) -> impl Iterator + '_ { - [ + pub fn e2e_specific(&mut self) { + let tasks = [ self.cargo_nextest( "run --features default,fuel-core-lib,test-type-paths", CiDeps { @@ -159,12 +130,13 @@ impl TasksBuilder { .map(|cmd| Task { cwd: self.workspace_path("e2e"), cmd, - }) - .into_iter() + }); + + self.tasks.extend(tasks); } - fn wasm_specific(&self) -> impl Iterator { - std::iter::once(Task { + pub fn wasm_specific(&mut self) { + let task = Task { cwd: self.workspace_path("wasm-tests"), cmd: self.custom( "wasm-pack", @@ -174,11 +146,12 @@ impl TasksBuilder { ..Default::default() }, ), - }) + }; + self.tasks.push(task) } - fn workspace_level(&self) -> impl Iterator { - [ + pub fn workspace_level(&mut self) { + let tasks = [ Command::MdCheck, self.custom( "cargo-machete", @@ -210,13 +183,15 @@ impl TasksBuilder { .map(|cmd| Task { cwd: self.workspace_path("."), cmd, - }) - .into_iter() + }); + + self.tasks.extend(tasks); } - fn hack_features_common(&self) -> Vec { + pub fn hack_features_common(&mut self) { let ignore = self.workspace_path("e2e"); - self.all_workspace_members(Some(&ignore)) + let tasks = self + .all_workspace_members(Some(&ignore)) .into_iter() .flat_map(|member| { [ @@ -229,11 +204,13 @@ impl TasksBuilder { cmd, }) }) - .collect() + .collect_vec(); + + self.tasks.extend(tasks); } - fn hack_features_e2e(&self) -> Vec { - [ + pub fn hack_features_e2e(&mut self) { + let tasks = [ self.cargo_hack( "--feature-powerset check --tests", CiDeps { @@ -253,12 +230,15 @@ impl TasksBuilder { cwd: self.workspace_path("e2e"), cmd, }) - .to_vec() + .to_vec(); + + self.tasks.extend(tasks); } - fn hack_deps_common(&self) -> impl Iterator + '_ { + pub fn hack_deps_common(&mut self) { let ignore = self.workspace_path("e2e"); - self.all_workspace_members(Some(&ignore)) + let tasks = self + .all_workspace_members(Some(&ignore)) .into_iter() .flat_map(|member| { let deps = CiDeps { @@ -282,6 +262,9 @@ impl TasksBuilder { cmd, }) }) + .collect_vec(); + + self.tasks.extend(tasks); } fn cargo_fmt(&self, cmd: impl Into, mut deps: CiDeps) -> Command { @@ -385,6 +368,10 @@ impl TasksBuilder { .filter(|member| ignore.map_or(true, |ignore| !member.starts_with(ignore))) .collect() } + + pub fn build(self) -> Tasks { + Tasks::new(self.tasks, self.workspace) + } } fn parse_cmd(prepend: &str, string: &str) -> Vec { diff --git a/scripts/checks/src/util.rs b/scripts/checks/src/util.rs index 9d5acb126..6b0f3fc52 100644 --- a/scripts/checks/src/util.rs +++ b/scripts/checks/src/util.rs @@ -1,29 +1,5 @@ use nix::unistd::Pid; -use crate::{cli, config, tasks::Tasks}; - -pub fn generate_tasks(cli: &cli::Cli) -> Tasks { - let mut tasks = match cli.flavor { - cli::Flavor::Normal => config::normal(cli.root.clone()), - cli::Flavor::HackFeatures => config::hack_features(cli.root.clone()), - cli::Flavor::HackDeps => config::hack_deps(cli.root.clone()), - }; - - if let Some(ids) = &cli.only_tasks_with_ids { - tasks.retain_with_ids(ids); - } - - if let Some(dirs) = &cli.only_tasks_in_dir { - tasks.retain_with_dirs(dirs); - } - - if !cli.sway_type_paths { - tasks.retain_without_type_paths(); - } - - tasks -} - pub fn watch_for_cancel(cancel_token: tokio_util::sync::CancellationToken) { tokio::task::spawn(async move { tokio::signal::ctrl_c().await.unwrap(); From e77e15f51843743edc8d37069872b6db72ddafa5 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Mon, 20 May 2024 13:01:54 +0200 Subject: [PATCH 61/70] clippy --- scripts/checks/build.rs | 8 +- scripts/checks/src/cli.rs | 10 +-- scripts/checks/src/customize.rs | 13 ++-- scripts/checks/src/md_check.rs | 71 +++++++++--------- scripts/checks/src/tasks.rs | 17 +++-- scripts/checks/src/tasks/builder.rs | 110 ++++++++++++++-------------- scripts/checks/src/tasks/command.rs | 14 ++-- scripts/checks/src/tasks/deps.rs | 36 ++++----- scripts/checks/src/tasks/task.rs | 16 ++-- 9 files changed, 146 insertions(+), 149 deletions(-) diff --git a/scripts/checks/build.rs b/scripts/checks/build.rs index 82e583265..d251cd69b 100644 --- a/scripts/checks/build.rs +++ b/scripts/checks/build.rs @@ -6,11 +6,11 @@ fn main() { let path = path .canonicalize() - .unwrap_or_else(|_| panic!("Path not found: {:?}", path)); + .unwrap_or_else(|_| panic!("Path not found: {path:?}")); let members = workspace_members(&path); - generate_rust_code(members); + generate_rust_code(&members); println!("cargo:rerun-if-changed={}", path.display()); } @@ -30,10 +30,10 @@ fn workspace_members(cargo: &Path) -> Vec { cargo_toml.workspace.members } -fn generate_rust_code(members: Vec) { +fn generate_rust_code(members: &[String]) { let members = members .iter() - .map(|member| format!("{:?}", member)) + .map(|member| format!("{member:?}")) .join(",\n"); let code = format!("static WORKSPACE_MEMBERS: &[&str] = &[{members}];"); diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index ea868c82c..6345738d3 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -5,7 +5,7 @@ use clap::{arg, Parser, ValueEnum}; #[derive(Parser)] #[command(about = "Runs pre-release checks deemed to heavy for CI.")] pub struct Cli { - ///Comma separated list of tasks to run + /// Comma separated list of tasks to run #[arg( short, long, @@ -44,13 +44,13 @@ pub struct Cli { #[arg(short, long, default_value = "false")] pub verbose: bool, - /// If ran as a binary from elsewhere the workspace_root needs to be pointed to where the + /// If ran as a binary from elsewhere the [`Self::root`] needs to be pointed to where the /// project workspace root is #[arg(short, long = "root", required = true)] pub root: PathBuf, } -#[derive(Debug, Copy, Clone, ValueEnum, PartialEq)] +#[derive(Debug, Copy, Clone, ValueEnum)] pub enum Flavor { Normal, HackFeatures, @@ -97,7 +97,7 @@ mod tests { let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then - assert_eq!(cli.flavor, Flavor::HackFeatures); + assert!(matches!(cli.flavor, Flavor::HackFeatures)); } #[test] @@ -109,6 +109,6 @@ mod tests { let cli = Cli::try_parse_from(cli.split_whitespace()).unwrap(); // then - assert_eq!(cli.flavor, Flavor::Normal); + assert!(matches!(cli.flavor, Flavor::Normal)); } } diff --git a/scripts/checks/src/customize.rs b/scripts/checks/src/customize.rs index d5950edf9..4805ab2db 100644 --- a/scripts/checks/src/customize.rs +++ b/scripts/checks/src/customize.rs @@ -1,6 +1,7 @@ -use crate::tasks::builder::TasksBuilder; -use crate::tasks::deps::CiJob; -use crate::{cli, tasks::Tasks}; +use crate::{ + cli, + tasks::{builder::Builder, deps::CiJob, Tasks}, +}; use std::path::PathBuf; pub fn ci_jobs(workspace_root: PathBuf) -> Vec { @@ -31,7 +32,7 @@ pub fn choose_tasks(cli: &cli::Cli) -> Tasks { } fn normal(workspace_root: PathBuf) -> Tasks { - let mut builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); + let mut builder = Builder::new(workspace_root, &["-Dwarnings"]); builder.common(); builder.e2e_specific(); @@ -42,7 +43,7 @@ fn normal(workspace_root: PathBuf) -> Tasks { } fn hack_features(workspace_root: PathBuf) -> Tasks { - let mut builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); + let mut builder = Builder::new(workspace_root, &["-Dwarnings"]); builder.hack_features_common(); builder.hack_features_e2e(); @@ -51,7 +52,7 @@ fn hack_features(workspace_root: PathBuf) -> Tasks { } fn hack_deps(workspace_root: PathBuf) -> Tasks { - let mut builder = TasksBuilder::new(workspace_root.clone(), &["-Dwarnings"]); + let mut builder = Builder::new(workspace_root, &["-Dwarnings"]); builder.hack_deps_common(); diff --git a/scripts/checks/src/md_check.rs b/scripts/checks/src/md_check.rs index 70b08b0ab..8822fb18c 100644 --- a/scripts/checks/src/md_check.rs +++ b/scripts/checks/src/md_check.rs @@ -1,5 +1,4 @@ -use anyhow::anyhow; -use anyhow::{bail, Error}; +use anyhow::{anyhow, bail, Error}; use duct::cmd; use itertools::{chain, Itertools}; use regex::Regex; @@ -12,16 +11,16 @@ pub fn run(dir: &Path) -> anyhow::Result<(), Error> { let sources = ["packages", "e2e", "examples"].map(|source| dir.join(source)); let text_w_anchors = search_for_pattern("ANCHOR", &sources)?; let (starts, ends) = extract_starts_and_ends(&text_w_anchors)?; - let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); + let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, &ends); let text_mentioning_include = search_for_pattern("{{#include", &[dir.join("docs")])?; - let (includes, include_path_errors) = parse_includes(text_mentioning_include); - let (include_errors, additional_warnings) = validate_includes(includes, valid_anchors); + let (includes, include_path_errors) = parse_includes(&text_mentioning_include); + let (include_errors, additional_warnings) = validate_includes(includes, &valid_anchors); let text_with_md_files = search_for_pattern(".md", &[dir.join("./docs/src/SUMMARY.md")])?; - let md_files_in_summary = parse_md_files(text_with_md_files, dir.join("./docs/src/")); + let md_files_in_summary = parse_md_files(&text_with_md_files, dir.join("./docs/src/")); let md_files_in_src = find_files("*.md", dir.join("./docs/src/"), "SUMMARY.md")?; - let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); + let md_files_errors = validate_md_files(&md_files_in_summary, &md_files_in_src); let errors = chain!( additional_warnings, @@ -33,7 +32,7 @@ pub fn run(dir: &Path) -> anyhow::Result<(), Error> { .collect_vec(); if !errors.is_empty() { - let err_str = errors.iter().map(|err| err.to_string()).join("\n"); + let err_str = errors.iter().map(ToString::to_string).join("\n"); bail!("Errors: {err_str}") } @@ -42,7 +41,7 @@ pub fn run(dir: &Path) -> anyhow::Result<(), Error> { pub fn validate_includes( includes: Vec, - valid_anchors: Vec, + valid_anchors: &[Anchor], ) -> (Vec, Vec) { let (pairs, errors): (Vec<_>, Vec<_>) = includes .into_iter() @@ -52,12 +51,14 @@ pub fn validate_includes( anchor.file == include.anchor_file && anchor.name == include.anchor_name }); - match maybe_anchor.take() { - Some(anchor) => Ok(anchor.clone()), - None => Err(anyhow!( - "No anchor available to satisfy include {include:?}" - )), - } + maybe_anchor.take().map_or_else( + || { + Err(anyhow!( + "No anchor available to satisfy include {include:?}" + )) + }, + |anchor| Ok(anchor.clone()), + ) }) .partition_result(); @@ -78,11 +79,11 @@ pub fn validate_includes( pub struct Include { pub anchor_name: String, pub anchor_file: PathBuf, - pub include_file: PathBuf, + pub file: PathBuf, pub line_no: usize, } -pub fn parse_includes(text_w_includes: String) -> (Vec, Vec) { +pub fn parse_includes(text_w_includes: &str) -> (Vec, Vec) { let apply_regex = |regex: Regex| { let (includes, errors): (Vec<_>, Vec<_>) = text_w_includes .lines() @@ -105,7 +106,7 @@ pub fn parse_includes(text_w_includes: String) -> (Vec, Vec) { Ok(Include { anchor_name, anchor_file, - include_file, + file: include_file, line_no, }) }) @@ -119,7 +120,7 @@ pub fn parse_includes(text_w_includes: String) -> (Vec, Vec) { ) } -pub fn filter_valid_anchors(starts: Vec, ends: Vec) -> (Vec, Vec) { +pub fn filter_valid_anchors(starts: Vec, ends: &[Anchor]) -> (Vec, Vec) { let find_anchor_end_by_name = |anchor_name: &str, file: &Path| { ends.iter() .filter(|el| el.name == *anchor_name && el.file == file) @@ -135,16 +136,13 @@ pub fn filter_valid_anchors(starts: Vec, ends: Vec) -> (Vec Err(anyhow!("Found too many matching anchor ends for anchor: {start:?}. The matching ends are: {multiple_ends:?}")), }?; - match check_validity_of_anchor_pair(&begin, &end) { - None => Ok((begin, end)), - Some(err) => { - let err_msg = err.to_string(); - Err(anyhow!("{err_msg}")) - } - } + check_validity_of_anchor_pair(&begin, &end).map_or_else(|| Ok((begin, end)), |err| { + let err_msg = err.to_string(); + Err(anyhow!("{err_msg}")) + }) }).partition_result(); - let additional_errors = filter_unused_ends(&ends, &pairs) + let additional_errors = filter_unused_ends(ends, &pairs) .into_iter() .map(|unused_end| anyhow!("Missing anchor start for {unused_end:?}")) .collect::>(); @@ -209,7 +207,7 @@ pub fn extract_starts_and_ends( Ok((begins, ends)) } -pub fn parse_md_files(text_w_files: String, path: impl AsRef) -> HashSet { +pub fn parse_md_files(text_w_files: &str, path: impl AsRef) -> HashSet { let regex = Regex::new(r"\((.*\.md)\)").expect("could not construct regex"); text_w_files @@ -224,10 +222,7 @@ pub fn parse_md_files(text_w_files: String, path: impl AsRef) -> HashSet

, - md_files_in_src: String, -) -> Vec { +pub fn validate_md_files(md_files_summary: &HashSet, md_files_in_src: &str) -> Vec { md_files_in_src .lines() .filter_map(|file| { @@ -304,7 +299,7 @@ mod tests { let data = search_for_pattern("ANCHOR", &[path.to_owned()])?; let (starts, ends) = extract_starts_and_ends(&data)?; - let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, ends); + let (valid_anchors, anchor_errors) = filter_valid_anchors(starts, &ends); let valid_vec = TestEnum::Anchor(valid_anchors.clone()); let anchor_err_vec = TestEnum::Errors(anchor_errors); @@ -335,7 +330,7 @@ mod tests { let text_mentioning_include = search_for_pattern("{{#include", &[path.to_owned()])?; - let (includes, include_path_errors) = parse_includes(text_mentioning_include); + let (includes, include_path_errors) = parse_includes(&text_mentioning_include); let includes_vec = TestEnum::Include(includes.clone()); @@ -345,7 +340,7 @@ mod tests { &includes_vec, "test_with_more_forward_slashes" )); - assert!(contains_any(&includes_vec, "")); //Check the file include without anchor + assert!(contains_any(&includes_vec, "")); // Check the file include without anchor let include_path_errors = TestEnum::Errors(include_path_errors); @@ -359,7 +354,7 @@ mod tests { "test_anchor_data3.rs\" when canonicalized gives error Os { code: 2, kind: NotFound" )); - let (include_errors, _) = validate_includes(includes, valid_anchors); + let (include_errors, _) = validate_includes(includes, &valid_anchors); let include_err_vec = TestEnum::Errors(include_errors); @@ -377,9 +372,9 @@ mod tests { let path = test_data.path(); let text_with_md_files = search_for_pattern(".md", &[path.join("docs/src/SUMMARY.md")])?; - let md_files_in_summary = parse_md_files(text_with_md_files, path.join("docs/src/")); + let md_files_in_summary = parse_md_files(&text_with_md_files, path.join("docs/src/")); let md_files_in_src = find_files("*.md", path.join("docs/src/"), "SUMMARY.md")?; - let md_files_errors = validate_md_files(md_files_in_summary, md_files_in_src); + let md_files_errors = validate_md_files(&md_files_in_summary, &md_files_in_src); let error_msg = md_files_errors.first().unwrap().to_string(); diff --git a/scripts/checks/src/tasks.rs b/scripts/checks/src/tasks.rs index 9fd808b5f..442c55f31 100644 --- a/scripts/checks/src/tasks.rs +++ b/scripts/checks/src/tasks.rs @@ -1,4 +1,8 @@ -use std::{collections::BTreeSet, fmt::Display, path::PathBuf}; +use std::{ + collections::BTreeSet, + fmt::Display, + path::{Path, PathBuf}, +}; use itertools::Itertools; use nix::{sys::signal::Signal, unistd::Pid, NixPath}; @@ -29,17 +33,20 @@ pub struct Tasks { impl Display for Tasks { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { for task in &self.tasks { - writeln!(f, "{}", task)?; + writeln!(f, "{task}")?; } Ok(()) } } impl Tasks { - pub fn new(tasks: impl IntoIterator, workspace_root: PathBuf) -> Self { + pub fn new( + tasks: impl IntoIterator, + workspace_root: impl AsRef, + ) -> Self { Self { tasks: BTreeSet::from_iter(tasks), - workspace_root: workspace_root.canonicalize().unwrap(), + workspace_root: workspace_root.as_ref().canonicalize().unwrap(), } } @@ -127,7 +134,7 @@ impl Tasks { loop { tokio::select! { - _ = cancel_token.cancelled() => { + () = cancel_token.cancelled() => { kill_processes()?; return Ok(()); } diff --git a/scripts/checks/src/tasks/builder.rs b/scripts/checks/src/tasks/builder.rs index 4822cb9c1..e2e722252 100644 --- a/scripts/checks/src/tasks/builder.rs +++ b/scripts/checks/src/tasks/builder.rs @@ -1,25 +1,27 @@ use itertools::Itertools; -use std::collections::BTreeSet; -use std::path::Path; -use std::path::PathBuf; - -use crate::tasks::command::Command; -use crate::tasks::deps; -use crate::tasks::deps::CiDeps; -use crate::tasks::deps::SwayArtifacts; -use crate::tasks::task::Task; -use crate::tasks::Tasks; -pub struct TasksBuilder { +use std::{ + collections::BTreeSet, + path::{Path, PathBuf}, +}; + +use crate::tasks::{ + command::Command, + deps, + deps::{All, SwayArtifacts}, + task::Task, + Tasks, +}; +pub struct Builder { workspace: PathBuf, rust_flags: Vec, tasks: Vec, } -impl TasksBuilder { +impl Builder { pub fn new(workspace: PathBuf, rust_flags: &[&str]) -> Self { Self { workspace, - rust_flags: rust_flags.iter().map(|s| s.to_string()).collect(), + rust_flags: rust_flags.iter().map(|s| (*s).to_string()).collect(), tasks: vec![], } } @@ -35,7 +37,7 @@ impl TasksBuilder { .starts_with(self.workspace_path("examples")) .then_some(SwayArtifacts::Normal); - CiDeps { + All { sway_artifacts, ..Default::default() } @@ -43,10 +45,10 @@ impl TasksBuilder { let mut commands = vec![ self.cargo_fmt("--verbose --check", deps.clone()), - self.custom( + Self::custom( "typos", "", - &CiDeps { + &All { typos_cli: true, ..deps.clone() }, @@ -80,7 +82,7 @@ impl TasksBuilder { let cmd = self.cargo( "doc --document-private-items", Some(("RUSTDOCFLAGS", "-Dwarnings")), - deps.clone(), + deps, ); commands.push(cmd); } @@ -99,21 +101,21 @@ impl TasksBuilder { let tasks = [ self.cargo_nextest( "run --features default,fuel-core-lib,test-type-paths", - CiDeps { + All { sway_artifacts: Some(deps::SwayArtifacts::TypePaths), ..Default::default() }, ), self.cargo_nextest( "run --features default,fuel-core-lib", - CiDeps { + All { sway_artifacts: Some(deps::SwayArtifacts::Normal), ..Default::default() }, ), self.cargo_nextest( "run --features default,test-type-paths", - CiDeps { + All { fuel_core_binary: true, sway_artifacts: Some(deps::SwayArtifacts::TypePaths), ..Default::default() @@ -121,7 +123,7 @@ impl TasksBuilder { ), self.cargo_clippy( "--all-targets --no-deps --features default,test-type-paths", - CiDeps { + All { sway_artifacts: Some(deps::SwayArtifacts::TypePaths), ..Default::default() }, @@ -138,26 +140,26 @@ impl TasksBuilder { pub fn wasm_specific(&mut self) { let task = Task { cwd: self.workspace_path("wasm-tests"), - cmd: self.custom( + cmd: Self::custom( "wasm-pack", "test --node", - &CiDeps { + &All { wasm: true, ..Default::default() }, ), }; - self.tasks.push(task) + self.tasks.push(task); } pub fn workspace_level(&mut self) { let tasks = [ Command::MdCheck, - self.custom( + Self::custom( "cargo-machete", "--skip-target-dir", - &CiDeps { - cargo: deps::CargoDeps { + &All { + cargo: deps::Cargo { machete: true, ..Default::default() }, @@ -166,15 +168,15 @@ impl TasksBuilder { ), self.cargo_clippy( "--workspace --all-features", - CiDeps { + All { sway_artifacts: Some(deps::SwayArtifacts::Normal), ..Default::default() }, ), - self.custom( + Self::custom( "typos", "", - &CiDeps { + &All { typos_cli: true, ..Default::default() }, @@ -195,8 +197,8 @@ impl TasksBuilder { .into_iter() .flat_map(|member| { [ - self.cargo_hack("--feature-powerset check", CiDeps::default()), - self.cargo_hack("--feature-powerset check --tests", CiDeps::default()), + self.cargo_hack("--feature-powerset check", All::default()), + self.cargo_hack("--feature-powerset check --tests", All::default()), ] .into_iter() .map(move |cmd| Task { @@ -213,14 +215,14 @@ impl TasksBuilder { let tasks = [ self.cargo_hack( "--feature-powerset check --tests", - CiDeps { + All { sway_artifacts: Some(deps::SwayArtifacts::TypePaths), ..Default::default() }, ), self.cargo_hack( "--feature-powerset --exclude-features test-type-paths check --tests", - CiDeps { + All { sway_artifacts: Some(deps::SwayArtifacts::Normal), ..Default::default() }, @@ -241,12 +243,12 @@ impl TasksBuilder { .all_workspace_members(Some(&ignore)) .into_iter() .flat_map(|member| { - let deps = CiDeps { - cargo: deps::CargoDeps { + let deps = All { + cargo: deps::Cargo { udeps: true, ..Default::default() }, - rust: Some(deps::RustDeps { + rust: Some(deps::Rust { nightly: true, ..Default::default() }), @@ -267,9 +269,9 @@ impl TasksBuilder { self.tasks.extend(tasks); } - fn cargo_fmt(&self, cmd: impl Into, mut deps: CiDeps) -> Command { - deps += CiDeps { - rust: Some(deps::RustDeps { + fn cargo_fmt(&self, cmd: impl Into, mut deps: All) -> Command { + deps += All { + rust: Some(deps::Rust { components: BTreeSet::from_iter(["rustfmt".to_string()]), ..Default::default() }), @@ -281,9 +283,9 @@ impl TasksBuilder { self.cargo(cmd, None, deps) } - fn cargo_clippy(&self, cmd: impl Into, mut deps: CiDeps) -> Command { - deps += CiDeps { - rust: Some(deps::RustDeps { + fn cargo_clippy(&self, cmd: impl Into, mut deps: All) -> Command { + deps += All { + rust: Some(deps::Rust { components: BTreeSet::from_iter(["clippy".to_string()]), ..Default::default() }), @@ -294,9 +296,9 @@ impl TasksBuilder { self.cargo(cmd, None, deps) } - fn cargo_hack(&self, cmd: impl Into, mut deps: CiDeps) -> Command { - deps += CiDeps { - cargo: deps::CargoDeps { + fn cargo_hack(&self, cmd: impl Into, mut deps: All) -> Command { + deps += All { + cargo: deps::Cargo { hack: true, ..Default::default() }, @@ -307,9 +309,9 @@ impl TasksBuilder { self.cargo(cmd, None, deps) } - fn cargo_nextest(&self, cmd: impl Into, mut deps: CiDeps) -> Command { - deps += CiDeps { - cargo: deps::CargoDeps { + fn cargo_nextest(&self, cmd: impl Into, mut deps: All) -> Command { + deps += All { + cargo: deps::Cargo { nextest: true, ..Default::default() }, @@ -321,7 +323,7 @@ impl TasksBuilder { self.cargo(cmd, None, deps) } - fn cargo(&self, cmd: impl Into, env: Option<(&str, &str)>, deps: CiDeps) -> Command { + fn cargo(&self, cmd: impl Into, env: Option<(&str, &str)>, deps: All) -> Command { let envs = { let flags = self.rust_flags.iter().join(" "); let mut envs = vec![("RUSTFLAGS".to_owned(), flags)]; @@ -342,11 +344,11 @@ impl TasksBuilder { program: "cargo".to_string(), args: parse_cmd(nightly, &cmd.into()), env: envs, - deps: deps.clone(), + deps, } } - fn custom(&self, program: &str, args: &str, deps: &CiDeps) -> Command { + fn custom(program: &str, args: &str, deps: &All) -> Command { Command::Custom { program: program.to_owned(), args: parse_cmd("", args), @@ -358,7 +360,7 @@ impl TasksBuilder { fn workspace_path(&self, path: &str) -> PathBuf { let path = self.workspace.join(path); path.canonicalize() - .unwrap_or_else(|_| panic!("Path not found: {:?}", path)) + .unwrap_or_else(|_| panic!("Path not found: {path:?}")) } fn all_workspace_members(&self, ignore: Option<&Path>) -> Vec { @@ -375,7 +377,7 @@ impl TasksBuilder { } fn parse_cmd(prepend: &str, string: &str) -> Vec { - let parts = string.split_whitespace().map(|s| s.to_string()).collect(); + let parts = string.split_whitespace().map(ToString::to_string).collect(); if prepend.is_empty() { parts } else { diff --git a/scripts/checks/src/tasks/command.rs b/scripts/checks/src/tasks/command.rs index af3179ad7..2e700547c 100644 --- a/scripts/checks/src/tasks/command.rs +++ b/scripts/checks/src/tasks/command.rs @@ -1,4 +1,4 @@ -use super::deps::CiDeps; +use super::deps::All; use itertools::Itertools; use std::fmt::Display; @@ -8,16 +8,16 @@ pub enum Command { program: String, args: Vec, env: Vec<(String, String)>, - deps: CiDeps, + deps: All, }, MdCheck, } impl Command { - pub fn deps(&self) -> CiDeps { + pub fn deps(&self) -> All { match self { - Command::Custom { deps, .. } => deps.clone(), - Command::MdCheck => CiDeps::default(), + Self::Custom { deps, .. } => deps.clone(), + Self::MdCheck => All::default(), } } } @@ -25,7 +25,7 @@ impl Command { impl Display for Command { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Command::Custom { + Self::Custom { program, args, env, .. } => { let args = args.iter().join(" "); @@ -39,7 +39,7 @@ impl Display for Command { write!(f, "{env} {program} {args}") } } - Command::MdCheck { .. } => write!(f, "MdCheck"), + Self::MdCheck { .. } => write!(f, "MdCheck"), } } } diff --git a/scripts/checks/src/tasks/deps.rs b/scripts/checks/src/tasks/deps.rs index eff06f32c..b5c5eac6a 100644 --- a/scripts/checks/src/tasks/deps.rs +++ b/scripts/checks/src/tasks/deps.rs @@ -5,8 +5,7 @@ use super::short_sha256; use super::task::Task; use itertools::Itertools; -use serde::Serialize; -use serde::Serializer; +use serde::{Serialize, Serializer}; #[derive(Debug, Clone, serde::Serialize, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum SwayArtifacts { @@ -15,16 +14,13 @@ pub enum SwayArtifacts { } #[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct RustDeps { +pub struct Rust { pub nightly: bool, #[serde(serialize_with = "comma_separated")] pub components: BTreeSet, } -pub(crate) fn comma_separated( - components: &BTreeSet, - serializer: S, -) -> Result +fn comma_separated(components: &BTreeSet, serializer: S) -> Result where S: Serializer, { @@ -33,14 +29,14 @@ where } #[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct CargoDeps { +pub struct Cargo { pub hack: bool, pub nextest: bool, pub machete: bool, pub udeps: bool, } -impl std::ops::Add for CargoDeps { +impl std::ops::Add for Cargo { type Output = Self; fn add(mut self, other: Self) -> Self { self += other; @@ -48,7 +44,7 @@ impl std::ops::Add for CargoDeps { } } -impl std::ops::AddAssign for CargoDeps { +impl std::ops::AddAssign for Cargo { fn add_assign(&mut self, other: Self) { self.hack |= other.hack; self.nextest |= other.nextest; @@ -57,18 +53,18 @@ impl std::ops::AddAssign for CargoDeps { } #[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct CiDeps { +pub struct All { pub fuel_core_binary: bool, #[serde(skip_serializing_if = "Option::is_none")] - pub rust: Option, + pub rust: Option, pub wasm: bool, - pub cargo: CargoDeps, + pub cargo: Cargo, pub typos_cli: bool, #[serde(skip_serializing_if = "Option::is_none")] pub sway_artifacts: Option, } -impl std::ops::Add for CiDeps { +impl std::ops::Add for All { type Output = Self; fn add(mut self, other: Self) -> Self { self += other; @@ -76,7 +72,7 @@ impl std::ops::Add for CiDeps { } } -impl std::ops::AddAssign for CiDeps { +impl std::ops::AddAssign for All { fn add_assign(&mut self, other: Self) { self.fuel_core_binary |= other.fuel_core_binary; @@ -102,11 +98,7 @@ impl std::ops::AddAssign for CiDeps { let sway_artifacts = match (self.sway_artifacts, other.sway_artifacts) { (Some(self_sway), Some(other_sway)) => { - if self_sway != other_sway { - panic!( - "Deps cannot be unified. Cannot have type paths and normal artifacts at once! {self_sway:?} != {other_sway:?}", - ); - } + assert_ne!(self_sway,other_sway, "Deps cannot be unified. Cannot have type paths and normal artifacts at once! {self_sway:?} != {other_sway:?}"); Some(self_sway) } (Some(self_sway), None) => Some(self_sway), @@ -119,7 +111,7 @@ impl std::ops::AddAssign for CiDeps { #[derive(Debug, Clone, serde::Serialize)] pub struct CiJob { - pub(crate) deps: CiDeps, + pub(crate) deps: All, // Comma separated task ids pub(crate) task_ids: String, pub(crate) name: String, @@ -128,7 +120,7 @@ pub struct CiJob { } impl CiJob { - pub fn new(deps: CiDeps, tasks: &[&Task], name: String) -> Self { + pub fn new(deps: All, tasks: &[&Task], name: String) -> Self { let ids = tasks.iter().map(|t| t.id()).join(","); Self { deps, diff --git a/scripts/checks/src/tasks/task.rs b/scripts/checks/src/tasks/task.rs index ea07a1b05..44ebf72a2 100644 --- a/scripts/checks/src/tasks/task.rs +++ b/scripts/checks/src/tasks/task.rs @@ -1,8 +1,10 @@ use crate::md_check; -use super::command::Command; -use super::report::{Report, Status}; -use super::short_sha256; +use super::{ + command::Command, + report::{Report, Status}, + short_sha256, +}; use std::fmt::Display; @@ -22,14 +24,14 @@ impl Display for Task { impl Task { pub fn id(&self) -> String { - short_sha256(&format!("{:?}", self)) + short_sha256(&format!("{self:?}")) } pub fn run(self) -> Report { match &self.cmd { Command::Custom { program, args, env, .. - } => self.run_custom(program, args.iter().map(|e| e.as_str()), env), + } => self.run_custom(program, args.iter().map(String::as_str), env), Command::MdCheck => self.run_md_check(), } } @@ -38,9 +40,7 @@ impl Task { let status = if let Err(e) = md_check::run(&self.cwd) { e.into() } else { - Status::Success { - out: "".to_string(), - } + Status::Success { out: String::new() } }; self.report(status) From f783d88bdabc8c96d7451be25c94f8114351132e Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Mon, 20 May 2024 13:22:44 +0200 Subject: [PATCH 62/70] fix unification --- scripts/checks/src/tasks/deps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checks/src/tasks/deps.rs b/scripts/checks/src/tasks/deps.rs index b5c5eac6a..74b0fe72d 100644 --- a/scripts/checks/src/tasks/deps.rs +++ b/scripts/checks/src/tasks/deps.rs @@ -98,7 +98,7 @@ impl std::ops::AddAssign for All { let sway_artifacts = match (self.sway_artifacts, other.sway_artifacts) { (Some(self_sway), Some(other_sway)) => { - assert_ne!(self_sway,other_sway, "Deps cannot be unified. Cannot have type paths and normal artifacts at once! {self_sway:?} != {other_sway:?}"); + assert_eq!(self_sway, other_sway, "Deps cannot be unified. Cannot have type paths and normal artifacts at once! {self_sway:?} != {other_sway:?}"); Some(self_sway) } (Some(self_sway), None) => Some(self_sway), From b2087d7289fe818e52d865e8e323f777bb3f010b Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 21 May 2024 20:10:56 +0200 Subject: [PATCH 63/70] self review --- packages/fuels-core/src/lib.rs | 4 -- packages/fuels-programs/src/lib.rs | 5 -- scripts/checks/src/cli.rs | 6 +- scripts/checks/src/main.rs | 2 +- scripts/checks/src/tasks.rs | 99 +++++++++++++++-------------- scripts/checks/src/tasks/builder.rs | 77 +++++++++++----------- scripts/checks/src/tasks/ci_job.rs | 21 ++++++ scripts/checks/src/tasks/deps.rs | 26 +------- scripts/checks/src/tasks/task.rs | 3 + 9 files changed, 118 insertions(+), 125 deletions(-) create mode 100644 scripts/checks/src/tasks/ci_job.rs diff --git a/packages/fuels-core/src/lib.rs b/packages/fuels-core/src/lib.rs index 4563e8695..4fe809b03 100644 --- a/packages/fuels-core/src/lib.rs +++ b/packages/fuels-core/src/lib.rs @@ -22,7 +22,3 @@ impl Configurables { } } } -#[cfg(test)] -mod tests { - use fuels_core as _; -} diff --git a/packages/fuels-programs/src/lib.rs b/packages/fuels-programs/src/lib.rs index ce48e6eca..899358e94 100644 --- a/packages/fuels-programs/src/lib.rs +++ b/packages/fuels-programs/src/lib.rs @@ -8,8 +8,3 @@ pub mod receipt_parser; pub mod script_calls; #[cfg(feature = "std")] mod submit_response; - -#[cfg(test)] -mod tests { - use fuels_programs as _; -} diff --git a/scripts/checks/src/cli.rs b/scripts/checks/src/cli.rs index 6345738d3..54415e6dc 100644 --- a/scripts/checks/src/cli.rs +++ b/scripts/checks/src/cli.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use clap::{arg, Parser, ValueEnum}; #[derive(Parser)] -#[command(about = "Runs pre-release checks deemed to heavy for CI.")] +#[command(about = "Runs various checks. Some part of the CI, others meant to be run manually.")] pub struct Cli { /// Comma separated list of tasks to run #[arg( @@ -19,9 +19,9 @@ pub struct Cli { #[arg(short, long, action)] pub list_tasks: bool, - /// Print json job description to be used for the CI + /// Print the JSON object used as configuration for the CI matrix step #[arg(long)] - pub print_ci_jobs_desc: bool, + pub dump_ci_config: bool, /// Only run tasks in the given directories #[arg( diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index 10d44d976..e7bd9abb6 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -12,7 +12,7 @@ async fn main() -> anyhow::Result<()> { let cli = cli::Cli::parse(); util::configure_child_process_cleanup()?; - if cli.print_ci_jobs_desc { + if cli.dump_ci_config { let jobs = customize::ci_jobs(cli.root.clone()); // Json used because the CI needs it as such let jsonified = serde_json::to_string_pretty(&jobs)?; diff --git a/scripts/checks/src/tasks.rs b/scripts/checks/src/tasks.rs index 442c55f31..329c167f5 100644 --- a/scripts/checks/src/tasks.rs +++ b/scripts/checks/src/tasks.rs @@ -11,13 +11,12 @@ use tokio::task::JoinSet; use tokio_util::sync::CancellationToken; pub mod builder; +pub mod ci_job; pub mod command; pub mod deps; pub mod report; pub mod task; -use self::deps::SwayArtifacts; - fn short_sha256(input: &str) -> String { let mut hasher = sha2::Sha256::default(); hasher.update(input.as_bytes()); @@ -50,56 +49,27 @@ impl Tasks { } } - pub fn ci_jobs(&self) -> Vec { + pub fn ci_jobs(&self) -> Vec { + // tasks grouped by dir to reuse compilation artifacts and shorten CI time self.tasks .iter() .sorted_by_key(|task| task.cwd.clone()) .group_by(|task| task.cwd.clone()) .into_iter() .flat_map(|(cwd, tasks)| { - let (tasks_requiring_type_paths, normal_tasks): (Vec<_>, Vec<_>) = - tasks.into_iter().partition(|task| { - task.cmd - .deps() - .sway_artifacts - .is_some_and(|dep| matches!(dep, SwayArtifacts::TypePaths)) - }); - - let type_paths_deps = tasks_requiring_type_paths - .iter() - .map(|ty| ty.cmd.deps()) - .reduce(|acc, next| acc + next); - - let normal_deps = normal_tasks - .iter() - .map(|ty| ty.cmd.deps()) - .reduce(|acc, next| acc + next); - - let mut jobs = vec![]; - - let relative_path = cwd.strip_prefix(&self.workspace_root).unwrap_or_else(|_| { - panic!("{cwd:?} is a prefix of {}", self.workspace_root.display()) - }); - - let name = if relative_path.is_empty() { - "workspace".to_string() - } else { - format!("{}", relative_path.display()) - }; - - if let Some(deps) = type_paths_deps { - jobs.push(deps::CiJob::new( - deps, - &tasks_requiring_type_paths, - name.clone(), - )); - } - - if let Some(deps) = normal_deps { - jobs.push(deps::CiJob::new(deps, &normal_tasks, name)); - } - - jobs + let (tasks_requiring_type_paths, normal_tasks) = + separate_out_type_path_tasks(tasks); + + let name = self.create_job_name(cwd); + + // You cannot have type paths and not have them in the same job, so they need to be + // separate jobs. + [ + job_with_merged_deps(&tasks_requiring_type_paths, name.clone()), + job_with_merged_deps(&normal_tasks, name), + ] + .into_iter() + .flatten() }) .collect() } @@ -174,8 +144,43 @@ impl Tasks { self.tasks.retain(|task| { matches!( task.cmd.deps().sway_artifacts, - Some(SwayArtifacts::Normal) | None + Some(deps::Sway::Normal) | None ) }); } + + fn create_job_name(&self, cwd: PathBuf) -> String { + // So we don't take up much real estate printing the full canonicalized path + let relative_path = cwd.strip_prefix(&self.workspace_root).unwrap_or_else(|_| { + panic!( + "expected {cwd:?} to be a prefix of {}", + self.workspace_root.display() + ) + }); + + if relative_path.is_empty() { + "workspace".to_string() + } else { + format!("{}", relative_path.display()) + } + } +} + +fn job_with_merged_deps(tasks: &[&task::Task], name: String) -> Option { + tasks + .iter() + .map(|ty| ty.cmd.deps()) + .reduce(|acc, next| acc + next) + .map(|dep| CiJob::new(dep, tasks, name)) +} + +fn separate_out_type_path_tasks<'a>( + tasks: impl IntoIterator, +) -> (Vec<&'a task::Task>, Vec<&'a task::Task>) { + tasks.into_iter().partition(|task| { + task.cmd + .deps() + .sway_artifacts + .is_some_and(|dep| matches!(dep, deps::Sway::TypePaths)) + }) } diff --git a/scripts/checks/src/tasks/builder.rs b/scripts/checks/src/tasks/builder.rs index e2e722252..dc42fba92 100644 --- a/scripts/checks/src/tasks/builder.rs +++ b/scripts/checks/src/tasks/builder.rs @@ -4,13 +4,7 @@ use std::{ path::{Path, PathBuf}, }; -use crate::tasks::{ - command::Command, - deps, - deps::{All, SwayArtifacts}, - task::Task, - Tasks, -}; +use crate::tasks::{command::Command, deps, task::Task, Tasks}; pub struct Builder { workspace: PathBuf, rust_flags: Vec, @@ -27,17 +21,18 @@ impl Builder { } pub fn common(&mut self) { + let exclude = None; let tasks = self - .all_workspace_members(None) + .all_workspace_members(exclude) .into_iter() .flat_map(|member| { let deps = { // Some examples run abigen! on sway projects in e2e let sway_artifacts = member .starts_with(self.workspace_path("examples")) - .then_some(SwayArtifacts::Normal); + .then_some(deps::Sway::Normal); - All { + deps::All { sway_artifacts, ..Default::default() } @@ -48,7 +43,7 @@ impl Builder { Self::custom( "typos", "", - &All { + &deps::All { typos_cli: true, ..deps.clone() }, @@ -101,30 +96,30 @@ impl Builder { let tasks = [ self.cargo_nextest( "run --features default,fuel-core-lib,test-type-paths", - All { - sway_artifacts: Some(deps::SwayArtifacts::TypePaths), + deps::All { + sway_artifacts: Some(deps::Sway::TypePaths), ..Default::default() }, ), self.cargo_nextest( "run --features default,fuel-core-lib", - All { - sway_artifacts: Some(deps::SwayArtifacts::Normal), + deps::All { + sway_artifacts: Some(deps::Sway::Normal), ..Default::default() }, ), self.cargo_nextest( "run --features default,test-type-paths", - All { + deps::All { fuel_core_binary: true, - sway_artifacts: Some(deps::SwayArtifacts::TypePaths), + sway_artifacts: Some(deps::Sway::TypePaths), ..Default::default() }, ), self.cargo_clippy( "--all-targets --no-deps --features default,test-type-paths", - All { - sway_artifacts: Some(deps::SwayArtifacts::TypePaths), + deps::All { + sway_artifacts: Some(deps::Sway::TypePaths), ..Default::default() }, ), @@ -143,7 +138,7 @@ impl Builder { cmd: Self::custom( "wasm-pack", "test --node", - &All { + &deps::All { wasm: true, ..Default::default() }, @@ -158,7 +153,7 @@ impl Builder { Self::custom( "cargo-machete", "--skip-target-dir", - &All { + &deps::All { cargo: deps::Cargo { machete: true, ..Default::default() @@ -168,15 +163,15 @@ impl Builder { ), self.cargo_clippy( "--workspace --all-features", - All { - sway_artifacts: Some(deps::SwayArtifacts::Normal), + deps::All { + sway_artifacts: Some(deps::Sway::Normal), ..Default::default() }, ), Self::custom( "typos", "", - &All { + &deps::All { typos_cli: true, ..Default::default() }, @@ -197,8 +192,8 @@ impl Builder { .into_iter() .flat_map(|member| { [ - self.cargo_hack("--feature-powerset check", All::default()), - self.cargo_hack("--feature-powerset check --tests", All::default()), + self.cargo_hack("--feature-powerset check", deps::All::default()), + self.cargo_hack("--feature-powerset check --tests", deps::All::default()), ] .into_iter() .map(move |cmd| Task { @@ -215,15 +210,15 @@ impl Builder { let tasks = [ self.cargo_hack( "--feature-powerset check --tests", - All { - sway_artifacts: Some(deps::SwayArtifacts::TypePaths), + deps::All { + sway_artifacts: Some(deps::Sway::TypePaths), ..Default::default() }, ), self.cargo_hack( "--feature-powerset --exclude-features test-type-paths check --tests", - All { - sway_artifacts: Some(deps::SwayArtifacts::Normal), + deps::All { + sway_artifacts: Some(deps::Sway::Normal), ..Default::default() }, ), @@ -243,7 +238,7 @@ impl Builder { .all_workspace_members(Some(&ignore)) .into_iter() .flat_map(|member| { - let deps = All { + let deps = deps::All { cargo: deps::Cargo { udeps: true, ..Default::default() @@ -269,8 +264,8 @@ impl Builder { self.tasks.extend(tasks); } - fn cargo_fmt(&self, cmd: impl Into, mut deps: All) -> Command { - deps += All { + fn cargo_fmt(&self, cmd: impl Into, mut deps: deps::All) -> Command { + deps += deps::All { rust: Some(deps::Rust { components: BTreeSet::from_iter(["rustfmt".to_string()]), ..Default::default() @@ -283,8 +278,8 @@ impl Builder { self.cargo(cmd, None, deps) } - fn cargo_clippy(&self, cmd: impl Into, mut deps: All) -> Command { - deps += All { + fn cargo_clippy(&self, cmd: impl Into, mut deps: deps::All) -> Command { + deps += deps::All { rust: Some(deps::Rust { components: BTreeSet::from_iter(["clippy".to_string()]), ..Default::default() @@ -296,8 +291,8 @@ impl Builder { self.cargo(cmd, None, deps) } - fn cargo_hack(&self, cmd: impl Into, mut deps: All) -> Command { - deps += All { + fn cargo_hack(&self, cmd: impl Into, mut deps: deps::All) -> Command { + deps += deps::All { cargo: deps::Cargo { hack: true, ..Default::default() @@ -309,8 +304,8 @@ impl Builder { self.cargo(cmd, None, deps) } - fn cargo_nextest(&self, cmd: impl Into, mut deps: All) -> Command { - deps += All { + fn cargo_nextest(&self, cmd: impl Into, mut deps: deps::All) -> Command { + deps += deps::All { cargo: deps::Cargo { nextest: true, ..Default::default() @@ -323,7 +318,7 @@ impl Builder { self.cargo(cmd, None, deps) } - fn cargo(&self, cmd: impl Into, env: Option<(&str, &str)>, deps: All) -> Command { + fn cargo(&self, cmd: impl Into, env: Option<(&str, &str)>, deps: deps::All) -> Command { let envs = { let flags = self.rust_flags.iter().join(" "); let mut envs = vec![("RUSTFLAGS".to_owned(), flags)]; @@ -348,7 +343,7 @@ impl Builder { } } - fn custom(program: &str, args: &str, deps: &All) -> Command { + fn custom(program: &str, args: &str, deps: &deps::All) -> Command { Command::Custom { program: program.to_owned(), args: parse_cmd("", args), diff --git a/scripts/checks/src/tasks/ci_job.rs b/scripts/checks/src/tasks/ci_job.rs new file mode 100644 index 000000000..406a9a7a1 --- /dev/null +++ b/scripts/checks/src/tasks/ci_job.rs @@ -0,0 +1,21 @@ +#[derive(Debug, Clone, serde::Serialize)] +pub struct CiJob { + pub(crate) deps: deps::All, + // Comma separated task ids + pub(crate) task_ids: String, + pub(crate) name: String, + // Must not contain commas, rust-cache complains + pub(crate) cache_key: String, +} + +impl CiJob { + pub fn new(deps: deps::All, tasks: &[&Task], name: String) -> Self { + let ids = tasks.iter().map(|t| t.id()).join(","); + Self { + deps, + cache_key: short_sha256(&ids), + task_ids: ids, + name, + } + } +} diff --git a/scripts/checks/src/tasks/deps.rs b/scripts/checks/src/tasks/deps.rs index 74b0fe72d..5da1de102 100644 --- a/scripts/checks/src/tasks/deps.rs +++ b/scripts/checks/src/tasks/deps.rs @@ -8,7 +8,7 @@ use itertools::Itertools; use serde::{Serialize, Serializer}; #[derive(Debug, Clone, serde::Serialize, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum SwayArtifacts { +pub enum Sway { TypePaths, Normal, } @@ -61,7 +61,7 @@ pub struct All { pub cargo: Cargo, pub typos_cli: bool, #[serde(skip_serializing_if = "Option::is_none")] - pub sway_artifacts: Option, + pub sway_artifacts: Option, } impl std::ops::Add for All { @@ -108,25 +108,3 @@ impl std::ops::AddAssign for All { self.sway_artifacts = sway_artifacts; } } - -#[derive(Debug, Clone, serde::Serialize)] -pub struct CiJob { - pub(crate) deps: All, - // Comma separated task ids - pub(crate) task_ids: String, - pub(crate) name: String, - // Must not contain commas, rust-cache complains - pub(crate) cache_key: String, -} - -impl CiJob { - pub fn new(deps: All, tasks: &[&Task], name: String) -> Self { - let ids = tasks.iter().map(|t| t.id()).join(","); - Self { - deps, - cache_key: short_sha256(&ids), - task_ids: ids, - name, - } - } -} diff --git a/scripts/checks/src/tasks/task.rs b/scripts/checks/src/tasks/task.rs index 44ebf72a2..e1b11ff82 100644 --- a/scripts/checks/src/tasks/task.rs +++ b/scripts/checks/src/tasks/task.rs @@ -1,7 +1,10 @@ +use itertools::Itertools; + use crate::md_check; use super::{ command::Command, + deps, report::{Report, Status}, short_sha256, }; From 30a0439e3789f7d480c7862578bc2d12aa86df89 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 21 May 2024 20:13:45 +0200 Subject: [PATCH 64/70] nits --- scripts/checks/src/customize.rs | 2 +- scripts/checks/src/tasks.rs | 2 ++ scripts/checks/src/tasks/ci_job.rs | 14 +++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/checks/src/customize.rs b/scripts/checks/src/customize.rs index 4805ab2db..9a664ccaf 100644 --- a/scripts/checks/src/customize.rs +++ b/scripts/checks/src/customize.rs @@ -1,6 +1,6 @@ use crate::{ cli, - tasks::{builder::Builder, deps::CiJob, Tasks}, + tasks::{builder::Builder, ci_job::CiJob, Tasks}, }; use std::path::PathBuf; diff --git a/scripts/checks/src/tasks.rs b/scripts/checks/src/tasks.rs index 329c167f5..5c0245da3 100644 --- a/scripts/checks/src/tasks.rs +++ b/scripts/checks/src/tasks.rs @@ -10,6 +10,8 @@ use sha2::Digest; use tokio::task::JoinSet; use tokio_util::sync::CancellationToken; +use self::ci_job::CiJob; + pub mod builder; pub mod ci_job; pub mod command; diff --git a/scripts/checks/src/tasks/ci_job.rs b/scripts/checks/src/tasks/ci_job.rs index 406a9a7a1..ff4f5c01d 100644 --- a/scripts/checks/src/tasks/ci_job.rs +++ b/scripts/checks/src/tasks/ci_job.rs @@ -1,11 +1,15 @@ +use itertools::Itertools; + +use super::{deps, task::Task}; + #[derive(Debug, Clone, serde::Serialize)] pub struct CiJob { - pub(crate) deps: deps::All, + deps: deps::All, // Comma separated task ids - pub(crate) task_ids: String, - pub(crate) name: String, + task_ids: String, + name: String, // Must not contain commas, rust-cache complains - pub(crate) cache_key: String, + cache_key: String, } impl CiJob { @@ -13,7 +17,7 @@ impl CiJob { let ids = tasks.iter().map(|t| t.id()).join(","); Self { deps, - cache_key: short_sha256(&ids), + cache_key: super::short_sha256(&ids), task_ids: ids, name, } From 3e3ca45e7beade7cbe900f79e09d402937b4b655 Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 21 May 2024 20:15:13 +0200 Subject: [PATCH 65/70] nits --- scripts/checks/src/tasks.rs | 4 ++-- scripts/checks/src/tasks/deps.rs | 4 ---- scripts/checks/src/tasks/task.rs | 3 --- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/scripts/checks/src/tasks.rs b/scripts/checks/src/tasks.rs index 5c0245da3..ac20c0118 100644 --- a/scripts/checks/src/tasks.rs +++ b/scripts/checks/src/tasks.rs @@ -62,7 +62,7 @@ impl Tasks { let (tasks_requiring_type_paths, normal_tasks) = separate_out_type_path_tasks(tasks); - let name = self.create_job_name(cwd); + let name = self.create_job_name(&cwd); // You cannot have type paths and not have them in the same job, so they need to be // separate jobs. @@ -151,7 +151,7 @@ impl Tasks { }); } - fn create_job_name(&self, cwd: PathBuf) -> String { + fn create_job_name(&self, cwd: &Path) -> String { // So we don't take up much real estate printing the full canonicalized path let relative_path = cwd.strip_prefix(&self.workspace_root).unwrap_or_else(|_| { panic!( diff --git a/scripts/checks/src/tasks/deps.rs b/scripts/checks/src/tasks/deps.rs index 5da1de102..d443f0fdd 100644 --- a/scripts/checks/src/tasks/deps.rs +++ b/scripts/checks/src/tasks/deps.rs @@ -1,9 +1,5 @@ use std::collections::BTreeSet; -use super::short_sha256; - -use super::task::Task; - use itertools::Itertools; use serde::{Serialize, Serializer}; diff --git a/scripts/checks/src/tasks/task.rs b/scripts/checks/src/tasks/task.rs index e1b11ff82..44ebf72a2 100644 --- a/scripts/checks/src/tasks/task.rs +++ b/scripts/checks/src/tasks/task.rs @@ -1,10 +1,7 @@ -use itertools::Itertools; - use crate::md_check; use super::{ command::Command, - deps, report::{Report, Status}, short_sha256, }; From c2d25c5afb31ad489bcd1a79b8e56dabc41857da Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 21 May 2024 20:38:30 +0200 Subject: [PATCH 66/70] fix ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ea98eda1..cdfa78a86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -113,7 +113,7 @@ jobs: run: | EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) echo "config<<$EOF" >> "$GITHUB_OUTPUT" - ./target/debug/checks -r . --print-ci-jobs-desc >> "$GITHUB_OUTPUT" + ./target/debug/checks -r . --dump-ci-config >> "$GITHUB_OUTPUT" echo "$EOF" >> "$GITHUB_OUTPUT" verify-rust-version: From 0dcc6a2c31f39b6608cb7a58498b69285270d47c Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Tue, 21 May 2024 21:26:11 +0200 Subject: [PATCH 67/70] remove debug --- .github/workflows/ci.yml | 3 -- scripts/checks/src/tasks/builder.rs | 55 ++++++++++++++++------------- scripts/checks/src/tasks/ci_job.rs | 4 +-- scripts/checks/src/tasks/command.rs | 8 ++--- scripts/checks/src/tasks/deps.rs | 6 ++-- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cdfa78a86..00f7afdac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,9 +163,6 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - - name: Debug config - run: | - echo ${{ matrix.config }} - name: Install Rust toolchain if: ${{ matrix.config.deps.rust && matrix.config.deps.rust.nightly == false }} diff --git a/scripts/checks/src/tasks/builder.rs b/scripts/checks/src/tasks/builder.rs index dc42fba92..6ac86a9ae 100644 --- a/scripts/checks/src/tasks/builder.rs +++ b/scripts/checks/src/tasks/builder.rs @@ -32,7 +32,7 @@ impl Builder { .starts_with(self.workspace_path("examples")) .then_some(deps::Sway::Normal); - deps::All { + deps::Deps { sway_artifacts, ..Default::default() } @@ -43,7 +43,7 @@ impl Builder { Self::custom( "typos", "", - &deps::All { + &deps::Deps { typos_cli: true, ..deps.clone() }, @@ -96,21 +96,21 @@ impl Builder { let tasks = [ self.cargo_nextest( "run --features default,fuel-core-lib,test-type-paths", - deps::All { + deps::Deps { sway_artifacts: Some(deps::Sway::TypePaths), ..Default::default() }, ), self.cargo_nextest( "run --features default,fuel-core-lib", - deps::All { + deps::Deps { sway_artifacts: Some(deps::Sway::Normal), ..Default::default() }, ), self.cargo_nextest( "run --features default,test-type-paths", - deps::All { + deps::Deps { fuel_core_binary: true, sway_artifacts: Some(deps::Sway::TypePaths), ..Default::default() @@ -118,7 +118,7 @@ impl Builder { ), self.cargo_clippy( "--all-targets --no-deps --features default,test-type-paths", - deps::All { + deps::Deps { sway_artifacts: Some(deps::Sway::TypePaths), ..Default::default() }, @@ -138,7 +138,7 @@ impl Builder { cmd: Self::custom( "wasm-pack", "test --node", - &deps::All { + &deps::Deps { wasm: true, ..Default::default() }, @@ -153,7 +153,7 @@ impl Builder { Self::custom( "cargo-machete", "--skip-target-dir", - &deps::All { + &deps::Deps { cargo: deps::Cargo { machete: true, ..Default::default() @@ -163,7 +163,7 @@ impl Builder { ), self.cargo_clippy( "--workspace --all-features", - deps::All { + deps::Deps { sway_artifacts: Some(deps::Sway::Normal), ..Default::default() }, @@ -171,7 +171,7 @@ impl Builder { Self::custom( "typos", "", - &deps::All { + &deps::Deps { typos_cli: true, ..Default::default() }, @@ -192,8 +192,8 @@ impl Builder { .into_iter() .flat_map(|member| { [ - self.cargo_hack("--feature-powerset check", deps::All::default()), - self.cargo_hack("--feature-powerset check --tests", deps::All::default()), + self.cargo_hack("--feature-powerset check", deps::Deps::default()), + self.cargo_hack("--feature-powerset check --tests", deps::Deps::default()), ] .into_iter() .map(move |cmd| Task { @@ -210,14 +210,14 @@ impl Builder { let tasks = [ self.cargo_hack( "--feature-powerset check --tests", - deps::All { + deps::Deps { sway_artifacts: Some(deps::Sway::TypePaths), ..Default::default() }, ), self.cargo_hack( "--feature-powerset --exclude-features test-type-paths check --tests", - deps::All { + deps::Deps { sway_artifacts: Some(deps::Sway::Normal), ..Default::default() }, @@ -238,7 +238,7 @@ impl Builder { .all_workspace_members(Some(&ignore)) .into_iter() .flat_map(|member| { - let deps = deps::All { + let deps = deps::Deps { cargo: deps::Cargo { udeps: true, ..Default::default() @@ -264,8 +264,8 @@ impl Builder { self.tasks.extend(tasks); } - fn cargo_fmt(&self, cmd: impl Into, mut deps: deps::All) -> Command { - deps += deps::All { + fn cargo_fmt(&self, cmd: impl Into, mut deps: deps::Deps) -> Command { + deps += deps::Deps { rust: Some(deps::Rust { components: BTreeSet::from_iter(["rustfmt".to_string()]), ..Default::default() @@ -278,8 +278,8 @@ impl Builder { self.cargo(cmd, None, deps) } - fn cargo_clippy(&self, cmd: impl Into, mut deps: deps::All) -> Command { - deps += deps::All { + fn cargo_clippy(&self, cmd: impl Into, mut deps: deps::Deps) -> Command { + deps += deps::Deps { rust: Some(deps::Rust { components: BTreeSet::from_iter(["clippy".to_string()]), ..Default::default() @@ -291,8 +291,8 @@ impl Builder { self.cargo(cmd, None, deps) } - fn cargo_hack(&self, cmd: impl Into, mut deps: deps::All) -> Command { - deps += deps::All { + fn cargo_hack(&self, cmd: impl Into, mut deps: deps::Deps) -> Command { + deps += deps::Deps { cargo: deps::Cargo { hack: true, ..Default::default() @@ -304,8 +304,8 @@ impl Builder { self.cargo(cmd, None, deps) } - fn cargo_nextest(&self, cmd: impl Into, mut deps: deps::All) -> Command { - deps += deps::All { + fn cargo_nextest(&self, cmd: impl Into, mut deps: deps::Deps) -> Command { + deps += deps::Deps { cargo: deps::Cargo { nextest: true, ..Default::default() @@ -318,7 +318,12 @@ impl Builder { self.cargo(cmd, None, deps) } - fn cargo(&self, cmd: impl Into, env: Option<(&str, &str)>, deps: deps::All) -> Command { + fn cargo( + &self, + cmd: impl Into, + env: Option<(&str, &str)>, + deps: deps::Deps, + ) -> Command { let envs = { let flags = self.rust_flags.iter().join(" "); let mut envs = vec![("RUSTFLAGS".to_owned(), flags)]; @@ -343,7 +348,7 @@ impl Builder { } } - fn custom(program: &str, args: &str, deps: &deps::All) -> Command { + fn custom(program: &str, args: &str, deps: &deps::Deps) -> Command { Command::Custom { program: program.to_owned(), args: parse_cmd("", args), diff --git a/scripts/checks/src/tasks/ci_job.rs b/scripts/checks/src/tasks/ci_job.rs index ff4f5c01d..4a8a0f508 100644 --- a/scripts/checks/src/tasks/ci_job.rs +++ b/scripts/checks/src/tasks/ci_job.rs @@ -4,7 +4,7 @@ use super::{deps, task::Task}; #[derive(Debug, Clone, serde::Serialize)] pub struct CiJob { - deps: deps::All, + deps: deps::Deps, // Comma separated task ids task_ids: String, name: String, @@ -13,7 +13,7 @@ pub struct CiJob { } impl CiJob { - pub fn new(deps: deps::All, tasks: &[&Task], name: String) -> Self { + pub fn new(deps: deps::Deps, tasks: &[&Task], name: String) -> Self { let ids = tasks.iter().map(|t| t.id()).join(","); Self { deps, diff --git a/scripts/checks/src/tasks/command.rs b/scripts/checks/src/tasks/command.rs index 2e700547c..ee253d88b 100644 --- a/scripts/checks/src/tasks/command.rs +++ b/scripts/checks/src/tasks/command.rs @@ -1,4 +1,4 @@ -use super::deps::All; +use crate::tasks::deps; use itertools::Itertools; use std::fmt::Display; @@ -8,16 +8,16 @@ pub enum Command { program: String, args: Vec, env: Vec<(String, String)>, - deps: All, + deps: deps::Deps, }, MdCheck, } impl Command { - pub fn deps(&self) -> All { + pub fn deps(&self) -> deps::Deps { match self { Self::Custom { deps, .. } => deps.clone(), - Self::MdCheck => All::default(), + Self::MdCheck => deps::Deps::default(), } } } diff --git a/scripts/checks/src/tasks/deps.rs b/scripts/checks/src/tasks/deps.rs index d443f0fdd..e20e23bf7 100644 --- a/scripts/checks/src/tasks/deps.rs +++ b/scripts/checks/src/tasks/deps.rs @@ -49,7 +49,7 @@ impl std::ops::AddAssign for Cargo { } #[derive(Debug, Default, Clone, serde::Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct All { +pub struct Deps { pub fuel_core_binary: bool, #[serde(skip_serializing_if = "Option::is_none")] pub rust: Option, @@ -60,7 +60,7 @@ pub struct All { pub sway_artifacts: Option, } -impl std::ops::Add for All { +impl std::ops::Add for Deps { type Output = Self; fn add(mut self, other: Self) -> Self { self += other; @@ -68,7 +68,7 @@ impl std::ops::Add for All { } } -impl std::ops::AddAssign for All { +impl std::ops::AddAssign for Deps { fn add_assign(&mut self, other: Self) { self.fuel_core_binary |= other.fuel_core_binary; From 9cba587435bc225778ff3b1dc3bd699ca659bbab Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Wed, 22 May 2024 15:45:49 +0200 Subject: [PATCH 68/70] use workspace package spec --- scripts/checks/Cargo.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index 465beb90e..c53f8e089 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "checks" -authors.workspace = true -edition.workspace = true -homepage.workspace = true -readme.workspace = true -license.workspace = true -repository.workspace = true -rust-version.workspace = true -version.workspace = true +authors = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +readme = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } publish = false build = "build.rs" From 860f228b7a171832a637120b83ae4a7646eb661e Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Wed, 22 May 2024 15:46:10 +0200 Subject: [PATCH 69/70] sort cargo --- scripts/checks/Cargo.toml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index c53f8e089..37db47e8c 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -13,26 +13,26 @@ publish = false build = "build.rs" [dependencies] -clap = { workspace = true, features = ["default", "derive"] } -tokio = { workspace = true, features = ["rt-multi-thread", "macros", "signal"] } anyhow = { workspace = true, features = ["std"] } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true, features = ["std"] } -itertools = { workspace = true, features = ["use_std"] } -tokio-util = { workspace = true } -nix = { workspace = true, features = ["process", "signal"] } +clap = { workspace = true, features = ["default", "derive"] } colored = { workspace = true } duct = { workspace = true } +hex = { workspace = true, features = ["std"] } +itertools = { workspace = true, features = ["use_std"] } +nix = { workspace = true, features = ["process", "signal"] } regex = { workspace = true, features = ["std", "unicode-perl"] } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true, features = ["std"] } sha2 = { workspace = true, features = ["std"] } -hex = { workspace = true, features = ["std"] } +tokio = { workspace = true, features = ["rt-multi-thread", "macros", "signal"] } +tokio-util = { workspace = true } [dev-dependencies] +pretty_assertions = { workspace = true, features = ["std"] } rand = { workspace = true, features = ["std", "std_rng"] } tempfile = { workspace = true } -pretty_assertions = { workspace = true, features = ["std"] } [build-dependencies] -toml = { workspace = true, features = ["parse"] } -serde = { workspace = true, features = ["derive"] } itertools = { workspace = true, features = ["use_alloc"] } +serde = { workspace = true, features = ["derive"] } +toml = { workspace = true, features = ["parse"] } From acee7847c5a9483a798e482d7c7f90b201d5158a Mon Sep 17 00:00:00 2001 From: Ahmed Sagdati Date: Wed, 22 May 2024 18:21:51 +0200 Subject: [PATCH 70/70] integrate fuel core version check --- Cargo.toml | 1 - packages/fuels-accounts/src/provider.rs | 1 + .../src/provider/supported_versions.rs | 3 +- .../fuels-accounts/src/provider/version.rs | 1 + scripts/checks/Cargo.toml | 3 + scripts/checks/build.rs | 60 +++++++++---- scripts/checks/src/custom_checks.rs | 3 + .../src/custom_checks/fuel_core_version.rs | 23 +++++ .../src/{ => custom_checks}/md_check.rs | 0 scripts/checks/src/customize.rs | 1 + scripts/checks/src/main.rs | 2 +- scripts/checks/src/tasks/builder.rs | 11 ++- scripts/checks/src/tasks/command.rs | 6 +- scripts/checks/src/tasks/task.rs | 24 ++++-- scripts/fuel-core-version/Cargo.toml | 16 ---- scripts/fuel-core-version/src/main.rs | 84 ------------------- scripts/fuel-core-version/version.rs | 1 - 17 files changed, 105 insertions(+), 135 deletions(-) create mode 100644 packages/fuels-accounts/src/provider/version.rs create mode 100644 scripts/checks/src/custom_checks.rs create mode 100644 scripts/checks/src/custom_checks/fuel_core_version.rs rename scripts/checks/src/{ => custom_checks}/md_check.rs (100%) delete mode 100644 scripts/fuel-core-version/Cargo.toml delete mode 100644 scripts/fuel-core-version/src/main.rs delete mode 100644 scripts/fuel-core-version/version.rs diff --git a/Cargo.toml b/Cargo.toml index 9d2706582..08252259d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ members = [ "packages/fuels-programs", "packages/fuels-test-helpers", "scripts/checks", - "scripts/fuel-core-version", "scripts/versions-replacer", "wasm-tests", ] diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index 761545e5e..988a0fcdc 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -3,6 +3,7 @@ use std::{collections::HashMap, fmt::Debug, net::SocketAddr}; mod retry_util; mod retryable_client; mod supported_versions; +mod version; #[cfg(feature = "coin-cache")] use std::sync::Arc; diff --git a/packages/fuels-accounts/src/provider/supported_versions.rs b/packages/fuels-accounts/src/provider/supported_versions.rs index da20a4b8f..957d91169 100644 --- a/packages/fuels-accounts/src/provider/supported_versions.rs +++ b/packages/fuels-accounts/src/provider/supported_versions.rs @@ -1,7 +1,6 @@ use semver::Version; -pub const SUPPORTED_FUEL_CORE_VERSION: Version = - include!("../../../../scripts/fuel-core-version/version.rs"); +use super::version::SUPPORTED_FUEL_CORE_VERSION; #[derive(Debug, PartialEq, Eq)] pub(crate) struct VersionCompatibility { diff --git a/packages/fuels-accounts/src/provider/version.rs b/packages/fuels-accounts/src/provider/version.rs new file mode 100644 index 000000000..bf74373d8 --- /dev/null +++ b/packages/fuels-accounts/src/provider/version.rs @@ -0,0 +1 @@ +pub(crate) const SUPPORTED_FUEL_CORE_VERSION: ::semver::Version = ::semver::Version::new(0, 26, 0); diff --git a/scripts/checks/Cargo.toml b/scripts/checks/Cargo.toml index 37db47e8c..2cd2fbcc9 100644 --- a/scripts/checks/Cargo.toml +++ b/scripts/checks/Cargo.toml @@ -13,6 +13,7 @@ publish = false build = "build.rs" [dependencies] +pretty_assertions = { workspace = true, features = ["alloc"] } anyhow = { workspace = true, features = ["std"] } clap = { workspace = true, features = ["default", "derive"] } colored = { workspace = true } @@ -26,6 +27,7 @@ serde_json = { workspace = true, features = ["std"] } sha2 = { workspace = true, features = ["std"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros", "signal"] } tokio-util = { workspace = true } +semver = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true, features = ["std"] } @@ -36,3 +38,4 @@ tempfile = { workspace = true } itertools = { workspace = true, features = ["use_alloc"] } serde = { workspace = true, features = ["derive"] } toml = { workspace = true, features = ["parse"] } +semver = { workspace = true } diff --git a/scripts/checks/build.rs b/scripts/checks/build.rs index d251cd69b..45b4d7644 100644 --- a/scripts/checks/build.rs +++ b/scripts/checks/build.rs @@ -1,5 +1,6 @@ use itertools::Itertools; -use std::path::Path; +use semver::Version; +use std::{collections::HashMap, path::Path, str::FromStr}; fn main() { let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../Cargo.toml"); @@ -8,37 +9,62 @@ fn main() { .canonicalize() .unwrap_or_else(|_| panic!("Path not found: {path:?}")); - let members = workspace_members(&path); + let cargo = workspace_cargo(&path); - generate_rust_code(&members); + let fuel_core_version = extract_fuel_core_version(&cargo); + + generate_rust_code(&cargo.workspace.members, &fuel_core_version); println!("cargo:rerun-if-changed={}", path.display()); } -fn workspace_members(cargo: &Path) -> Vec { - #[derive(Debug, Clone, serde::Deserialize)] - struct Workspace { - members: Vec, - } - #[derive(Debug, Clone, serde::Deserialize)] - struct Cargo { - workspace: Workspace, - } +fn extract_fuel_core_version(cargo: &Cargo) -> Version { + let fuel_core = cargo.workspace.dependencies.get("fuel-core").expect("fuel-core to be present in the workspace Cargo.toml so that we may use its version when doing compatibility checks in fuels-accounts"); + let version_str = fuel_core + .version + .clone() + .expect("fuel-core dep in workspace Cargo.toml to have `version` field set"); + + Version::from_str(&version_str).expect("fuel-core version to be a valid semver version") +} +fn workspace_cargo(cargo: &Path) -> Cargo { let data = std::fs::read_to_string(cargo).unwrap(); - let cargo_toml: Cargo = toml::from_str(&data).unwrap(); - cargo_toml.workspace.members + toml::from_str(&data).unwrap() } -fn generate_rust_code(members: &[String]) { +fn generate_rust_code(members: &[String], fuel_core_version: &Version) { let members = members .iter() .map(|member| format!("{member:?}")) .join(",\n"); - let code = format!("static WORKSPACE_MEMBERS: &[&str] = &[{members}];"); + let members_code = + format!("#[allow(dead_code)] static WORKSPACE_MEMBERS: &[&str] = &[{members}];"); + let version_code = { + let major = fuel_core_version.major; + let minor = fuel_core_version.minor; + let patch = fuel_core_version.patch; + format!("#[allow(dead_code)] static FUEL_CORE_VERSION: ::semver::Version = ::semver::Version::new({major}, {minor}, {patch});") + }; + let code = format!("{}\n{}", members_code, version_code); let out_dir = std::env::var("OUT_DIR").unwrap(); - let dest_path = Path::new(&out_dir).join("workspace_members.rs"); + let dest_path = Path::new(&out_dir).join("workspace_cargo.rs"); std::fs::write(dest_path, code).unwrap(); } + +#[derive(Debug, Clone, serde::Deserialize)] +struct Dep { + version: Option, +} + +#[derive(Debug, Clone, serde::Deserialize)] +struct Workspace { + members: Vec, + dependencies: HashMap, +} +#[derive(Debug, Clone, serde::Deserialize)] +struct Cargo { + workspace: Workspace, +} diff --git a/scripts/checks/src/custom_checks.rs b/scripts/checks/src/custom_checks.rs new file mode 100644 index 000000000..ba4cd068c --- /dev/null +++ b/scripts/checks/src/custom_checks.rs @@ -0,0 +1,3 @@ +pub mod md_check; + +pub mod fuel_core_version; diff --git a/scripts/checks/src/custom_checks/fuel_core_version.rs b/scripts/checks/src/custom_checks/fuel_core_version.rs new file mode 100644 index 000000000..4b73b7a89 --- /dev/null +++ b/scripts/checks/src/custom_checks/fuel_core_version.rs @@ -0,0 +1,23 @@ +use std::path::Path; + +include!(concat!(env!("OUT_DIR"), "/workspace_cargo.rs")); + +pub fn verify_core_version(fuels_accounts: &Path) -> anyhow::Result<()> { + let contents = std::fs::read_to_string(fuels_accounts.join("./src/provider/version.rs"))?; + + let correct_version = &self::FUEL_CORE_VERSION; + let apply_template = |version: &semver::Version| -> String { + let major = version.major; + let minor = version.minor; + let patch = version.patch; + format!("pub(crate) const SUPPORTED_FUEL_CORE_VERSION: ::semver::Version = ::semver::Version::new({major}, {minor}, {patch});\n") + }; + + let expected_contents = apply_template(correct_version); + let diff = pretty_assertions::StrComparison::new(&expected_contents, &contents); + if contents != expected_contents { + return Err(anyhow::anyhow!("Fuel core version mismatch. {diff}")); + } + + Ok(()) +} diff --git a/scripts/checks/src/md_check.rs b/scripts/checks/src/custom_checks/md_check.rs similarity index 100% rename from scripts/checks/src/md_check.rs rename to scripts/checks/src/custom_checks/md_check.rs diff --git a/scripts/checks/src/customize.rs b/scripts/checks/src/customize.rs index 9a664ccaf..4328d12ac 100644 --- a/scripts/checks/src/customize.rs +++ b/scripts/checks/src/customize.rs @@ -38,6 +38,7 @@ fn normal(workspace_root: PathBuf) -> Tasks { builder.e2e_specific(); builder.wasm_specific(); builder.workspace_level(); + builder.fuels_accounts_core_version(); builder.build() } diff --git a/scripts/checks/src/main.rs b/scripts/checks/src/main.rs index e7bd9abb6..c407af549 100644 --- a/scripts/checks/src/main.rs +++ b/scripts/checks/src/main.rs @@ -2,8 +2,8 @@ use std::io::IsTerminal; use clap::Parser; mod cli; +mod custom_checks; mod customize; -mod md_check; mod tasks; mod util; diff --git a/scripts/checks/src/tasks/builder.rs b/scripts/checks/src/tasks/builder.rs index 6ac86a9ae..64ddba172 100644 --- a/scripts/checks/src/tasks/builder.rs +++ b/scripts/checks/src/tasks/builder.rs @@ -11,6 +11,7 @@ pub struct Builder { tasks: Vec, } +include!(concat!(env!("OUT_DIR"), "/workspace_cargo.rs")); impl Builder { pub fn new(workspace: PathBuf, rust_flags: &[&str]) -> Self { Self { @@ -147,6 +148,14 @@ impl Builder { self.tasks.push(task); } + pub fn fuels_accounts_core_version(&mut self) { + let task = Task { + cwd: self.workspace_path("packages/fuels-accounts"), + cmd: Command::VerifyCoreVersion, + }; + self.tasks.push(task); + } + pub fn workspace_level(&mut self) { let tasks = [ Command::MdCheck, @@ -384,5 +393,3 @@ fn parse_cmd(prepend: &str, string: &str) -> Vec { [vec![prepend.to_owned()], parts].concat() } } - -include!(concat!(env!("OUT_DIR"), "/workspace_members.rs")); diff --git a/scripts/checks/src/tasks/command.rs b/scripts/checks/src/tasks/command.rs index ee253d88b..e116b008e 100644 --- a/scripts/checks/src/tasks/command.rs +++ b/scripts/checks/src/tasks/command.rs @@ -11,13 +11,14 @@ pub enum Command { deps: deps::Deps, }, MdCheck, + VerifyCoreVersion, } impl Command { pub fn deps(&self) -> deps::Deps { match self { Self::Custom { deps, .. } => deps.clone(), - Self::MdCheck => deps::Deps::default(), + Self::MdCheck | Self::VerifyCoreVersion => deps::Deps::default(), } } } @@ -39,7 +40,8 @@ impl Display for Command { write!(f, "{env} {program} {args}") } } - Self::MdCheck { .. } => write!(f, "MdCheck"), + Self::MdCheck => write!(f, "MdCheck"), + Self::VerifyCoreVersion => write!(f, "VerifyCoreVersion"), } } } diff --git a/scripts/checks/src/tasks/task.rs b/scripts/checks/src/tasks/task.rs index 44ebf72a2..fba867964 100644 --- a/scripts/checks/src/tasks/task.rs +++ b/scripts/checks/src/tasks/task.rs @@ -1,4 +1,4 @@ -use crate::md_check; +use crate::custom_checks; use super::{ command::Command, @@ -33,11 +33,22 @@ impl Task { program, args, env, .. } => self.run_custom(program, args.iter().map(String::as_str), env), Command::MdCheck => self.run_md_check(), + Command::VerifyCoreVersion => self.run_verify_core_version(), } } - pub(crate) fn run_md_check(&self) -> Report { - let status = if let Err(e) = md_check::run(&self.cwd) { + fn run_verify_core_version(&self) -> Report { + let status = + if let Err(e) = custom_checks::fuel_core_version::verify_core_version(&self.cwd) { + e.into() + } else { + Status::Success { out: String::new() } + }; + self.report(status) + } + + fn run_md_check(&self) -> Report { + let status = if let Err(e) = custom_checks::md_check::run(&self.cwd) { e.into() } else { Status::Success { out: String::new() } @@ -46,12 +57,7 @@ impl Task { self.report(status) } - pub(crate) fn run_custom<'a, F>( - &self, - program: &str, - args: F, - env: &[(String, String)], - ) -> Report + fn run_custom<'a, F>(&self, program: &str, args: F, env: &[(String, String)]) -> Report where F: IntoIterator, { diff --git a/scripts/fuel-core-version/Cargo.toml b/scripts/fuel-core-version/Cargo.toml deleted file mode 100644 index eb595fb23..000000000 --- a/scripts/fuel-core-version/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "fuel-core-version" -version = { workspace = true } -authors = { workspace = true } -edition = { workspace = true } -homepage = { workspace = true } -license = { workspace = true } -publish = false -repository = { workspace = true } -rust-version = { workspace = true } - -[dependencies] -clap = { workspace = true, features = ["derive"] } -color-eyre = { workspace = true } -semver = { workspace = true } -versions-replacer = { workspace = true } diff --git a/scripts/fuel-core-version/src/main.rs b/scripts/fuel-core-version/src/main.rs deleted file mode 100644 index 4725a0808..000000000 --- a/scripts/fuel-core-version/src/main.rs +++ /dev/null @@ -1,84 +0,0 @@ -use std::{ - fs, - path::{Path, PathBuf}, -}; - -use clap::{Parser, Subcommand}; -use color_eyre::{ - eyre::{bail, ContextCompat}, - Result, -}; -use semver::Version; -use versions_replacer::metadata::collect_versions_from_cargo_toml; - -fn get_version_from_toml(manifest_path: impl AsRef) -> Result { - let versions = collect_versions_from_cargo_toml(manifest_path)?; - let version = versions["fuel-core-types"].parse::()?; - Ok(version) -} - -fn write_version_to_file(version: Version, version_file_path: impl AsRef) -> Result<()> { - let Version { - major, - minor, - patch, - .. - } = version; - let text = format!("Version::new({major}, {minor}, {patch})"); - fs::write(version_file_path, text.as_bytes())?; - Ok(()) -} - -fn get_version_file_path( - manifest_path: impl AsRef, -) -> Result { - Ok(manifest_path - .as_ref() - .parent() - .wrap_err("Invalid manifest path")? - .join("scripts/fuel-core-version/version.rs")) -} - -fn verify_version_from_file(version: Version) -> Result<()> { - let version_from_file: Version = include!("../version.rs"); - if version != version_from_file { - bail!( - "fuel_core version in version.rs ({}) doesn't match one in Cargo.toml ({})", - version_from_file, - version - ); - } - println!( - "fuel_core versions in versions.rs and Cargo.toml match ({})", - version - ); - Ok(()) -} - -#[derive(Debug, Parser)] -struct App { - #[clap(subcommand)] - command: Command, - #[clap(long)] - manifest_path: PathBuf, -} - -#[derive(Debug, Subcommand)] -enum Command { - Write, - Verify, -} - -fn main() -> Result<()> { - let App { - command, - manifest_path, - } = App::parse(); - let version = get_version_from_toml(&manifest_path)?; - let version_file_path = get_version_file_path(&manifest_path)?; - match command { - Command::Write => write_version_to_file(version, version_file_path)?, - Command::Verify => verify_version_from_file(version)?, - } - Ok(()) -} diff --git a/scripts/fuel-core-version/version.rs b/scripts/fuel-core-version/version.rs deleted file mode 100644 index e41fa22a2..000000000 --- a/scripts/fuel-core-version/version.rs +++ /dev/null @@ -1 +0,0 @@ -Version::new(0, 26, 0)