Skip to content
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
185 changes: 185 additions & 0 deletions .github/workflows/wasm-sdk-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: WASM SDK Tests

on:
pull_request:
paths:
- 'packages/wasm-sdk/**'
- 'packages/rs-sdk/**'
- 'packages/rs-drive-proof-verifier/**'
- 'packages/rs-platform-value/**'
- 'packages/rs-dpp/**'
- 'packages/rs-drive/src/verify/**'
- 'packages/rs-context-provider/**'
push:
branches:
- main
- master
- 'v[0-9]+.[0-9]+-dev'
- 'v[0-9]+.[0-9]+-dev-sdk'
paths:
- 'packages/wasm-sdk/**'
- 'packages/rs-sdk/**'
- 'packages/rs-drive-proof-verifier/**'
- 'packages/rs-platform-value/**'
- 'packages/rs-dpp/**'
- 'packages/rs-drive/src/verify/**'
- 'packages/rs-context-provider/**'
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-C lto=off"
CARGO_PROFILE_RELEASE_LTO: false

jobs:
build-and-test-wasm-sdk:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown

- name: Install protoc
run: |
curl -Lo /tmp/protoc.zip \
"https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-linux-x86_64.zip"
unzip -o /tmp/protoc.zip -d ${HOME}/.local
echo "${HOME}/.local/bin" >> $GITHUB_PATH
export PATH="${PATH}:${HOME}/.local/bin"

- name: Install clang
run: |
sudo apt update -qq
sudo apt install -qq --yes clang llvm

- name: Cache cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-wasm-sdk-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-wasm-sdk-

- name: Install wasm-pack
run: |
if ! command -v wasm-pack &> /dev/null; then
echo "Installing wasm-pack..."
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
else
echo "wasm-pack already installed"
fi

