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

build(wasm_samples): pre-compiled wasm_samples #5123

Merged
merged 7 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
33 changes: 25 additions & 8 deletions .github/workflows/iroha2-dev-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ env:
CARGO_TERM_COLOR: always
IROHA_CLI_DIR: "/__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/test"
DOCKER_COMPOSE_PATH: defaults
WASM_SAMPLES_TARGET_DIR: wasm_samples/target/prebuilt

jobs:
consistency:
Expand Down Expand Up @@ -60,16 +61,22 @@ jobs:
name: report-clippy
path: clippy.json

build_executor:
build_wasm_samples:
runs-on: ubuntu-latest
container:
image: hyperledger/iroha2-ci:nightly-2024-09-09
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Build iroha executor
run: mold --run cargo run --bin iroha_wasm_builder -- build ./wasm_samples/default_executor --optimize --out-file ${{ env.DOCKER_COMPOSE_PATH }}/executor.wasm
- name: Upload executor to reuse in other jobs
- name: Build
run: ./scripts/build_wasm_samples.sh
- name: Upload all built WASMs
uses: actions/upload-artifact@v4
with:
name: wasm_samples
path: ${{ env.WASM_SAMPLES_TARGET_DIR }}
retention-days: 1
- name: Upload executor.wasm specifically
uses: actions/upload-artifact@v4
with:
name: executor.wasm
Expand All @@ -80,7 +87,7 @@ jobs:
runs-on: [self-hosted, Linux, iroha2]
container:
image: hyperledger/iroha2-ci:nightly-2024-09-09
needs: build_executor
needs: build_wasm_samples
env:
LLVM_PROFILE_FILE_NAME: "iroha-%p-%m.profraw"
steps:
Expand Down Expand Up @@ -122,7 +129,7 @@ jobs:
runs-on: [self-hosted, Linux, iroha2]
container:
image: hyperledger/iroha2-ci:nightly-2024-09-09
needs: build_executor
needs: build_wasm_samples
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
Expand All @@ -131,6 +138,11 @@ jobs:
with:
name: executor.wasm
path: ${{ env.DOCKER_COMPOSE_PATH }}
- name: Download the rest of WASM samples
uses: actions/download-artifact@v4
with:
name: wasm_samples
path: ${{ env.WASM_SAMPLES_TARGET_DIR }}
- uses: taiki-e/install-action@nextest
- name: Run integration tests, with all features
run: >
Expand All @@ -145,7 +157,7 @@ jobs:
runs-on: [self-hosted, Linux, iroha2]
container:
image: hyperledger/iroha2-ci:nightly-2024-09-09
needs: build_executor
needs: build_wasm_samples
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
Expand All @@ -154,6 +166,11 @@ jobs:
with:
name: executor.wasm
path: ${{ env.DOCKER_COMPOSE_PATH }}
- name: Download the rest of WASM samples
uses: actions/download-artifact@v4
with:
name: wasm_samples
path: ${{ env.WASM_SAMPLES_TARGET_DIR }}
- uses: taiki-e/install-action@nextest
- name: Run integration tests, with all features
run: >
Expand Down Expand Up @@ -198,7 +215,7 @@ jobs:
context: .

