Skip to content

Commit

Permalink
Merge branch 'master' into oleksii/testnet-live-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Br1ght0ne authored Oct 15, 2024
2 parents d1b7a33 + d99edd0 commit d8df87d
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 33 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ 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.37.0
FUEL_CORE_VERSION: 0.40.0
FUEL_CORE_PATCH_BRANCH: ""
FUEL_CORE_PATCH_REVISION: ""
RUST_VERSION: 1.79.0
FORC_VERSION: 0.64.0
FORC_VERSION: 0.65.2
FORC_PATCH_BRANCH: ""
FORC_PATCH_REVISION: ""
NEXTEST_HIDE_PROGRESS_BAR: "true"
Expand All @@ -31,7 +31,7 @@ env:

jobs:
setup-test-projects:
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v3
- name: Install toolchain
Expand All @@ -40,7 +40,7 @@ jobs:
toolchain: ${{ env.RUST_VERSION }}
# selecting a toolchain either by action or manual `rustup` calls should happen
# before the cache plugin, as it uses the current rustc version as its cache key
- uses: Swatinem/rust-cache@v2.7.3
- uses: buildjet/cache@v3
with:
prefix-key: "v1-rust"

Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
e2e/sway/**/out/*
get-workspace-members:
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
outputs:
members: ${{ steps.set-members.outputs.members }}
steps:
Expand All @@ -91,7 +91,7 @@ jobs:
echo "members=$members" >> $GITHUB_OUTPUT
verify-rust-version:
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v3
# Ensure CI is using the same minimum toolchain specified in fuels Cargo.toml
Expand All @@ -106,7 +106,7 @@ jobs:
# Fetch Fuel Core and upload as artifact, useful when we build the core from a
# revision so that we can repeat flaky tests without rebuilding the core.
fetch-fuel-core:
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- uses: dtolnay/rust-toolchain@master
with:
Expand All @@ -115,7 +115,7 @@ jobs:

# selecting a toolchain either by action or manual `rustup` calls should happen
# before the cache plugin, as it uses the current rustc version as its cache key
- uses: Swatinem/rust-cache@v2.7.3
- uses: buildjet/cache@v3
continue-on-error: true
with:
key: "fuel-core-build"
Expand All @@ -141,7 +141,7 @@ jobs:

# Ensure workspace is publishable
publish-crates-check:
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -164,7 +164,7 @@ jobs:
- get-workspace-members
- publish-crates-check
- fetch-fuel-core
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
strategy:
matrix:
cargo_command: [check]
Expand Down Expand Up @@ -219,7 +219,7 @@ jobs:

# selecting a toolchain either by action or manual `rustup` calls should happen
# before the cache plugin, as it uses the current rustc version as its cache key
- uses: Swatinem/rust-cache@v2.7.3
- uses: buildjet/cache@v3
continue-on-error: true
with:
key: "${{ matrix.cargo_command }} ${{ matrix.args }} ${{ matrix.package }}"
Expand Down Expand Up @@ -301,7 +301,7 @@ jobs:
- publish-crates-check
# Only do this job if publishing a release
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204

steps:
- name: Checkout repository
Expand Down
31 changes: 16 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ readme = "README.md"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/fuels-rs"
rust-version = "1.79.0"
version = "0.66.7"
version = "0.66.9"

[workspace.dependencies]
Inflector = "0.11.4"
Expand All @@ -48,6 +48,7 @@ async-trait = { version = "0.1.74", default-features = false }
bech32 = "0.9.1"
bytes = { version = "1.5.0", default-features = false }
chrono = "0.4.31"
cynic = { version = "2.2", default-features = false }
elliptic-curve = { version = "0.13.8", default-features = false }
eth-keystore = "0.5.0"
flate2 = { version = "1.0", default-features = false }
Expand Down Expand Up @@ -87,14 +88,14 @@ octocrab = { version = "0.39", default-features = false }
dotenv = { version = "0.15", default-features = false }

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

# Dependencies from the `fuel-vm` repository:
fuel-asm = { version = "0.58.0" }
Expand All @@ -106,11 +107,11 @@ fuel-types = { version = "0.58.0" }
fuel-vm = { version = "0.58.0" }

# Workspace projects
fuels = { version = "0.66.7", path = "./packages/fuels", default-features = false }
fuels-accounts = { version = "0.66.7", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.66.7", path = "./packages/fuels-code-gen", default-features = false }
fuels-core = { version = "0.66.7", path = "./packages/fuels-core", default-features = false }
fuels-macros = { version = "0.66.7", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.66.7", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.66.7", path = "./packages/fuels-test-helpers", default-features = false }
versions-replacer = { version = "0.66.7", path = "./scripts/versions-replacer", default-features = false }
fuels = { version = "0.66.9", path = "./packages/fuels", default-features = false }
fuels-accounts = { version = "0.66.9", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.66.9", path = "./packages/fuels-code-gen", default-features = false }
fuels-core = { version = "0.66.9", path = "./packages/fuels-core", default-features = false }
fuels-macros = { version = "0.66.9", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.66.9", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.66.9", path = "./packages/fuels-test-helpers", default-features = false }
versions-replacer = { version = "0.66.9", path = "./scripts/versions-replacer", default-features = false }
4 changes: 2 additions & 2 deletions docs/src/connecting/short-lived.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ let wallet = launch_provider_and_get_wallet().await?;
The `fuel-core-lib` feature allows us to run a `fuel-core` node without installing the `fuel-core` binary on the local machine. Using the `fuel-core-lib` feature flag entails downloading all the dependencies needed to run the fuel-core node.

```rust,ignore
fuels = { version = "0.66.7", features = ["fuel-core-lib"] }
fuels = { version = "0.66.9", features = ["fuel-core-lib"] }
```

### RocksDB

The `rocksdb` is an additional feature that, when combined with `fuel-core-lib`, provides persistent storage capabilities while using `fuel-core` as a library.

```rust,ignore
fuels = { version = "0.66.7", features = ["rocksdb"] }
fuels = { version = "0.66.9", features = ["rocksdb"] }
```
67 changes: 67 additions & 0 deletions e2e/tests/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,3 +1207,70 @@ async fn contract_call_with_impersonation() -> Result<()> {

Ok(())
}

#[tokio::test]
async fn is_account_query_test() -> Result<()> {
{
let wallet = launch_provider_and_get_wallet().await?;
let provider = wallet.provider().unwrap().clone();

let blob = Blob::new(vec![1; 100]);
let blob_id = blob.id();

let is_account = provider.is_user_account(blob_id).await?;
assert!(is_account);

let mut tb = BlobTransactionBuilder::default().with_blob(blob);
wallet.adjust_for_fee(&mut tb, 0).await?;
wallet.add_witnesses(&mut tb)?;
let tx = tb.build(provider.clone()).await?;

provider
.send_transaction_and_await_commit(tx)
.await?
.check(None)?;

let is_account = provider.is_user_account(blob_id).await?;
assert!(!is_account);
}
{
let wallet = launch_provider_and_get_wallet().await?;
let provider = wallet.provider().unwrap().clone();

let contract = Contract::load_from(
"sway/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?;
let contract_id = contract.contract_id();

let is_account = provider.is_user_account(*contract_id).await?;
assert!(is_account);

contract.deploy(&wallet, TxPolicies::default()).await?;

let is_account = provider.is_user_account(*contract_id).await?;
assert!(!is_account);
}
{
let wallet = launch_provider_and_get_wallet().await?;
let provider = wallet.provider().unwrap().clone();

let mut tb = ScriptTransactionBuilder::default();
wallet.adjust_for_fee(&mut tb, 0).await?;
wallet.add_witnesses(&mut tb)?;
let tx = tb.build(provider.clone()).await?;

let tx_id = tx.id(provider.chain_id());
let is_account = provider.is_user_account(tx_id).await?;
assert!(is_account);

provider
.send_transaction_and_await_commit(tx)
.await?
.check(None)?;
let is_account = provider.is_user_account(tx_id).await?;
assert!(!is_account);
}

Ok(())
}
2 changes: 0 additions & 2 deletions examples/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
mod tests {
use std::str::FromStr;

#[cfg(feature = "fuel-core-lib")]
use fuels::prelude::NodeConfig;
use fuels::{
prelude::Result,
types::{Bits256, EvmAddress, Identity},
Expand Down
6 changes: 6 additions & 0 deletions packages/fuels-accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = "Fuel Rust SDK accounts."
[dependencies]
async-trait = { workspace = true, default-features = false }
chrono = { workspace = true }
cynic = { workspace = true, optional = true }
elliptic-curve = { workspace = true, default-features = false }
eth-keystore = { workspace = true, optional = true }
fuel-core-client = { workspace = true, optional = true }
Expand All @@ -35,6 +36,10 @@ fuel-tx = { workspace = true, features = ["test-helpers", "random"] }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["test-util"] }

[build-dependencies]
cynic = { workspace = true, features = ["default"], optional = true }
fuel-core-client = { workspace = true, optional = true }

[features]
default = ["std"]
coin-cache = ["tokio?/time"]
Expand All @@ -43,4 +48,5 @@ std = [
"dep:tokio",
"fuel-core-client/default",
"dep:eth-keystore",
"dep:cynic",
]
15 changes: 15 additions & 0 deletions packages/fuels-accounts/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main() {
#[cfg(feature = "std")]
{
use std::fs;

fs::create_dir_all("target").expect("Unable to create target directory");
fs::write(
"target/fuel-core-client-schema.sdl",
fuel_core_client::SCHEMA_SDL,
)
.expect("Unable to write schema file");

println!("cargo:rerun-if-changed=build.rs");
}
}
4 changes: 4 additions & 0 deletions packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,10 @@ impl Provider {
Ok(proof)
}

pub async fn is_user_account(&self, address: impl Into<Bytes32>) -> Result<bool> {
self.client.is_user_account(*address.into()).await
}

pub fn with_retry_config(mut self, retry_config: RetryConfig) -> Self {
self.client.set_retry_config(retry_config);

Expand Down
52 changes: 52 additions & 0 deletions packages/fuels-accounts/src/provider/retryable_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{future::Future, io, time::Duration};

use custom_queries::{IsUserAccountQuery, IsUserAccountVariables};
use cynic::QueryBuilder;
use fuel_core_client::client::{
pagination::{PaginatedResult, PaginationRequest},
types::{
Expand Down Expand Up @@ -310,4 +312,54 @@ impl RetryableClient {
.await
}
// DELEGATION END

pub async fn is_user_account(&self, address: [u8; 32]) -> Result<bool> {
let blob_id = BlobId::from(address);
let contract_id = ContractId::from(address);
let transaction_id = TransactionId::from(address);

let query = IsUserAccountQuery::build(IsUserAccountVariables {
blob_id: blob_id.into(),
contract_id: contract_id.into(),
transaction_id: transaction_id.into(),
});

let response = self.client.query(query).await?;

let is_resource = response.blob.is_some()
|| response.contract.is_some()
|| response.transaction.is_some();

Ok(!is_resource)
}
}

mod custom_queries {
use fuel_core_client::client::schema::blob::BlobIdFragment;
use fuel_core_client::client::schema::schema;
use fuel_core_client::client::schema::{
contract::ContractIdFragment, tx::TransactionIdFragment, BlobId, ContractId, TransactionId,
};

#[derive(cynic::QueryVariables, Debug)]
pub struct IsUserAccountVariables {
pub blob_id: BlobId,
pub contract_id: ContractId,
pub transaction_id: TransactionId,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(
graphql_type = "Query",
variables = "IsUserAccountVariables",
schema_path = "./target/fuel-core-client-schema.sdl"
)]
pub struct IsUserAccountQuery {
#[arguments(id: $blob_id)]
pub blob: Option<BlobIdFragment>,
#[arguments(id: $contract_id)]
pub contract: Option<ContractIdFragment>,
#[arguments(id: $transaction_id)]
pub transaction: Option<TransactionIdFragment>,
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub const SUPPORTED_FUEL_CORE_VERSION: semver::Version = semver::Version::new(0, 37, 0);
pub const SUPPORTED_FUEL_CORE_VERSION: semver::Version = semver::Version::new(0, 40, 0);
1 change: 1 addition & 0 deletions packages/fuels-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ itertools = { workspace = true }
postcard = { version = "1", default-features = true, features = ["alloc"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, default-features = true }
sha2 = { workspace = true }
thiserror = { workspace = true, default-features = false }
uint = { workspace = true, default-features = false }

Expand Down
1 change: 1 addition & 0 deletions packages/fuels-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod transaction_builders;
pub mod tx_status;
mod wrappers;
pub use dry_runner::*;
pub mod checksum_address;

pub type ByteArray = [u8; 8];
pub type Selector = Vec<u8>;
Expand Down
Loading

0 comments on commit d8df87d

Please sign in to comment.