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

fuel core 0.13 upgrade #657

Merged
merged 20 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ jobs:
run: |
git config --global core.bigfilethreshold 100m

- name: Install Forc
run: |
curl -sSLf https://github.com/FuelLabs/sway/releases/download/v${{ env.FORC_VERSION }}/forc-binaries-linux_amd64.tar.gz -L -o forc.tar.gz
tar -xvf forc.tar.gz
chmod +x forc-binaries/forc
mv forc-binaries/forc /usr/local/bin/forc

- name: Build Sway Examples
uses: actions-rs/cargo@v1
with:
command: run
args: --bin build-test-projects
# - name: Install Forc
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out until forc can be released using this version of the sdk

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out until forc can be released using this version of the sdk

# run: |
# curl -sSLf https://github.com/FuelLabs/sway/releases/download/v${{ env.FORC_VERSION }}/forc-binaries-linux_amd64.tar.gz -L -o forc.tar.gz
# tar -xvf forc.tar.gz
# chmod +x forc-binaries/forc
# mv forc-binaries/forc /usr/local/bin/forc
#
# - name: Build Sway Examples
# uses: actions-rs/cargo@v1
# with:
# command: run
# args: --bin build-test-projects

- uses: actions/upload-artifact@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ docs/book/
packages/fuels/tests/**/**/Forc.lock

# Don't add out/ files from test Sway projects.
packages/fuels/tests/**/**/out/
# packages/fuels/tests/**/**/out/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO you need to remove this.

Copy link
Member Author

@Voxelot Voxelot Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentional.

sway tests were compiled using forc from this PR: FuelLabs/sway#3181

We can't get these sway files to work with the new VM without this version of forc. However forc can't be released until the SDK is published with fuel-core v0.13 support.

See this thread for more context: https://fuellabs.slack.com/archives/C02RU9MNVKN/p1666934602020589


# Don't add target/ files from test Sway projects.
packages/fuels/tests/**/**/target/
3 changes: 3 additions & 0 deletions examples/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ description = "Fuel Rust SDK contract examples."
fuels = { version = "0.27.0", path = "../../packages/fuels" }
rand = "0.8"
tokio = { version = "1.10", features = ["full"] }

