mirror of
https://github.com/FuelLabs/sway.git
synced 2025-12-23 10:11:56 +00:00
|
Some checks are pending
Codspeed Benchmarks / benchmarks (push) Waiting to run
CI / verifications-complete (push) Blocked by required conditions
CI / check-dependency-version-formats (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 / build-reference-examples (push) Waiting to run
CI / forc-fmt-check-sway-lib-std (push) Waiting to run
CI / forc-fmt-check-sway-examples (push) Waiting to run
CI / forc-fmt-check-panic (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 / 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 / Build and test various forc tools (push) Blocked by required conditions
CI / cargo-unused-deps-check (push) Waiting to run
CI / notify-slack-on-failure (push) Blocked by required conditions
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
## Description This PR adds `--gas-costs` option to `forc-test` and E2E test runner. The option enables providing realistic gas costs to use for gas measurements during executions of tests and/or scripts. The gas costs can be provided from the following sources: - `built-in` Default value. It is hardcode in `forc test` based on the mainnet gas costs at the time of `forc` release. - `mainnet` Fetches the current gas costs from the mainnet using GraphQL. - `testnet` Fetches the current gas costs from the testnet using GraphQL. - `<FILE>` Reads the gas costs from a local JSON file. This PR implements only the `built-in` source and the remaining will be done in a follow up PR that will address #7472. The reason for adding gas costs is that both `forc test` and E2E test runner currently use `GasCosts::default()` when initializing the `Interpreter`. This can lead to very misleading gas cost interpretations. E.g, the default costs of `cfei`, `aloc`, `srwq`, and `swwq` are: ```console cfei: DependentCost::LightOperation { base: 2, units_per_gas: 214, }, aloc: DependentCost::LightOperation { base: 2, units_per_gas: 214, }, srwq: DependentCost::LightOperation { base: 47, units_per_gas: 5, }, swwq: DependentCost::LightOperation { base: 44, units_per_gas: 5, }, ``` Their on-chain costs, taken from the [Chain configuration repository](https://github.com/FuelLabs/chain-configuration/blob/master/upgradelog/ignition/consensus_parameters/6.json), are: ```console "cfei": { "LightOperation": { "base": 2, "units_per_gas": 562 } }, "aloc": { "LightOperation": { "base": 3, "units_per_gas": 562 } }, "srwq": { "HeavyOperation": { "base": 311, "gas_per_unit": 312 } }, "swwq": { "HeavyOperation": { "base": 7838, "gas_per_unit": 8156 } }, ``` The difference between the real on-chain cost and default parameters are significant, especially for `srwq` and `swwq`. In a general case, this difference can make gas usages printed by `forc test` or fetched by E2E `--perf` option very misleading, especially when used to benchmark performance. With the `--gas-costs` option we by default get the realistic, mainnet based built-in cost, and can even specify particular costs we want to have. ## Checklist - [x] I have linked to any relevant issues. - [x] 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) - [ ] 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 | ||
| tests/fixtures/bytecode | ||
| Cargo.toml | ||