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

fix!: wasm compatibility for fuels-types #839

Merged
merged 20 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d58dac0
make fuel-core-client optional in fuels-types, introduced std feature
segfault-magnet Feb 15, 2023
8b766fb
export Source for indexer needs
segfault-magnet Feb 15, 2023
44715b3
Merge branch 'master' into segfault_magnet/wasm_friendly_abigen
segfault-magnet Feb 16, 2023
5a59ad3
Merge branch 'master' into segfault_magnet/wasm_friendly_abigen
segfault-magnet Feb 16, 2023
3d782ce
Merge branch 'master' into segfault_magnet/wasm_friendly_abigen
segfault-magnet Feb 17, 2023
4f3c7c3
Merge branch 'master' into segfault_magnet/wasm_friendly_abigen
segfault-magnet Feb 21, 2023
4ad7609
tests passing, CI left to fix
segfault-magnet Feb 22, 2023
b165460
add wasm-pack adn node.js installation on CI
segfault-magnet Feb 22, 2023
0484ebd
workspace `fuels` will use defaults
segfault-magnet Feb 22, 2023
eee4723
Merge branch 'master' into segfault_magnet/wasm_friendly_abigen
segfault-magnet Feb 22, 2023
36d57b8
Merge branch 'master' into segfault_magnet/testing_out_the_wasm_ci
segfault-magnet Feb 22, 2023
0f7fa48
remove no_std from wasm tests due to a required global allocator
segfault-magnet Feb 22, 2023
78a72bc
download wasm-pack instead of compiling
segfault-magnet Feb 22, 2023
b7a0690
if this works, we're awesome
segfault-magnet Feb 22, 2023
a9f9fc3
run and use cannot be in the same step
segfault-magnet Feb 22, 2023
873053c
add missing args
segfault-magnet Feb 22, 2023
e6379fd
Merge branch 'segfault_magnet/testing_out_the_wasm_ci' into segfault_…
segfault-magnet Feb 22, 2023
f231170
disable fuel-core feature
segfault-magnet Feb 22, 2023
bbd7b3f
add readme for wasm tests
segfault-magnet Feb 22, 2023
2af5527
Merge branch 'master' into segfault_magnet/wasm_friendly_abigen
segfault-magnet Feb 22, 2023
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
73 changes: 37 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,24 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
command: [check]
cargo_command: [check]
args: [--all-features]
package: ${{fromJSON(needs.get-workspace-members.outputs.members)}}
include:
- command: fmt
- cargo_command: fmt
args: --all --verbose -- --check
- command: clippy
- cargo_command: clippy
args: --all-targets --all-features
- command: test
- cargo_command: test
args: --all-targets --all-features --workspace
- command: test
- cargo_command: test
args: --all-targets --workspace
- command: test_wasm
args:
- command: check_doc_anchors_valid
args:
- command: check_doc_unresolved_links
args:
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -140,61 +146,56 @@ jobs:
- uses: Swatinem/rust-cache@v2.0.1
continue-on-error: true
with:
key: "${{ matrix.command }} ${{ matrix.args }} ${{ matrix.package }}"

- name: Add WASM target
if: ${{ matrix.command == 'test' }}
run: rustup target add wasm32-unknown-unknown

- name: Install WebAssembly Test harness
if: ${{ matrix.command == 'test' }}
uses: baptiste0928/cargo-install@v1
with:
crate: webassembly-test-runner
cache-key: "${{ matrix.command }} ${{ matrix.args }} ${{ matrix.package }}"

# TODO: Enable WASM tests
# - name: Test WASM package
# if: ${{ matrix.command == 'test' }}
# run: |
# cd packages/wasm-tests
# cargo test --target wasm32-unknown-unknown --all-targets --all-features
# cargo test --target wasm32-unknown-unknown --all-targets --no-default-features
key: "${{ matrix.cargo_command }} ${{ matrix.args }} ${{ matrix.package }}"

- name: Install Fuel Core
if: ${{ matrix.command == 'test' }}
if: ${{ matrix.cargo_command == 'test' }}
run: |
curl -sSLf https://github.com/FuelLabs/fuel-core/releases/download/v${{ env.FUEL_CORE_VERSION }}/fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu.tar.gz -L -o fuel-core.tar.gz
tar -xvf fuel-core.tar.gz
chmod +x fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core
mv fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core

- name: Download sway example artifacts
if: ${{ matrix.command == 'test' || matrix.command == 'clippy' }}
if: ${{ matrix.cargo_command == 'test' || matrix.cargo_command == 'clippy' }}
uses: actions/download-artifact@v3
with:
name: sway-examples
path: packages/fuels/tests/

