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

feat: bump forc to 0.46.0 #1148

Merged
merged 18 commits into from
Oct 9, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ env:
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v1.24.3/dasel_linux_amd64
RUSTFLAGS: "-D warnings"
FUEL_CORE_VERSION: 0.20.4
RUST_VERSION: 1.71.1
FORC_VERSION: 0.45.0
RUST_VERSION: 1.72.0
FORC_VERSION: 0.46.0
FORC_PATCH_BRANCH: ""
FORC_PATCH_REVISION: ""

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ homepage = "https://fuel.network/"
readme = "README.md"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/fuels-rs"
rust-version = "1.71.1"
rust-version = "1.72.0"
version = "0.48.0"

[workspace.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions docs/src/calling-contracts/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ You can use the `decode_logs()` function to retrieve a `LogResult` struct contai
```

Due to possible performance hits, it is not recommended to use `decode_logs()` outside of a debugging scenario.

> **Note:** String slices can not be logged directly. Use the `__to_str_array()` function to convert it to a `str[N]` first.
6 changes: 3 additions & 3 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ mod tests {
.await?;
// ANCHOR_END: contract_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 331);
assert_eq!(transaction_cost.gas_used, 397);

Ok(())
}
Expand Down Expand Up @@ -364,7 +364,7 @@ mod tests {
let response = contract_methods.mint_coins(1_000_000).call().await?;
// ANCHOR: variable_outputs
let address = wallet.address();
let asset_id = contract_id.asset_id(&Bits256::zeroed()).into();
let asset_id = contract_id.asset_id(&Bits256::zeroed());

// withdraw some tokens to wallet
let response = contract_methods
Expand Down Expand Up @@ -657,7 +657,7 @@ mod tests {
.await?;
// ANCHOR_END: multi_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 542);
assert_eq!(transaction_cost.gas_used, 618);

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions packages/fuels-code-gen/src/program_bindings/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ mod tests {
pub(crate) fn sdk_provided_custom_types_lookup() -> HashMap<TypePath, TypePath> {
[
("std::address::Address", "::fuels::types::Address"),
("std::contract_id::AssetId", "::fuels::types::AssetId"),
("std::b512::B512", "::fuels::types::B512"),
("std::bytes::Bytes", "::fuels::types::Bytes"),
("std::contract_id::ContractId", "::fuels::types::ContractId"),
Expand Down
23 changes: 19 additions & 4 deletions packages/fuels-core/src/codec/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use fuel_tx::{ContractId, Receipt};
use crate::{
codec::{try_from_bytes, DecoderConfig},
traits::{Parameterize, Tokenizable},
types::errors::{error, Error, Result},
types::{
errors::{error, Error, Result},
param_types::ParamType,
},
};

#[derive(Clone)]
Expand All @@ -31,9 +34,22 @@ impl LogFormatter {
decoder_config: DecoderConfig,
bytes: &[u8],
) -> Result<String> {
Self::can_decode_log_with_type::<T>()?;
Ok(format!("{:?}", try_from_bytes::<T>(bytes, decoder_config)?))
}

fn can_decode_log_with_type<T: Parameterize>() -> Result<()> {
match T::param_type() {
// String slices can not be decoded from logs as they are encoded as ptr, len
// TODO: Once https://github.com/FuelLabs/sway/issues/5110 is resolved we can remove this
ParamType::StringSlice => Err(error!(
InvalidData,
"String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
)),
_ => Ok(()),
}
}

pub fn can_handle_type<T: Tokenizable + Parameterize + 'static>(&self) -> bool {
TypeId::of::<T>() == self.type_id
}
Expand Down Expand Up @@ -162,9 +178,8 @@ impl LogDecoder {
let target_ids: HashSet<LogId> = self
.log_formatters
.iter()
.filter_map(|(log_id, log_formatter)| {
log_formatter.can_handle_type::<T>().then(|| log_id.clone())
})
.filter(|(_, log_formatter)| log_formatter.can_handle_type::<T>())
.map(|(log_id, _)| log_id.clone())
.collect();

receipts
Expand Down
4 changes: 3 additions & 1 deletion packages/fuels/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ members = [
'tests/types/scripts/options_results',
'tests/types/scripts/script_bytes',
'tests/types/scripts/script_generics',
'tests/types/scripts/script_raw_slice',
#TODO: Decide what to do with this test project once
# https://github.com/FuelLabs/sway/issues/5145 is resolved
# 'tests/types/scripts/script_raw_slice',
'tests/types/scripts/script_std_lib_string',
'tests/types/scripts/script_tuples',
'tests/types/scripts/script_u128',
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels/tests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ async fn test_contract_call_fee_estimation() -> Result<()> {
let tolerance = 0.2;

let expected_min_gas_price = 0; // This is the default min_gas_price from the ConsensusParameters
let expected_gas_used = 397;
let expected_gas_used = 476;
let expected_metered_bytes_size = 712;
let expected_total_fee = 325;
let expected_total_fee = 333;

let estimated_transaction_cost = contract_instance
.methods()
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/tests/contracts/configurables/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ configurable {
U8: u8 = 8u8,
BOOL: bool = true,
ARRAY: [u32; 3] = [253u32, 254u32, 255u32],
STR_4: str[4] = "fuel",
STR_4: str[4] = __to_str_array("fuel"),
STRUCT: StructWithGeneric<u8> = StructWithGeneric {
field_1: 8u8,
field_2: 16,
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/tests/contracts/contract_test/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const COUNTER_KEY = 0x0000000000000000000000000000000000000000000000000000000000

storage {
value: u64 = 0,
value_str: str[4] = "none",
value_str: str[4] = __to_str_array("none"),
value_bool: bool = false,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ impl TestContract for Contract {
}

fn get_small_string() -> str[8] {
let my_string: str[8] = "gggggggg";
let my_string: str[8] = __to_str_array("gggggggg");
my_string
}

fn get_large_string() -> str[9] {
let my_string: str[9] = "ggggggggg";
let my_string: str[9] = __to_str_array("ggggggggg");
my_string
}

Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/tests/contracts/lib_contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ impl LibContract for Contract {
}

fn require() -> () {
require(false, "require from contract");
require(false, __to_str_array("require from contract"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abi LiquidityPool {
fn withdraw(recipient: Address);
}

const BASE_TOKEN: b256 = 0x9ae5b658754e096e4d681c548daf46354495a437cc61492599e33fc64dcdc30c;
const BASE_TOKEN: AssetId = AssetId::from(0x9ae5b658754e096e4d681c548daf46354495a437cc61492599e33fc64dcdc30c);

impl LiquidityPool for Contract {
#[payable]
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels/tests/contracts/require/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl TestContract for Contract {
}

fn require_string() {
require(false, "fuel");
require(false, __to_str_array("fuel"));
}

fn require_custom_generic() {
Expand All @@ -54,7 +54,7 @@ impl TestContract for Contract {

fn require_with_additional_logs() {
log(42);
log("fuel");
log(__to_str_array("fuel"));
require(false, 64);
}
}
Loading
Loading