Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug!: updating consensus parameters #1569

Merged
merged 7 commits into from
Jan 9, 2025
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ zeroize = "1.7.0"
octocrab = { version = "0.39", default-features = false }
dotenv = { version = "0.15", default-features = false }
toml = { version = "0.8", default-features = false }
mockall = { version = "0.13", default-features = false }

# Dependencies from the `fuel-core` repository:
fuel-core = { version = "0.40.1", default-features = false, features = [
Expand Down
19 changes: 14 additions & 5 deletions e2e/tests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ async fn test_contract_call_with_non_default_max_input() -> Result<()> {

let provider = setup_test_provider(coins, vec![], None, Some(chain_config)).await?;
wallet.set_provider(provider.clone());
assert_eq!(consensus_parameters, *provider.consensus_parameters());
assert_eq!(consensus_parameters, provider.consensus_parameters().await?);

setup_program_test!(
Abigen(Contract(
Expand Down Expand Up @@ -1708,8 +1708,9 @@ async fn contract_custom_call_no_signatures_strategy() -> Result<()> {
let mut tb = call_handler.transaction_builder().await?;

let amount = 10;
let consensus_parameters = provider.consensus_parameters().await?;
let new_base_inputs = wallet
.get_asset_inputs_for_amount(*provider.base_asset_id(), amount, None)
.get_asset_inputs_for_amount(*consensus_parameters.base_asset_id(), amount, None)
.await?;
tb.inputs_mut().extend(new_base_inputs);

Expand All @@ -1719,7 +1720,8 @@ async fn contract_custom_call_no_signatures_strategy() -> Result<()> {
.build(provider)
.await?;
// ANCHOR: tx_sign_with
tx.sign_with(&wallet, provider.chain_id()).await?;
tx.sign_with(&wallet, consensus_parameters.chain_id())
.await?;
// ANCHOR_END: tx_sign_with
// ANCHOR_END: tb_no_signatures_strategy

Expand Down Expand Up @@ -1856,7 +1858,14 @@ async fn msg_sender_gas_estimation_issue() {
let asset_id = ids[0];

// The fake coin won't be added if we add a base asset, so let's not do that
assert!(asset_id != *provider.base_asset_id());
assert!(
asset_id
!= *provider
.consensus_parameters()
.await
.unwrap()
.base_asset_id()
);
let call_params = CallParameters::default()
.with_amount(100)
.with_asset_id(asset_id);
Expand Down Expand Up @@ -2207,7 +2216,7 @@ async fn blob_contract_deployment() -> Result<()> {

let provider = wallets[0].provider().unwrap().clone();

let consensus_parameters = provider.consensus_parameters();
let consensus_parameters = provider.consensus_parameters().await?;

let contract_max_size = consensus_parameters.contract_params().contract_max_size();
assert!(
Expand Down
23 changes: 16 additions & 7 deletions e2e/tests/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ async fn pay_with_predicate() -> Result<()> {

// TODO: https://github.com/FuelLabs/fuels-rs/issues/1394
let expected_fee = 1;
let consensus_parameters = provider.consensus_parameters().await?;
assert_eq!(
predicate
.get_asset_balance(provider.base_asset_id())
.get_asset_balance(consensus_parameters.base_asset_id())
.await?,
192 - expected_fee
);
Expand All @@ -258,7 +259,7 @@ async fn pay_with_predicate() -> Result<()> {
let expected_fee = 2;
assert_eq!(
predicate
.get_asset_balance(provider.base_asset_id())
.get_asset_balance(consensus_parameters.base_asset_id())
.await?,
191 - expected_fee
);
Expand Down Expand Up @@ -309,9 +310,10 @@ async fn pay_with_predicate_vector_data() -> Result<()> {

// TODO: https://github.com/FuelLabs/fuels-rs/issues/1394
let expected_fee = 1;
let consensus_parameters = provider.consensus_parameters().await?;
assert_eq!(
predicate
.get_asset_balance(provider.base_asset_id())
.get_asset_balance(consensus_parameters.base_asset_id())
.await?,
192 - expected_fee
);
Expand All @@ -327,7 +329,7 @@ async fn pay_with_predicate_vector_data() -> Result<()> {
assert_eq!(42, response.value);
assert_eq!(
predicate
.get_asset_balance(provider.base_asset_id())
.get_asset_balance(consensus_parameters.base_asset_id())
.await?,
191 - expected_fee
);
Expand Down Expand Up @@ -849,9 +851,14 @@ async fn predicate_transfer_non_base_asset() -> Result<()> {
let inputs = predicate
.get_asset_inputs_for_amount(non_base_asset_id, amount, None)
.await?;
let consensus_parameters = provider.consensus_parameters().await?;
let outputs = vec![
Output::change(wallet.address().into(), 0, non_base_asset_id),
Output::change(wallet.address().into(), 0, *provider.base_asset_id()),
Output::change(
wallet.address().into(),
0,
*consensus_parameters.base_asset_id(),
),
];

let mut tb = ScriptTransactionBuilder::prepare_transfer(
Expand Down Expand Up @@ -982,14 +989,16 @@ async fn tx_id_not_changed_after_adding_witnesses() -> Result<()> {
.build(&provider)
.await?;

let tx_id = tx.id(provider.chain_id());
let consensus_parameters = provider.consensus_parameters().await?;
let chain_id = consensus_parameters.chain_id();
let tx_id = tx.id(chain_id);

let witness = ABIEncoder::default().encode(&[64u64.into_token()])?; // u64 because this is VM memory
let witness2 = ABIEncoder::default().encode(&[4096u64.into_token()])?;

tx.append_witness(witness.into())?;
tx.append_witness(witness2.into())?;
let tx_id_after_witnesses = tx.id(provider.chain_id());
let tx_id_after_witnesses = tx.id(chain_id);

let tx_id_from_provider = provider.send_transaction(tx).await?;

Expand Down
49 changes: 34 additions & 15 deletions e2e/tests/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ async fn test_input_message_pays_fee() -> Result<()> {
);

let provider = setup_test_provider(vec![], vec![messages], None, None).await?;
let base_asset_id = *provider.base_asset_id();
let consensus_parameters = provider.consensus_parameters().await?;
let base_asset_id = consensus_parameters.base_asset_id();
wallet.set_provider(provider);

abigen!(Contract(
Expand All @@ -192,7 +193,7 @@ async fn test_input_message_pays_fee() -> Result<()> {

assert_eq!(42, response.value);

let balance = wallet.get_asset_balance(&base_asset_id).await?;
let balance = wallet.get_asset_balance(base_asset_id).await?;
// TODO: https://github.com/FuelLabs/fuels-rs/issues/1394
let expected_fee = 2;
assert_eq!(balance, DEFAULT_COIN_AMOUNT - expected_fee);
Expand Down Expand Up @@ -649,9 +650,14 @@ async fn test_get_spendable_with_exclusion() -> Result<()> {
wallet.set_provider(provider.clone());

let requested_amount = coin_amount_1 + coin_amount_2 + message_amount;
let consensus_parameters = provider.consensus_parameters().await?;
{
let resources = wallet
.get_spendable_resources(*provider.base_asset_id(), requested_amount, None)
.get_spendable_resources(
*consensus_parameters.base_asset_id(),
requested_amount,
None,
)
.await
.unwrap();
assert_eq!(resources.len(), 3);
Expand Down Expand Up @@ -895,8 +901,9 @@ async fn test_cache_invalidation_on_await() -> Result<()> {

assert!(matches!(tx_status, TxStatus::Revert { .. }));

let consensus_parameters = provider.consensus_parameters().await?;
let coins = wallet
.get_spendable_resources(*provider.base_asset_id(), 1, None)
.get_spendable_resources(*consensus_parameters.base_asset_id(), 1, None)
.await?;
assert_eq!(coins.len(), 1);

Expand Down Expand Up @@ -950,11 +957,15 @@ async fn test_build_with_provider() -> Result<()> {

let receiver = WalletUnlocked::new_random(Some(provider.clone()));

let consensus_parameters = provider.consensus_parameters().await?;
let inputs = wallet
.get_asset_inputs_for_amount(*provider.base_asset_id(), 100, None)
.get_asset_inputs_for_amount(*consensus_parameters.base_asset_id(), 100, None)
.await?;
let outputs =
wallet.get_asset_outputs_for_amount(receiver.address(), *provider.base_asset_id(), 100);
let outputs = wallet.get_asset_outputs_for_amount(
receiver.address(),
*consensus_parameters.base_asset_id(),
100,
);

let mut tb = ScriptTransactionBuilder::prepare_transfer(inputs, outputs, TxPolicies::default());
tb.add_signer(wallet.clone())?;
Expand All @@ -963,7 +974,9 @@ async fn test_build_with_provider() -> Result<()> {

provider.send_transaction_and_await_commit(tx).await?;

let receiver_balance = receiver.get_asset_balance(provider.base_asset_id()).await?;
let receiver_balance = receiver
.get_asset_balance(consensus_parameters.base_asset_id())
.await?;

assert_eq!(receiver_balance, 100);

Expand All @@ -982,19 +995,20 @@ async fn can_produce_blocks_with_trig_never() -> Result<()> {
let wallet = &wallets[0];
let provider = wallet.try_provider()?;

let consensus_parameters = provider.consensus_parameters().await?;
let inputs = wallet
.get_asset_inputs_for_amount(*provider.base_asset_id(), 100, None)
.get_asset_inputs_for_amount(*consensus_parameters.base_asset_id(), 100, None)
.await?;
let outputs = wallet.get_asset_outputs_for_amount(
&Bech32Address::default(),
*provider.base_asset_id(),
*consensus_parameters.base_asset_id(),
100,
);

let mut tb = ScriptTransactionBuilder::prepare_transfer(inputs, outputs, TxPolicies::default());
tb.add_signer(wallet.clone())?;
let tx = tb.build(provider).await?;
let tx_id = tx.id(provider.chain_id());
let tx_id = tx.id(consensus_parameters.chain_id());

provider.send_transaction(tx).await?;
provider.produce_blocks(1, None).await?;
Expand Down Expand Up @@ -1140,11 +1154,15 @@ async fn tx_with_witness_data() -> Result<()> {

let receiver = WalletUnlocked::new_random(Some(provider.clone()));

let consensus_parameters = provider.consensus_parameters().await?;
let inputs = wallet
.get_asset_inputs_for_amount(*provider.base_asset_id(), 10000, None)
.get_asset_inputs_for_amount(*consensus_parameters.base_asset_id(), 10000, None)
.await?;
let outputs =
wallet.get_asset_outputs_for_amount(receiver.address(), *provider.base_asset_id(), 1);
let outputs = wallet.get_asset_outputs_for_amount(
receiver.address(),
*consensus_parameters.base_asset_id(),
1,
);

let mut tb = ScriptTransactionBuilder::prepare_transfer(inputs, outputs, TxPolicies::default());
tb.add_signer(wallet.clone())?;
Expand Down Expand Up @@ -1297,7 +1315,8 @@ async fn is_account_query_test() -> Result<()> {
wallet.add_witnesses(&mut tb)?;
let tx = tb.build(provider.clone()).await?;

let tx_id = tx.id(provider.chain_id());
let consensus_parameters = provider.consensus_parameters().await?;
let tx_id = tx.id(consensus_parameters.chain_id());
let is_account = provider.is_user_account(tx_id).await?;
assert!(is_account);

Expand Down
20 changes: 15 additions & 5 deletions e2e/tests/wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn compare_inputs(inputs: &[Input], expected_inputs: &mut Vec<Input>) -> bool {
return false;
}

return comparison_results.iter().all(|&r| r);
comparison_results.iter().all(|&r| r)
}

fn base_asset_wallet_config(num_wallets: u64) -> WalletsConfig {
Expand Down Expand Up @@ -348,7 +348,10 @@ async fn test_wallet_get_coins() -> Result<()> {
let provider = setup_test_provider(coins, vec![], None, None).await?;
wallet.set_provider(provider.clone());

let wallet_initial_coins = wallet.get_coins(*provider.base_asset_id()).await?;
let consensus_parameters = provider.consensus_parameters().await?;
let wallet_initial_coins = wallet
.get_coins(*consensus_parameters.base_asset_id())
.await?;
let total_amount: u64 = wallet_initial_coins.iter().map(|c| c.amount).sum();

assert_eq!(wallet_initial_coins.len(), NUM_COINS as usize);
Expand Down Expand Up @@ -445,10 +448,15 @@ async fn test_transfer_with_multiple_signatures() -> Result<()> {
let amount_to_transfer = 20;

let mut inputs = vec![];
let consensus_parameters = provider.consensus_parameters().await?;
for wallet in &wallets {
inputs.extend(
wallet
.get_asset_inputs_for_amount(*provider.base_asset_id(), amount_to_transfer, None)
.get_asset_inputs_for_amount(
*consensus_parameters.base_asset_id(),
amount_to_transfer,
None,
)
.await?,
);
}
Expand All @@ -458,7 +466,7 @@ async fn test_transfer_with_multiple_signatures() -> Result<()> {
// all change goes to the first wallet
let outputs = wallets[0].get_asset_outputs_for_amount(
receiver.address(),
*provider.base_asset_id(),
*consensus_parameters.base_asset_id(),
amount_to_receive,
);

Expand All @@ -472,7 +480,9 @@ async fn test_transfer_with_multiple_signatures() -> Result<()> {
provider.send_transaction_and_await_commit(tx).await?;

assert_eq!(
receiver.get_asset_balance(provider.base_asset_id()).await?,
receiver
.get_asset_balance(consensus_parameters.base_asset_id())
.await?,
amount_to_receive,
);

Expand Down
13 changes: 11 additions & 2 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ mod tests {
)?;
let max_allowed = provider
.consensus_parameters()
.await?
.contract_params()
.contract_max_size();

Expand Down Expand Up @@ -1105,11 +1106,19 @@ mod tests {
// ANCHOR_END: use_loader

// ANCHOR: show_max_tx_size
provider.consensus_parameters().tx_params().max_size();
provider
.consensus_parameters()
.await?
.tx_params()
.max_size();
// ANCHOR_END: show_max_tx_size

// ANCHOR: show_max_tx_gas
provider.consensus_parameters().tx_params().max_gas_per_tx();
provider
.consensus_parameters()
.await?
.tx_params()
.max_gas_per_tx();
// ANCHOR_END: show_max_tx_gas

let wallet = main_wallet;
Expand Down
10 changes: 6 additions & 4 deletions examples/cookbook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ mod tests {
// ANCHOR: transfer_multiple_input
let balances = wallet_1.get_balances().await?;

let consensus_parameters = provider.consensus_parameters().await?;
let mut inputs = vec![];
let mut outputs = vec![];
for (id_string, amount) in balances {
Expand All @@ -174,7 +175,7 @@ mod tests {
inputs.extend(input);

// we don't transfer the full base asset so we can cover fees
let output = if id == *provider.base_asset_id() {
let output = if id == *consensus_parameters.base_asset_id() {
wallet_1.get_asset_outputs_for_amount(wallet_2.address(), id, amount / 2)
} else {
wallet_1.get_asset_outputs_for_amount(wallet_2.address(), id, amount)
Expand All @@ -197,7 +198,7 @@ mod tests {

assert_eq!(balances.len(), NUM_ASSETS as usize);
for (id, balance) in balances {
if id == provider.base_asset_id().to_string() {
if id == *consensus_parameters.base_asset_id().to_string() {
assert_eq!(balance, AMOUNT / 2);
} else {
assert_eq!(balance, AMOUNT);
Expand Down Expand Up @@ -269,12 +270,13 @@ mod tests {
// ANCHOR_END: custom_tx

// ANCHOR: custom_tx_io_base
let consensus_parameters = provider.consensus_parameters().await?;
let base_inputs = hot_wallet
.get_asset_inputs_for_amount(*provider.base_asset_id(), ask_amount, None)
.get_asset_inputs_for_amount(*consensus_parameters.base_asset_id(), ask_amount, None)
.await?;
let base_outputs = hot_wallet.get_asset_outputs_for_amount(
&receiver,
*provider.base_asset_id(),
*consensus_parameters.base_asset_id(),
ask_amount,
);
// ANCHOR_END: custom_tx_io_base
Expand Down
Loading
Loading