|
Some checks are pending
CI / verifications-complete (push) Blocked by required conditions
CI / check-dependency-version-formats (push) Waiting to run
CI / forc-fmt-check-panic (push) Waiting to run
CI / check-forc-manifest-version (push) Waiting to run
CI / get-fuel-core-version (push) Waiting to run
CI / build-sway-lib-std (push) Waiting to run
CI / build-sway-examples (push) Waiting to run
CI / forc-fmt-check-sway-lib-std (push) Waiting to run
CI / check-sdk-harness-test-suite-compatibility (push) Waiting to run
CI / build-mdbook (push) Waiting to run
CI / build-forc-doc-sway-lib-std (push) Waiting to run
CI / build-forc-test-project (push) Waiting to run
CI / cargo-build-workspace (push) Waiting to run
CI / Build and test various forc tools (push) Blocked by required conditions
CI / cargo-unused-deps-check (push) Waiting to run
CI / pre-publish-check (push) Waiting to run
CI / publish (push) Blocked by required conditions
CI / publish-sway-lib-std (push) Blocked by required conditions
CI / Build and upload forc binaries to release (push) Blocked by required conditions
github pages / deploy (push) Waiting to run
Codspeed Benchmarks / benchmarks (push) Waiting to run
CI / build-reference-examples (push) Waiting to run
CI / forc-fmt-check-sway-examples (push) Waiting to run
CI / cargo-clippy (push) Waiting to run
CI / cargo-toml-fmt-check (push) Waiting to run
CI / cargo-fmt-check (push) Waiting to run
CI / cargo-run-e2e-test (push) Blocked by required conditions
CI / cargo-run-e2e-test-release (push) Blocked by required conditions
CI / cargo-test-lib-std (push) Waiting to run
CI / forc-run-benchmarks (push) Waiting to run
CI / forc-unit-tests (push) Waiting to run
CI / forc-pkg-fuels-deps-check (push) Waiting to run
CI / notify-slack-on-failure (push) Blocked by required conditions
## Description This is an optimization of contract calls on top of https://github.com/FuelLabs/sway/pull/7440. ```csv const_of_contract_call::cost_of_in_array_0,1976,1285 const_of_contract_call::cost_of_in_array_1,3164,1779 const_of_contract_call::cost_of_in_array_16,5096,4753 const_of_contract_call::cost_of_in_array_32,8421,8079 const_of_contract_call::cost_of_in_array_64,60382,14545 const_of_contract_call::cost_of_in_array_8,4724,4382 const_of_contract_call::cost_of_in_b256,2491,2147 const_of_contract_call::cost_of_in_bool,2627,2279 const_of_contract_call::cost_of_in_str_0,3043,2697 const_of_contract_call::cost_of_in_str_1,3345,2998 const_of_contract_call::cost_of_in_str_16,3374,3030 const_of_contract_call::cost_of_in_str_32,3572,3227 const_of_contract_call::cost_of_in_str_8,3768,3421 const_of_contract_call::cost_of_in_tuple_0,3822,3479 const_of_contract_call::cost_of_in_tuple_1,4392,4050 const_of_contract_call::cost_of_in_tuple_2,4761,4418 const_of_contract_call::cost_of_in_tuple_3,5104,4761 const_of_contract_call::cost_of_in_tuple_4,5468,5126 const_of_contract_call::cost_of_in_u16,4493,4141 const_of_contract_call::cost_of_in_u256,4777,4433 const_of_contract_call::cost_of_in_u32,4926,4582 const_of_contract_call::cost_of_in_u64,4934,4589 const_of_contract_call::cost_of_in_u8,4874,4526 const_of_contract_call::in_enum_u64,3186,2843 const_of_contract_call::in_enum_u64_u64,3061,2718 const_of_contract_call::in_enum_u64_u64_u64,3173,2830 const_of_contract_call::in_struct_u64,3635,3293 const_of_contract_call::in_struct_u64_u64,3897,3554 const_of_contract_call::in_struct_u64_u64_u64,4156,3813 const_of_contract_call::isolated_cost_of_in_array_0,956,956 const_of_contract_call::isolated_cost_of_in_array_1,1515,1185 const_of_contract_call::isolated_cost_of_in_array_16,3955,3266 const_of_contract_call::isolated_cost_of_in_array_32,6544,5471 const_of_contract_call::isolated_cost_of_in_array_64,9914,9914 const_of_contract_call::isolated_cost_of_in_array_8,3225,2728 const_of_contract_call::isolated_cost_of_in_b256,1462,1120 const_of_contract_call::isolated_cost_of_in_bool,1358,1047 const_of_contract_call::isolated_cost_of_in_str_0,1451,1140 const_of_contract_call::isolated_cost_of_in_str_1,1547,1237 const_of_contract_call::isolated_cost_of_in_str_16,1552,1241 const_of_contract_call::isolated_cost_of_in_str_32,1553,1242 const_of_contract_call::isolated_cost_of_in_str_8,1551,1241 const_of_contract_call::isolated_cost_of_in_tuple_0,820,820 const_of_contract_call::isolated_cost_of_in_tuple_1,1412,1090 const_of_contract_call::isolated_cost_of_in_tuple_2,1615,1304 const_of_contract_call::isolated_cost_of_in_tuple_3,1766,1455 const_of_contract_call::isolated_cost_of_in_tuple_4,1916,1605 const_of_contract_call::isolated_cost_of_in_u16,1428,1117 const_of_contract_call::isolated_cost_of_in_u256,1431,1120 const_of_contract_call::isolated_cost_of_in_u32,1554,1243 const_of_contract_call::isolated_cost_of_in_u64,1336,1025 const_of_contract_call::isolated_cost_of_in_u8,1352,1041 ``` ## Checklist - [x] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. |
||
|---|---|---|
| .. | ||
| src | ||
| bench.sh | ||
| Cargo.toml | ||
| README.md | ||
| update-contract-ids.sh | ||
Snapshot tests
There are two ways to run snapshot tests:
> cargo r -p test --release
> cargo r -p test --release -- -k snapshot
When the snapshot flag is enabled (the default) the test harness will search for snapshot.toml files. For every toml file found a new snapshot test will run. If the toml file is empty, it will be interpreted as simply being:
# this is how the test harness understands an empty `snapshot.toml
cmds = [
\"forc build --path {root}\"
]
When the test harness runs a snapshot test, it will iterate the cmds array of each file, run each command, and append everything into the snapshot.
So the snapshot of the above file would be something like:
> forc test --path test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/const_of_contract_call
exit status: 0
output:
Building test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/const_of_contract_call
Compiling library std (test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-core)
Compiling contract const_of_contract_call (test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/const_of_contract_call)
Finished release [optimized + fuel] target(s) [1.88 KB] in ???
To make snapshot "environment free", the test harness changes forc output a little bit.
1 - First it does not show complete file paths. All paths are relative to the Sway repo root. 2 - Test harness also removes all printing of times. 3 - It also removes all ANSI codes for coloring and others.
Commands
To make snapshot tests more versatile there are a lot of options of what one can use inside cmds:
1 - forc; Any native forc command is available;
2 - Forc plugins; Currently only forc doc is available;
3 - echo; One can use echo to write a message. Usage is:
cmds = [
"echo Explain something here.",
"forc build --path {root}",
]
4 - sub; Sub will iterate all lines of the previous command and filter in only those that contain its argument.
cmds = [
"forc build --path {root} --asm final | sub ecal"
]
The example above will only show asm lines that contain the ecal instruction.
5 - regex; Regex is very similar to sub, but allows a regex to be written.
cmds = [
"forc build --path {root} --ir initial | regex ' (v0 = call call|v0 = const|v1 = const|revert)'"
]
6 - filter-fn. This command only shows IR, ASM for a specific function. It needs that previous command return a complete IR of a program.
cmds = [
"forc build --path {root} --ir final --asm final | filter-fn {name} transmute_by_reference_7",
]
In the example above, the snapshot will only contain IR and asm from the function "transmute_by_reference_7"
Some commands manipulate files. These commands have an "undo" list that will restore the file original content when they are finished. So it is guaranteed that if the test harness finishes gracefully, manipulated files will have their original values.
For security reasons, these commands can ONLY manipulate files under its project folder.
1 - replace. Replace a simple string for another.
cmds = [
"replace src/main.sw \"fn cost_of_in\" \"fn isolated_cost_of_in\"",
]
Variables
1 - root. Is the folder of the project being compiled.
2 - name. Is the name of the specific project being compiled.
Blocks
Blocks are blocks of code that live inside two comments of the form below:
/* START BOOL */
#[test]
fn cost_of_in_bool() {
let _ = abi(MyContract, CONTRACT_ID).in_bool(false);
}
/* END BOOL */
These blocks can be manipulated from inside the snapshot.toml and allowing multiples tests to use the same project.
To manipulate these blocks one can:
1 - Use the repeat-for-each-block.
cmds = [
{ repeat = "for-each-block", cmds = [
"forc test --path {root} --release --experimental const_generics"
] }
]
In the example above, the test harness will collect all "blocks" in the project being compiled, and will run the cmds inside the inner table for each block, removing all others. So for example:
/* START BOOL */
#[test]
fn cost_of_in_bool() {
let _ = abi(MyContract, CONTRACT_ID).in_bool(false);
}
/* END BOOL */
/* START U8 */
#[test]
fn cost_of_in_u8() {
let _ = abi(MyContract, CONTRACT_ID).in_u8(0);
}
/* END U8 */
In the example above, the repeat = "for-each-block" means that its cmds list will be run twice. First removing the block U8; and after, it will restore the original file contents and remove "BOOL".