Skip to content

Commit

Permalink
refactor!: update sway and fuel-core to 0.18.1 (#950)
Browse files Browse the repository at this point in the history
BREAKING CHANGES: 
- `Predicate::from_code` and `Predicate::load_from` use default `ConsensusParameters` for instantiation of the predicate address. To use non-default `ConsensusParameters`, the user should use `Predicate::from_code(...).with_provider()`, that will use the provider's `ConsensusParameters`. 
- `Provider::new` now takes a `ConsensusParameters` argument, so we can
avoid changing the API of downstream clients.
- `setup_test_client` now returns `ConsensusParameters` of the client. It is less used than `setup_test_provider` so it's its API that was changed. 
- `produce_block` API now takes in a `start_time` as an `Option<DateTime<Utc>>` (no need for the `TimeParameters` struct)
- To produce blocks, the user now needs to set `block_production` to `Trigger::Interval` (see docs) in `ChainConfig`


Internal changes: 
- The signing of the transaction and predicate id generation requires
`ChainId`(`ConsensusParameters`).
- Now tokens should be transferred to the contract first, and after you
can transfer them via `SMO` or another transfer. So in some tests first
we need to transfer money to the contract first.
- Replaced all unsafe code from `fuel-crypto` with safe analog.
- On the `fuel-tx`/`fuel-core` side now, there is a difference in
whether the message contains data. If data is empty, it is `MessageCoin`
that acts like a `Coin`(has the same rules during execution). If the
data field is not empty, then it is a retryable message(or
`MessageData`). Messages like this can't be used to pay a transaction
fee, and if the execution fails, the message is not consumed(you can use
it again in the next transactions). More about them you can read in
FuelLabs/fuel-core#946. Also, the API changed
for resources and not it is `Coins` again. Because of that, some tests
now require messages with empty data to be able to spend them.
- Removed redundant usage of `MessageId`. Now the identifier of the
message is a `Nonce`.
- Removed `Output::Message`. Now you don't need to specify it in the
outputs. Because of that `SMO` opcode doesn't require a message output
index anymore.
- The proof API is updated with a new design:
FuelLabs/fuel-core#1046. If you want to prove
the block at height `X` you need at least a committed `X + 1` block.

Because some of opcodes were updated the examples require a new `sway`.
The corresponding PR: FuelLabs/sway#4525. It
creates a cycle of dependencies with this PR.

Closes #829
#933
---------

Co-authored-by: iqdecay <[email protected]>
Co-authored-by: Brandon Kite <[email protected]>
Co-authored-by: Ahmed Sagdati <[email protected]>
Co-authored-by: Halil Beglerović <[email protected]>
Co-authored-by: hal3e <[email protected]>
  • Loading branch information
6 people authored May 25, 2023
1 parent e2ca004 commit bd258b2
Show file tree
Hide file tree
Showing 125 changed files with 663 additions and 671 deletions.
6 changes: 3 additions & 3 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.17.11
FUEL_CORE_VERSION: 0.18.1
RUST_VERSION: 1.68.0
FORC_VERSION: 0.38.0
FORC_PATCH_BRANCH: ""
FORC_VERSION: 0.39.0
FORC_PATCH_BRANCH: "feature/fuel-core-0.18"
FORC_PATCH_REVISION: ""

jobs:
Expand Down
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ chrono = "0.4.24"
elliptic-curve = { version = "0.13.4", default-features = false }
eth-keystore = "0.5.0"
fuel-abi-types = "0.2.1"
fuel-asm = "0.26"
fuel-core = { version = "0.17", default-features = false }
fuel-core-chain-config = { version = "0.17", default-features = false }
fuel-core-client = { version = "0.17", default-features = false }
fuel-core-types = { version = "0.17", default-features = false }
fuel-crypto = "0.26"
fuel-merkle = "0.26"
fuel-storage = "0.26"
fuel-tx = "0.26"
fuel-types = { version = "0.26", default-features = false }
fuel-vm = "0.26"
fuel-asm = "0.31.1"
fuel-core = { version = "0.18.1", default-features = false }
fuel-core-chain-config = { version = "0.18.1", default-features = false }
fuel-core-client = { version = "0.18.1", default-features = false }
fuel-core-types = { version = "0.18.1", default-features = false }
fuel-crypto = "0.31.1"
fuel-merkle = "0.31.1"
fuel-storage = "0.31.1"
fuel-tx = "0.31.1"
fuel-types = { version = "0.31.1", default-features = false }
fuel-vm = "0.31.1"
fuels = { version = "0.41.0", path = "./packages/fuels" }
fuels-accounts = { version = "0.41.0", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.41.0", path = "./packages/fuels-code-gen", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Requires installed:
# The latest version of the `forc`,`forc-fmt` and `fuel-core`.
# `cargo install fuel-core-bin --git https://github.com/FuelLabs/fuel-core --tag v0.17.11 --locked`
# `cargo install fuel-core-bin --git https://github.com/FuelLabs/fuel-core --tag v0.18.1 --locked`
# `cargo install forc --git https://github.com/FuelLabs/sway --tag v0.38.0 --locked`
# `cargo install forc-fmt --git https://github.com/FuelLabs/sway --tag v0.38.0 --locked`
# Note, if you need a custom branch, you can replace `--tag {RELEASE}` with the `--branch {BRANCH_NAME}`.
Expand All @@ -17,4 +17,4 @@ cargo test --all-targets --all-features &&
cargo test --all-targets --all-features --workspace &&
cargo test --all-targets --workspace &&
cargo run --bin check-docs &&
cargo doc |& grep -A 6 "warning: unresolved link to"
$(cargo doc |& grep -A 6 "warning: unresolved link to")
10 changes: 0 additions & 10 deletions docs/src/calling-contracts/variable-outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,3 @@ When calling `transfer_coins_to_output` with the SDK, you can specify the number
<!-- append_variable_outputs:example:end -->

> **Note:** that the Sway `lib-std` function `mint_to_address` calls `transfer_to_address` under the hood, so you need to call `append_variable_outputs` in the Rust SDK tests like you would for `transfer_to_address`.
# Output messages

Similarly, when your contract transfers messages, the underlying transaction has to have the appropriate number of [output messages](https://github.com/FuelLabs/fuel-specs/blob/master/src/protocol/tx_format/output.md#outputmessage).

Output messages can be added to a contract call by chaining `append_output_messages(amount)`:

```rust,ignore
{{#include ../../../examples/contracts/src/lib.rs:message_outputs}}
```
7 changes: 4 additions & 3 deletions docs/src/cookbook/custom-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This example demonstrates how to start a short-lived Fuel node with custom consensus parameters for the underlying chain.

First, we have to import `ConsensusParameters` from the fuels-tx crate:
First, we have to import `ConsensusParameters` and `ChainConfig`:

```rust,ignore
{{#include ../../../examples/cookbook/src/lib.rs:custom_chain_import}}
Expand All @@ -20,8 +20,9 @@ Before we can start a node, we probably also want to define some genesis coins a
{{#include ../../../examples/cookbook/src/lib.rs:custom_chain_coins}}
```

Finally, we call `setup_test_client()`, which starts a node with the given configs and returns a client:
Finally, we call `setup_test_provider()`, which starts a node with the given configs and returns a
provider attached to that node:

```rust,ignore
{{#include ../../../examples/cookbook/src/lib.rs:custom_chain_client}}
{{#include ../../../examples/cookbook/src/lib.rs:custom_chain_provider}}
```
8 changes: 1 addition & 7 deletions docs/src/testing/chains.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ You can use `produce_blocks` to help achieve an arbitrary block height; this is
{{#include ../../../packages/fuels/tests/providers.rs:use_produce_blocks_to_increase_block_height}}
````

You can also set a custom block time by providing `TimeParameters` as the second, optional argument. `TimeParameters` is defined as:

````rust,ignore
{{#include ../../../packages/fuels-accounts/src/provider.rs:time_parameters}}
````

And here is an example:
You can also set a custom block time as the second, optional argument. Here is an example:

````rust,ignore
{{#include ../../../packages/fuels/tests/providers.rs:use_produce_blocks_custom_time}}
Expand Down
54 changes: 3 additions & 51 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#[cfg(test)]
mod tests {
use fuels::types::{
errors::{error, Error, Result},
Bits256,
};
use fuels::types::errors::{error, Error, Result};

#[tokio::test]
async fn instantiate_client() -> Result<()> {
Expand Down Expand Up @@ -107,7 +104,7 @@ mod tests {
.await?;
// ANCHOR_END: contract_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 616);
assert_eq!(transaction_cost.gas_used, 625);

Ok(())
}
Expand Down Expand Up @@ -358,51 +355,6 @@ mod tests {
Ok(())
}

#[tokio::test]
#[allow(unused_variables)]
async fn output_messages_test() -> Result<()> {
use fuels::prelude::*;
abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/token_ops/out/debug/token_ops-abi.json"
));

let wallet = launch_provider_and_get_wallet().await;

let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/token_ops/out/debug/token_ops\
.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet, TxParameters::default())
.await?;

let contract_methods = MyContract::new(contract_id.clone(), wallet.clone()).methods();
// ANCHOR: message_outputs
let base_layer_address = Bits256([1u8; 32]);
let amount = 1000;

let response = contract_methods
.send_message(base_layer_address, amount)
.append_message_outputs(1)
.call()
.await?;
// ANCHOR_END: message_outputs

// fails due to missing message output
let response = contract_methods
.send_message(base_layer_address, amount)
.call()
.await;

assert!(matches!(
response,
Err(Error::RevertTransactionError { .. })
));

Ok(())
}

#[tokio::test]
#[allow(unused_variables)]
async fn dependency_estimation() -> Result<()> {
Expand Down Expand Up @@ -676,7 +628,7 @@ mod tests {
.await?;
// ANCHOR_END: multi_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 1003);
assert_eq!(transaction_cost.gas_used, 1021);

Ok(())
}
Expand Down
20 changes: 9 additions & 11 deletions examples/cookbook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ mod tests {
async fn custom_chain() -> Result<()> {
use fuels::prelude::*;
// ANCHOR: custom_chain_import
use fuels::fuel_node::ChainConfig;
use fuels::tx::ConsensusParameters;
// ANCHOR_END: custom_chain_import

Expand All @@ -97,6 +98,10 @@ mod tests {
.with_max_gas_per_tx(1000)
.with_gas_price_factor(10)
.with_max_inputs(2);
let chain_config = ChainConfig {
transaction_parameters: consensus_parameters_config,
..ChainConfig::default()
};
// ANCHOR_END: custom_chain_consensus

// ANCHOR: custom_chain_coins
Expand All @@ -109,18 +114,11 @@ mod tests {
);
// ANCHOR_END: custom_chain_coins

// ANCHOR: custom_chain_client
// ANCHOR: custom_chain_provider
let node_config = Config::local_node();
let (client, _) = setup_test_client(
coins,
vec![],
Some(node_config),
None,
Some(consensus_parameters_config),
)
.await;
let _provider = Provider::new(client);
// ANCHOR_END: custom_chain_client
let (_provider, _bound_address) =
setup_test_provider(coins, vec![], Some(node_config), Some(chain_config)).await;
// ANCHOR_END: custom_chain_provider
Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions examples/predicates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ mod tests {
let code_path = "../../packages/fuels/tests/predicates/signatures/out/debug/signatures.bin";

let predicate: Predicate = Predicate::load_from(code_path)?
.with_data(predicate_data)
.with_provider(provider.clone());
.with_provider(provider)
.with_data(predicate_data);
// ANCHOR_END: predicate_load

// ANCHOR: predicate_receive
Expand Down Expand Up @@ -152,8 +152,8 @@ mod tests {
"../../packages/fuels/tests/predicates/basic_predicate/out/debug/basic_predicate.bin";

let predicate: Predicate = Predicate::load_from(code_path)?
.with_data(predicate_data)
.with_provider(first_wallet.try_provider()?.clone());
.with_provider(first_wallet.try_provider()?.clone())
.with_data(predicate_data);
// ANCHOR_END: with_predicate_data

// ANCHOR: predicate_data_lock_amount
Expand Down
5 changes: 5 additions & 0 deletions examples/providers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ mod tests {
use fuels::prelude::Result;

#[tokio::test]
/// This test will not work for as no endpoint supports the new `fuel-core` release yet
/// TODO: https://github.com/FuelLabs/fuels-rs/issues/978
#[ignore]
async fn connect_to_fuel_node() {
// ANCHOR: connect_to_testnet
use std::str::FromStr;

use fuels::{accounts::fuel_crypto::SecretKey, prelude::*};

// Create a provider pointing to the testnet.
// This example will not work as the testnet does not support the new version of fuel-core
// yet
let provider = Provider::connect("node-beta-2.fuel.network").await.unwrap();

// Setup a private key
Expand Down
16 changes: 14 additions & 2 deletions examples/wallets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,17 @@ mod tests {

use fuels::prelude::*;

let wallet = launch_provider_and_get_wallet().await;
let config = Config {
manual_blocks_enabled: true,
..Config::local_node()
};
let wallets = launch_custom_provider_and_get_wallets(
WalletsConfig::new(Some(1), None, None),
Some(config),
None,
)
.await;
let wallet = wallets.first().unwrap();

let amount = 1000;
let base_layer_address =
Expand All @@ -356,10 +366,12 @@ mod tests {
.withdraw_to_base_layer(&base_layer_address, amount, TxParameters::default())
.await?;

let _block_height = wallet.try_provider()?.produce_blocks(1, None).await?;

// Retrieve a message proof from the provider
let proof = wallet
.try_provider()?
.get_message_proof(&tx_id, &msg_id)
.get_message_proof(&tx_id, &msg_id, None, Some(2))
.await?
.expect("Failed to retrieve message proof.");

Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-accounts/src/accounts_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fuels_types::{
transaction_builders::TransactionBuilder,
};

pub fn extract_message_id(receipts: &[Receipt]) -> Option<&MessageId> {
pub fn extract_message_id(receipts: &[Receipt]) -> Option<MessageId> {
receipts.iter().find_map(|m| m.message_id())
}

Expand Down
Loading

0 comments on commit bd258b2

Please sign in to comment.