Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
90 changes: 71 additions & 19 deletions Cargo.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ cargo-features = ["resolver"]
members = [
"auction",
"authority",
"bencher",
"benchmarking",
"currencies",
"gradually-update",
"oracle",
"oracle/rpc",
"oracle/rpc/runtime-api",
"tokens",
"traits",
"utilities",
Expand All @@ -16,25 +19,74 @@ members = [
"nft",
"xtokens",
"xcm-support",
"unknown-tokens",
"build-script-utils",
"weight-gen",
"weight-meter",
]
resolver = "2"

[patch.crates-io]
frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
pallet-treasury = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-application-crypto = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-arithmetic = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-trie = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "rococo-v1" }
[patch.'https://github.com/paritytech/substrate']
frame-benchmarking = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
frame-support = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
frame-system = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-balances = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-elections-phragmen = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-scheduler = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-treasury = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-authorship = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-vesting = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-timestamp = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-session = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-staking = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-offences = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
pallet-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-api = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-application-crypto = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-arithmetic = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-core = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-inherents = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-io = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-runtime = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-runtime-interface = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-std = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-trie = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-version = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-externalities = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-state-machine = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-wasm-interface = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-keystore = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-staking = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-storage = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-panic-handler = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-npos-elections = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-npos-elections-compact = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-debug-derive = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-allocator = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-authority-discovery = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sc-executor-common = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sc-executor-wasmi = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sc-executor = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sc-client-api = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-tasks = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-authorship = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-consensus = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-timestamp = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-session = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-blockchain = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }
sp-transaction-pool = { git = "https://github.com/paritytech//substrate", rev = "816ed3d4e77a2463c86e69ec5a26fc307ef452b9" }

[patch.'https://github.com/paritytech/cumulus']
cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "3db8a38cfad53c4fe742ca68d7b425b88c61813d" }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech//cumulus", rev = "3db8a38cfad53c4fe742ca68d7b425b88c61813d" }
parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "3db8a38cfad53c4fe742ca68d7b425b88c61813d" }
cumulus-pallet-xcm-handler = { git = "https://github.com/paritytech//cumulus", rev = "3db8a38cfad53c4fe742ca68d7b425b88c61813d" }

[patch.'https://github.com/paritytech/polkadot']
xcm = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" }
xcm-executor = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" }
xcm-builder = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" }
polkadot-core-primitives = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" }
polkadot-parachain = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" }
polkadot-primitives = { git = "https://github.com/paritytech//polkadot", rev = "8adff378fe35c850d5155732ae32260bcb5feb9b" }
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ check-tests: githooks

test: githooks
./scripts/run.sh test
cargo test --manifest-path nft/Cargo.toml -p orml-nft --features disable-tokens-by-owner

