Skip to content

Commit

Permalink
Merge branch 'segfault_magnet/testing_out_the_wasm_ci' into segfault_…
Browse files Browse the repository at this point in the history
…magnet/wasm_friendly_abigen
  • Loading branch information
segfault-magnet committed Feb 22, 2023
2 parents eee4723 + 873053c commit e6379fd
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 90 deletions.
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
12 changes: 6 additions & 6 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-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 }
7 changes: 5 additions & 2 deletions packages/fuels-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = "Fuel Rust SDK core."
fuel-tx = { workspace = true }
fuel-vm = { workspace = true }
fuel-types = { workspace = true }
fuels-types = { workspace = true, default-features = false }
fuels-types = { workspace = true }
hex = { version = "0.4.3", features = ["std"] }
itertools = "0.10"
sha2 = "0.9.5"
Expand All @@ -23,4 +23,7 @@ fuels-test-helpers = { workspace = true }

[features]
default = ["std"]
std = ["fuels-types/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"]
2 changes: 1 addition & 1 deletion packages/fuels-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ fuels-macros = { workspace = true }

[features]
default = ["std"]
std = ["fuel-core-client"]
std = ["dep:fuel-core-client"]
8 changes: 8 additions & 0 deletions 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]
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", "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"
65 changes: 23 additions & 42 deletions packages/wasm-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#![no_std]

extern crate alloc;

use alloc::{string::ToString, vec};
#[cfg(test)]
mod tests {
use wasm_bindgen_test::wasm_bindgen_test;

use fuels_core::abi_decoder::ABIDecoder;
use fuels_macros::wasm_abigen;
use fuels_types::param_types::ParamType;
use fuels_core::abi_encoder::ABIEncoder;
use fuels_macros::wasm_abigen;
use fuels_types::traits::Tokenizable;
use fuels_types::Bits256;

wasm_abigen!(Contract(
name = "no_name",
abi = r#"
wasm_abigen!(Contract(
name = "no_name",
abi = r#"
{
"types": [
{
Expand Down Expand Up @@ -102,42 +103,22 @@ wasm_abigen!(Contract(
"loggedTypes": []
}
"#
));

pub fn the_fn() {
use fuels_types::traits::Tokenizable;
let data = vec![
0, 0, 0, 0, 0, 0, 3, 252, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175,
175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175,
175,
];
));

let obj = ABIDecoder::decode_single(
&ParamType::Struct {
name: "".to_string(),
fields: vec![
("unused".to_string(), ParamType::U64),
("unused".to_string(), ParamType::B256),
],
generics: vec![],
},
&data,
)
.expect("Failed to decode");

let a_struct = SomeEvent::from_token(obj).unwrap();

assert_eq!(1020, a_struct.id);
}
#[wasm_bindgen_test]
fn decoding_and_encoding() {
let original_event = AnotherEvent {
id: 2,
hash: Bits256([2; 32]),
bar: true,
};

#[cfg(test)]
mod tests {
use webassembly_test::webassembly_test;
let bytes = ABIEncoder::encode(&[original_event.clone().into_token()])
.unwrap()
.resolve(0);

use super::*;
let reconstructed_event: AnotherEvent = bytes.try_into().unwrap();

#[webassembly_test]
fn test() {
the_fn();
assert_eq!(original_event, reconstructed_event);
}
}

0 comments on commit e6379fd

Please sign in to comment.