- name: Cargo (workspace-level)
if: ${{ !matrix.package }}
run: cargo ${{ matrix.command }} ${{ matrix.args }}
if: ${{ matrix.cargo_command && !matrix.package }}
run: cargo ${{ matrix.cargo_command }} ${{ matrix.args }}

- name: Cargo (package-level)
if: ${{ matrix.package }}
run: cargo ${{ matrix.command }} -p ${{ matrix.package }} ${{ matrix.args }}
if: ${{ matrix.cargo_command && matrix.package }}
run: cargo ${{ matrix.cargo_command }} -p ${{ matrix.package }} ${{ matrix.args }}

- name: Check Docs. Validity
uses: actions-rs/cargo@v1
- name: Install NodeJS for WASM testing
if: ${{ matrix.command == 'test_wasm' }}
uses: actions/setup-node@v3
with:
command: run
args: --bin check-docs
node-version: 18

- name: Check Docs. Warnings
- name: Test WASM
if: ${{ matrix.command == 'test_wasm' }}
run: |
rustup target add wasm32-unknown-unknown
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
cd packages/wasm-tests
wasm-pack test --node

- name: Check for invalid documentation anchors
if: ${{ matrix.command == 'check_doc_anchors_valid' }}
run: cargo run --bin check-docs

- name: Check for unresolved documentation links
if: ${{ matrix.command == 'check_doc_unresolved_links' }}
run: |
! cargo doc |& grep -A 6 "warning: unresolved link to"



