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!: upgrade fuel-core to v0.20.1 #1053

Merged
merged 22 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 18 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 @@ -16,10 +16,10 @@ env:
CARGO_TERM_COLOR: always
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v1.24.3/dasel_linux_amd64
RUSTFLAGS: "-D warnings"
FUEL_CORE_VERSION: 0.19.1
FUEL_CORE_VERSION: 0.20.3
RUST_VERSION: 1.70.0
FORC_VERSION: 0.42.1
FORC_PATCH_BRANCH: ""
FORC_PATCH_BRANCH: "upgrade/fuel-core-v0.20.1"
Br1ght0ne marked this conversation as resolved.
Show resolved Hide resolved
FORC_PATCH_REVISION: ""

jobs:
Expand Down
26 changes: 15 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ chrono = "0.4.24"
elliptic-curve = { version = "0.13.4", default-features = false }
eth-keystore = "0.5.0"
fuel-abi-types = "0.3.0"
fuel-core = { version = "0.19.1", default-features = false }
fuel-core-chain-config = { version = "0.19.1", default-features = false }
fuel-core-client = { version = "0.19.1", default-features = false }
fuel-core-types = { version = "0.19.1", default-features = false }
fuel-asm = "0.34.0"
fuel-crypto = "0.34.0"
fuel-merkle = "0.34.0"
fuel-storage = "0.34.0"
fuel-tx = "0.34.0"
fuel-types = { version = "0.34.0", default-features = false }
fuel-vm = "0.34.0"
fuels = { version = "0.44.0", path = "./packages/fuels" }
fuels-accounts = { version = "0.44.0", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.44.0", path = "./packages/fuels-code-gen", default-features = false }
Expand Down Expand Up @@ -84,3 +73,18 @@ thiserror = { version = "1.0.40", default-features = false }
tokio = { version = "1.27.0", default-features = false }
trybuild = "1.0.80"
which = { version = "4.4", default-features = false }

# Dependencies from the `fuel-core` repository:
fuel-core = { version = "0.20.3", default-features = false }
fuel-core-chain-config = { version = "0.20.3", default-features = false }
fuel-core-client = { version = "0.20.3", default-features = false }
fuel-core-types = { version = "0.20.3", default-features = false }

# Dependencies from the `fuel-vm` repository:
fuel-asm = "0.35.3"
fuel-crypto = "0.35.3"
fuel-merkle = "0.35.3"
fuel-storage = "0.35.3"
fuel-tx = "0.35.3"
fuel-types = { version = "0.35.3", default-features = false }
fuel-vm = "0.35.3"
14 changes: 9 additions & 5 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(test)]
mod tests {
use fuels::tx::{Bytes32, ContractIdExt};
use fuels::types::errors::{error, Error, Result};

#[tokio::test]
Expand Down Expand Up @@ -104,7 +105,7 @@ mod tests {
.await?;
// ANCHOR_END: contract_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 499);
assert_eq!(transaction_cost.gas_used, 333);

Ok(())
}
Expand Down Expand Up @@ -344,10 +345,13 @@ mod tests {
let response = contract_methods.mint_coins(1_000_000).call().await?;
// ANCHOR: variable_outputs
let address = wallet.address();
let asset_id = ContractId::from(contract_id)
.asset_id(&Bytes32::zeroed())
.into();
hal3e marked this conversation as resolved.
Show resolved Hide resolved

// withdraw some tokens to wallet
let response = contract_methods
.transfer_coins_to_output(1_000_000, contract_id, address)
.transfer_coins_to_output(1_000_000, asset_id, address)
.append_variable_outputs(1)
.call()
.await?;
Expand Down Expand Up @@ -406,7 +410,7 @@ mod tests {
.await?;
// ANCHOR_END: dependency_estimation_manual

let asset_id = AssetId::from(*caller_contract_id.hash());
let asset_id = ContractId::from(*caller_contract_id.hash()).asset_id(&Bytes32::zeroed());
let balance = wallet.get_asset_balance(&asset_id).await?;
assert_eq!(balance, amount);

Expand Down Expand Up @@ -530,7 +534,7 @@ mod tests {
// Set the transaction `gas_limit` to 10_000 and `gas_forwarded` to 4300 to specify that
xgreenx marked this conversation as resolved.
Show resolved Hide resolved
// the contract call transaction may consume up to 10_000 gas, while the actual call may
xgreenx marked this conversation as resolved.
Show resolved Hide resolved
// only use 4300 gas
let tx_params = TxParameters::default().set_gas_limit(10_000);
let tx_params = TxParameters::default().set_gas_limit(1_000_000);
let call_params = CallParameters::default().set_gas_forwarded(4300);

let response = contract_methods
Expand Down Expand Up @@ -628,7 +632,7 @@ mod tests {
.await?;
// ANCHOR_END: multi_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 786);
assert_eq!(transaction_cost.gas_used, 546);

Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion examples/cookbook/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(test)]
mod tests {
use fuels::tx::{Bytes32, ContractIdExt};
use fuels::{
prelude::Result,
types::transaction_builders::{ScriptTransactionBuilder, TransactionBuilder},
Expand Down Expand Up @@ -65,7 +66,7 @@ mod tests {
// ANCHOR_END: liquidity_deposit

// ANCHOR: liquidity_withdraw
let lp_asset_id = AssetId::from(*contract_id.hash());
let lp_asset_id = ContractId::from(*contract_id.hash()).asset_id(&Bytes32::zeroed());
let lp_token_balance = wallet.get_asset_balance(&lp_asset_id).await?;

let call_params = CallParameters::default()
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ mod tests {
let message = Message::from_bytes(*tx.id(consensus_parameters.chain_id.into()));

// Check if signature is what we expect it to be
assert_eq!(signature, Signature::from_str("13ce336c5f239a748f20f39323e3df3237ccfe104b04f128be66f26a49abd09d3b4b19c7f07efbb708c442371feb5fc6545f2b614e1f9f336702cca3e62d0cc8")?);
assert_eq!(signature, Signature::from_str("df91e8ae723165f9a28b70910e3da41300da413607065618522f3084c9f051114acb1b51a836bd63c3d84a1ac904bf37b82ef03973c19026b266d04872f170a6")?);

// Recover address that signed the transaction
let recovered_address = signature.recover(&message)?;
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub type ByteArray = [u8; 8];
pub type Selector = ByteArray;
pub type EnumSelector = (u8, Token, EnumVariants);

#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
pub struct StringToken {
data: String,
expected_len: Option<usize>,
Expand Down Expand Up @@ -70,7 +70,7 @@ impl TryFrom<StringToken> for String {
}
}

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
digorithm marked this conversation as resolved.
Show resolved Hide resolved
pub enum Token {
// Used for unit type variants in Enum. An "empty" enum is not represented as Enum<empty box>,
// because this way we can have both unit and non-unit type variants.
Expand Down
7 changes: 7 additions & 0 deletions packages/fuels-core/src/types/core/bits.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use fuel_types::AssetId;
use fuels_macros::{Parameterize, Tokenizable, TryFrom};

use crate::types::errors::{error, Error, Result};
Expand Down Expand Up @@ -29,6 +30,12 @@ impl Bits256 {
}
}

impl From<AssetId> for Bits256 {
fn from(value: AssetId) -> Self {
Self(value.into())
}
}

// A simple wrapper around [Bits256; 2] representing the `B512` type.
#[derive(Debug, PartialEq, Eq, Copy, Clone, Parameterize, Tokenizable, TryFrom)]
#[FuelsCorePath = "crate"]
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-core/src/types/enum_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
},
};

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct EnumVariants {
param_types: Vec<ParamType>,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-core/src/types/param_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
},
};

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum ParamType {
U8,
U16,
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-core/src/utils/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const WORD_SIZE: usize = core::mem::size_of::<Word>();

// ANCHOR: default_tx_parameters
pub const DEFAULT_GAS_PRICE: u64 = 0;
pub const DEFAULT_GAS_LIMIT: u64 = 1_000_000;
pub const DEFAULT_GAS_LIMIT: u64 = 100_000_000;
pub const DEFAULT_MATURITY: u32 = 0;
// ANCHOR_END: default_tx_parameters

Expand Down
7 changes: 6 additions & 1 deletion packages/fuels-programs/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ impl<'a, I: Iterator<Item = &'a Receipt>> ExtractLogIdData for I {
type Output = FilterMap<Self, fn(&Receipt) -> Option<(LogId, Vec<u8>)>>;
fn extract_log_id_and_data(self) -> Self::Output {
self.filter_map(|r| match r {
Receipt::LogData { rb, data, id, .. } => Some((LogId(*id, *rb), data.clone())),
Receipt::LogData {
rb,
data: Some(data),
id,
..
} => Some((LogId(*id, *rb), data.clone())),
Receipt::Log { ra, rb, id, .. } => Some((LogId(*id, *rb), ra.to_be_bytes().to_vec())),
_ => None,
})
Expand Down
13 changes: 9 additions & 4 deletions packages/fuels-programs/src/receipt_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ impl ReceiptParser {

fn extract_return_data(&mut self, contract_id: &ContractId) -> Option<Vec<u8>> {
for (index, receipt) in self.receipts.iter_mut().enumerate() {
if let Receipt::ReturnData { id, data, .. } = receipt {
if let Receipt::ReturnData {
id,
data: Some(data),
..
} = receipt
{
if id == contract_id {
let data = std::mem::take(data);
self.receipts.remove(index);
Expand Down Expand Up @@ -134,10 +139,10 @@ impl ReceiptParser {
..
},
) if *first_id == *contract_id
&& !first_data.is_empty()
&& first_data.is_some()
&& *second_id == ContractId::zeroed() =>
{
Some(vec_data)
vec_data.as_ref()
}
_ => None,
}
Expand Down Expand Up @@ -176,7 +181,7 @@ mod tests {
ptr: Default::default(),
len: Default::default(),
digest: Default::default(),
data: data.to_vec(),
data: Some(data.to_vec()),
pc: Default::default(),
is: Default::default(),
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

pub mod tx {
pub use fuel_tx::{
field, Bytes32, ConsensusParameters, Receipt, Salt, ScriptExecutionResult, StorageSlot,
Transaction as FuelTransaction, TxId,
field, Bytes32, ConsensusParameters, ContractIdExt, Receipt, Salt, ScriptExecutionResult,
StorageSlot, Transaction as FuelTransaction, TxId,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ name = "contract_a"

[dependencies]
shared_lib = { path = "../shared_lib" }
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ name = "contract_b"

[dependencies]
shared_lib = { path = "../shared_lib" }
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "shared_lib"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
1 change: 1 addition & 0 deletions packages/fuels/tests/bindings/simple_contract/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "simple_contract"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
1 change: 1 addition & 0 deletions packages/fuels/tests/bindings/type_paths/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "type_paths"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
8 changes: 5 additions & 3 deletions packages/fuels/tests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::future::Future;
use std::vec;

use fuel_core::chain_config::ChainConfig;
use fuel_tx::{Bytes32, ContractIdExt};
use fuels::{
accounts::{predicate::Predicate, Account},
core::codec::{calldata, fn_selector},
Expand Down Expand Up @@ -280,7 +281,7 @@ 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 = 598;
let expected_gas_used = 399;
let expected_metered_bytes_size = 728;
let expected_total_fee = 372;

Expand Down Expand Up @@ -620,7 +621,7 @@ async fn test_connect_wallet() -> Result<()> {
// pay for call with wallet
let tx_params = TxParameters::default()
.set_gas_price(10)
.set_gas_limit(10000);
.set_gas_limit(1_000_000);
contract_instance
.methods()
.initialize_counter(42)
Expand Down Expand Up @@ -661,7 +662,7 @@ async fn setup_output_variable_estimation_test(
.deploy(&wallets[0], TxParameters::default())
.await?;

let mint_asset_id = AssetId::from(*contract_id.hash());
let mint_asset_id = ContractId::from(&contract_id).asset_id(&Bytes32::zeroed());
let addresses: [Address; 3] = wallets
.iter()
.map(|wallet| wallet.address().into())
Expand Down Expand Up @@ -692,6 +693,7 @@ async fn test_output_variable_estimation() -> Result<()> {
.mint_to_addresses(amount, addresses)
.call()
.await;
println!("{:?}", response);
xgreenx marked this conversation as resolved.
Show resolved Hide resolved
xgreenx marked this conversation as resolved.
Show resolved Hide resolved

assert!(matches!(
response,
Expand Down
1 change: 1 addition & 0 deletions packages/fuels/tests/contracts/asserts/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "asserts"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "auth_testing_abi"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "auth_testing_contract"

[dependencies]

auth_testing_abi = { path = "../auth_testing_abi" }
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
1 change: 1 addition & 0 deletions packages/fuels/tests/contracts/block_timestamp/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "block_timestamp"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
1 change: 1 addition & 0 deletions packages/fuels/tests/contracts/configurables/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "configurables"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
1 change: 1 addition & 0 deletions packages/fuels/tests/contracts/contract_test/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ name = "contract_test"

[dependencies]
increment_abi = { path = "../library_test", package = "library_test" }
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "large_return_data"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
1 change: 1 addition & 0 deletions packages/fuels/tests/contracts/lib_contract/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ name = "lib_contract"

[dependencies]
lib_contract = { path = "../lib_contract_abi/", package = "lib_contract_abi" }
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "lib_contract_abi"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ name = "lib_contract_caller"

[dependencies]
lib_contract = { path = "../lib_contract_abi/", package = "lib_contract_abi" }
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ contract;

use lib_contract::LibContract;
use std::token::mint_to_address;
use std::constants::ZERO_B256;

abi ContractCaller {
fn increment_from_contract(contract_id: ContractId, value: u64) -> u64;
Expand Down Expand Up @@ -32,7 +33,7 @@ impl ContractCaller for Contract {
let contract_instance = abi(LibContract, contract_id.into());
let _ = contract_instance.increment(42);

mint_to_address(amount, address);
mint_to_address(address, ZERO_B256, amount);
}

fn require_from_contract(contract_id: ContractId) {
Expand Down
1 change: 1 addition & 0 deletions packages/fuels/tests/contracts/library_test/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "library_test"

[dependencies]
std = { git = "https://github.com/FuelLabs/sway", branch = "upgrade/fuel-core-v0.20.1" }
Loading
Loading