Skip to content

Commit

Permalink
fix: bump fuel-core to 0.41.3 and fix test (#1584)
Browse files Browse the repository at this point in the history
closes: #1579 and
#1580
# Summary
Bump `fuel-core` to `0.41.3` and fix ignored tests.
  • Loading branch information
hal3e authored and segfault-magnet committed Jan 30, 2025
1 parent 66b3f0f commit c39edd3
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.41.0
FUEL_CORE_VERSION: 0.41.3
FUEL_CORE_PATCH_BRANCH: ""
FUEL_CORE_PATCH_REVISION: ""
RUST_VERSION: 1.81.0
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ toml = { version = "0.8", default-features = false }
mockall = { version = "0.13", default-features = false }

# Dependencies from the `fuel-core` repository:
fuel-core = { version = "0.41.0", default-features = false, features = [
fuel-core = { version = "0.41.3", default-features = false, features = [
"wasm-executor",
] }
fuel-core-chain-config = { version = "0.41.0", default-features = false }
fuel-core-client = { version = "0.41.0", default-features = false }
fuel-core-poa = { version = "0.41.0", default-features = false }
fuel-core-services = { version = "0.41.0", default-features = false }
fuel-core-types = { version = "0.41.0", default-features = false }
fuel-core-chain-config = { version = "0.41.3", default-features = false }
fuel-core-client = { version = "0.41.3", default-features = false }
fuel-core-poa = { version = "0.41.3", default-features = false }
fuel-core-services = { version = "0.41.3", default-features = false }
fuel-core-types = { version = "0.41.3", default-features = false }

# Dependencies from the `fuel-vm` repository:
fuel-asm = { version = "0.59.1" }
Expand Down
65 changes: 30 additions & 35 deletions e2e/tests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use fuels::{
core::codec::{calldata, encode_fn_selector, DecoderConfig, EncoderConfig},
prelude::*,
tx::ContractParameters,
types::{errors::transaction::Reason, Bits256, Identity},
types::{errors::transaction::Reason, input::Input, Bits256, Identity},
};
use tokio::time::Instant;

Expand Down Expand Up @@ -2145,33 +2145,32 @@ async fn max_fee_estimation_respects_tolerance() -> Result<()> {
}
};

//TODO:https://github.com/FuelLabs/fuels-rs/issues/1579
// let base_amount_in_inputs = |tolerance: f32| {
// let contract_instance = contract_instance.clone();
// let call_wallet = &call_wallet;
// async move {
// let mut tb = contract_instance
// .methods()
// .initialize_counter(42)
// .transaction_builder()
// .await
// .unwrap()
// .with_max_fee_estimation_tolerance(tolerance);

// call_wallet.adjust_for_fee(&mut tb, 0).await.unwrap();
// tb.inputs
// .iter()
// .filter_map(|input: &Input| match input {
// Input::ResourceSigned { resource }
// if resource.coin_asset_id().unwrap() == AssetId::BASE =>
// {
// Some(resource.amount())
// }
// _ => None,
// })
// .sum::<u64>()
// }
// };
let base_amount_in_inputs = |tolerance: f32| {
let contract_instance = contract_instance.clone();
let call_wallet = &call_wallet;
async move {
let mut tb = contract_instance
.methods()
.initialize_counter(42)
.transaction_builder()
.await
.unwrap()
.with_max_fee_estimation_tolerance(tolerance);

call_wallet.adjust_for_fee(&mut tb, 0).await.unwrap();
tb.inputs
.iter()
.filter_map(|input: &Input| match input {
Input::ResourceSigned { resource }
if resource.coin_asset_id().unwrap() == AssetId::BASE =>
{
Some(resource.amount())
}
_ => None,
})
.sum::<u64>()
}
};

let no_increase_max_fee = max_fee_from_tx(0.0).await;
let increased_max_fee = max_fee_from_tx(2.00).await;
Expand All @@ -2188,13 +2187,9 @@ async fn max_fee_estimation_respects_tolerance() -> Result<()> {
1.00 + 2.00
);

//TODO:https://github.com/FuelLabs/fuels-rs/issues/1579
// let normal_base_asset = base_amount_in_inputs(0.0).await;
// let more_base_asset_due_to_bigger_tolerance = base_amount_in_inputs(2.00).await;
// assert_eq!(
// more_base_asset_due_to_bigger_tolerance as f64 / normal_base_asset as f64,
// 1.00 + 2.00
// );
let normal_base_asset = base_amount_in_inputs(0.0).await;
let more_base_asset_due_to_bigger_tolerance = base_amount_in_inputs(5.00).await;
assert!(more_base_asset_due_to_bigger_tolerance > normal_base_asset);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/types_predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn assert_predicate_spendable(data: Vec<u8>, project_path: impl AsRef<Path
.await?;

// The predicate has spent the funds
//TODO:https://github.com/FuelLabs/fuels-rs/issues/1579
//TODO:https://github.com/FuelLabs/fuels-rs/issues/1394
// assert that the amount_to_send + fee was deducted from the predicate
// assert_address_balance(predicate.address(), &provider, asset_id, 0).await;

Expand Down
110 changes: 17 additions & 93 deletions e2e/tests/wallets.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
use std::iter::repeat;

use fuel_tx::{input::coin::CoinSigned, Input};
use fuels::{
prelude::*,
tx::{TxPointer, UtxoId},
types::{output::Output, Bytes32},
};
use fuels::{prelude::*, types::output::Output};

#[tokio::test]
async fn test_wallet_balance_api_multi_asset() -> Result<()> {
Expand Down Expand Up @@ -71,54 +64,6 @@ async fn test_wallet_balance_api_single_asset() -> Result<()> {
Ok(())
}

fn compare_inputs(inputs: &[Input], expected_inputs: &mut Vec<Input>) -> bool {
let zero_utxo_id = UtxoId::new(Bytes32::zeroed(), 0);

// change UTXO_ids to 0s for comparison, because we can't guess the genesis coin ids
let inputs: Vec<Input> = inputs
.iter()
.map(|input| match input {
Input::CoinSigned(CoinSigned {
owner,
amount,
asset_id,
tx_pointer,
witness_index,
..
}) => Input::coin_signed(
zero_utxo_id,
*owner,
*amount,
*asset_id,
*tx_pointer,
*witness_index,
),
other => other.clone(),
})
.collect();

let comparison_results: Vec<bool> = inputs
.iter()
.map(|input| {
let found_index = expected_inputs
.iter()
.position(|expected| expected == input);
if let Some(index) = found_index {
expected_inputs.remove(index);
true
} else {
false
}
})
.collect();

if !expected_inputs.is_empty() {
return false;
}

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

fn base_asset_wallet_config(num_wallets: u64) -> WalletsConfig {
let asset_configs = vec![AssetConfig {
id: AssetId::zeroed(),
Expand All @@ -129,52 +74,40 @@ fn base_asset_wallet_config(num_wallets: u64) -> WalletsConfig {
}

#[tokio::test]
//TODO:https://github.com/FuelLabs/fuels-rs/issues/1579
#[ignore]
async fn adjust_fee_empty_transaction() -> Result<()> {
let wallet_config = base_asset_wallet_config(1);
let wallet = launch_custom_provider_and_get_wallets(wallet_config, None, None)
.await?
.pop()
.unwrap();
let wallet = launch_provider_and_get_wallet().await?;

let mut tb = ScriptTransactionBuilder::prepare_transfer(vec![], vec![], TxPolicies::default());
tb.add_signer(wallet.clone())?;
assert!(tb.inputs().is_empty());
assert!(tb.outputs().is_empty());

tb.add_signer(wallet.clone())?;
wallet.adjust_for_fee(&mut tb, 0).await?;
assert!(!tb.inputs().is_empty(), "inputs should be added");
assert_eq!(tb.outputs().len(), 1, "output should be added");

let tx = tb.build(wallet.try_provider()?).await?;

let zero_utxo_id = UtxoId::new(Bytes32::zeroed(), 0);
let mut expected_inputs = vec![Input::coin_signed(
zero_utxo_id,
wallet.address().into(),
20,
AssetId::zeroed(),
TxPointer::default(),
0,
)];
let total_amount_inputs: u64 = tx.inputs().iter().map(|i| i.amount().unwrap()).sum();
assert!(
total_amount_inputs > tx.max_fee().unwrap(),
"amount should cover tx"
);

let expected_outputs = vec![Output::change(
wallet.address().into(),
0,
AssetId::zeroed(),
)];

assert!(compare_inputs(tx.inputs(), &mut expected_inputs));
assert_eq!(tx.outputs(), &expected_outputs);

Ok(())
}

#[tokio::test]
//TODO:https://github.com/FuelLabs/fuels-rs/issues/1579
#[ignore]
async fn adjust_fee_resources_to_transfer_with_base_asset() -> Result<()> {
let wallet_config = base_asset_wallet_config(1);
let wallet = launch_custom_provider_and_get_wallets(wallet_config, None, None)
.await?
.pop()
.unwrap();
let wallet = launch_provider_and_get_wallet().await?;

let base_amount = 30;
let base_asset_id = AssetId::zeroed();
Expand All @@ -191,23 +124,14 @@ async fn adjust_fee_resources_to_transfer_with_base_asset() -> Result<()> {

let tx = tb.build(wallet.try_provider()?).await?;

let zero_utxo_id = UtxoId::new(Bytes32::zeroed(), 0);
let mut expected_inputs = repeat(Input::coin_signed(
zero_utxo_id,
wallet.address().into(),
20,
base_asset_id,
TxPointer::default(),
0,
))
.take(3)
.collect::<Vec<_>>();
let total_amount_inputs: u64 = tx.inputs().iter().map(|i| i.amount().unwrap()).sum();
assert!(total_amount_inputs > tx.max_fee().unwrap()); // can cover tx

let expected_outputs = vec![
Output::coin(Address::zeroed(), base_amount, base_asset_id),
Output::change(wallet.address().into(), 0, base_asset_id),
];

assert!(compare_inputs(tx.inputs(), &mut expected_inputs));
assert_eq!(tx.outputs(), &expected_outputs);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub const SUPPORTED_FUEL_CORE_VERSION: semver::Version = semver::Version::new(0, 41, 0);
pub const SUPPORTED_FUEL_CORE_VERSION: semver::Version = semver::Version::new(0, 41, 3);
16 changes: 16 additions & 0 deletions packages/fuels-accounts/src/schema/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,21 @@ type HeavyOperation {
scalar HexString


type IndexationFlags {
"""
Is balances indexation enabled
"""
balances: Boolean!
"""
Is coins to spend indexation enabled
"""
coinsToSpend: Boolean!
"""
Is asset metadata indexation enabled
"""
assetMetadata: Boolean!
}

union Input = InputCoin | InputContract | InputMessage

type InputCoin {
Expand Down Expand Up @@ -764,6 +779,7 @@ type NodeInfo {
maxSize: U64!
maxDepth: U64!
nodeVersion: String!
indexation: IndexationFlags!
txPoolStats: TxPoolStats!
peers: [PeerInfo!]!
}
Expand Down
4 changes: 1 addition & 3 deletions packages/fuels-test-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,5 @@ which = { workspace = true, default-features = false }
[features]
default = ["fuels-accounts", "std"]
std = ["fuels-accounts?/std", "fuels-core/std", "fuel-core-chain-config/std"]
#TODO: remove the rocksdb dep once fuel-core is fixed
#https://github.com/FuelLabs/fuels-rs/issues/1580
fuel-core-lib = ["fuel-core/rocksdb", "rocksdb"]
fuel-core-lib = ["dep:fuel-core"]
rocksdb = ["fuel-core?/rocksdb"]
1 change: 1 addition & 0 deletions packages/fuels-test-helpers/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl FuelService {
max_fds: 512,
columns_policy: ColumnsPolicy::Lazy,
},
#[cfg(feature = "rocksdb")]
state_rewind_policy: Default::default(),
};
ServiceConfig {
Expand Down

0 comments on commit c39edd3

Please sign in to comment.