[features]
fuel-core-lib = ["fuels/fuel-core-lib"]
12 changes: 6 additions & 6 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod tests {
.await?;
// ANCHOR_END: contract_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 592);
assert_eq!(transaction_cost.gas_used, 7146);

Ok(())
}
Expand Down Expand Up @@ -451,11 +451,11 @@ mod tests {
let contract_methods = MyContract::new(contract_id, wallet.clone()).methods();

// ANCHOR: call_params_gas
// Set the transaction `gas_limit` to 1000 and `gas_forwarded` to 200 to specify that the
// contract call transaction may consume up to 1000 gas, while the actual call may only use 200
// Set the transaction `gas_limit` to 10000 and `gas_forwarded` to 3000 to specify that the
// contract call transaction may consume up to 10000 gas, while the actual call may only use 3000
// gas
let tx_params = TxParameters::new(None, Some(1000), None);
let call_params = CallParameters::new(None, None, Some(200));
let tx_params = TxParameters::new(None, Some(10000), None);
let call_params = CallParameters::new(None, None, Some(3000));

let response = contract_methods
.get_msg_amount() // Our contract method.
Expand Down Expand Up @@ -554,7 +554,7 @@ mod tests {
.await?;
// ANCHOR_END: multi_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 1006);
assert_eq!(transaction_cost.gas_used, 15176);

Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion examples/predicates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ mod tests {
all_coins,
vec![],
Some(Config {
predicates: true,
utxo_validation: true,
..Config::local_node()
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ description = "Fuel Rust SDK contracts."
[dependencies]
anyhow = "1"
bytes = { version = "1.0.1", features = ["serde"] }
fuel-gql-client = { version = "0.11.2", default-features = false }
fuel-tx = "0.20.2"
fuel-gql-client = { version = "0.13", default-features = false }
fuel-tx = "0.23"
fuels-core = { version = "0.27.0", path = "../fuels-core" }
fuels-signers = { version = "0.27.0", path = "../fuels-signers" }
fuels-types = { version = "0.27.0", path = "../fuels-types" }
Expand Down
7 changes: 4 additions & 3 deletions packages/fuels-contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use fuel_gql_client::{
fuel_tx::{Contract as FuelContract, Output, Receipt, StorageSlot, Transaction},
fuel_types::{Address, AssetId, Salt},
};
use fuel_tx::{Checkable, Create};

use fuels_core::abi_decoder::ABIDecoder;
use fuels_core::abi_encoder::{ABIEncoder, UnresolvedBytes};
Expand Down Expand Up @@ -239,8 +240,8 @@ impl Contract {
let provider = wallet.get_provider()?;
let chain_info = provider.chain_info().await?;

tx.validate_without_signature(
chain_info.latest_block.height.0,
tx.check_without_signatures(
chain_info.latest_block.header.height.0,
&chain_info.consensus_parameters.into(),
)?;
provider.send_transaction(&tx).await?;
Expand Down Expand Up @@ -303,7 +304,7 @@ impl Contract {
pub async fn contract_deployment_transaction(
compiled_contract: &CompiledContract,
params: TxParameters,
) -> Result<(Transaction, Bech32ContractId), Error> {
) -> Result<(Create, Bech32ContractId), Error> {
let bytecode_witness_index = 0;
let storage_slots: Vec<StorageSlot> = compiled_contract.storage_slots.clone();
let witnesses = vec![compiled_contract.raw.clone().into()];
Expand Down
55 changes: 28 additions & 27 deletions packages/fuels-contract/src/script.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use anyhow::Result;
use fuel_gql_client::fuel_tx::{ConsensusParameters, Receipt, Transaction};
use fuel_gql_client::fuel_tx::{Input, Output, TxPointer, UtxoId};
use fuel_gql_client::fuel_tx::{
field::Script as ScriptField, ConsensusParameters, Input, Output, Receipt, Transaction,
TxPointer, UtxoId,
};
use fuel_gql_client::fuel_types::{
bytes::padded_len_usize, AssetId, Bytes32, ContractId, Immediate18, Word,
};
use fuel_gql_client::fuel_vm::{consts::REG_ONE, prelude::Opcode};
use itertools::{chain, Itertools};

use fuel_gql_client::client::schema::coin::Coin;
use fuel_tx::{Metadata, ScriptExecutionResult, Witness};
use fuel_tx::{Checkable, ScriptExecutionResult, TransactionBuilder, Witness};
use fuels_core::parameters::TxParameters;
use fuels_signers::provider::Provider;
use fuels_signers::{Signer, WalletUnlocked};
Expand All @@ -33,7 +35,7 @@ struct CallParamOffsets {
/// Script provides methods to create and a call/simulate a
/// script transaction that carries out contract method calls
pub struct Script {
pub tx: Transaction,
pub tx: fuels_core::tx::Script,
}

#[derive(Debug, Clone)]
Expand All @@ -43,7 +45,7 @@ pub struct CompiledScript {
}

impl Script {
pub fn new(tx: Transaction) -> Self {
pub fn new(tx: fuels_core::tx::Script) -> Self {
Self { tx }
}

Expand Down Expand Up @@ -365,16 +367,16 @@ impl Script {
len_script += Opcode::LEN;

ConsensusParameters::DEFAULT.tx_offset()
+ Transaction::script_offset()
+ fuel_tx::Script::script_offset_static()
+ padded_len_usize(len_script)
}

/// Execute the transaction in a state-modifying manner.
pub async fn call(self, provider: &Provider) -> Result<Vec<Receipt>, Error> {
let chain_info = provider.chain_info().await?;

self.tx.validate_without_signature(
chain_info.latest_block.height.0,
self.tx.check_without_signatures(
chain_info.latest_block.header.height.0,
&chain_info.consensus_parameters.into(),
)?;

Expand All @@ -385,12 +387,12 @@ impl Script {
pub async fn simulate(self, provider: &Provider) -> Result<Vec<Receipt>, Error> {
let chain_info = provider.chain_info().await?;

self.tx.validate_without_signature(
chain_info.latest_block.height.0,
self.tx.check_without_signatures(
chain_info.latest_block.header.height.0,
&chain_info.consensus_parameters.into(),
)?;

let receipts = provider.dry_run(&self.tx).await?;
let receipts = provider.dry_run(&self.tx.clone().into()).await?;
if receipts
.iter()
.any(|r|
Expand Down Expand Up @@ -879,13 +881,11 @@ pub struct ScriptBuilder {
gas_price: Word,
gas_limit: Word,
maturity: Word,
receipts_root: Bytes32,
script: Vec<u8>,
script_data: Vec<u8>,
inputs: Vec<Input>,
outputs: Vec<Output>,
witnesses: Vec<Witness>,
metadata: Option<Metadata>,
asset_id: AssetId,
amount: u64,
}
Expand All @@ -896,13 +896,11 @@ impl ScriptBuilder {
gas_price: 0,
gas_limit: 0,
maturity: 0,
receipts_root: Default::default(),
script: vec![],
script_data: vec![],
inputs: vec![],
outputs: vec![],
witnesses: vec![],
metadata: None,
asset_id: AssetId::default(),
amount: 0,
}
Expand Down Expand Up @@ -955,18 +953,21 @@ impl ScriptBuilder {
}

pub async fn build(self, wallet: &WalletUnlocked) -> Result<Script, Error> {
let mut tx = Transaction::Script {
gas_price: self.gas_price,
gas_limit: self.gas_limit,
maturity: self.maturity,
receipts_root: self.receipts_root,
script: self.script,
script_data: self.script_data,
inputs: self.inputs,
outputs: self.outputs,
witnesses: self.witnesses,
metadata: self.metadata,
};
let mut builder = TransactionBuilder::script(self.script, self.script_data);
builder.gas_price(self.gas_price);
builder.gas_limit(self.gas_limit);
builder.maturity(self.maturity);
for input in self.inputs {
builder.add_input(input);
}
for output in self.outputs {
builder.add_output(output);
}
for witness in self.witnesses {
builder.add_witness(witness);
}

let mut tx = builder.finalize_without_signature();

let base_amount = if self.asset_id == AssetId::default() {
self.amount
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description = "Fuel Rust SDK core."
[dependencies]
Inflector = "0.11"
anyhow = "1"
fuel-tx = "0.20.2"
fuel-tx = { version = "0.23", features = ["builder"] }
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
fuel-types = "0.5"
fuels-types = { version = "0.27.0", path = "../fuels-types" }
hex = { version = "0.4.3", features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub const DEFAULT_MATURITY: u64 = 0;
// ANCHOR: default_call_parameters
pub const DEFAULT_CALL_PARAMS_AMOUNT: u64 = 0;
// Bytes representation of the asset ID of the "base" asset used for gas fees.
pub const BASE_ASSET_ID: AssetId = AssetId::new([0u8; 32]);
pub const BASE_ASSET_ID: AssetId = AssetId::BASE;
// ANCHOR_END: default_call_parameters

pub const BASE_MESSAGE_ID: MessageId = MessageId::zeroed();
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels-signers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ async-trait = { version = "0.1.50", default-features = false }
bytes = { version = "1.1.0", features = ["serde"] }
elliptic-curve = { version = "0.11.6", default-features = false }
eth-keystore = { version = "0.3.0" }
fuel-core = { version = "0.11.2", default-features = false, optional = true }
fuel-core = { version = "0.13", default-features = false, optional = true }
fuel-crypto = { version = "0.6", features = ["random"] }
fuel-gql-client = { version = "0.11.2", default-features = false }
fuel-gql-client = { version = "0.13", default-features = false }
fuel-types = { version = "0.5", default-features = false, features = ["random"] }
fuels-core = { version = "0.27.0", path = "../fuels-core" }
fuels-types = { version = "0.27.0", path = "../fuels-types" }
Expand Down
19 changes: 13 additions & 6 deletions packages/fuels-signers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use fuel_crypto;

use async_trait::async_trait;
use fuel_crypto::Signature;
use fuel_gql_client::fuel_tx::Transaction;
use fuels_core::tx::{field, Cacheable, UniqueIdentifier};
use fuels_types::bech32::Bech32Address;
use std::error::Error;
pub use wallet::{Wallet, WalletUnlocked};
Expand All @@ -27,7 +27,10 @@ pub trait Signer: std::fmt::Debug + Send + Sync {
) -> Result<Signature, Self::Error>;

/// Signs the transaction
async fn sign_transaction(&self, message: &mut Transaction) -> Result<Signature, Self::Error>;
async fn sign_transaction<Tx: Cacheable + UniqueIdentifier + field::Witnesses + Send>(
&self,
message: &mut Tx,
) -> Result<Signature, Self::Error>;

/// Returns the signer's Fuel Address
fn address(&self) -> &Bech32Address;
Expand All @@ -40,7 +43,10 @@ mod tests {
use fuels_core::constants::BASE_ASSET_ID;
use fuels_core::{
parameters::TxParameters,
tx::{Address, AssetId, Bytes32, Input, Output, TxPointer, UtxoId},
tx::{
field::Maturity, Address, AssetId, Bytes32, Chargeable, Input, Output, Transaction,
TxPointer, UtxoId,
},
};
use fuels_test_helpers::{setup_single_asset_coins, setup_test_client};
use rand::{rngs::StdRng, RngCore, SeedableRng};
Expand Down Expand Up @@ -187,9 +193,10 @@ mod tests {
.get_transaction_by_id(&tx_id)
.await?;

assert_eq!(res.transaction.gas_limit(), gas_limit);
assert_eq!(res.transaction.gas_price(), gas_price);
assert_eq!(res.transaction.maturity(), maturity);
let script = res.transaction.as_script().cloned().unwrap();
assert_eq!(script.limit(), gas_limit);
assert_eq!(script.price(), gas_price);
assert_eq!(*script.maturity(), maturity);

let wallet_1_spendable_coins = wallet_1.get_spendable_coins(BASE_ASSET_ID, 0).await?;
let wallet_1_all_coins = wallet_1.get_coins(BASE_ASSET_ID).await?;
Expand Down
Loading