Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extend-ignore-identifiers-re = [
"ALOC",
"Aloc",
"aloc",
"SHW",
]

extend-ignore-re = [
Expand Down
3 changes: 2 additions & 1 deletion forc-plugins/forc-debug/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use forc_pkg::{
use forc_test::{
execute::{DebugResult, TestExecutor},
setup::TestSetup,
BuiltTests,
BuiltTests, TestGasLimit,
};
use fuel_tx::GasCostsValues;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -252,6 +252,7 @@ impl DapServer {
// TODO: (GAS-COSTS) Provide gas costs values here, similar like in `forc test`.
// See: https://github.com/FuelLabs/sway/issues/7472
GasCostsValues::default(),
TestGasLimit::default(),
)
.ok()
})
Expand Down
4 changes: 3 additions & 1 deletion forc-test/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::ecal::EcalSyscallHandler;
use crate::maxed_consensus_params;
use crate::setup::TestSetup;
use crate::TestGasLimit;
use crate::TestResult;
use crate::TEST_METADATA_SEED;
use forc_pkg::PkgTestEntry;
Expand Down Expand Up @@ -50,6 +51,7 @@ impl TestExecutor {
test_entry: &PkgTestEntry,
name: String,
gas_costs_values: GasCostsValues,
gas_limit: TestGasLimit,
) -> anyhow::Result<Self> {
let storage = test_setup.storage().clone();

Expand All @@ -76,7 +78,7 @@ impl TestExecutor {

let mut tx_builder = tx::TransactionBuilder::script(bytecode.to_vec(), script_input_data);

let params = maxed_consensus_params(gas_costs_values);
let params = maxed_consensus_params(gas_costs_values, gas_limit);

tx_builder
.with_params(params)
Expand Down
59 changes: 50 additions & 9 deletions forc-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ pub struct TestResult {
pub ecal: Box<EcalSyscallHandler>,
}

#[derive(Default, Debug, Clone, Copy)]
pub enum TestGasLimit {
#[default]
Default,
Unlimited,
Limited(u64),
}

const TEST_METADATA_SEED: u64 = 0x7E57u64;
/// A mapping from each member package of a build plan to its compiled contract dependencies.
type ContractDependencyMap = HashMap<pkg::Pinned, Vec<Arc<pkg::BuiltPackage>>>;
Expand Down Expand Up @@ -265,7 +273,7 @@ impl PackageWithDeploymentToTest {
// We are not concerned about gas costs of contract deployments for tests,
// only the gas costs of test executions. So, we can simply provide the
// default, built-in, gas costs values here.
let params = maxed_consensus_params(GasCostsValues::default());
let params = maxed_consensus_params(GasCostsValues::default(), TestGasLimit::default());
let storage = vm::storage::MemoryStorage::default();
let interpreter_params = InterpreterParams::new(gas_price, params.clone());
let mut interpreter: vm::prelude::Interpreter<_, _, _, vm::interpreter::NotSupportedEcal> =
Expand Down Expand Up @@ -433,6 +441,7 @@ impl<'a> PackageTests {
test_runners: &rayon::ThreadPool,
test_filter: Option<&TestFilter>,
gas_costs_values: GasCostsValues,
gas_limit: TestGasLimit,
) -> anyhow::Result<TestedPackage> {
let pkg_with_tests = self.built_pkg_with_tests();
let tests = test_runners.install(|| {
Expand Down Expand Up @@ -467,6 +476,7 @@ impl<'a> PackageTests {
test_entry,
name,
gas_costs_values.clone(),
gas_limit,
)?
.execute()
})
Expand Down Expand Up @@ -663,14 +673,21 @@ impl BuiltTests {
test_runner_count: TestRunnerCount,
test_filter: Option<TestFilter>,
gas_costs_values: GasCostsValues,
gas_limit: TestGasLimit,
) -> anyhow::Result<Tested> {
let test_runners = match test_runner_count {
TestRunnerCount::Manual(runner_count) => rayon::ThreadPoolBuilder::new()
.num_threads(runner_count)
.build(),
TestRunnerCount::Auto => rayon::ThreadPoolBuilder::new().build(),
}?;
run_tests(self, &test_runners, test_filter, gas_costs_values)
run_tests(
self,
&test_runners,
test_filter,
gas_costs_values,
gas_limit,
)
}
}

Expand All @@ -684,11 +701,19 @@ pub fn build(opts: TestOpts) -> anyhow::Result<BuiltTests> {

/// Returns a `ConsensusParameters` which has maximum length/size allowance for scripts, contracts,
/// and transactions.
pub(crate) fn maxed_consensus_params(gas_costs_values: GasCostsValues) -> ConsensusParameters {
pub(crate) fn maxed_consensus_params(
gas_costs_values: GasCostsValues,
gas_limit: TestGasLimit,
) -> ConsensusParameters {
let script_params = ScriptParameters::DEFAULT
.with_max_script_length(u64::MAX)
.with_max_script_data_length(u64::MAX);
let tx_params = TxParameters::DEFAULT.with_max_size(u64::MAX);
let tx_params = match gas_limit {
TestGasLimit::Default => TxParameters::DEFAULT,
TestGasLimit::Unlimited => TxParameters::DEFAULT.with_max_gas_per_tx(u64::MAX),
TestGasLimit::Limited(limit) => TxParameters::DEFAULT.with_max_gas_per_tx(limit),
}
.with_max_size(u64::MAX);
let contract_params = ContractParameters::DEFAULT
.with_contract_max_size(u64::MAX)
.with_max_storage_slots(u64::MAX);
Expand All @@ -697,6 +722,7 @@ pub(crate) fn maxed_consensus_params(gas_costs_values: GasCostsValues) -> Consen
tx_params,
contract_params,
gas_costs: gas_costs_values.into(),
block_gas_limit: u64::MAX,
..Default::default()
})
}
Expand Down Expand Up @@ -750,18 +776,28 @@ fn run_tests(
test_runners: &rayon::ThreadPool,
test_filter: Option<TestFilter>,
gas_costs_values: GasCostsValues,
gas_limit: TestGasLimit,
) -> anyhow::Result<Tested> {
match built {
BuiltTests::Package(pkg) => {
let tested_pkg =
pkg.run_tests(test_runners, test_filter.as_ref(), gas_costs_values.clone())?;
let tested_pkg = pkg.run_tests(
test_runners,
test_filter.as_ref(),
gas_costs_values.clone(),
gas_limit,
)?;
Ok(Tested::Package(Box::new(tested_pkg)))
}
BuiltTests::Workspace(workspace) => {
let tested_pkgs = workspace
.into_iter()
.map(|pkg| {
pkg.run_tests(test_runners, test_filter.as_ref(), gas_costs_values.clone())
pkg.run_tests(
test_runners,
test_filter.as_ref(),
gas_costs_values.clone(),
gas_limit,
)
})
.collect::<anyhow::Result<Vec<TestedPackage>>>()?;
Ok(Tested::Workspace(tested_pkgs))
Expand All @@ -775,7 +811,7 @@ mod tests {

use fuel_tx::GasCostsValues;

use crate::{build, BuiltTests, TestFilter, TestOpts, TestResult};
use crate::{build, BuiltTests, TestFilter, TestGasLimit, TestOpts, TestResult};

/// Name of the folder containing required data for tests to run, such as an example forc
/// project.
Expand Down Expand Up @@ -813,7 +849,12 @@ mod tests {
) -> anyhow::Result<Vec<TestResult>> {
let built_tests = test_package_built_tests(package_name)?;
let test_runner_count = crate::TestRunnerCount::Auto;
let tested = built_tests.run(test_runner_count, test_filter, GasCostsValues::default())?;
let tested = built_tests.run(
test_runner_count,
test_filter,
GasCostsValues::default(),
TestGasLimit::default(),
)?;
match tested {
crate::Tested::Package(tested_pkg) => Ok(tested_pkg.tests),
crate::Tested::Workspace(_) => {
Expand Down
14 changes: 12 additions & 2 deletions forc/src/cli/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use crate::cli::{self, shared::IrCliOpt};
use ansiterm::Colour;
use clap::Parser;
use forc_pkg as pkg;
use forc_test::{GasCostsSource, TestFilter, TestResult, TestRunnerCount, TestedPackage};
use forc_test::{
GasCostsSource, TestFilter, TestGasLimit, TestResult, TestRunnerCount, TestedPackage,
};
use forc_tracing::println_action_green;
use forc_util::{
tx_utils::{decode_fuel_vm_log_data, format_log_receipts},
Expand Down Expand Up @@ -68,6 +70,9 @@ pub struct Command {
/// [possible values: built-in, mainnet, testnet, <FILE_PATH>]
#[clap(long)]
pub gas_costs: Option<GasCostsSource>,
/// Remove gas limit for test executions.
#[clap(long)]
pub no_gas_limit: bool,
}

/// The set of options provided for controlling output of a test.
Expand Down Expand Up @@ -107,6 +112,11 @@ pub(crate) fn exec(cmd: Command) -> ForcResult<()> {
.as_ref()
.unwrap_or(&GasCostsSource::BuiltIn)
.provide_gas_costs()?;
let gas_limit = if cmd.no_gas_limit {
TestGasLimit::Unlimited
} else {
TestGasLimit::Default
};
let opts = opts_from_cmd(cmd);
let built_tests = forc_test::build(opts)?;
let start = std::time::Instant::now();
Expand All @@ -123,7 +133,7 @@ pub(crate) fn exec(cmd: Command) -> ForcResult<()> {
formatted_test_count_string(num_tests_ignored)
),
);
let tested = built_tests.run(test_runner_count, test_filter, gas_costs_values)?;
let tested = built_tests.run(test_runner_count, test_filter, gas_costs_values, gas_limit)?;
let duration = start.elapsed();

// Eventually we'll print this in a fancy manner, but this will do for testing.
Expand Down
3 changes: 2 additions & 1 deletion test/src/e2e_vm_tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use forc_client::{
NodeTarget,
};
use forc_pkg::{BuildProfile, Built, BuiltPackage, PrintOpts};
use forc_test::ecal::EcalSyscallHandler;
use forc_test::{ecal::EcalSyscallHandler, TestGasLimit};
use fuel_tx::TransactionBuilder;
use fuel_vm::checked_transaction::builder::TransactionBuilderExt;
use fuel_vm::fuel_tx::{self, consensus_parameters::ConsensusParametersV1};
Expand Down Expand Up @@ -366,6 +366,7 @@ pub(crate) async fn compile_and_run_unit_tests(
forc_test::TestRunnerCount::Auto,
test_filter,
run_config.gas_costs_values.clone(),
TestGasLimit::default(),
)?;
match tested {
forc_test::Tested::Package(tested_pkg) => Ok(vec![*tested_pkg]),
Expand Down
Loading