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

Wasm test #772

Merged
merged 18 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 36 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:

# Test for 32 bit and wasm32-unknown-unknown compatibility
cargo build --target wasm32-unknown-unknown --no-default-features --features sync-api,
cargo build --release -p ac-examples-wasm --examples --target wasm32-unknown-unknown,

# Test for 32 bit and wasm32-wasip1 compatibility
cargo build --target wasm32-wasip1 --no-default-features --features std --features staking-xt --features contracts-xt --features sync-api,
Expand Down Expand Up @@ -120,6 +121,14 @@ jobs:
!target/release/examples/*.d
!target/release/examples/*-*

- name: Upload wasm examples
uses: actions/upload-artifact@v4
if: contains(matrix.check, 'examples-wasm')
with:
name: examples-wasm
path: |
target/wasm32-unknown-unknown/release/examples/*.wasm

- name: Upload async testing examples
uses: actions/upload-artifact@v4
if: contains(matrix.check, 'testing-async')
Expand Down Expand Up @@ -235,9 +244,35 @@ jobs:
nc -z -v 127.0.0.1 9944
chmod +x ${{ matrix.example }}
./${{ matrix.example }}

wasm_examples:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add a newline before this, or even put this block below the next block "merge", as the merge is using only the examples. I'm almost wondering if we should put the wasm-stuff into its own yml-file (?). But I leave this up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the newline. The merge is actually also for the wasm-example as this can also be downloaded. I also updated the merge to reflect this.

runs-on: ${{ matrix.os }}
needs: build
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
example: [
wasm_example,
]
steps:
- uses: actions/checkout@v4

- name: Download examples from previous run
uses: actions/download-artifact@v4
with:
pattern: examples-wasm
merge-multiple: true

- name: Setup `wasmtime`
uses: bytecodealliance/actions/wasmtime/setup@v1

- name: Run wasm example
run: wasmtime --invoke main ${{ matrix.example }}.wasm 0 0

merge:
runs-on: ubuntu-latest
needs: examples
needs: [examples, wasm_examples]
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"compose-macros",
"examples/async",
"examples/sync",
"examples/wasm",
"node-api",
"test-no-std",
"testing/async",
Expand Down
11 changes: 11 additions & 0 deletions examples/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "ac-examples-wasm"
version = "0.5.0"
license = "Apache-2.0"
edition = "2021"

[dev-dependencies]
sp-core = { default-features = false, features = ["full_crypto", "serde"], git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master" }
substrate-api-client = { default-features = false, path = "../..", version = "0.17" }
pallet-balances = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master" }
50 changes: 50 additions & 0 deletions examples/wasm/examples/wasm_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2024 Supercomputing Systems AG
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

//! Example that some basic functions that can be executed in WebAssembly.

pub use pallet_balances::Call as BalancesCall;
use sp_core::{
crypto::{AccountId32, Ss58Codec},
sr25519, Pair,
};
use sp_runtime::MultiAddress;
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
use std::process::ExitCode;
use substrate_api_client::ac_primitives::{AssetRuntimeConfig, ExtrinsicSigner};

fn main() -> Result<ExitCode, i32> {
// This test is not yet very sophisticated and not exhaustive.
// Still it shows how some basic data structures can be constructed and used.
let alice: sr25519::Pair = Pair::from_string(
"0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a",
None,
)
.unwrap();

let bob_account: AccountId32 =
sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty")
.unwrap()
.into();
let _bob: MultiAddress<AccountId32, AccountId32> = MultiAddress::Id(bob_account);
let es_converted: ExtrinsicSigner<AssetRuntimeConfig> = alice.clone().into();
let es_new = ExtrinsicSigner::<AssetRuntimeConfig>::new(alice.clone());
assert_eq!(es_converted.signer().public(), es_new.signer().public());

let extrinsic = UncheckedExtrinsic::from_bytes(&[]);
match extrinsic {
Ok(_) => panic!("Extrinsic should be invalid"),
Err(_) => (),
}
Ok(ExitCode::from(0))
}