- name: Install wasm-opt
run: |
if ! command -v wasm-opt &> /dev/null; then
echo "Installing wasm-opt from GitHub releases..."
# Get the latest release version
WASM_OPT_VERSION=$(curl -s https://api.github.com/repos/WebAssembly/binaryen/releases/latest | grep -oP '"tag_name": "\K[^"]+')
echo "Installing wasm-opt version: $WASM_OPT_VERSION"

# Detect architecture
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
BINARYEN_ARCH="x86_64"
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
BINARYEN_ARCH="aarch64"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi

echo "Detected architecture: $ARCH, using binaryen arch: $BINARYEN_ARCH"

# Download and extract binaryen
curl -L "https://github.com/WebAssembly/binaryen/releases/download/${WASM_OPT_VERSION}/binaryen-${WASM_OPT_VERSION}-${BINARYEN_ARCH}-linux.tar.gz" -o /tmp/binaryen.tar.gz
tar -xzf /tmp/binaryen.tar.gz -C /tmp

# Move wasm-opt to PATH
sudo mv /tmp/binaryen-${WASM_OPT_VERSION}/bin/wasm-opt /usr/local/bin/
sudo chmod +x /usr/local/bin/wasm-opt

# Clean up
rm -rf /tmp/binaryen.tar.gz /tmp/binaryen-${WASM_OPT_VERSION}

echo "wasm-opt installed successfully"
else
echo "wasm-opt already installed"
fi

- name: Build WASM SDK
working-directory: packages/wasm-sdk
run: |
chmod +x build.sh
./build.sh

- name: Verify build output
working-directory: packages/wasm-sdk
run: |
echo "Checking build output..."
ls -lah pkg/
# Verify required files exist
test -f pkg/wasm_sdk_bg.wasm
test -f pkg/optimized.wasm
test -f pkg/wasm_sdk.js
test -f pkg/wasm_sdk.d.ts
test -f pkg/package.json
echo "Build verification successful!"

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install test dependencies
working-directory: packages/wasm-sdk/test
run: |
if [ -f package.json ]; then
npm install
fi

- name: Run custom test runner
working-directory: packages/wasm-sdk
run: |
echo "Running WASM SDK tests with custom runner..."
node test/run-tests.mjs

- name: Run Jest tests
working-directory: packages/wasm-sdk/test
run: |
echo "Running WASM SDK Jest tests..."
npm test || echo "Jest tests completed with status $?"

- name: Run all .mjs test files
working-directory: packages/wasm-sdk
run: |
echo "Running all .mjs test files..."
for test_file in test/*.test.mjs; do
if [ -f "$test_file" ]; then
echo "Running $test_file..."
node "$test_file" || echo "Test $test_file completed with status $?"
fi
done

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: wasm-sdk-test-results
path: packages/wasm-sdk/test-results/
retention-days: 7

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: wasm-sdk-build
path: packages/wasm-sdk/pkg/
retention-days: 7
4 changes: 3 additions & 1 deletion packages/rs-sdk/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ pub use {
fetch::Fetch,
fetch_many::FetchMany,
fetch_unproved::FetchUnproved,
query::{LimitQuery, Query, QueryStartInfo, DEFAULT_EPOCH_QUERY_LIMIT},
query::{
LimitQuery, ProposerBlockCountByIdsQuery, Query, QueryStartInfo, DEFAULT_EPOCH_QUERY_LIMIT,
},
};
51 changes: 50 additions & 1 deletion packages/rs-sdk/src/platform/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use dapi_grpc::platform::v0::get_contested_resource_identity_votes_request::GetC
use dapi_grpc::platform::v0::get_contested_resource_voters_for_identity_request::GetContestedResourceVotersForIdentityRequestV0;
use dapi_grpc::platform::v0::get_contested_resources_request::GetContestedResourcesRequestV0;
use dapi_grpc::platform::v0::get_current_quorums_info_request::GetCurrentQuorumsInfoRequestV0;
use dapi_grpc::platform::v0::get_evonodes_proposed_epoch_blocks_by_ids_request::GetEvonodesProposedEpochBlocksByIdsRequestV0;
use dapi_grpc::platform::v0::get_evonodes_proposed_epoch_blocks_by_range_request::GetEvonodesProposedEpochBlocksByRangeRequestV0;
use dapi_grpc::platform::v0::get_path_elements_request::GetPathElementsRequestV0;
use dapi_grpc::platform::v0::get_status_request::GetStatusRequestV0;
Expand All @@ -19,7 +20,7 @@ use dapi_grpc::platform::v0::{
get_identity_keys_request::GetIdentityKeysRequestV0, get_path_elements_request,
get_total_credits_in_platform_request, AllKeys, GetContestedResourceVoteStateRequest,
GetContestedResourceVotersForIdentityRequest, GetContestedResourcesRequest,
GetCurrentQuorumsInfoRequest, GetEpochsInfoRequest,
GetCurrentQuorumsInfoRequest, GetEpochsInfoRequest, GetEvonodesProposedEpochBlocksByIdsRequest,
GetEvonodesProposedEpochBlocksByRangeRequest, GetIdentityKeysRequest, GetPathElementsRequest,
GetProtocolVersionUpgradeStateRequest, GetProtocolVersionUpgradeVoteStatusRequest,
GetTotalCreditsInPlatformRequest, KeyRequestType,
Expand Down Expand Up @@ -732,3 +733,51 @@ impl Query<GetTokenPerpetualDistributionLastClaimRequest> for TokenLastClaimQuer
Ok(request)
}
}

/// Query for fetching proposed block counts by specific evonode IDs
#[derive(Debug, Clone)]
pub struct ProposerBlockCountByIdsQuery {
/// The epoch to query
pub epoch: Option<EpochIndex>,
/// The ProTxHashes to query for
pub pro_tx_hashes: Vec<ProTxHash>,
}

impl Query<GetEvonodesProposedEpochBlocksByIdsRequest> for ProposerBlockCountByIdsQuery {
fn query(self, prove: bool) -> Result<GetEvonodesProposedEpochBlocksByIdsRequest, Error> {
if !prove {
unimplemented!("queries without proofs are not supported yet");
}

// Convert ProTxHash to bytes
let ids: Vec<Vec<u8>> = self
.pro_tx_hashes
.into_iter()
.map(|hash| hash.to_byte_array().to_vec())
.collect();

Ok(GetEvonodesProposedEpochBlocksByIdsRequest {
version: Some(
proto::get_evonodes_proposed_epoch_blocks_by_ids_request::Version::V0(
GetEvonodesProposedEpochBlocksByIdsRequestV0 {
epoch: self.epoch.map(|e| e as u32),
ids,
prove,
},
),
),
})
}
}

// Convenience implementation for tuple of (epoch, Vec<ProTxHash>)
impl Query<GetEvonodesProposedEpochBlocksByIdsRequest> for (EpochIndex, Vec<ProTxHash>) {
fn query(self, prove: bool) -> Result<GetEvonodesProposedEpochBlocksByIdsRequest, Error> {
let (epoch, pro_tx_hashes) = self;
ProposerBlockCountByIdsQuery {
epoch: Some(epoch),
pro_tx_hashes,
}
.query(prove)
}
}
Loading
Loading