feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
[package]
|
||||
name = "pezpallet-contracts-fixtures"
|
||||
publish = false
|
||||
version = "1.0.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
description = "Fixtures for testing contracts pallet."
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true, default-features = true }
|
||||
pezframe-system = { workspace = true, default-features = true }
|
||||
pezsp-runtime = { workspace = true, default-features = true }
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = { workspace = true, default-features = true }
|
||||
parity-wasm = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
twox-hash = { workspace = true, default-features = true }
|
||||
|
||||
[features]
|
||||
runtime-benchmarks = [
|
||||
"pezframe-system/runtime-benchmarks",
|
||||
"pezsp-runtime/runtime-benchmarks",
|
||||
]
|
||||
@@ -0,0 +1,295 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! Compile contracts to wasm.
|
||||
use anyhow::{bail, Context, Result};
|
||||
use parity_wasm::elements::{deserialize_file, serialize_to_file, Internal};
|
||||
use std::{
|
||||
env, fs,
|
||||
hash::Hasher,
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
use twox_hash::XxHash32;
|
||||
|
||||
/// Read the file at `path` and return its hash as a hex string.
|
||||
fn file_hash(path: &Path) -> String {
|
||||
let data = fs::read(path).expect("file exists; qed");
|
||||
let mut hasher = XxHash32::default();
|
||||
hasher.write(&data);
|
||||
hasher.write(include_bytes!("build.rs"));
|
||||
let hash = hasher.finish();
|
||||
format!("{:x}", hash)
|
||||
}
|
||||
|
||||
/// A contract entry.
|
||||
struct Entry {
|
||||
/// The path to the contract source file.
|
||||
path: PathBuf,
|
||||
/// The hash of the contract source file.
|
||||
hash: String,
|
||||
}
|
||||
|
||||
impl Entry {
|
||||
/// Create a new contract entry from the given path.
|
||||
fn new(path: PathBuf) -> Self {
|
||||
let hash = file_hash(&path);
|
||||
Self { path, hash }
|
||||
}
|
||||
|
||||
/// Return the path to the contract source file.
|
||||
fn path(&self) -> &str {
|
||||
self.path.to_str().expect("path is valid unicode; qed")
|
||||
}
|
||||
|
||||
/// Return the name of the contract.
|
||||
fn name(&self) -> &str {
|
||||
self.path
|
||||
.file_stem()
|
||||
.expect("file exits; qed")
|
||||
.to_str()
|
||||
.expect("name is valid unicode; qed")
|
||||
}
|
||||
|
||||
/// Return whether the contract has already been compiled.
|
||||
fn is_cached(&self, out_dir: &Path) -> bool {
|
||||
out_dir.join(self.name()).join(&self.hash).exists()
|
||||
}
|
||||
|
||||
/// Update the cache file for the contract.
|
||||
fn update_cache(&self, out_dir: &Path) -> Result<()> {
|
||||
let cache_dir = out_dir.join(self.name());
|
||||
|
||||
// clear the cache dir if it exists
|
||||
if cache_dir.exists() {
|
||||
fs::remove_dir_all(&cache_dir)?;
|
||||
}
|
||||
|
||||
// re-populate the cache dir with the new hash
|
||||
fs::create_dir_all(&cache_dir)?;
|
||||
fs::write(out_dir.join(&self.hash), "")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Return the name of the output wasm file.
|
||||
fn out_wasm_filename(&self) -> String {
|
||||
format!("{}.wasm", self.name())
|
||||
}
|
||||
}
|
||||
|
||||
/// Collect all contract entries from the given source directory.
|
||||
/// Contracts that have already been compiled are filtered out.
|
||||
fn collect_entries(contracts_dir: &Path, out_dir: &Path) -> Vec<Entry> {
|
||||
fs::read_dir(contracts_dir)
|
||||
.expect("src dir exists; qed")
|
||||
.filter_map(|file| {
|
||||
let path = file.expect("file exists; qed").path();
|
||||
if path.extension().map_or(true, |ext| ext != "rs") {
|
||||
return None;
|
||||
}
|
||||
|
||||
let entry = Entry::new(path);
|
||||
if entry.is_cached(out_dir) {
|
||||
None
|
||||
} else {
|
||||
Some(entry)
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
/// Create a `Cargo.toml` to compile the given contract entries.
|
||||
fn create_cargo_toml<'a>(
|
||||
fixtures_dir: &Path,
|
||||
root_cargo_toml: &Path,
|
||||
entries: impl Iterator<Item = &'a Entry>,
|
||||
output_dir: &Path,
|
||||
) -> Result<()> {
|
||||
let root_toml: toml::Value = toml::from_str(&fs::read_to_string(root_cargo_toml)?)?;
|
||||
let mut cargo_toml: toml::Value = toml::from_str(include_str!("./build/Cargo.toml"))?;
|
||||
let mut set_dep = |name, path| -> Result<()> {
|
||||
cargo_toml["dependencies"][name]["path"] = toml::Value::String(
|
||||
fixtures_dir.join(path).canonicalize()?.to_str().unwrap().to_string(),
|
||||
);
|
||||
Ok(())
|
||||
};
|
||||
set_dep("uapi", "../uapi")?;
|
||||
set_dep("common", "./contracts/common")?;
|
||||
cargo_toml["dependencies"]["polkavm-derive"]["version"] =
|
||||
root_toml["workspace"]["dependencies"]["polkavm-derive"].clone();
|
||||
|
||||
cargo_toml["bin"] = toml::Value::Array(
|
||||
entries
|
||||
.map(|entry| {
|
||||
let name = entry.name();
|
||||
let path = entry.path();
|
||||
toml::Value::Table(toml::toml! {
|
||||
name = name
|
||||
path = path
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
|
||||
let cargo_toml = toml::to_string_pretty(&cargo_toml)?;
|
||||
fs::write(output_dir.join("Cargo.toml"), cargo_toml).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Invoke `cargo fmt` to check that fixtures files are formatted.
|
||||
fn invoke_cargo_fmt<'a>(
|
||||
config_path: &Path,
|
||||
files: impl Iterator<Item = &'a Path>,
|
||||
contract_dir: &Path,
|
||||
) -> Result<()> {
|
||||
// If rustfmt is not installed, skip the check.
|
||||
if !Command::new("rustup")
|
||||
.args(["nightly-2024-04-10", "run", "rustfmt", "--version"])
|
||||
.output()
|
||||
.map_or(false, |o| o.status.success())
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let fmt_res = Command::new("rustup")
|
||||
.args(["nightly-2024-04-10", "run", "rustfmt", "--check", "--config-path"])
|
||||
.arg(config_path)
|
||||
.args(files)
|
||||
.output()
|
||||
.expect("failed to execute process");
|
||||
|
||||
if fmt_res.status.success() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&fmt_res.stdout);
|
||||
let stderr = String::from_utf8_lossy(&fmt_res.stderr);
|
||||
eprintln!("{}\n{}", stdout, stderr);
|
||||
eprintln!(
|
||||
"Fixtures files are not formatted.\n
|
||||
Please run `rustup nightly-2024-04-10 run rustfmt --config-path {} {}/*.rs`",
|
||||
config_path.display(),
|
||||
contract_dir.display()
|
||||
);
|
||||
|
||||
anyhow::bail!("Fixtures files are not formatted")
|
||||
}
|
||||
|
||||
/// Build contracts for wasm.
|
||||
fn invoke_wasm_build(current_dir: &Path) -> Result<()> {
|
||||
let encoded_rustflags = [
|
||||
"-Clink-arg=-zstack-size=65536",
|
||||
"-Clink-arg=--import-memory",
|
||||
"-Clinker-plugin-lto",
|
||||
"-Ctarget-cpu=mvp",
|
||||
"-Dwarnings",
|
||||
]
|
||||
.join("\x1f");
|
||||
|
||||
let build_res = Command::new(env::var("CARGO")?)
|
||||
.current_dir(current_dir)
|
||||
.env("CARGO_TARGET_DIR", current_dir.join("target").display().to_string())
|
||||
.env("CARGO_ENCODED_RUSTFLAGS", encoded_rustflags)
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
.args(["build", "--release", "--target=wasm32-unknown-unknown"])
|
||||
.args(["-Z", "build-std=core,alloc"])
|
||||
.output()
|
||||
.expect("failed to execute process");
|
||||
|
||||
if build_res.status.success() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let stderr = String::from_utf8_lossy(&build_res.stderr);
|
||||
eprintln!("{}", stderr);
|
||||
bail!("Failed to build wasm contracts");
|
||||
}
|
||||
|
||||
/// Post-process the compiled wasm contracts.
|
||||
fn post_process_wasm(input_path: &Path, output_path: &Path) -> Result<()> {
|
||||
let mut module =
|
||||
deserialize_file(input_path).with_context(|| format!("Failed to read {:?}", input_path))?;
|
||||
if let Some(section) = module.export_section_mut() {
|
||||
section.entries_mut().retain(|entry| {
|
||||
matches!(entry.internal(), Internal::Function(_)) &&
|
||||
(entry.field() == "call" || entry.field() == "deploy")
|
||||
});
|
||||
}
|
||||
|
||||
serialize_to_file(output_path, module).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Write the compiled contracts to the given output directory.
|
||||
fn write_output(build_dir: &Path, out_dir: &Path, entries: Vec<Entry>) -> Result<()> {
|
||||
for entry in entries {
|
||||
let wasm_output = entry.out_wasm_filename();
|
||||
post_process_wasm(
|
||||
&build_dir.join("target/wasm32-unknown-unknown/release").join(&wasm_output),
|
||||
&out_dir.join(&wasm_output),
|
||||
)?;
|
||||
|
||||
entry.update_cache(out_dir)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns the root path of the wasm workspace.
|
||||
fn find_workspace_root(current_dir: &Path) -> Option<PathBuf> {
|
||||
let mut current_dir = current_dir.to_path_buf();
|
||||
|
||||
while current_dir.parent().is_some() {
|
||||
if current_dir.join("Cargo.toml").exists() {
|
||||
let cargo_toml_contents =
|
||||
std::fs::read_to_string(current_dir.join("Cargo.toml")).ok()?;
|
||||
if cargo_toml_contents.contains("[workspace]") {
|
||||
return Some(current_dir);
|
||||
}
|
||||
}
|
||||
|
||||
current_dir.pop();
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let fixtures_dir: PathBuf = env::var("CARGO_MANIFEST_DIR")?.into();
|
||||
let contracts_dir = fixtures_dir.join("contracts");
|
||||
let out_dir: PathBuf = env::var("OUT_DIR")?.into();
|
||||
let workspace_root = find_workspace_root(&fixtures_dir).expect("workspace root exists; qed");
|
||||
let root_cargo_toml = workspace_root.join("Cargo.toml");
|
||||
|
||||
let entries = collect_entries(&contracts_dir, &out_dir);
|
||||
if entries.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let tmp_dir = tempfile::tempdir()?;
|
||||
let tmp_dir_path = tmp_dir.path();
|
||||
|
||||
create_cargo_toml(&fixtures_dir, &root_cargo_toml, entries.iter(), tmp_dir.path())?;
|
||||
invoke_cargo_fmt(
|
||||
&workspace_root.join(".rustfmt.toml"),
|
||||
entries.iter().map(|entry| &entry.path as _),
|
||||
&contracts_dir,
|
||||
)?;
|
||||
|
||||
invoke_wasm_build(tmp_dir_path)?;
|
||||
|
||||
write_output(tmp_dir_path, &out_dir, entries)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "contracts"
|
||||
version = "0.6.3"
|
||||
edition = "2021"
|
||||
|
||||
# Binary targets are injected dynamically by the build script.
|
||||
[[bin]]
|
||||
|
||||
# All paths or versions are injected dynamically by the build script.
|
||||
[dependencies]
|
||||
common = { package = 'pezpallet-contracts-fixtures-common', path = "" }
|
||||
polkavm-derive = { version = "" }
|
||||
uapi = { package = 'pezpallet-contracts-uapi', path = "", default-features = false }
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
@@ -0,0 +1,39 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This fixture tests if account_reentrance_count works as expected.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(callee: [u8; 32],);
|
||||
|
||||
#[allow(deprecated)]
|
||||
let reentrance_count = api::account_reentrance_count(callee);
|
||||
|
||||
// Return the reentrance count.
|
||||
api::return_value(uapi::ReturnFlags::empty(), &reentrance_count.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::output;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
// Initialize buffer with 1s so that we can check that it is overwritten.
|
||||
output!(balance, [1u8; 8], api::balance,);
|
||||
|
||||
// Assert that the balance is 0.
|
||||
assert_eq!(&[0u8; 8], balance);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This calls another contract as passed as its account id.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
callee_input: [u8; 4],
|
||||
callee_addr: [u8; 32],
|
||||
);
|
||||
|
||||
// Call the callee
|
||||
api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
0u64, // How much ref_time to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&0u64.to_le_bytes(), // Value transferred to the contract.
|
||||
callee_input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This calls the supplied dest and transfers 100 balance during this call and copies
|
||||
//! the return code of this call to the output buffer.
|
||||
//! It also forwards its input to the callee.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
100,
|
||||
callee_addr: [u8; 32],
|
||||
input: [u8],
|
||||
);
|
||||
|
||||
// Call the callee
|
||||
let err_code = match api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
0u64, // How much ref_time to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&100u64.to_le_bytes(), // Value transferred to the contract.
|
||||
input,
|
||||
None,
|
||||
) {
|
||||
Ok(_) => 0u32,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
api::return_value(uapi::ReturnFlags::empty(), &err_code.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This passes its input to `call_runtime` and returns the return value to its caller.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
// Fixture calls should fit into 100 bytes.
|
||||
input!(100, call: [u8], );
|
||||
|
||||
// Use the call passed as input to call the runtime.
|
||||
let err_code = match api::call_runtime(call) {
|
||||
Ok(_) => 0u32,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
api::return_value(uapi::ReturnFlags::empty(), &err_code.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
512,
|
||||
callee_input: [u8; 4],
|
||||
callee_addr: [u8; 32],
|
||||
call: [u8],
|
||||
);
|
||||
|
||||
// Use the call passed as input to call the runtime.
|
||||
api::call_runtime(call).unwrap();
|
||||
|
||||
// Call the callee
|
||||
api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
0u64, // How much ref_time to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&0u64.to_le_bytes(), // Value transferred to the contract.
|
||||
callee_input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This fixture calls the account_id with the flags and value.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
256,
|
||||
callee_addr: [u8; 32],
|
||||
flags: u32,
|
||||
value: u64,
|
||||
forwarded_input: [u8],
|
||||
);
|
||||
|
||||
api::call_v2(
|
||||
uapi::CallFlags::from_bits(flags).unwrap(),
|
||||
callee_addr,
|
||||
0u64, // How much ref_time to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&value.to_le_bytes(), // Value transferred to the contract.
|
||||
forwarded_input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This fixture calls the account_id with the 2D Weight limit.
|
||||
//! It returns the result of the call as output data.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
256,
|
||||
callee_addr: [u8; 32],
|
||||
ref_time: u64,
|
||||
proof_size: u64,
|
||||
forwarded_input: [u8],
|
||||
);
|
||||
|
||||
api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
ref_time,
|
||||
proof_size,
|
||||
None, // No deposit limit.
|
||||
&0u64.to_le_bytes(), // value transferred to the contract.
|
||||
forwarded_input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api, ReturnErrorCode};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(code_hash: [u8; 32],);
|
||||
|
||||
// The value to transfer on instantiation and calls. Chosen to be greater than existential
|
||||
// deposit.
|
||||
let value = 32768u64.to_le_bytes();
|
||||
let salt = [0u8; 0];
|
||||
|
||||
// Callee will use the first 4 bytes of the input to return an exit status.
|
||||
let input = [0u8, 1, 34, 51, 68, 85, 102, 119];
|
||||
let reverted_input = [1u8, 34, 51, 68, 85, 102, 119];
|
||||
|
||||
// Fail to deploy the contract since it returns a non-zero exit status.
|
||||
let res = api::instantiate_v2(
|
||||
code_hash,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&value,
|
||||
&reverted_input,
|
||||
None,
|
||||
None,
|
||||
&salt,
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::CalleeReverted)));
|
||||
|
||||
// Fail to deploy the contract due to insufficient ref_time weight.
|
||||
let res = api::instantiate_v2(
|
||||
code_hash, 1u64, // too little ref_time weight
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&value, &input, None, None, &salt,
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::CalleeTrapped)));
|
||||
|
||||
// Fail to deploy the contract due to insufficient proof_size weight.
|
||||
let res = api::instantiate_v2(
|
||||
code_hash, 0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
1u64, // Too little proof_size weight
|
||||
None, // No deposit limit.
|
||||
&value, &input, None, None, &salt,
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::CalleeTrapped)));
|
||||
|
||||
// Deploy the contract successfully.
|
||||
let mut callee = [0u8; 32];
|
||||
let callee = &mut &mut callee[..];
|
||||
|
||||
api::instantiate_v2(
|
||||
code_hash,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&value,
|
||||
&input,
|
||||
Some(callee),
|
||||
None,
|
||||
&salt,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(callee.len(), 32);
|
||||
|
||||
// Call the new contract and expect it to return failing exit code.
|
||||
let res = api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&value,
|
||||
&reverted_input,
|
||||
None,
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::CalleeReverted)));
|
||||
|
||||
// Fail to call the contract due to insufficient ref_time weight.
|
||||
let res = api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee,
|
||||
1u64, // Too little ref_time weight.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&value,
|
||||
&input,
|
||||
None,
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::CalleeTrapped)));
|
||||
|
||||
// Fail to call the contract due to insufficient proof_size weight.
|
||||
let res = api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
1u64, // too little proof_size weight
|
||||
None, // No deposit limit.
|
||||
&value,
|
||||
&input,
|
||||
None,
|
||||
);
|
||||
assert!(matches!(res, Err(ReturnErrorCode::CalleeTrapped)));
|
||||
|
||||
// Call the contract successfully.
|
||||
let mut output = [0u8; 4];
|
||||
api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&value,
|
||||
&input,
|
||||
Some(&mut &mut output[..]),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(&output, &input[4..])
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This fixture calls caller_is_origin `n` times.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(n: u32, );
|
||||
|
||||
for _ in 0..n {
|
||||
let _ = api::caller_is_origin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! Call chain extension by passing through input and output of this contract.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(input, 8, func_id: u32,);
|
||||
|
||||
// the chain extension passes through the input and returns it as output
|
||||
let mut output_buffer = [0u8; 32];
|
||||
let output = &mut &mut output_buffer[0..input.len()];
|
||||
|
||||
let ret_id = api::call_chain_extension(func_id, input, Some(output));
|
||||
assert_eq!(ret_id, func_id);
|
||||
|
||||
api::return_value(uapi::ReturnFlags::empty(), output);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! Call chain extension two times with the specified func_ids
|
||||
//! It then calls itself once
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::{input, output};
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
input,
|
||||
func_id1: u32,
|
||||
func_id2: u32,
|
||||
stop_recurse: u8,
|
||||
);
|
||||
|
||||
api::call_chain_extension(func_id1, input, None);
|
||||
api::call_chain_extension(func_id2, input, None);
|
||||
|
||||
if stop_recurse == 0 {
|
||||
// Setup next call
|
||||
input[0..4].copy_from_slice(&((3 << 16) | 2u32).to_le_bytes());
|
||||
input[4..8].copy_from_slice(&((3 << 16) | 3u32).to_le_bytes());
|
||||
input[8] = 1u8;
|
||||
|
||||
// Read the contract address.
|
||||
output!(addr, [0u8; 32], api::address,);
|
||||
|
||||
// call self
|
||||
api::call_v2(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
addr,
|
||||
0u64, // How much ref_time to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&0u64.to_le_bytes(), // Value transferred to the contract.
|
||||
input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "pezpallet-contracts-fixtures-common"
|
||||
publish = false
|
||||
version = "1.0.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
description = "Common utilities for pezpallet-contracts-fixtures."
|
||||
|
||||
[dependencies]
|
||||
uapi = { package = 'pezpallet-contracts-uapi', path = "../../../uapi", default-features = false }
|
||||
@@ -0,0 +1,154 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
#![no_std]
|
||||
|
||||
pub use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
core::arch::wasm32::unreachable();
|
||||
}
|
||||
|
||||
/// Utility macro to read input passed to a contract.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// ```
|
||||
/// input$!(
|
||||
/// var1: u32, // [0, 4) var1 decoded as u32
|
||||
/// var2: [u8; 32], // [4, 36) var2 decoded as a [u8] slice
|
||||
/// var3: u8, // [36, 37) var3 decoded as a u8
|
||||
/// );
|
||||
///
|
||||
/// // Input and size can be specified as well:
|
||||
/// input$!(
|
||||
/// input, // input buffer (optional)
|
||||
/// 512, // input size (optional)
|
||||
/// var4: u32, // [0, 4) var4 decoded as u32
|
||||
/// var5: [u8], // [4, ..) var5 decoded as a [u8] slice
|
||||
/// );
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! input {
|
||||
(@inner $input:expr, $cursor:expr,) => {};
|
||||
(@size $size:expr, ) => { $size };
|
||||
|
||||
// Match a u8 variable.
|
||||
// e.g input!(var1: u8, );
|
||||
(@inner $input:expr, $cursor:expr, $var:ident: u8, $($rest:tt)*) => {
|
||||
let $var = $input[$cursor];
|
||||
input!(@inner $input, $cursor + 1, $($rest)*);
|
||||
};
|
||||
|
||||
// Size of u8 variable.
|
||||
(@size $size:expr, $var:ident: u8, $($rest:tt)*) => {
|
||||
input!(@size $size + 1, $($rest)*)
|
||||
};
|
||||
|
||||
// Match a u64 variable.
|
||||
// e.g input!(var1: u64, );
|
||||
(@inner $input:expr, $cursor:expr, $var:ident: u64, $($rest:tt)*) => {
|
||||
let $var = u64::from_le_bytes($input[$cursor..$cursor + 8].try_into().unwrap());
|
||||
input!(@inner $input, $cursor + 8, $($rest)*);
|
||||
};
|
||||
|
||||
// Size of u64 variable.
|
||||
(@size $size:expr, $var:ident: u64, $($rest:tt)*) => {
|
||||
input!(@size $size + 8, $($rest)*)
|
||||
};
|
||||
|
||||
// Match a u32 variable.
|
||||
// e.g input!(var1: u32, );
|
||||
(@inner $input:expr, $cursor:expr, $var:ident: u32, $($rest:tt)*) => {
|
||||
let $var = u32::from_le_bytes($input[$cursor..$cursor + 4].try_into().unwrap());
|
||||
input!(@inner $input, $cursor + 4, $($rest)*);
|
||||
};
|
||||
|
||||
// Size of u32 variable.
|
||||
(@size $size:expr, $var:ident: u32, $($rest:tt)*) => {
|
||||
input!(@size $size + 4, $($rest)*)
|
||||
};
|
||||
|
||||
// Match a u8 slice with the remaining bytes.
|
||||
// e.g input!(512, var1: [u8; 32], var2: [u8], );
|
||||
(@inner $input:expr, $cursor:expr, $var:ident: [u8],) => {
|
||||
let $var = &$input[$cursor..];
|
||||
};
|
||||
|
||||
// Match a u8 slice of the given size.
|
||||
// e.g input!(var1: [u8; 32], );
|
||||
(@inner $input:expr, $cursor:expr, $var:ident: [u8; $n:expr], $($rest:tt)*) => {
|
||||
let $var = &$input[$cursor..$cursor+$n];
|
||||
input!(@inner $input, $cursor + $n, $($rest)*);
|
||||
};
|
||||
|
||||
// Size of a u8 slice.
|
||||
(@size $size:expr, $var:ident: [u8; $n:expr], $($rest:tt)*) => {
|
||||
input!(@size $size + $n, $($rest)*)
|
||||
};
|
||||
|
||||
// Entry point, with the buffer and it's size specified first.
|
||||
// e.g input!(buffer, 512, var1: u32, var2: [u8], );
|
||||
($buffer:ident, $size:expr, $($rest:tt)*) => {
|
||||
let mut $buffer = [0u8; $size];
|
||||
let $buffer = &mut &mut $buffer[..];
|
||||
$crate::api::input($buffer);
|
||||
input!(@inner $buffer, 0, $($rest)*);
|
||||
};
|
||||
|
||||
// Entry point, with the name of the buffer specified and size of the input buffer computed.
|
||||
// e.g input!(buffer, var1: u32, var2: u64, );
|
||||
($buffer: ident, $($rest:tt)*) => {
|
||||
input!($buffer, input!(@size 0, $($rest)*), $($rest)*);
|
||||
};
|
||||
|
||||
// Entry point, with the size of the input buffer computed.
|
||||
// e.g input!(var1: u32, var2: u64, );
|
||||
($($rest:tt)*) => {
|
||||
input!(buffer, $($rest)*);
|
||||
};
|
||||
}
|
||||
|
||||
/// Utility macro to invoke a host function that expect a `output: &mut &mut [u8]` as last argument.
|
||||
///
|
||||
/// Example:
|
||||
/// ```
|
||||
/// // call `api::caller` and store the output in `caller`
|
||||
/// output!(caller, [0u8; 32], api::caller,);
|
||||
///
|
||||
/// // call `api::get_storage` and store the output in `address`
|
||||
/// output!(address, [0u8; 32], api::get_storage, &[1u8; 32]);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! output {
|
||||
($output: ident, $buffer: expr, $host_fn:path, $($arg:expr),*) => {
|
||||
let mut $output = $buffer;
|
||||
let $output = &mut &mut $output[..];
|
||||
$host_fn($($arg,)* $output);
|
||||
};
|
||||
}
|
||||
|
||||
/// Similar to `output!` but unwraps the result.
|
||||
#[macro_export]
|
||||
macro_rules! unwrap_output {
|
||||
($output: ident, $buffer: expr, $host_fn:path, $($arg:expr),*) => {
|
||||
let mut $output = $buffer;
|
||||
let $output = &mut &mut $output[..];
|
||||
$host_fn($($arg,)* $output).unwrap();
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This calls another contract as passed as its account id. It also creates some storage.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
buffer,
|
||||
input: [u8; 4],
|
||||
callee: [u8; 32],
|
||||
deposit_limit: [u8; 8],
|
||||
);
|
||||
|
||||
// create 4 byte of storage before calling
|
||||
api::set_storage(buffer, &[1u8; 4]);
|
||||
|
||||
// Call the callee
|
||||
api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
Some(deposit_limit),
|
||||
&0u64.to_le_bytes(), // Value transferred to the contract.
|
||||
input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// create 8 byte of storage after calling
|
||||
// item of 12 bytes because we override 4 bytes
|
||||
api::set_storage(buffer, &[1u8; 12]);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This instantiates another contract and passes some input to its constructor.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
input: [u8; 4],
|
||||
code_hash: [u8; 32],
|
||||
deposit_limit: [u8; 8],
|
||||
);
|
||||
|
||||
let value = 10_000u64.to_le_bytes();
|
||||
let salt = [0u8; 0];
|
||||
let mut address = [0u8; 32];
|
||||
let address = &mut &mut address[..];
|
||||
|
||||
api::instantiate_v2(
|
||||
code_hash,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
Some(deposit_limit),
|
||||
&value,
|
||||
input,
|
||||
Some(address),
|
||||
None,
|
||||
&salt,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Return the deployed contract address.
|
||||
api::return_value(uapi::ReturnFlags::empty(), address);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This calls another contract as passed as its account id. It also creates some transient storage.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
buffer,
|
||||
len: u32,
|
||||
input: [u8; 4],
|
||||
callee: [u8; 32],
|
||||
);
|
||||
|
||||
let data = [0u8; 16 * 1024];
|
||||
let value = &data[..len as usize];
|
||||
#[allow(deprecated)]
|
||||
api::set_transient_storage(buffer, value);
|
||||
|
||||
// Call the callee
|
||||
api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None,
|
||||
&0u64.to_le_bytes(), // Value transferred to the contract.
|
||||
input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
/// Called by the tests.
|
||||
///
|
||||
/// The `call` function expects data in a certain format in the input buffer.
|
||||
///
|
||||
/// 1. The first byte encodes an identifier for the crypto hash function under test. (*)
|
||||
/// 2. The rest encodes the input data that is directly fed into the crypto hash function chosen in
|
||||
/// 1.
|
||||
///
|
||||
/// The `deploy` function then computes the chosen crypto hash function
|
||||
/// given the input and puts the result into the output buffer.
|
||||
/// After contract execution the test driver then asserts that the returned
|
||||
/// values are equal to the expected bytes for the input and chosen hash
|
||||
/// function.
|
||||
///
|
||||
/// (*) The possible value for the crypto hash identifiers can be found below:
|
||||
///
|
||||
/// | value | Algorithm | Bit Width |
|
||||
/// |-------|-----------|-----------|
|
||||
/// | 0 | SHA2 | 256 |
|
||||
/// | 1 | KECCAK | 256 |
|
||||
/// | 2 | BLAKE2 | 256 |
|
||||
/// | 3 | BLAKE2 | 128 |
|
||||
/// ---------------------------------
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
256,
|
||||
chosen_hash_fn: u8,
|
||||
input: [u8],
|
||||
);
|
||||
|
||||
match chosen_hash_fn {
|
||||
1 => {
|
||||
let mut output = [0u8; 32];
|
||||
api::hash_sha2_256(input, &mut output);
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output);
|
||||
},
|
||||
2 => {
|
||||
let mut output = [0u8; 32];
|
||||
api::hash_keccak_256(input, &mut output);
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output);
|
||||
},
|
||||
3 => {
|
||||
let mut output = [0u8; 32];
|
||||
api::hash_blake2_256(input, &mut output);
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output);
|
||||
},
|
||||
4 => {
|
||||
let mut output = [0u8; 16];
|
||||
api::hash_blake2_128(input, &mut output);
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output);
|
||||
},
|
||||
_ => panic!("unknown crypto hash function identifier"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! Emit a debug message with an invalid utf-8 code.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::debug_message(b"\xFC").unwrap();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! Emit a "Hello World!" debug message but assume that logging is disabled.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::debug_message(b"Hello World!").unwrap();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! Emit a "Hello World!" debug message.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::debug_message(b"Hello World!").unwrap();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(code_hash: [u8; 32],);
|
||||
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1u8;
|
||||
|
||||
let mut value = [0u8; 32];
|
||||
let value = &mut &mut value[..];
|
||||
value[0] = 2u8;
|
||||
|
||||
api::set_storage(&key, value);
|
||||
api::get_storage(&key, value).unwrap();
|
||||
assert!(value[0] == 2u8);
|
||||
|
||||
let input = [0u8; 0];
|
||||
api::delegate_call(uapi::CallFlags::empty(), code_hash, &input, None).unwrap();
|
||||
|
||||
api::get_storage(&[1u8], value).unwrap();
|
||||
assert!(value[0] == 1u8);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::output;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1u8;
|
||||
|
||||
// Place a value in storage.
|
||||
let mut value = [0u8; 32];
|
||||
let value = &mut &mut value[..];
|
||||
value[0] = 1u8;
|
||||
api::set_storage(&key, value);
|
||||
|
||||
// Assert that `value_transferred` is equal to the value
|
||||
// passed to the `caller` contract: 1337.
|
||||
output!(value_transferred, [0u8; 8], api::value_transferred,);
|
||||
let value_transferred = u64::from_le_bytes(value_transferred[..].try_into().unwrap());
|
||||
assert_eq!(value_transferred, 1337);
|
||||
|
||||
// Assert that ALICE is the caller of the contract.
|
||||
output!(caller, [0u8; 32], api::caller,);
|
||||
assert_eq!(&caller[..], &[1u8; 32]);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(code_hash: [u8; 32],);
|
||||
|
||||
// Delegate call into passed code hash.
|
||||
let input = [0u8; 0];
|
||||
api::delegate_call(uapi::CallFlags::empty(), code_hash, &input, None).unwrap();
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
const ADDRESS_KEY: [u8; 32] = [0u8; 32];
|
||||
const VALUE: [u8; 8] = [0, 0, 1u8, 0, 0, 0, 0, 0];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
input!(code_hash: [u8; 32],);
|
||||
|
||||
let input = [0u8; 0];
|
||||
let mut address = [0u8; 32];
|
||||
let address = &mut &mut address[..];
|
||||
let salt = [71u8, 17u8];
|
||||
|
||||
api::instantiate_v2(
|
||||
code_hash,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&VALUE,
|
||||
&input,
|
||||
Some(address),
|
||||
None,
|
||||
&salt,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Return the deployed contract address.
|
||||
api::set_storage(&ADDRESS_KEY, address);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let mut callee_addr = [0u8; 32];
|
||||
let callee_addr = &mut &mut callee_addr[..];
|
||||
api::get_storage(&ADDRESS_KEY, callee_addr).unwrap();
|
||||
|
||||
// Calling the destination contract with non-empty input data should fail.
|
||||
let res = api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&VALUE,
|
||||
&[0u8; 1],
|
||||
None,
|
||||
);
|
||||
assert!(matches!(res, Err(uapi::ReturnErrorCode::CalleeTrapped)));
|
||||
|
||||
// Call the destination contract regularly, forcing it to self-destruct.
|
||||
api::call_v2(
|
||||
uapi::CallFlags::empty(),
|
||||
callee_addr,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size weight to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&VALUE,
|
||||
&[0u8; 0],
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::output;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
output!(balance, [0u8; 8], api::balance,);
|
||||
let balance = u64::from_le_bytes(balance[..].try_into().unwrap());
|
||||
|
||||
output!(minimum_balance, [0u8; 8], api::minimum_balance,);
|
||||
let minimum_balance = u64::from_le_bytes(minimum_balance[..].try_into().unwrap());
|
||||
|
||||
// Make the transferred value exceed the balance by adding the minimum balance.
|
||||
let balance = balance + minimum_balance;
|
||||
|
||||
// Try to self-destruct by sending more balance to the 0 address.
|
||||
// The call will fail because a contract transfer has a keep alive requirement.
|
||||
let res = api::transfer(&[0u8; 32], &balance.to_le_bytes());
|
||||
assert!(matches!(res, Err(uapi::ReturnErrorCode::TransferFailed)));
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,44 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
signature: [u8; 65],
|
||||
hash: [u8; 32],
|
||||
);
|
||||
|
||||
let mut output = [0u8; 33];
|
||||
api::ecdsa_recover(
|
||||
&signature[..].try_into().unwrap(),
|
||||
&hash[..].try_into().unwrap(),
|
||||
&mut output,
|
||||
)
|
||||
.unwrap();
|
||||
api::return_value(uapi::ReturnFlags::empty(), &output);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
let buffer = [1u8, 2, 3, 4];
|
||||
api::deposit_event(&[0u8; 0], &buffer);
|
||||
api::return_value(uapi::ReturnFlags::empty(), &buffer);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
unreachable!()
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(len: u32,);
|
||||
|
||||
let buffer = [0u8; 16 * 1024 + 1];
|
||||
let data = &buffer[..len as usize];
|
||||
|
||||
api::deposit_event(&[0u8; 0], data);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add(a: f32, b: f32) -> f32 {
|
||||
a + b
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(buffer, 36, code_hash: [u8; 32],);
|
||||
let input = &buffer[32..];
|
||||
|
||||
let err_code = match api::instantiate_v2(
|
||||
code_hash,
|
||||
0u64, // How much ref_time weight to devote for the execution. 0 = all.
|
||||
0u64, /* How much proof_size weight to devote for the execution. 0 =
|
||||
* all. */
|
||||
None, // No deposit limit.
|
||||
&10_000u64.to_le_bytes(), // Value to transfer.
|
||||
input,
|
||||
None,
|
||||
None,
|
||||
&[0u8; 0], // Empty salt.
|
||||
) {
|
||||
Ok(_) => 0u32,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
// Exit with success and take transfer return code to the output buffer.
|
||||
api::return_value(uapi::ReturnFlags::empty(), &err_code.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This contract tests the behavior of locking / unlocking delegate_dependencies when delegate
|
||||
//! calling into a contract.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
const ALICE: [u8; 32] = [1u8; 32];
|
||||
|
||||
/// Load input data and perform the action specified by the input.
|
||||
/// If `delegate_call` is true, then delegate call into the contract.
|
||||
fn load_input(delegate_call: bool) {
|
||||
input!(
|
||||
action: u32,
|
||||
code_hash: [u8; 32],
|
||||
);
|
||||
|
||||
match action {
|
||||
// 1 = Lock delegate dependency
|
||||
1 => {
|
||||
api::lock_delegate_dependency(code_hash);
|
||||
},
|
||||
// 2 = Unlock delegate dependency
|
||||
2 => {
|
||||
api::unlock_delegate_dependency(code_hash);
|
||||
},
|
||||
// 3 = Terminate
|
||||
3 => {
|
||||
api::terminate_v1(&ALICE);
|
||||
},
|
||||
// Everything else is a noop
|
||||
_ => {},
|
||||
}
|
||||
|
||||
if delegate_call {
|
||||
api::delegate_call(uapi::CallFlags::empty(), code_hash, &[], None).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
load_input(false);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
load_input(true);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! Does two stores to two separate storage items
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
size1: u32,
|
||||
size2: u32,
|
||||
);
|
||||
|
||||
let buffer = [0u8; 16 * 1024];
|
||||
|
||||
// Place a values in storage sizes are specified in the input buffer.
|
||||
// We don't care about the contents of the storage item.
|
||||
api::set_storage(&[1u8; 32], &buffer[0..size1 as _]);
|
||||
api::set_storage(&[2u8; 32], &buffer[0..size2 as _]);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::return_value(uapi::ReturnFlags::empty(), &2u32.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
ok_trap_revert();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
ok_trap_revert();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
fn ok_trap_revert() {
|
||||
input!(buffer, 4,);
|
||||
match buffer.first().unwrap_or(&0) {
|
||||
1 => api::return_value(uapi::ReturnFlags::REVERT, &[0u8; 0]),
|
||||
2 => panic!(),
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
// This fixture tests if read-only call works as expected.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
256,
|
||||
callee_addr: [u8; 32],
|
||||
callee_input: [u8],
|
||||
);
|
||||
|
||||
// Call the callee
|
||||
api::call_v2(
|
||||
uapi::CallFlags::READ_ONLY,
|
||||
callee_addr,
|
||||
0u64, // How much ref_time to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&0u64.to_le_bytes(), // Value transferred to the contract.
|
||||
callee_input,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This fixture calls itself as many times as passed as argument.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::{input, output};
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(calls_left: u32, );
|
||||
|
||||
// own address
|
||||
output!(addr, [0u8; 32], api::address,);
|
||||
|
||||
if calls_left == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
api::call_v2(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
addr,
|
||||
0u64, // How much ref_time to devote for the execution. 0 = all.
|
||||
0u64, // How much deposit_limit to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&0u64.to_le_bytes(), // Value transferred to the contract.
|
||||
&(calls_left - 1).to_le_bytes(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
// This fixture tests if account_reentrance_count works as expected.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::{input, output};
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(expected_reentrance_count: u32,);
|
||||
|
||||
// Read the contract address.
|
||||
output!(addr, [0u8; 32], api::address,);
|
||||
|
||||
#[allow(deprecated)]
|
||||
let reentrance_count = api::reentrance_count();
|
||||
assert_eq!(reentrance_count, expected_reentrance_count);
|
||||
|
||||
// Re-enter 5 times in a row and assert that the reentrant counter works as expected.
|
||||
if expected_reentrance_count != 5 {
|
||||
let count = (expected_reentrance_count + 1).to_le_bytes();
|
||||
|
||||
api::call_v2(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
addr,
|
||||
0u64, // How much ref_time to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&0u64.to_le_bytes(), // Value transferred to the contract.
|
||||
&count,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
// This fixture tests if account_reentrance_count works as expected.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
input,
|
||||
code_hash: [u8; 32],
|
||||
call_stack_height: u32,
|
||||
);
|
||||
|
||||
let call_stack_height = call_stack_height + 1;
|
||||
|
||||
#[allow(deprecated)]
|
||||
let reentrance_count = api::reentrance_count();
|
||||
|
||||
// Reentrance count stays 0.
|
||||
assert_eq!(reentrance_count, 0);
|
||||
|
||||
// Re-enter 5 times in a row and assert that the reentrant counter works as expected.
|
||||
if call_stack_height != 5 {
|
||||
let mut input = [0u8; 36];
|
||||
input[0..32].copy_from_slice(code_hash);
|
||||
input[32..36].copy_from_slice(&call_stack_height.to_le_bytes());
|
||||
api::delegate_call(uapi::CallFlags::empty(), code_hash, &input, None).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
call();
|
||||
}
|
||||
|
||||
/// Reads the first byte as the exit status and copy all but the first 4 bytes of the input as
|
||||
/// output data.
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
input, 128,
|
||||
exit_status: [u8; 4],
|
||||
output: [u8],
|
||||
);
|
||||
|
||||
// Burn some PoV, clear_storage consumes some PoV as in order to clear the storage we need to we
|
||||
// need to read its size first.
|
||||
api::clear_storage_v1(b"");
|
||||
|
||||
let exit_status = uapi::ReturnFlags::from_bits(exit_status[0] as u32).unwrap();
|
||||
api::return_value(exit_status, output);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
#[allow(clippy::empty_loop)]
|
||||
loop {}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::{input, output};
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
const DJANGO: [u8; 32] = [4u8; 32];
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
// If the input data is not empty, then recursively call self with empty input data.
|
||||
// This should trap instead of self-destructing since a contract cannot be removed, while it's
|
||||
// in the execution stack. If the recursive call traps, then trap here as well.
|
||||
input!(input, 4,);
|
||||
|
||||
if !input.is_empty() {
|
||||
output!(addr, [0u8; 32], api::address,);
|
||||
api::call_v2(
|
||||
uapi::CallFlags::ALLOW_REENTRY,
|
||||
addr,
|
||||
0u64, // How much ref_time to devote for the execution. 0 = all.
|
||||
0u64, // How much proof_size to devote for the execution. 0 = all.
|
||||
None, // No deposit limit.
|
||||
&0u64.to_le_bytes(), // Value to transfer.
|
||||
&[0u8; 0],
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
} else {
|
||||
// Try to terminate and give balance to django.
|
||||
api::terminate_v1(&DJANGO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
api::terminate_v1(&[0u8; 32]);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(addr: [u8; 32],);
|
||||
api::set_code_hash(addr).unwrap();
|
||||
|
||||
// we return 1 after setting new code_hash
|
||||
// next `call` will NOT return this value, because contract code has been changed
|
||||
api::return_value(uapi::ReturnFlags::empty(), &1u32.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
api::set_storage(&[0u8; 32], &[0u8; 4]);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(len: u32, );
|
||||
|
||||
let buffer = [0u8; 16 * 1024];
|
||||
let data = &buffer[..len as usize];
|
||||
|
||||
// Place a garbage value in the transient storage, with the size specified by the call input.
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1;
|
||||
|
||||
#[allow(deprecated)]
|
||||
api::set_transient_storage(&key, data);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
signature: [u8; 64],
|
||||
pub_key: [u8; 32],
|
||||
msg: [u8; 11],
|
||||
);
|
||||
|
||||
let exit_status = match api::sr25519_verify(
|
||||
&signature.try_into().unwrap(),
|
||||
msg,
|
||||
&pub_key.try_into().unwrap(),
|
||||
) {
|
||||
Ok(_) => 0u32,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
// Exit with success and take transfer return code to the output buffer.
|
||||
api::return_value(uapi::ReturnFlags::empty(), &exit_status.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This contract tests the storage APIs. It sets and clears storage values using the different
|
||||
//! versions of the storage APIs.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::unwrap_output;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
const KEY: [u8; 32] = [1u8; 32];
|
||||
const VALUE_1: [u8; 4] = [1u8; 4];
|
||||
const VALUE_2: [u8; 4] = [2u8; 4];
|
||||
const VALUE_3: [u8; 4] = [3u8; 4];
|
||||
|
||||
api::set_storage(&KEY, &VALUE_1);
|
||||
assert_eq!(api::contains_storage(&KEY), Some(VALUE_1.len() as _));
|
||||
unwrap_output!(val, [0u8; 4], api::get_storage, &KEY);
|
||||
assert_eq!(**val, VALUE_1);
|
||||
|
||||
let existing = api::set_storage_v1(&KEY, &VALUE_2);
|
||||
assert_eq!(existing, Some(VALUE_1.len() as _));
|
||||
unwrap_output!(val, [0u8; 4], api::get_storage, &KEY);
|
||||
assert_eq!(**val, VALUE_2);
|
||||
|
||||
api::clear_storage(&KEY);
|
||||
assert_eq!(api::contains_storage(&KEY), None);
|
||||
|
||||
let existing = api::set_storage_v2(&KEY, &VALUE_3);
|
||||
assert_eq!(existing, None);
|
||||
assert_eq!(api::contains_storage_v1(&KEY), Some(VALUE_1.len() as _));
|
||||
unwrap_output!(val, [0u8; 32], api::get_storage_v1, &KEY);
|
||||
assert_eq!(**val, VALUE_3);
|
||||
|
||||
api::clear_storage_v1(&KEY);
|
||||
assert_eq!(api::contains_storage_v1(&KEY), None);
|
||||
let existing = api::set_storage_v2(&KEY, &VALUE_3);
|
||||
assert_eq!(existing, None);
|
||||
unwrap_output!(val, [0u8; 32], api::take_storage, &KEY);
|
||||
assert_eq!(**val, VALUE_3);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(len: u32, );
|
||||
|
||||
let mut buffer = [0u8; 16 * 1024 + 1];
|
||||
let data = &buffer[..len as usize];
|
||||
|
||||
// Place a garbage value in storage, the size of which is specified by the call input.
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1;
|
||||
|
||||
api::set_storage(&key, data);
|
||||
|
||||
let data = &mut &mut buffer[..];
|
||||
api::get_storage(&key, data).unwrap();
|
||||
assert_eq!(data.len(), len as usize);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(len: u32, );
|
||||
|
||||
let buffer = [0u8; 16 * 1024 + 1];
|
||||
let data = &buffer[..len as usize];
|
||||
|
||||
// Place a garbage value in storage, the size of which is specified by the call input.
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1;
|
||||
|
||||
api::set_storage(&key, data);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {
|
||||
input!(len: u32, );
|
||||
|
||||
let buffer = [0u8; 16 * 1024 + 1];
|
||||
let data = &buffer[..len as usize];
|
||||
|
||||
// place a garbage value in storage, the size of which is specified by the call input.
|
||||
let mut key = [0u8; 32];
|
||||
key[0] = 1;
|
||||
|
||||
api::set_storage(&key, data);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {}
|
||||
@@ -0,0 +1,38 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate common;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
let ret_code = match api::transfer(&[0u8; 32], &100u64.to_le_bytes()) {
|
||||
Ok(_) => 0u32,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
// Exit with success and take transfer return code to the output buffer.
|
||||
api::return_value(uapi::ReturnFlags::empty(), &ret_code.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
//! This contract tests the transient storage APIs.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::unwrap_output;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
const KEY: [u8; 32] = [1u8; 32];
|
||||
const VALUE_1: [u8; 4] = [1u8; 4];
|
||||
const VALUE_2: [u8; 4] = [2u8; 4];
|
||||
const VALUE_3: [u8; 4] = [3u8; 4];
|
||||
|
||||
#[allow(deprecated)]
|
||||
{
|
||||
let existing = api::set_transient_storage(&KEY, &VALUE_1);
|
||||
assert_eq!(existing, None);
|
||||
assert_eq!(api::contains_transient_storage(&KEY), Some(VALUE_1.len() as _));
|
||||
unwrap_output!(val, [0u8; 4], api::get_transient_storage, &KEY);
|
||||
assert_eq!(**val, VALUE_1);
|
||||
|
||||
let existing = api::set_transient_storage(&KEY, &VALUE_2);
|
||||
assert_eq!(existing, Some(VALUE_1.len() as _));
|
||||
unwrap_output!(val, [0u8; 4], api::get_transient_storage, &KEY);
|
||||
assert_eq!(**val, VALUE_2);
|
||||
|
||||
api::clear_transient_storage(&KEY);
|
||||
assert_eq!(api::contains_transient_storage(&KEY), None);
|
||||
|
||||
let existing = api::set_transient_storage(&KEY, &VALUE_3);
|
||||
assert_eq!(existing, None);
|
||||
unwrap_output!(val, [0u8; 32], api::take_transient_storage, &KEY);
|
||||
assert_eq!(**val, VALUE_3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(512, msg: [u8],);
|
||||
|
||||
#[allow(deprecated)]
|
||||
let err_code = match api::xcm_execute(msg) {
|
||||
Ok(_) => 0u32,
|
||||
Err(code) => code as u32,
|
||||
};
|
||||
|
||||
api::return_value(uapi::ReturnFlags::empty(), &err_code.to_le_bytes());
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use common::input;
|
||||
use uapi::{HostFn, HostFnImpl as api};
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn deploy() {}
|
||||
|
||||
#[no_mangle]
|
||||
#[polkavm_derive::polkavm_export]
|
||||
pub extern "C" fn call() {
|
||||
input!(
|
||||
512,
|
||||
dest: [u8; 3],
|
||||
msg: [u8],
|
||||
);
|
||||
|
||||
let mut message_id = [0u8; 32];
|
||||
|
||||
#[allow(deprecated)]
|
||||
api::xcm_send(dest, msg, &mut message_id).unwrap();
|
||||
api::return_value(uapi::ReturnFlags::empty(), &message_id);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// 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.
|
||||
|
||||
use pezsp_runtime::traits::Hash;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
/// Load a given wasm module and returns a wasm binary contents along with it's hash.
|
||||
/// Use the legacy compile_module as fallback, if the rust fixture does not exist yet.
|
||||
pub fn compile_module<T>(
|
||||
fixture_name: &str,
|
||||
) -> anyhow::Result<(Vec<u8>, <T::Hashing as Hash>::Output)>
|
||||
where
|
||||
T: pezframe_system::Config,
|
||||
{
|
||||
let out_dir: PathBuf = env!("OUT_DIR").into();
|
||||
let fixture_path = out_dir.join(format!("{fixture_name}.wasm"));
|
||||
let binary = fs::read(fixture_path)?;
|
||||
let code_hash = T::Hashing::hash(&binary);
|
||||
Ok((binary, code_hash))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn out_dir_should_have_compiled_mocks() {
|
||||
let out_dir: std::path::PathBuf = env!("OUT_DIR").into();
|
||||
assert!(out_dir.join("dummy.wasm").exists());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user