# Ensure workspace is publishable
publish-crates-check:
runs-on: ubuntu-latest
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ fuel-core-chain-config = "0.17"
fuel-core-types = "0.17"
fuel-vm = "0.26"
fuels = { version = "0.36.1", path = "./packages/fuels" }
fuels-code-gen = { version = "0.36.1", path = "./packages/fuels-code-gen" }
fuels-core = { version = "0.36.1", path = "./packages/fuels-core" }
fuels-macros = { version = "0.36.1", path = "./packages/fuels-macros" }
fuels-programs = { version = "0.36.1", path = "./packages/fuels-programs" }
fuels-signers = { version = "0.36.1", path = "./packages/fuels-signers" }
fuels-test-helpers = { version = "0.36.1", path = "./packages/fuels-test-helpers" }
fuels-types = { version = "0.36.1", path = "./packages/fuels-types" }
fuels-code-gen = { version = "0.36.1", path = "./packages/fuels-code-gen", default-features = false }
fuels-core = { version = "0.36.1", path = "./packages/fuels-core", default-features = false }
fuels-macros = { version = "0.36.1", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.36.1", path = "./packages/fuels-programs", default-features = false }
fuels-signers = { version = "0.36.1", path = "./packages/fuels-signers", default-features = false }
fuels-test-helpers = { version = "0.36.1", path = "./packages/fuels-test-helpers", default-features = false }
fuels-types = { version = "0.36.1", path = "./packages/fuels-types", default-features = false }
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ You can also run specific tests. The following example will run all integration
```shell
cargo test --test types in_vector -- --show-output
```
### How to run WASM tests?
You need to have wasm32 as a target, if you don't already:
```shell
rustup target add wasm32-unknown-unknown
```
You also need `wasm-pack`, if you don't already:
```shell
cargo install wasm-pack
```

Navigate to `packages/wasm-tests` and run `wasm-pack test`.
### What to do if my tests are failing on `master`

Before doing anything else, try all these commands:
Expand Down
1 change: 0 additions & 1 deletion packages/fuels-code-gen/src/program_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod abigen;
mod custom_types;
mod generated_code;
mod resolved_type;
mod source;
mod utils;

pub use abigen::{Abigen, AbigenTarget, ProgramType};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::convert::TryFrom;

use crate::{
error::{Error, Result},
program_bindings::{abi_types::FullProgramABI, source::Source},
program_bindings::abi_types::FullProgramABI,
utils::Source,
};

#[derive(Debug, Clone)]
Expand Down
2 changes: 2 additions & 0 deletions packages/fuels-code-gen/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub use ident::{ident, safe_ident};
pub use source::Source;
pub use type_path::TypePath;

mod ident;
mod source;
mod type_path;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::error::{error, Error, Result};

/// A source of a Truffle artifact JSON.
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) enum Source {
pub enum Source {
/// A raw ABI string
String(String),

Expand Down
7 changes: 7 additions & 0 deletions packages/fuels-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ sha2 = "0.9.5"

[dev-dependencies]
fuels-test-helpers = { workspace = true }

[features]
default = ["std"]
std = [
"fuels-test-helpers/std",
"fuels-types/std",
]
9 changes: 9 additions & 0 deletions packages/fuels-programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ tokio = "1.12"

[dev-dependencies]
fuels-test-helpers = { path = "../fuels-test-helpers" }

[features]
default = ["std"]
std = [
"fuels-core/std",
"fuels-signers/std",
"fuels-test-helpers/std",
"fuels-types/std",
]
6 changes: 6 additions & 0 deletions packages/fuels-signers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ hex = { version = "0.4.3", default-features = false, features = ["std"] }
tempfile = "3.3.0"

[features]
default = ["std"]
std = [
"fuels-core/std",
"fuels-test-helpers/std",
"fuels-types/std",
]
test-helpers = ["fuel-core"]
8 changes: 7 additions & 1 deletion packages/fuels-test-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ futures = "0.3.26"
which = { version = "4.3", default-features = false }

[features]
default = ["fuels-signers"]
default = ["fuels-signers", "std"]
std = [
"fuels-programs/std",
"fuels-core/std",
"fuels-signers?/std",
"fuels-types/std",
]
fuel-core-lib = ["fuel-core"]
6 changes: 4 additions & 2 deletions packages/fuels-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fuel-asm = { workspace = true }
fuel-abi-types = { workspace = true }
fuel-core = { workspace = true, default-features = false, optional = true }
fuel-core-chain-config = { workspace = true, default-features = false }
fuel-core-client = { workspace = true, default-features = false }
fuel-core-client = { workspace = true, default-features = false, optional = true }
hex = { version = "0.4.3", features = ["std"] }
proc-macro2 = "1.0"
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -29,6 +29,8 @@ strum = "0.21"
strum_macros = "0.21"
itertools = "0.10.5"
thiserror = { version = "1.0.26", default-features = false }
tokio = "1.15"
fuels-macros = { workspace = true }

[features]
default = ["std"]
std = ["dep:fuel-core-client"]
2 changes: 2 additions & 0 deletions packages/fuels-types/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use chrono::{DateTime, NaiveDateTime, Utc};
use fuel_core_client::client::schema::block::{Block as ClientBlock, Header as ClientHeader};
use fuel_tx::Bytes32;
Expand Down
2 changes: 2 additions & 0 deletions packages/fuels-types/src/chain_info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use fuel_core_client::client::schema::chain::ChainInfo as ClientChainInfo;
use fuel_tx::ConsensusParameters;

Expand Down
2 changes: 2 additions & 0 deletions packages/fuels-types/src/coin.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use fuel_core_chain_config::CoinConfig;
use fuel_core_client::client::schema::coin::{Coin as ClientCoin, CoinStatus as ClientCoinStatus};
use fuel_tx::{AssetId, UtxoId};
Expand Down
2 changes: 2 additions & 0 deletions packages/fuels-types/src/message.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use fuel_core_chain_config::MessageConfig;
use fuel_core_client::client::schema::message::{
Message as ClientMessage, MessageStatus as ClientMessageStatus,
Expand Down
2 changes: 2 additions & 0 deletions packages/fuels-types/src/message_proof.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use fuel_core_client::client::schema::message::MessageProof as ClientMessageProof;
use fuel_tx::{Bytes32, Bytes64};

Expand Down
2 changes: 2 additions & 0 deletions packages/fuels-types/src/node_info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use fuel_core_client::client::schema::node_info::NodeInfo as ClientNodeInfo;

#[derive(Debug)]
Expand Down
2 changes: 2 additions & 0 deletions packages/fuels-types/src/resource.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use fuel_core_client::client::schema::resource::Resource as ClientResource;

use crate::{coin::Coin, message::Message};
Expand Down
2 changes: 2 additions & 0 deletions packages/fuels-types/src/transaction_response.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use std::str::FromStr;

use chrono::{DateTime, NaiveDateTime, Utc};
Expand Down
10 changes: 9 additions & 1 deletion packages/fuels/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ sha2 = "0.9.5"
tokio = "1.15.0"

[features]
fuel-core-lib = ["fuels-test-helpers/fuel-core-lib", "fuel-core"]
default = ["std", "fuels-test-helpers/fuels-signers"]
std = [
"fuels-programs/std",
"fuels-core/std",
"fuels-signers/std",
"fuels-test-helpers/std",
"fuels-types/std",
]
fuel-core-lib = ["fuels-test-helpers/fuel-core-lib", "dep:fuel-core"]
2 changes: 1 addition & 1 deletion packages/wasm-tests/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
target = "wasm32-unknown-unknown"

[target.wasm32-unknown-unknown]
runner = "webassembly-test-runner"
runner = "wasm-bindgen-test-runner"
2 changes: 1 addition & 1 deletion packages/wasm-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ fuels-macros = { workspace = true }
fuels-core = { workspace = true }

[dev-dependencies]
webassembly-test = "0.1"
wasm-bindgen-test = "0.3.34"
Loading