diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13072cf99..5eb19eebe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ env: CARGO_TERM_COLOR: always DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v2.3.6/dasel_linux_amd64 RUSTFLAGS: "-D warnings" - FUEL_CORE_VERSION: 0.23.0 + FUEL_CORE_VERSION: 0.24.2 FUEL_CORE_PATCH_BRANCH: RUST_VERSION: 1.76.0 FORC_VERSION: 0.52.1 diff --git a/Cargo.toml b/Cargo.toml index 6f7315cd8..fb7924094 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,21 +72,21 @@ which = { version = "6.0.0", default-features = false } zeroize = "1.7.0" # Dependencies from the `fuel-core` repository: -fuel-core = { version = "0.23.0", default-features = false } -fuel-core-chain-config = { version = "0.23.0", default-features = false } -fuel-core-client = { version = "0.23.0", default-features = false } -fuel-core-poa = { version = "0.23.0", default-features = false } -fuel-core-services = { version = "0.23.0", default-features = false } -fuel-core-types = { version = "0.23.0", default-features = false } +fuel-core = { version = "0.24.2", default-features = false } +fuel-core-chain-config = { version = "0.24.2", default-features = false } +fuel-core-client = { version = "0.24.2", default-features = false } +fuel-core-poa = { version = "0.24.2", default-features = false } +fuel-core-services = { version = "0.24.2", default-features = false } +fuel-core-types = { version = "0.24.2", default-features = false } # Dependencies from the `fuel-vm` repository: -fuel-asm = { version = "0.47.1" } -fuel-crypto = { version = "0.47.1" } -fuel-merkle = { version = "0.47.1" } -fuel-storage = { version = "0.47.1" } -fuel-tx = { version = "0.47.1" } -fuel-types = { version = "0.47.1" } -fuel-vm = { version = "0.47.1" } +fuel-asm = { version = "0.48.0" } +fuel-crypto = { version = "0.48.0" } +fuel-merkle = { version = "0.48.0" } +fuel-storage = { version = "0.48.0" } +fuel-tx = { version = "0.48.0" } +fuel-types = { version = "0.48.0" } +fuel-vm = { version = "0.48.0" } # Workspace projects fuels = { version = "0.56.0", path = "./packages/fuels" } diff --git a/examples/contracts/src/lib.rs b/examples/contracts/src/lib.rs index 99b928c45..886d3072c 100644 --- a/examples/contracts/src/lib.rs +++ b/examples/contracts/src/lib.rs @@ -2,7 +2,8 @@ mod tests { use fuels::{ core::codec::{DecoderConfig, EncoderConfig}, - prelude::{Config, LoadConfiguration, StorageConfiguration}, + prelude::{LoadConfiguration, NodeConfig, StorageConfiguration}, + test_helpers::{ChainConfig, StateConfig}, types::{ errors::{transaction::Reason, Result}, Bits256, @@ -15,7 +16,12 @@ mod tests { use fuels::prelude::{FuelService, Provider}; // Run the fuel node. - let server = FuelService::start(Config::default()).await?; + let server = FuelService::start( + NodeConfig::default(), + ChainConfig::default(), + StateConfig::default(), + ) + .await?; // Create a client that will talk to the node created above. let client = Provider::from(server.bound_address()).await?; diff --git a/examples/cookbook/src/lib.rs b/examples/cookbook/src/lib.rs index b63d52cc5..e3648c21c 100644 --- a/examples/cookbook/src/lib.rs +++ b/examples/cookbook/src/lib.rs @@ -111,11 +111,9 @@ mod tests { .with_max_inputs(2); let fee_params = FeeParameters::default().with_gas_price_factor(10); - let consensus_parameters = ConsensusParameters { - tx_params, - fee_params, - ..Default::default() - }; + let mut consensus_parameters = ConsensusParameters::default(); + consensus_parameters.set_tx_params(tx_params); + consensus_parameters.set_fee_params(fee_params); let chain_config = ChainConfig { consensus_parameters, @@ -134,7 +132,7 @@ mod tests { // ANCHOR_END: custom_chain_coins // ANCHOR: custom_chain_provider - let node_config = Config::default(); + let node_config = NodeConfig::default(); let _provider = setup_test_provider(coins, vec![], Some(node_config), Some(chain_config)).await?; // ANCHOR_END: custom_chain_provider @@ -210,9 +208,9 @@ mod tests { use fuels::prelude::*; // ANCHOR: create_or_use_rocksdb - let provider_config = Config { + let provider_config = NodeConfig { database_type: DbType::RocksDb(Some(PathBuf::from("/tmp/.spider/db"))), - ..Config::default() + ..NodeConfig::default() }; // ANCHOR_END: create_or_use_rocksdb diff --git a/examples/types/src/lib.rs b/examples/types/src/lib.rs index 2fcf44745..c4b2f65e4 100644 --- a/examples/types/src/lib.rs +++ b/examples/types/src/lib.rs @@ -3,7 +3,7 @@ mod tests { use std::str::FromStr; #[cfg(feature = "fuel-core-lib")] - use fuels::prelude::Config; + use fuels::prelude::NodeConfig; use fuels::{ prelude::Result, types::{Bits256, EvmAddress, Identity}, diff --git a/packages/fuels-accounts/src/account.rs b/packages/fuels-accounts/src/account.rs index 34a8cd953..69766306d 100644 --- a/packages/fuels-accounts/src/account.rs +++ b/packages/fuels-accounts/src/account.rs @@ -398,7 +398,7 @@ mod tests { assert_eq!(signature, tx_signature); // Check if the signature is what we expect it to be - assert_eq!(signature, Signature::from_str("37cf6bdefc9e673f99a7fdbbeff454cb5c1bdf632c072f19cf8ac68fa1ede2749c568c56f87d73fc5c97f73b76dfe637422b77c1fdc6010fb4f488444ff5df1a")?); + assert_eq!(signature, Signature::from_str("8afd30de7039faa07aac1cf2676970a77dc8ef3f779b44c1510ad7bf58ea56f43727b23142bd7252b79ae2c832e073927f84f6b0857fedf2f6d86e9535e48fd0")?); // Recover the address that signed the transaction let recovered_address = signature.recover(&message)?; diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index 039306e05..50ef9d809 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -240,7 +240,7 @@ impl Provider { } pub fn base_asset_id(&self) -> &AssetId { - &self.consensus_parameters.base_asset_id + self.consensus_parameters.base_asset_id() } fn ensure_client_version_is_supported(node_info: &NodeInfo) -> Result<()> { @@ -276,7 +276,7 @@ impl Provider { } pub fn chain_id(&self) -> ChainId { - self.consensus_parameters.chain_id + self.consensus_parameters.chain_id() } pub async fn node_info(&self) -> Result { diff --git a/packages/fuels-accounts/src/provider/supported_versions.rs b/packages/fuels-accounts/src/provider/supported_versions.rs index 478b6e894..eae993bb2 100644 --- a/packages/fuels-accounts/src/provider/supported_versions.rs +++ b/packages/fuels-accounts/src/provider/supported_versions.rs @@ -1,7 +1,7 @@ use semver::Version; fn get_supported_fuel_core_version() -> Version { - "0.23.0".parse().expect("is valid version") + "0.24.2".parse().expect("is valid version") } #[derive(Debug, PartialEq, Eq)] diff --git a/packages/fuels-core/src/types/transaction_builders.rs b/packages/fuels-core/src/types/transaction_builders.rs index f85f1362d..ff70d70db 100644 --- a/packages/fuels-core/src/types/transaction_builders.rs +++ b/packages/fuels-core/src/types/transaction_builders.rs @@ -10,12 +10,11 @@ use async_trait::async_trait; use fuel_asm::{op, GTFArgs, RegId}; use fuel_crypto::{Message as CryptoMessage, Signature}; use fuel_tx::{ - field::{Inputs, Policies as PoliciesField, WitnessLimit, Witnesses}, + field::{Inputs, Policies as PoliciesField, ScriptGasLimit, WitnessLimit, Witnesses}, input::coin::{CoinPredicate, CoinSigned}, policies::{Policies, PolicyType}, - Buildable, Chargeable, ConsensusParameters, Create, Input as FuelInput, Output, Script, - StorageSlot, Transaction as FuelTransaction, TransactionFee, TxPointer, UniqueIdentifier, - Witness, + Chargeable, ConsensusParameters, Create, Input as FuelInput, Output, Script, StorageSlot, + Transaction as FuelTransaction, TransactionFee, TxPointer, UniqueIdentifier, Witness, }; use fuel_types::{bytes::padded_len_usize, canonical::Serialize, Bytes32, ChainId, Salt}; use itertools::Itertools; @@ -187,8 +186,8 @@ macro_rules! impl_tx_trait { } Ok(TransactionFee::checked_from_tx( - &consensus_parameters.gas_costs, - &consensus_parameters.fee_params, + &consensus_parameters.gas_costs(), + &consensus_parameters.fee_params(), &tx.tx, provider .estimate_gas_price(self.gas_price_estimation_block_horizon) @@ -288,17 +287,17 @@ macro_rules! impl_tx_trait { .any(|input| matches!(input, Input::ResourcePredicate { .. })) } - fn num_witnesses(&self) -> Result { + fn num_witnesses(&self) -> Result { let num_witnesses = self.witnesses().len(); - if num_witnesses + self.unresolved_signers.len() > 256 { + if num_witnesses + self.unresolved_signers.len() > u16::MAX as usize { return Err(error_transaction!( Builder, - "tx cannot have more than 256 witnesses" + "tx exceeds maximum number of witnesses" )); } - Ok(num_witnesses as u8) + Ok(num_witnesses as u16) } fn calculate_witnesses_size(&self) -> Option { @@ -318,7 +317,7 @@ macro_rules! impl_tx_trait { let consensus_parameters = provider.consensus_parameters(); let tx_fee = TransactionFee::checked_from_tx( - &consensus_parameters.gas_costs, + &consensus_parameters.gas_costs(), consensus_parameters.fee_params(), tx, gas_price, @@ -362,7 +361,7 @@ pub struct ScriptTransactionBuilder { #[derive(Default)] pub struct CreateTransactionBuilder { pub bytecode_length: u64, - pub bytecode_witness_index: u8, + pub bytecode_witness_index: u16, pub storage_slots: Vec, pub inputs: Vec, pub outputs: Vec, @@ -398,7 +397,7 @@ impl ScriptTransactionBuilder { // However, the node will check if the right number of witnesses is present. // This function will create witnesses from a default `Signature` such that the total length matches the expected one. // Using a `Signature` ensures that the calculated fee includes the fee generated by the witnesses. - fn create_dry_run_witnesses(&self, num_witnesses: u8) -> Vec { + fn create_dry_run_witnesses(&self, num_witnesses: u16) -> Vec { let unresolved_witnesses_len = self.unresolved_witness_indexes.owner_to_idx_offset.len(); let witness: Witness = Signature::default().as_ref().into(); repeat(witness) @@ -408,12 +407,12 @@ impl ScriptTransactionBuilder { fn no_base_asset_input<'a>( inputs: impl IntoIterator, - base_asset_id: AssetId, + base_asset_id: &AssetId, ) -> bool { let has_base_asset = inputs.into_iter().any(|i| match i { FuelInput::CoinSigned(CoinSigned { asset_id, .. }) | FuelInput::CoinPredicate(CoinPredicate { asset_id, .. }) - if *asset_id == base_asset_id => + if asset_id == base_asset_id => { true } @@ -430,7 +429,7 @@ impl ScriptTransactionBuilder { tolerance: f32, ) -> Result<()> { let consensus_params = provider.consensus_parameters(); - let base_asset_id = provider.consensus_parameters().base_asset_id; + let base_asset_id = provider.consensus_parameters().base_asset_id(); // The dry-run validation will check if there is any base asset input. // If we are dry-running without inputs we have to add a temporary one. @@ -454,7 +453,7 @@ impl ScriptTransactionBuilder { // Get `max_gas` used by everything except the script execution. Add `1` because of rounding. let max_gas = tx.max_gas(consensus_params.gas_costs(), consensus_params.fee_params()) + 1; // Increase `script_gas_limit` to the maximum allowed value. - tx.set_script_gas_limit(consensus_params.tx_params().max_gas_per_tx - max_gas); + *tx.script_gas_limit_mut() = consensus_params.tx_params().max_gas_per_tx() - max_gas; let gas_used = provider .dry_run_and_get_used_gas(tx.clone().into(), tolerance) @@ -467,7 +466,7 @@ impl ScriptTransactionBuilder { tx.set_witness_limit(tx.witness_limit() - WITNESS_STATIC_SIZE as u64); } - tx.set_script_gas_limit(gas_used); + *tx.script_gas_limit_mut() = gas_used; Ok(()) } @@ -494,11 +493,11 @@ impl ScriptTransactionBuilder { ); if has_no_code { - tx.set_script_gas_limit(0); + *tx.script_gas_limit_mut() = 0; // Use the user defined value even if it makes the transaction revert. } else if let Some(gas_limit) = self.tx_policies.script_gas_limit() { - tx.set_script_gas_limit(gas_limit); + *tx.script_gas_limit_mut() = gas_limit; // If the `script_gas_limit` was not set by the user, // dry-run the tx to get the `gas_used` @@ -515,7 +514,7 @@ impl ScriptTransactionBuilder { .await?; let missing_witnesses = generate_missing_witnesses( - tx.id(&provider.consensus_parameters().chain_id), + tx.id(&provider.consensus_parameters().chain_id()), &self.unresolved_signers, ) .await?; @@ -665,7 +664,7 @@ impl CreateTransactionBuilder { }; let tx = self - .resolve_fuel_tx(base_offset, &consensus_parameters.chain_id, &provider) + .resolve_fuel_tx(base_offset, &consensus_parameters.chain_id(), &provider) .await?; Ok(CreateTransaction { @@ -720,7 +719,7 @@ impl CreateTransactionBuilder { self } - pub fn with_bytecode_witness_index(mut self, bytecode_witness_index: u8) -> Self { + pub fn with_bytecode_witness_index(mut self, bytecode_witness_index: u16) -> Self { self.bytecode_witness_index = bytecode_witness_index; self } @@ -781,7 +780,7 @@ impl CreateTransactionBuilder { fn resolve_fuel_inputs( inputs: Vec, mut data_offset: usize, - num_witnesses: u8, + num_witnesses: u16, unresolved_witness_indexes: &UnresolvedWitnessIndexes, ) -> Result> { inputs @@ -821,7 +820,7 @@ fn resolve_fuel_inputs( fn resolve_signed_resource( resource: CoinType, data_offset: &mut usize, - num_witnesses: u8, + num_witnesses: u16, unresolved_witness_indexes: &UnresolvedWitnessIndexes, ) -> Result { match resource { @@ -837,7 +836,7 @@ fn resolve_signed_resource( "signature missing for coin with owner: `{owner:?}`" )) .map(|witness_idx_offset| { - create_coin_input(coin, num_witnesses + *witness_idx_offset as u8) + create_coin_input(coin, num_witnesses + *witness_idx_offset as u16) }) } CoinType::Message(message) => { @@ -852,7 +851,7 @@ fn resolve_signed_resource( "signature missing for message with recipient: `{recipient:?}`" )) .map(|witness_idx_offset| { - create_coin_message_input(message, num_witnesses + *witness_idx_offset as u8) + create_coin_message_input(message, num_witnesses + *witness_idx_offset as u16) }) } } @@ -885,7 +884,7 @@ fn resolve_predicate_resource( } } -pub fn create_coin_input(coin: Coin, witness_index: u8) -> FuelInput { +pub fn create_coin_input(coin: Coin, witness_index: u16) -> FuelInput { FuelInput::coin_signed( coin.utxo_id, coin.owner.into(), @@ -896,7 +895,7 @@ pub fn create_coin_input(coin: Coin, witness_index: u8) -> FuelInput { ) } -pub fn create_coin_message_input(message: Message, witness_index: u8) -> FuelInput { +pub fn create_coin_message_input(message: Message, witness_index: u16) -> FuelInput { if message.data.is_empty() { FuelInput::message_coin_signed( message.sender.into(), @@ -1069,11 +1068,18 @@ mod tests { repeat_with(Witness::default).take(num_witnesses).collect() } - #[derive(Default)] struct MockDryRunner { c_param: ConsensusParameters, } + impl Default for MockDryRunner { + fn default() -> Self { + Self { + c_param: ConsensusParameters::standard(), + } + } + } + #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl DryRunner for MockDryRunner { diff --git a/packages/fuels-core/src/types/wrappers/block.rs b/packages/fuels-core/src/types/wrappers/block.rs index ee97c4002..1877c8ca1 100644 --- a/packages/fuels-core/src/types/wrappers/block.rs +++ b/packages/fuels-core/src/types/wrappers/block.rs @@ -13,7 +13,10 @@ pub struct Header { pub transactions_count: u64, pub message_receipt_count: u64, pub transactions_root: Bytes32, - pub message_receipt_root: Bytes32, + pub message_outbox_root: Bytes32, + pub event_inbox_root: Bytes32, + pub consensus_parameters_version: u32, + pub state_transition_bytecode_version: u32, pub height: u32, pub prev_root: Bytes32, pub time: Option>, @@ -30,7 +33,10 @@ impl From for Header { transactions_count: client_header.transactions_count, message_receipt_count: client_header.message_receipt_count, transactions_root: client_header.transactions_root, - message_receipt_root: client_header.message_receipt_root, + message_outbox_root: client_header.message_outbox_root, + event_inbox_root: client_header.event_inbox_root, + consensus_parameters_version: client_header.consensus_parameters_version, + state_transition_bytecode_version: client_header.state_transition_bytecode_version, height: client_header.height, prev_root: client_header.prev_root, time, diff --git a/packages/fuels-core/src/types/wrappers/coin.rs b/packages/fuels-core/src/types/wrappers/coin.rs index 2b8093a9b..c1daeed1a 100644 --- a/packages/fuels-core/src/types/wrappers/coin.rs +++ b/packages/fuels-core/src/types/wrappers/coin.rs @@ -41,10 +41,10 @@ impl From for Coin { impl From for CoinConfig { fn from(coin: Coin) -> CoinConfig { Self { - tx_id: Some(*coin.utxo_id.tx_id()), - output_index: Some(coin.utxo_id.output_index()), - tx_pointer_block_height: Some(coin.block_created.into()), - tx_pointer_tx_idx: None, + tx_id: *coin.utxo_id.tx_id(), + output_index: coin.utxo_id.output_index(), + tx_pointer_block_height: coin.block_created.into(), + tx_pointer_tx_idx: Default::default(), owner: coin.owner.into(), amount: coin.amount, asset_id: coin.asset_id, diff --git a/packages/fuels-core/src/types/wrappers/node_info.rs b/packages/fuels-core/src/types/wrappers/node_info.rs index 9a4bb8613..e79929787 100644 --- a/packages/fuels-core/src/types/wrappers/node_info.rs +++ b/packages/fuels-core/src/types/wrappers/node_info.rs @@ -6,7 +6,6 @@ use fuel_core_client::client::types::node_info::NodeInfo as ClientNodeInfo; pub struct NodeInfo { pub utxo_validation: bool, pub vm_backtrace: bool, - pub min_gas_price: u64, pub max_tx: u64, pub max_depth: u64, pub node_version: String, @@ -17,7 +16,6 @@ impl From for NodeInfo { Self { utxo_validation: client_node_info.utxo_validation, vm_backtrace: client_node_info.vm_backtrace, - min_gas_price: client_node_info.min_gas_price, max_tx: client_node_info.max_tx, max_depth: client_node_info.max_depth, node_version: client_node_info.node_version, diff --git a/packages/fuels-core/src/types/wrappers/transaction.rs b/packages/fuels-core/src/types/wrappers/transaction.rs index b29545429..4c5126172 100644 --- a/packages/fuels-core/src/types/wrappers/transaction.rs +++ b/packages/fuels-core/src/types/wrappers/transaction.rs @@ -13,9 +13,9 @@ use fuel_tx::{ MessageCoinPredicate, MessageCoinSigned, MessageDataPredicate, MessageDataSigned, }, }, - Buildable, Bytes32, Cacheable, Chargeable, ConsensusParameters, Create, FormatValidityChecks, - Input, Mint, Output, Salt as FuelSalt, Script, StorageSlot, Transaction as FuelTransaction, - TransactionFee, UniqueIdentifier, Witness, + Bytes32, Cacheable, Chargeable, ConsensusParameters, Create, FormatValidityChecks, Input, Mint, + Output, Salt as FuelSalt, Script, StorageSlot, Transaction as FuelTransaction, TransactionFee, + UniqueIdentifier, Witness, }; use fuel_types::{bytes::padded_len_usize, AssetId, ChainId}; use fuel_vm::checked_transaction::{ @@ -176,7 +176,7 @@ impl TxPolicies { } } -use fuel_tx::field::{BytecodeLength, BytecodeWitnessIndex, Salt, StorageSlots}; +use fuel_tx::field::{BytecodeWitnessIndex, Salt, StorageSlots}; use crate::types::coin_type_id::CoinTypeId; @@ -373,7 +373,7 @@ macro_rules! impl_tx_wrapper { gas_price: u64, ) -> Option { TransactionFee::checked_from_tx( - &consensus_parameters.gas_costs, + &consensus_parameters.gas_costs(), consensus_parameters.fee_params(), &self.tx, gas_price, @@ -500,17 +500,13 @@ impl CreateTransaction { self.tx.salt() } - pub fn bytecode_witness_index(&self) -> u8 { + pub fn bytecode_witness_index(&self) -> u16 { *self.tx.bytecode_witness_index() } pub fn storage_slots(&self) -> &Vec { self.tx.storage_slots() } - - pub fn bytecode_length(&self) -> u64 { - *self.tx.bytecode_length() - } } impl EstimablePredicates for ScriptTransaction { @@ -556,7 +552,7 @@ impl ScriptTransaction { } pub fn with_gas_limit(mut self, gas_limit: u64) -> Self { - self.tx.set_script_gas_limit(gas_limit); + *self.tx.script_gas_limit_mut() = gas_limit; self } } diff --git a/packages/fuels-core/src/utils/offsets.rs b/packages/fuels-core/src/utils/offsets.rs index 2b8492825..2228a9353 100644 --- a/packages/fuels-core/src/utils/offsets.rs +++ b/packages/fuels-core/src/utils/offsets.rs @@ -1,7 +1,7 @@ use fuel_asm::Instruction; use fuel_tx::{ - field::{Salt, Script}, - Bytes32, ConsensusParameters, InputRepr, + field::{Script, StorageSlots}, + ConsensusParameters, InputRepr, }; use fuel_types::{bytes::padded_len_usize, ContractId}; @@ -17,9 +17,7 @@ pub fn base_offset_create(consensus_parameters: &ConsensusParameters) -> usize { // The easiest way to get the offset of `fuel_tx::Create` is to get the offset of the last field // of `Create` -- i.e. `salt` and skip it by adding its length. // This should be updated if `fuel_tx::Create` ever adds more fields after `salt`. - consensus_parameters.tx_params().tx_offset() - + fuel_tx::Create::salt_offset_static() - + Bytes32::LEN + consensus_parameters.tx_params().tx_offset() + fuel_tx::Create::storage_slots_offset_static() } /// Calculates the length of the script based on the number of contract calls it diff --git a/packages/fuels-programs/src/call_utils.rs b/packages/fuels-programs/src/call_utils.rs index ad771b4e8..6fb9da987 100644 --- a/packages/fuels-programs/src/call_utils.rs +++ b/packages/fuels-programs/src/call_utils.rs @@ -610,7 +610,7 @@ fn generate_asset_change_outputs( pub(crate) fn generate_contract_outputs(num_of_contracts: usize) -> Vec { (0..num_of_contracts) - .map(|idx| Output::contract(idx as u8, Bytes32::zeroed(), Bytes32::zeroed())) + .map(|idx| Output::contract(idx as u16, Bytes32::zeroed(), Bytes32::zeroed())) .collect() } @@ -620,7 +620,7 @@ pub(crate) fn generate_contract_inputs(contract_ids: HashSet) -> Vec .enumerate() .map(|(idx, contract_id)| { Input::contract( - UtxoId::new(Bytes32::zeroed(), idx as u8), + UtxoId::new(Bytes32::zeroed(), idx as u16), Bytes32::zeroed(), Bytes32::zeroed(), TxPointer::default(), @@ -925,7 +925,7 @@ mod test { tx_pointer, contract_id, } => { - assert_eq!(utxo_id, UtxoId::new(Bytes32::zeroed(), index as u8)); + assert_eq!(utxo_id, UtxoId::new(Bytes32::zeroed(), index as u16)); assert_eq!(balance_root, Bytes32::zeroed()); assert_eq!(state_root, Bytes32::zeroed()); assert_eq!(tx_pointer, TxPointer::default()); diff --git a/packages/fuels-test-helpers/Cargo.toml b/packages/fuels-test-helpers/Cargo.toml index b3e3bcee1..844fb7c0d 100644 --- a/packages/fuels-test-helpers/Cargo.toml +++ b/packages/fuels-test-helpers/Cargo.toml @@ -10,8 +10,8 @@ rust-version = { workspace = true } description = "Fuel Rust SDK test helpers." [dependencies] -fuel-core = { workspace = true, default-features = false, optional = true } -fuel-core-chain-config = { workspace = true } +fuel-core = { workspace = true, default-features = false, 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-services = { workspace = true } @@ -21,17 +21,13 @@ fuel-types = { workspace = true, features = ["random"] } fuels-accounts = { workspace = true, optional = true } fuels-core = { workspace = true } futures = { workspace = true } -hex = { workspace = true, default-features = false, features = ["std", "serde"] } portpicker = { workspace = true } rand = { workspace = true, default-features = false } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true, features = ["raw_value"] } -serde_with = { workspace = true } tempfile = { workspace = true, default-features = false } 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-lib = ["fuel-core"] +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/accounts.rs b/packages/fuels-test-helpers/src/accounts.rs index f14d0a670..1dc9e99e6 100644 --- a/packages/fuels-test-helpers/src/accounts.rs +++ b/packages/fuels-test-helpers/src/accounts.rs @@ -5,7 +5,7 @@ use fuels_accounts::wallet::WalletUnlocked; use fuels_core::types::errors::Result; use crate::{ - node_types::{ChainConfig, Config}, + node_types::{ChainConfig, NodeConfig}, setup_custom_assets_coins, setup_test_provider, wallets_config::*, }; @@ -52,7 +52,7 @@ pub async fn launch_provider_and_get_wallet() -> Result { /// ``` pub async fn launch_custom_provider_and_get_wallets( wallet_config: WalletsConfig, - provider_config: Option, + provider_config: Option, chain_config: Option, ) -> Result> { const SIZE_SECRET_KEY: usize = size_of::(); @@ -193,15 +193,17 @@ mod tests { #[tokio::test] async fn generated_wallets_with_custom_chain_config() -> Result<()> { - let consensus_parameters = ConsensusParameters { - tx_params: TxParameters::default().with_max_gas_per_tx(10_000_000_000), - ..Default::default() - }; + let mut consensus_parameters = ConsensusParameters::default(); let block_gas_limit = 10_000_000_000; + consensus_parameters.set_block_gas_limit(block_gas_limit); + + let max_gas_per_tx = 10_000_000_000; + let tx_params = TxParameters::default().with_max_gas_per_tx(max_gas_per_tx); + consensus_parameters.set_tx_params(tx_params); + let chain_config = ChainConfig { consensus_parameters, - block_gas_limit, ..ChainConfig::default() }; @@ -223,8 +225,8 @@ mod tests { .try_provider()? .consensus_parameters() .tx_params() - .max_gas_per_tx, - block_gas_limit + .max_gas_per_tx(), + max_gas_per_tx ); assert_eq!( wallet.get_coins(AssetId::zeroed()).await?.len() as u64, diff --git a/packages/fuels-test-helpers/src/fuel_bin_service.rs b/packages/fuels-test-helpers/src/fuel_bin_service.rs index 84cc91e80..486256928 100644 --- a/packages/fuels-test-helpers/src/fuel_bin_service.rs +++ b/packages/fuels-test-helpers/src/fuel_bin_service.rs @@ -4,6 +4,7 @@ use std::{ time::Duration, }; +use fuel_core_chain_config::{ChainConfig, SnapshotWriter, StateConfig}; use fuel_core_client::client::FuelClient; use fuel_core_services::State; use fuels_core::{ @@ -11,30 +12,30 @@ use fuels_core::{ types::errors::{Error, Result as FuelResult}, }; use portpicker::{is_free, pick_unused_port}; -use tempfile::NamedTempFile; +use tempfile::{tempdir, TempDir}; use tokio::{process::Command, spawn, task::JoinHandle, time::sleep}; -use crate::node_types::{Config, DbType, Trigger}; +use crate::node_types::{DbType, NodeConfig, Trigger}; #[derive(Debug)] -struct ExtendedConfig { - config: Config, - config_file: NamedTempFile, +pub(crate) struct ExtendedConfig { + pub node_config: NodeConfig, + pub chain_config: ChainConfig, + pub state_config: StateConfig, + pub snapshot_dir: TempDir, } impl ExtendedConfig { - pub fn config_to_args_vec(&mut self) -> FuelResult> { - self.write_temp_chain_config_file()?; - - let port = self.config.addr.port().to_string(); + pub fn args_vec(&self) -> fuels_core::types::errors::Result> { + let port = self.node_config.addr.port().to_string(); let mut args = vec![ - "run".to_string(), // `fuel-core` is now run with `fuel-core run` + "run".to_string(), "--ip".to_string(), "127.0.0.1".to_string(), "--port".to_string(), port, - "--chain".to_string(), - self.config_file + "--snapshot".to_string(), + self.snapshot_dir .path() .to_str() .expect("Failed to find config file") @@ -42,7 +43,7 @@ impl ExtendedConfig { ]; args.push("--db-type".to_string()); - match &self.config.database_type { + match &self.node_config.database_type { DbType::InMemory => args.push("in-memory".to_string()), DbType::RocksDb(path_to_db) => { args.push("rocks-db".to_string()); @@ -55,12 +56,12 @@ impl ExtendedConfig { } } - if let Some(cache_size) = self.config.max_database_cache_size { + if let Some(cache_size) = self.node_config.max_database_cache_size { args.push("--max-database-cache-size".to_string()); args.push(cache_size.to_string()); } - match self.config.block_production { + match self.node_config.block_production { Trigger::Instant => { args.push("--poa-instant=true".to_string()); } @@ -77,9 +78,9 @@ impl ExtendedConfig { args.extend( [ - (self.config.vm_backtrace, "--vm-backtrace"), - (self.config.utxo_validation, "--utxo-validation"), - (self.config.debug, "--debug"), + (self.node_config.vm_backtrace, "--vm-backtrace"), + (self.node_config.utxo_validation, "--utxo-validation"), + (self.node_config.debug, "--debug"), ] .into_iter() .filter(|(flag, _)| *flag) @@ -89,11 +90,16 @@ impl ExtendedConfig { Ok(args) } - pub fn write_temp_chain_config_file(&mut self) -> FuelResult<()> { - Ok(serde_json::to_writer( - &mut self.config_file, - &self.config.chain_conf, - )?) + pub fn write_temp_snapshot_files(self) -> FuelResult { + let mut writer = SnapshotWriter::json(self.snapshot_dir.path()); + writer + .write_chain_config(&self.chain_config) + .map_err(|e| error!(Other, "could not write chain config: {}", e))?; + writer + .write_state_config(self.state_config) + .map_err(|e| error!(Other, "could not write state config: {}", e))?; + + Ok(self.snapshot_dir) } } @@ -103,26 +109,32 @@ pub struct FuelService { } impl FuelService { - pub async fn new_node(config: Config) -> FuelResult { - let requested_port = config.addr.port(); + pub async fn new_node( + node_config: NodeConfig, + chain_config: ChainConfig, + state_config: StateConfig, + ) -> FuelResult { + let requested_port = node_config.addr.port(); let bound_address = match requested_port { 0 => get_socket_address()?, - _ if is_free(requested_port) => config.addr, + _ if is_free(requested_port) => node_config.addr, _ => return Err(Error::IO(std::io::ErrorKind::AddrInUse.into())), }; - let config = Config { + let node_config = NodeConfig { addr: bound_address, - ..config + ..node_config }; let extended_config = ExtendedConfig { - config, - config_file: NamedTempFile::new()?, + node_config, + state_config, + chain_config, + snapshot_dir: tempdir()?, }; - let addr = extended_config.config.addr; + let addr = extended_config.node_config.addr; let handle = run_node(extended_config).await?; server_health_check(addr).await?; @@ -165,8 +177,9 @@ fn get_socket_address() -> FuelResult { Ok(SocketAddr::new(address, free_port)) } -async fn run_node(mut extended_config: ExtendedConfig) -> FuelResult> { - let args = extended_config.config_to_args_vec()?; +async fn run_node(extended_config: ExtendedConfig) -> FuelResult> { + let args = extended_config.args_vec()?; + let tempdir = extended_config.write_temp_snapshot_files()?; let binary_name = "fuel-core"; @@ -189,8 +202,8 @@ async fn run_node(mut extended_config: ExtendedConfig) -> FuelResult, messages: Vec, - node_config: Option, + 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 mut chain_conf = chain_config.unwrap_or_else(ChainConfig::local_testnet); - - chain_conf.initial_state = Some(StateConfig { - coins: Some(coin_configs), - contracts: None, - messages: Some(message_configs), - ..StateConfig::default() - }); - let mut config = node_config.unwrap_or_default(); - config.chain_conf = chain_conf; + let state_config = StateConfig { + coins: coin_configs, + messages: message_configs, + ..StateConfig::local_testnet() + }; - let srv = FuelService::start(config).await?; + let srv = FuelService::start(node_config, chain_config, state_config).await?; let address = srv.bound_address(); @@ -156,6 +153,20 @@ pub async fn setup_test_provider( 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}; @@ -289,9 +300,9 @@ mod tests { #[tokio::test] async fn test_setup_test_provider_custom_config() -> Result<()> { let socket = SocketAddr::new(Ipv4Addr::new(127, 0, 0, 1).into(), 4000); - let config = Config { + let config = NodeConfig { addr: socket, - ..Config::default() + ..NodeConfig::default() }; let provider = setup_test_provider(vec![], vec![], Some(config.clone()), None).await?; @@ -314,12 +325,10 @@ mod tests { let fee_params = FeeParameters::default().with_gas_per_byte(2); let contract_params = ContractParameters::default().with_max_storage_slots(83); - let consensus_parameters = ConsensusParameters { - tx_params, - fee_params, - contract_params, - ..Default::default() - }; + let mut consensus_parameters = ConsensusParameters::default(); + consensus_parameters.set_tx_params(tx_params); + consensus_parameters.set_fee_params(fee_params); + consensus_parameters.set_contract_params(contract_params); let chain_config = ChainConfig { consensus_parameters: consensus_parameters.clone(), @@ -339,11 +348,13 @@ mod tests { let max_inputs = 123; let gas_per_byte = 456; - let consensus_parameters = ConsensusParameters { - tx_params: TxParameters::default().with_max_inputs(max_inputs), - fee_params: FeeParameters::default().with_gas_per_byte(gas_per_byte), - ..Default::default() - }; + let mut consensus_parameters = ConsensusParameters::default(); + + let tx_params = TxParameters::default().with_max_inputs(max_inputs); + consensus_parameters.set_tx_params(tx_params); + + let fee_params = FeeParameters::default().with_gas_per_byte(gas_per_byte); + consensus_parameters.set_fee_params(fee_params); let chain_name = "fuel-0".to_string(); let chain_config = ChainConfig { @@ -358,11 +369,11 @@ mod tests { assert_eq!(chain_info.name, chain_name); assert_eq!( - chain_info.consensus_parameters.tx_params().max_inputs, + chain_info.consensus_parameters.tx_params().max_inputs(), max_inputs ); assert_eq!( - chain_info.consensus_parameters.fee_params().gas_per_byte, + chain_info.consensus_parameters.fee_params().gas_per_byte(), gas_per_byte ); Ok(()) diff --git a/packages/fuels-test-helpers/src/node_types.rs b/packages/fuels-test-helpers/src/node_types.rs index 6297f8353..e59858a14 100644 --- a/packages/fuels-test-helpers/src/node_types.rs +++ b/packages/fuels-test-helpers/src/node_types.rs @@ -1,16 +1,11 @@ +pub use fuel_core_chain_config::{ChainConfig, StateConfig}; use std::{ net::{Ipv4Addr, SocketAddr}, path::PathBuf, time::Duration, }; -pub use fuel_core_chain_config::ChainConfig; -use fuel_types::{BlockHeight, Word}; -use fuels_core::constants::WORD_SIZE; -use serde::{de::Error as SerdeError, Deserializer, Serializer}; -use serde_with::{DeserializeAs, SerializeAs}; - -const MAX_DATABASE_CACHE_SIZE: usize = 10 * 1024 * 1024; +pub(crate) const MAX_DATABASE_CACHE_SIZE: usize = 10 * 1024 * 1024; #[derive(Clone, Debug)] pub enum Trigger { @@ -47,7 +42,7 @@ impl From for fuel_core::service::DbType { } #[derive(Clone, Debug)] -pub struct Config { +pub struct NodeConfig { pub addr: SocketAddr, pub max_database_cache_size: Option, pub database_type: DbType, @@ -56,10 +51,9 @@ pub struct Config { pub block_production: Trigger, pub vm_backtrace: bool, pub silent: bool, - pub chain_conf: ChainConfig, } -impl Default for Config { +impl Default for NodeConfig { fn default() -> Self { Self { addr: SocketAddr::new(Ipv4Addr::new(127, 0, 0, 1).into(), 0), @@ -70,115 +64,6 @@ impl Default for Config { block_production: Trigger::Instant, vm_backtrace: false, silent: true, - chain_conf: ChainConfig::local_testnet(), - } - } -} - -#[cfg(feature = "fuel-core-lib")] -impl From for fuel_core::service::Config { - fn from(value: Config) -> Self { - Self { - addr: value.addr, - max_database_cache_size: value - .max_database_cache_size - .unwrap_or(MAX_DATABASE_CACHE_SIZE), - database_path: match &value.database_type { - DbType::InMemory => Default::default(), - DbType::RocksDb(path) => path.clone().unwrap_or_default(), - }, - database_type: value.database_type.into(), - utxo_validation: value.utxo_validation, - debug: value.debug, - block_production: value.block_production.into(), - chain_conf: value.chain_conf, - ..fuel_core::service::Config::local_node() - } - } -} - -pub(crate) mod serde_hex { - use std::{convert::TryFrom, fmt}; - - use hex::{FromHex, ToHex}; - use serde::{de::Error, Deserializer, Serializer}; - - pub fn serialize(target: T, ser: S) -> Result - where - S: Serializer, - T: ToHex, - { - let s = format!("0x{}", target.encode_hex::()); - ser.serialize_str(&s) - } - - pub fn deserialize<'de, T, E, D>(des: D) -> Result - where - D: Deserializer<'de>, - for<'a> T: TryFrom<&'a [u8], Error = E>, - E: fmt::Display, - { - let raw_string: String = serde::Deserialize::deserialize(des)?; - let stripped_prefix = raw_string.trim_start_matches("0x"); - let bytes: Vec = FromHex::from_hex(stripped_prefix).map_err(D::Error::custom)?; - let result = T::try_from(bytes.as_slice()).map_err(D::Error::custom)?; - Ok(result) - } -} - -pub(crate) struct HexNumber; - -impl SerializeAs for HexNumber { - fn serialize_as(value: &u64, serializer: S) -> Result - where - S: Serializer, - { - let bytes = value.to_be_bytes(); - serde_hex::serialize(bytes, serializer) - } -} - -impl<'de> DeserializeAs<'de, Word> for HexNumber { - fn deserialize_as(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let mut bytes: Vec = serde_hex::deserialize(deserializer)?; - match bytes.len() { - len if len > WORD_SIZE => { - return Err(D::Error::custom(format!( - "value can't exceed {WORD_SIZE} bytes", - ))); - } - len if len < WORD_SIZE => { - // pad if length < word size - bytes = (0..WORD_SIZE - len).map(|_| 0u8).chain(bytes).collect(); - } - _ => {} } - // We've already verified the bytes.len == WORD_SIZE, force the conversion here. - Ok(Word::from_be_bytes( - bytes.try_into().expect("byte lengths checked"), - )) - } -} - -impl SerializeAs for HexNumber { - fn serialize_as(value: &BlockHeight, serializer: S) -> Result - where - S: Serializer, - { - let number = u32::from(*value) as u64; - HexNumber::serialize_as(&number, serializer) - } -} - -impl<'de> DeserializeAs<'de, BlockHeight> for HexNumber { - fn deserialize_as(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let number: u64 = HexNumber::deserialize_as(deserializer)?; - Ok((number as u32).into()) } } diff --git a/packages/fuels-test-helpers/src/service.rs b/packages/fuels-test-helpers/src/service.rs index c6fcb66c0..497d5e5c1 100644 --- a/packages/fuels-test-helpers/src/service.rs +++ b/packages/fuels-test-helpers/src/service.rs @@ -1,7 +1,8 @@ use std::net::SocketAddr; #[cfg(feature = "fuel-core-lib")] -use fuel_core::service::FuelService as CoreFuelService; +use fuel_core::service::{Config as ServiceConfig, FuelService as CoreFuelService}; +use fuel_core_chain_config::{ChainConfig, StateConfig}; #[cfg(feature = "fuel-core-lib")] use fuel_core_services::Service; use fuel_core_services::State; @@ -9,7 +10,7 @@ use fuels_core::types::errors::{error, Result}; #[cfg(not(feature = "fuel-core-lib"))] use crate::fuel_bin_service::FuelService as BinFuelService; -use crate::Config; +use crate::NodeConfig; pub struct FuelService { #[cfg(feature = "fuel-core-lib")] @@ -20,14 +21,21 @@ pub struct FuelService { } impl FuelService { - pub async fn start(config: Config) -> Result { + pub async fn start( + node_config: NodeConfig, + chain_config: ChainConfig, + state_config: StateConfig, + ) -> Result { #[cfg(feature = "fuel-core-lib")] - let service = CoreFuelService::new_node(config.into()) - .await - .map_err(|err| error!(Other, "{err}"))?; + let service = { + let config = Self::service_config(node_config, chain_config, state_config); + CoreFuelService::new_node(config) + .await + .map_err(|err| error!(Other, "{err}"))? + }; #[cfg(not(feature = "fuel-core-lib"))] - let service = BinFuelService::new_node(config).await?; + let service = BinFuelService::new_node(node_config, chain_config, state_config).await?; let bound_address = service.bound_address; @@ -50,4 +58,37 @@ impl FuelService { pub fn bound_address(&self) -> SocketAddr { self.bound_address } + + #[cfg(feature = "fuel-core-lib")] + fn service_config( + node_config: NodeConfig, + chain_config: ChainConfig, + state_config: StateConfig, + ) -> ServiceConfig { + use crate::{DbType, MAX_DATABASE_CACHE_SIZE}; + use fuel_core::combined_database::CombinedDatabaseConfig; + use fuel_core_chain_config::SnapshotReader; + + let snapshot_reader = SnapshotReader::new_in_memory(chain_config, state_config); + + let combined_db_config = CombinedDatabaseConfig { + max_database_cache_size: node_config + .max_database_cache_size + .unwrap_or(MAX_DATABASE_CACHE_SIZE), + database_path: match &node_config.database_type { + DbType::InMemory => Default::default(), + DbType::RocksDb(path) => path.clone().unwrap_or_default(), + }, + database_type: node_config.database_type.into(), + }; + ServiceConfig { + addr: node_config.addr, + combined_db_config, + snapshot_reader, + utxo_validation: node_config.utxo_validation, + debug: node_config.debug, + block_production: node_config.block_production.into(), + ..ServiceConfig::local_node() + } + } } diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 1e3034df7..49edcf9a3 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1,3 +1,4 @@ +use fuel_tx::ContractParameters; #[cfg(not(feature = "experimental"))] use fuels::core::codec::{calldata, fn_selector}; use fuels::{ @@ -1017,10 +1018,13 @@ async fn test_contract_call_with_non_default_max_input() -> Result<()> { types::coin::Coin, }; - let consensus_parameters = ConsensusParameters { - tx_params: TxParameters::default().with_max_inputs(123), - ..Default::default() - }; + let mut consensus_parameters = ConsensusParameters::default(); + let tx_params = TxParameters::default() + .with_max_inputs(123) + .with_max_size(1_000_000); + consensus_parameters.set_tx_params(tx_params); + let contract_params = ContractParameters::default().with_contract_max_size(1_000_000); + consensus_parameters.set_contract_params(contract_params); let mut wallet = WalletUnlocked::new_random(None); @@ -1344,19 +1348,19 @@ fn db_rocksdb() { prelude::{setup_test_provider, DbType, Error, ViewOnlyAccount, DEFAULT_COIN_AMOUNT}, }; - let temp_dir = tempfile::tempdir() - .expect("failed to make tempdir") - .into_path(); + let temp_dir = tempfile::tempdir().expect("failed to make tempdir"); let temp_dir_name = temp_dir + .path() .file_name() .expect("failed to get file name") .to_string_lossy() .to_string(); - let temp_database_path = temp_dir.join("db"); + let temp_database_path = temp_dir.path().join("db"); tokio::runtime::Runtime::new() .expect("tokio runtime failed") .block_on(async { + let _ = temp_dir; let wallet = WalletUnlocked::new_from_private_key( SecretKey::from_str( "0x4433d156e8c53bf5b50af07aa95a29436f29a94e0ccc5d58df8e57bdc8583c32", @@ -1365,14 +1369,13 @@ fn db_rocksdb() { ); const NUMBER_OF_ASSETS: u64 = 2; - let node_config = Config { + let node_config = NodeConfig { database_type: DbType::RocksDb(Some(temp_database_path.clone())), - ..Config::default() + ..NodeConfig::default() }; let chain_config = ChainConfig { chain_name: temp_dir_name.clone(), - initial_state: None, consensus_parameters: Default::default(), ..ChainConfig::local_testnet() }; @@ -1399,9 +1402,9 @@ fn db_rocksdb() { tokio::runtime::Runtime::new() .expect("tokio runtime failed") .block_on(async { - let node_config = Config { + let node_config = NodeConfig { database_type: DbType::RocksDb(Some(temp_database_path.clone())), - ..Config::default() + ..NodeConfig::default() }; let provider = setup_test_provider(vec![], vec![], Some(node_config), None).await?; diff --git a/packages/fuels/tests/providers.rs b/packages/fuels/tests/providers.rs index 0b0a52407..95b11b97f 100644 --- a/packages/fuels/tests/providers.rs +++ b/packages/fuels/tests/providers.rs @@ -1,6 +1,7 @@ use std::{ops::Add, str::FromStr}; use chrono::{DateTime, Duration, TimeZone, Utc}; +use fuel_core::chain_config::StateConfig; use fuels::{ accounts::Account, client::{PageDirection, PaginationRequest}, @@ -73,8 +74,10 @@ async fn test_network_error() -> Result<()> { let mut wallet = WalletUnlocked::new_random(None); - let config = Config::default(); - let service = FuelService::start(config).await?; + let node_config = NodeConfig::default(); + let chain_config = ChainConfig::default(); + let state_config = StateConfig::default(); + let service = FuelService::start(node_config, chain_config, state_config).await?; let provider = Provider::connect(service.bound_address().to_string()).await?; wallet.set_provider(provider); @@ -218,12 +221,12 @@ async fn can_increase_block_height() -> Result<()> { async fn can_set_custom_block_time() -> Result<()> { // ANCHOR: use_produce_blocks_custom_time let block_time = 20u32; // seconds - let config = Config { + let config = NodeConfig { // This is how you specify the time between blocks block_production: Trigger::Interval { block_time: std::time::Duration::from_secs(block_time.into()), }, - ..Config::default() + ..NodeConfig::default() }; let wallets = launch_custom_provider_and_get_wallets(WalletsConfig::default(), Some(config), None) @@ -752,11 +755,11 @@ fn convert_to_datetime(timestamp: u64) -> DateTime { #[tokio::test] async fn test_sway_timestamp() -> Result<()> { let block_time = 1u32; // seconds - let provider_config = Config { + let provider_config = NodeConfig { block_production: Trigger::Interval { block_time: std::time::Duration::from_secs(block_time.into()), }, - ..Config::default() + ..NodeConfig::default() }; let mut wallets = launch_custom_provider_and_get_wallets( WalletsConfig::new(Some(1), Some(1), Some(100)), @@ -833,7 +836,7 @@ async fn test_caching() -> Result<()> { let num_coins = 10; let mut wallets = launch_custom_provider_and_get_wallets( WalletsConfig::new(Some(1), Some(num_coins), Some(amount)), - Some(Config::default()), + Some(NodeConfig::default()), None, ) .await?; @@ -889,11 +892,11 @@ async fn test_cache_invalidation_on_await() -> Result<()> { use fuels_core::types::tx_status::TxStatus; let block_time = 1u32; - let provider_config = Config { + let provider_config = NodeConfig { block_production: Trigger::Interval { block_time: std::time::Duration::from_secs(block_time.into()), }, - ..Config::default() + ..NodeConfig::default() }; // create wallet with 1 coin so that the cache prevents further @@ -993,9 +996,9 @@ async fn test_build_with_provider() -> Result<()> { #[tokio::test] async fn can_produce_blocks_with_trig_never() -> Result<()> { - let config = Config { + let config = NodeConfig { block_production: Trigger::Never, - ..Config::default() + ..NodeConfig::default() }; let wallets = launch_custom_provider_and_get_wallets(WalletsConfig::default(), Some(config), None) diff --git a/packages/fuels/tests/scripts.rs b/packages/fuels/tests/scripts.rs index 3d36cb291..2fc2a98b3 100644 --- a/packages/fuels/tests/scripts.rs +++ b/packages/fuels/tests/scripts.rs @@ -107,10 +107,9 @@ async fn test_script_call_with_non_default_max_input() -> Result<()> { types::coin::Coin, }; - let consensus_parameters = ConsensusParameters { - tx_params: TxParameters::default().with_max_inputs(128), - ..Default::default() - }; + let mut consensus_parameters = ConsensusParameters::default(); + let tx_params = TxParameters::default().with_max_inputs(128); + consensus_parameters.set_tx_params(tx_params); let chain_config = ChainConfig { consensus_parameters: consensus_parameters.clone(), ..ChainConfig::default()