GITHOOKS_SRC = $(wildcard githooks/*)
GITHOOKS_DEST = $(patsubst githooks/%, $(GITHOOK)/%, $(GITHOOKS_SRC))
Expand Down Expand Up @@ -47,5 +46,4 @@ dev-check-tests: Cargo.toml
cargo check --tests --all

dev-test: Cargo.toml
cargo test --all
cargo test --manifest-path nft/Cargo.toml -p orml-nft --features disable-tokens-by-owner
cargo test --all --features runtime-benchmarks
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ The Open Runtime Module Library (ORML) is a community maintained collection of S
- Provides scheduled balance locking mechanism, in a *graded vesting* way.
- [orml-gradually-update](./gradually-update)
- Provides way to adjust numeric parameter gradually over a period of time.
- [orml-xtokens](./xtokens)
- Provides way to do cross-chain assets transfer.
- [Step-by-Step guide](https://github.com/open-web3-stack/open-runtime-module-library/wiki/xtokens) to make XCM cross-chain fungible asset transfer available on your parachain
- [orml-xcm-support](./xcm-support)
- Provides traits, types, and implementations to support XCM integration.

## Example

Expand All @@ -48,7 +53,7 @@ ORML use `Cargo.dev.toml` to avoid workspace conflicts with project cargo config
- change the command to `make dev-check` etc which does the copy. (For the full list of `make` commands, check `Makefile`)

# Web3 Foundation Grant Project
ORML is part of the bigger `Open-Web3-Stack` initiative, that is currently under a General Grant from Web3 Foundation. See Application details [here](https://github.com/open-web3-stack/General-Grants-Program/blob/master/grants/speculative/open_web3_stack.md). The 1st milestone has been delivered.
ORML is part of the bigger `Open-Web3-Stack` initiative, that is currently under a General Grant from Web3 Foundation. See Application details [here](https://github.com/open-web3-stack/General-Grants-Program/blob/master/grants/speculative/open_web3_stack.md). The 1st milestone has been delivered.

# Projects using ORML
- [If you intend or are using ORML, please add your project here](https://github.com/open-web3-stack/open-runtime-module-library/edit/master/README.md)
Expand All @@ -61,6 +66,10 @@ _In alphabetical order_
- [ChainX](https://github.com/chainx-org/ChainX)
- [HydraDX](https://github.com/galacticcouncil/hack.HydraDX-node)
- [Laminar Chain](https://github.com/laminar-protocol/laminar-chain)
- [Listen](https://github.com/listenofficial)
- [Minterest](https://github.com/minterest-finance/minterest-chain-node)
- [Plasm Network](https://github.com/PlasmNetwork)
- [Setheum Network](https://github.com/Setheum-Labs/Setheum)
- [Valiu Liquidity Network](https://github.com/valibre-org/vln-node)
- [Zeitgeist](https://github.com/zeitgeistpm/zeitgeist)

2 changes: 1 addition & 1 deletion auction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = ["Acala Developers"]
edition = "2018"

[dependencies]
serde = { version = "1.0.111", optional = true }
serde = { version = "1.0.124", optional = true }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
Expand Down
10 changes: 0 additions & 10 deletions auction/src/default_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ impl crate::WeightInfo for () {
.saturating_add(DbWeight::get().reads(12 as Weight))
.saturating_add(DbWeight::get().writes(12 as Weight))
}
fn bid_surplus_auction() -> Weight {
(257_830_000 as Weight)
.saturating_add(DbWeight::get().reads(6 as Weight))
.saturating_add(DbWeight::get().writes(5 as Weight))
}
fn bid_debit_auction() -> Weight {
(287_271_000 as Weight)
.saturating_add(DbWeight::get().reads(7 as Weight))
.saturating_add(DbWeight::get().writes(8 as Weight))
}
fn on_finalize(c: u32) -> Weight {
(50_992_000 as Weight)
.saturating_add((171_653_000 as Weight).saturating_mul(c as Weight))
Expand Down
4 changes: 1 addition & 3 deletions auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ pub mod module {

pub trait WeightInfo {
fn bid_collateral_auction() -> Weight;
fn bid_surplus_auction() -> Weight;
fn bid_debit_auction() -> Weight;
fn on_finalize(c: u32) -> Weight;
}

Expand Down Expand Up @@ -131,7 +129,7 @@ pub mod module {
Auctions::<T>::try_mutate_exists(id, |auction| -> DispatchResult {
let mut auction = auction.as_mut().ok_or(Error::<T>::AuctionNotExist)?;

let block_number = <frame_system::Module<T>>::block_number();
let block_number = <frame_system::Pallet<T>>::block_number();

// make sure auction is started
ensure!(block_number >= auction.start, Error::<T>::AuctionNotStarted);
Expand Down
5 changes: 3 additions & 2 deletions auction/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

pub struct Handler;
Expand Down Expand Up @@ -86,8 +87,8 @@ construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Storage, Config, Event<T>},
AuctionModule: auction::{Module, Storage, Call, Event<T>},
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
AuctionModule: auction::{Pallet, Storage, Call, Event<T>},
}
);

Expand Down
4 changes: 3 additions & 1 deletion authority/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = ["Acala Developers"]
edition = "2018"

[dependencies]
serde = { version = "1.0.111", optional = true }
serde = { version = "1.0.124", optional = true }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
Expand Down Expand Up @@ -38,4 +38,6 @@ std = [
"orml-traits/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
6 changes: 3 additions & 3 deletions authority/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub mod module {
*id = id.checked_add(1).ok_or(Error::<T>::Overflow)?;
Ok(current_id)
})?;
let now = frame_system::Module::<T>::block_number();
let now = frame_system::Pallet::<T>::block_number();
let delay = match when {
DispatchTime::At(x) => x.checked_sub(&now).ok_or(Error::<T>::Overflow)?,
DispatchTime::After(x) => x,
Expand Down Expand Up @@ -283,7 +283,7 @@ pub mod module {
task_id: ScheduleTaskIndex,
when: DispatchTime<T::BlockNumber>,
) -> DispatchResultWithPostInfo {
let now = frame_system::Module::<T>::block_number();
let now = frame_system::Pallet::<T>::block_number();
let new_delay = match when {
DispatchTime::At(x) => x.checked_sub(&now).ok_or(Error::<T>::Overflow)?,
DispatchTime::After(x) => x,
Expand Down Expand Up @@ -317,7 +317,7 @@ pub mod module {
)
.map_err(|_| Error::<T>::FailedToDelay)?;

let now = frame_system::Module::<T>::block_number();
let now = frame_system::Pallet::<T>::block_number();
let dispatch_at = now.saturating_add(additional_delay);

Self::deposit_event(Event::Delayed(initial_origin, task_id, dispatch_at));
Expand Down
7 changes: 4 additions & 3 deletions authority/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

parameter_types! {
Expand Down Expand Up @@ -162,9 +163,9 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Config, Event<T>},
Authority: authority::{Module, Call, Origin<T>, Event<T>},
Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config, Event<T>},
Authority: authority::{Pallet, Call, Origin<T>, Event<T>},
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},
}
);

Expand Down
40 changes: 40 additions & 0 deletions bencher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "orml-bencher"
description = "Provide macro to benchmark pallets."
repository = "https://github.com/open-web3-stack/open-runtime-module-library/tree/master/bencher"
license = "Apache-2.0"
version = "0.1.0"
authors = ["Laminar Developers <hello@laminar.one>"]
edition = "2018"

[dependencies]
linregress = { version = "0.4.0", optional = true }
handlebars = {version = "3.5.2", optional = true }
serde = { features = ['derive'], optional = true, version = "1.0.119" }
serde_json = "1.0"
codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"], default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false, optional = true }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false, features = ["wasmtime"], optional = true }
sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false, features = ["with-kvdb-rocksdb"], optional = true }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }

[features]
default = ["std"]
std = [
"linregress",
"handlebars",
"serde/std",
"codec/std",
"sp-core/std",
"sp-std/std",
"sp-io/std",
"sp-runtime-interface/std",
"sp-state-machine/std",
"sc-executor/std",
"sc-client-db",
"frame-benchmarking/std",
]
39 changes: 39 additions & 0 deletions bencher/src/bench_runner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use frame_benchmarking::{
benchmarking,
frame_support::sp_runtime::traits::{Block, NumberFor},
};
use sc_client_db::BenchmarkingState;
use sc_executor::{sp_wasm_interface::HostFunctions, WasmExecutionMethod, WasmExecutor};
use sp_core::traits::{CallInWasm, MissingHostFunctions};
use sp_io::SubstrateHostFunctions;
use sp_state_machine::{Ext, OverlayedChanges, StorageTransactionCache};

/// Run benches
pub fn run<B: Block>(wasm_code: Vec<u8>) -> Vec<u8> {
let mut overlay = OverlayedChanges::default();
let mut cache = StorageTransactionCache::default();
let state = BenchmarkingState::<B>::new(Default::default(), Default::default(), false).unwrap();
let mut ext = Ext::<_, NumberFor<B>, _>::new(&mut overlay, &mut cache, &state, None, None);

let mut host_functions = benchmarking::HostFunctions::host_functions();
host_functions.append(&mut SubstrateHostFunctions::host_functions());

let executor = WasmExecutor::new(
WasmExecutionMethod::Compiled,
Default::default(),
host_functions,
1,
None,
);

executor
.call_in_wasm(
&wasm_code[..],
None,
"run_benches",
&[],
&mut ext,
MissingHostFunctions::Disallow,
)
.unwrap()
}
Loading