docker-compose-and-pytests:
needs: build_executor
needs: build_wasm_samples
runs-on: [self-hosted, Linux, iroha2]
timeout-minutes: 60
env:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ result
/test/
/iroha-java/
/lcov.info
**/test-smartcontracts/
test_docker
**/*.wasm
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/iroha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ nonzero_ext = { workspace = true }
# Hopefully, once the integration tests migration is finished these can be removed
irohad = { workspace = true }

iroha_wasm_builder = { workspace = true }
iroha_genesis = { workspace = true }
iroha_test_network = { workspace = true }
executor_custom_data_model = { version = "=2.0.0-rc.1.0", path = "../../wasm_samples/executor_custom_data_model" }
Expand Down
12 changes: 4 additions & 8 deletions crates/iroha/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use iroha::{
};
use iroha_genesis::GenesisBuilder;
use iroha_primitives::unique_vec;
use iroha_test_network::{
construct_executor, get_chain_id, get_key_pair, Peer as TestPeer, PeerBuilder, TestRuntime,
};
use iroha_test_samples::gen_account_in;
use iroha_test_network::{get_chain_id, get_key_pair, Peer as TestPeer, PeerBuilder, TestRuntime};
use iroha_test_samples::{gen_account_in, load_sample_wasm};
use irohad::samples::get_config;
use tokio::runtime::Runtime;

Expand All @@ -31,8 +29,7 @@ fn query_requests(criterion: &mut Criterion) {
);

let rt = Runtime::test();
let executor = construct_executor("../../wasm_samples/default_executor")
.expect("Failed to construct executor");
let executor = Executor::new(load_sample_wasm("default_executor"));
let topology = vec![peer.id.clone()];
let genesis = GenesisBuilder::default()
.domain("wonderland".parse().expect("Valid"))
Expand Down Expand Up @@ -133,8 +130,7 @@ fn instruction_submits(criterion: &mut Criterion) {
get_key_pair(iroha_test_network::Signatory::Peer),
genesis_key_pair.public_key(),
);
let executor = construct_executor("../../wasm_samples/default_executor")
.expect("Failed to construct executor");
let executor = Executor::new(load_sample_wasm("default_executor"));
let genesis = GenesisBuilder::default()
.domain("wonderland".parse().expect("Valid"))
.account(configuration.common.key_pair.public_key().clone())
Expand Down
8 changes: 4 additions & 4 deletions crates/iroha/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use iroha::{
use iroha_genesis::{GenesisBlock, GenesisBuilder};
use iroha_primitives::unique_vec;
use iroha_test_network::{
construct_executor, get_chain_id, get_key_pair, wait_for_genesis_committed, Peer as TestPeer,
PeerBuilder, TestRuntime,
get_chain_id, get_key_pair, wait_for_genesis_committed, Peer as TestPeer, PeerBuilder,
TestRuntime,
};
use iroha_test_samples::load_sample_wasm;
use irohad::samples::get_config;
use tokio::runtime::Runtime;

Expand All @@ -36,8 +37,7 @@ fn generate_genesis(
.finish_domain();
}

let executor = construct_executor("../../wasm_samples/default_executor")
.expect("Failed to construct executor");
let executor = Executor::new(load_sample_wasm("default_executor"));
builder.build_and_sign(chain_id, executor, topology, genesis_key_pair)
}

Expand Down
17 changes: 5 additions & 12 deletions crates/iroha/examples/register_1000_triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use iroha_data_model::parameter::{Parameter, SmartContractParameter};
use iroha_genesis::{GenesisBlock, GenesisBuilder};
use iroha_primitives::unique_vec;
use iroha_test_network::{
construct_executor, get_chain_id, get_key_pair, wait_for_genesis_committed_with_max_retries,
Peer as TestPeer, PeerBuilder, TestClient, TestRuntime,
get_chain_id, get_key_pair, wait_for_genesis_committed_with_max_retries, Peer as TestPeer,
PeerBuilder, TestClient, TestRuntime,
};
use iroha_test_samples::gen_account_in;
use iroha_test_samples::{gen_account_in, load_sample_wasm};
use irohad::samples::get_config;
use tokio::runtime::Runtime;

Expand All @@ -33,19 +33,13 @@ fn generate_genesis(
SmartContractParameter::Memory(NonZeroU64::MAX),
)));

let wasm = iroha_wasm_builder::Builder::new("wasm_samples/mint_rose_trigger")
.show_output()
.build()?
.optimize()?
.into_bytes()?;
let wasm = WasmSmartContract::from_compiled(wasm);
let (account_id, _account_keypair) = gen_account_in("wonderland");

let build_trigger = |trigger_id: TriggerId| {
Trigger::new(
trigger_id.clone(),
Action::new(
wasm.clone(),
load_sample_wasm("mint_rose_trigger"),
Repeats::Indefinitely,
account_id.clone(),
ExecuteTriggerEventFilter::new()
Expand All @@ -63,8 +57,7 @@ fn generate_genesis(
})
.fold(builder, GenesisBuilder::append_instruction);

let executor = construct_executor("../../wasm_samples/default_executor")
.expect("Failed to construct executor");
let executor = Executor::new(load_sample_wasm("default_executor"));
Ok(builder.build_and_sign(chain_id, executor, topology, genesis_key_pair))
}

Expand Down
13 changes: 3 additions & 10 deletions crates/iroha/tests/integration/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use iroha::{
parameter::SmartContractParameter,
prelude::*,
query::{builder::SingleQueryError, trigger::FindTriggers},
transaction::{TransactionBuilder, WasmSmartContract},
transaction::TransactionBuilder,
},
};
use iroha_data_model::asset::{AssetDefinition, AssetDefinitionId};
use iroha_executor_data_model::permission::asset_definition::CanRegisterAssetDefinition;
use iroha_test_network::*;
use iroha_test_samples::{gen_account_in, ALICE_ID};
use iroha_test_samples::{gen_account_in, load_sample_wasm, ALICE_ID};
use nonzero_ext::nonzero;

#[test]
Expand All @@ -36,17 +36,10 @@ fn mutlisig() -> Result<()> {
let account_id = ALICE_ID.clone();
let multisig_register_trigger_id = "multisig_register".parse::<TriggerId>()?;

let wasm = iroha_wasm_builder::Builder::new("../../wasm_samples/multisig_register")
.show_output()
.build()?
.optimize()?
.into_bytes()?;
let wasm = WasmSmartContract::from_compiled(wasm);

let trigger = Trigger::new(
multisig_register_trigger_id.clone(),
Action::new(
wasm,
load_sample_wasm("multisig_register"),
Repeats::Indefinitely,
account_id.clone(),
ExecuteTriggerEventFilter::new().for_trigger(multisig_register_trigger_id.clone()),
Expand Down
26 changes: 9 additions & 17 deletions crates/iroha/tests/integration/queries/smart_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ use iroha::{
data_model::{prelude::*, query::error::QueryExecutionFail},
};
use iroha_test_network::*;
use iroha_test_samples::load_sample_wasm;

#[test]
fn live_query_is_dropped_after_smart_contract_end() -> Result<()> {
let (_rt, _peer, client) = <PeerBuilder>::new().with_port(11_140).start_with_runtime();
wait_for_genesis_committed(&[client.clone()], 0);

let wasm = iroha_wasm_builder::Builder::new("../../wasm_samples/query_assets_and_save_cursor")
.show_output()
.build()?
.optimize()?
.into_bytes()?;

let transaction =
client.build_transaction(WasmSmartContract::from_compiled(wasm), Metadata::default());
let transaction = client.build_transaction(
load_sample_wasm("query_assets_and_save_cursor"),
Metadata::default(),
);
client.submit_transaction_blocking(&transaction)?;

let metadata_value: JsonString = client.query_single(FindAccountMetadata::new(
Expand All @@ -44,15 +41,10 @@ fn smart_contract_can_filter_queries() -> Result<()> {
let (_rt, _peer, client) = <PeerBuilder>::new().with_port(11_260).start_with_runtime();
wait_for_genesis_committed(&[client.clone()], 0);

let wasm =
iroha_wasm_builder::Builder::new("../../wasm_samples/smart_contract_can_filter_queries")
.show_output()
.build()?
.optimize()?
.into_bytes()?;

let transaction =
client.build_transaction(WasmSmartContract::from_compiled(wasm), Metadata::default());
let transaction = client.build_transaction(
load_sample_wasm("smart_contract_can_filter_queries"),
Metadata::default(),
);
client.submit_transaction_blocking(&transaction)?;

Ok(())
Expand Down
Loading
Loading