Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/checks-quick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ jobs:
--exclude
"substrate/frame/contracts/fixtures/build"
"substrate/frame/contracts/fixtures/contracts/common"
"substrate/frame/revive/fixtures/contracts/common"
- name: deny git deps
run: python3 .github/scripts/deny-git-deps.py .
check-markdown:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions prdoc/pr_7844.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: '[pallet-revive] Update fixture build script'
doc:
- audience: Runtime Dev
description: |-
Update the fixture build script so that it can be built from crates.io registry
crates:
- name: pallet-revive-uapi
bump: patch
- name: pallet-revive-fixtures
bump: patch
- name: pallet-revive-eth-rpc
bump: patch

2 changes: 2 additions & 0 deletions substrate/frame/revive/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ sp-io = { workspace = true, default-features = true, optional = true }

[build-dependencies]
anyhow = { workspace = true, default-features = true }
cargo_metadata = { workspace = true }
pallet-revive-uapi = { workspace = true }
polkavm-linker = { version = "0.21.0" }
toml = { workspace = true }

Expand Down
37 changes: 27 additions & 10 deletions substrate/frame/revive/fixtures/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
// limitations under the License.

//! Compile text fixtures to PolkaVM binaries.
use anyhow::Result;

use anyhow::{bail, Context};
use anyhow::{bail, Context, Result};
use cargo_metadata::MetadataCommand;
use std::{
env, fs,
io::Write,
Expand Down Expand Up @@ -84,14 +83,32 @@ fn create_cargo_toml<'a>(
output_dir: &Path,
) -> Result<()> {
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(),
let uapi_dep = cargo_toml["dependencies"]["uapi"].as_table_mut().unwrap();

let metadata = MetadataCommand::new()
.manifest_path(fixtures_dir.join("Cargo.toml"))
.exec()
.expect("Failed to fetch cargo metadata");

let mut uapi_pkgs: Vec<_> = metadata
.packages
.iter()
.filter(|pkg| pkg.name == "pallet-revive-uapi")
.collect();

uapi_pkgs.sort_by(|a, b| b.version.cmp(&a.version));
let uapi_pkg = uapi_pkgs.first().unwrap();

if uapi_pkg.source.is_none() {
uapi_dep.insert(
"path".to_string(),
toml::Value::String(
fixtures_dir.join("../uapi").canonicalize()?.to_str().unwrap().to_string(),
),
Comment on lines +102 to +107
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How is this supposed to work? Is it set depending on whether we are in a workspace or not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, would need to test it out, to make sure it works with the release deployment pipeline

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aye if this works as expected its a good solution.

);
Ok(())
};
set_dep("uapi", "../uapi")?;
set_dep("common", "./contracts/common")?;
} else {
uapi_dep.insert("version".to_string(), toml::Value::String(uapi_pkg.version.to_string()));
}

cargo_toml["bin"] = toml::Value::Array(
entries
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/revive/fixtures/build/_Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ edition = "2021"

# All paths are injected dynamically by the build script.
[dependencies]
uapi = { package = 'pallet-revive-uapi', path = "", features = ["unstable-hostfn"], default-features = false }
common = { package = 'pallet-revive-fixtures-common', path = "" }
uapi = { package = 'pallet-revive-uapi', features = ["unstable-hostfn"], default-features = false }
hex-literal = { version = "0.4.1", default-features = false }
polkavm-derive = { version = "0.21.0" }

Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::u64_output;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{u64_output, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/balance_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::{input, u64_output};
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, u64_output, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/fixtures/contracts/base_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

extern crate common;
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};

#[no_mangle]
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/revive/fixtures/contracts/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

#![no_std]
#![no_main]

extern crate common;
include!("../panic_handler.rs");

use core::arch::asm;

Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/block_author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/block_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! This calls another contract as passed as its account id.
#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! This calls another contract as passed as its account id.
#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::{input, u256_bytes};
use uapi::{HostFn, HostFnImpl as api, ReturnErrorCode, ReturnFlags};
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, ReturnErrorCode, ReturnFlags};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

extern crate common;
use uapi::{HostFn, HostFnImpl as api};

const TEST_DATA: [u8; 32] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

extern crate common;
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};

#[no_mangle]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

extern crate common;
use uapi::{HostFn, HostFnImpl as api, ReturnFlags};

#[no_mangle]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

#![no_std]
#![no_main]

extern crate common;
include!("../panic_handler.rs");

use uapi::{HostFn, HostFnImpl as api};

Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/revive/fixtures/contracts/call_return_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
//! It also forwards its input to the callee.
#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -42,10 +42,10 @@ pub extern "C" fn call() {
let err_code = match api::call(
uapi::CallFlags::empty(),
callee_addr,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
value, // Value transferred to the contract.
value, // Value transferred to the contract.
input,
None,
) {
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/call_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! This passes its input to `call_runtime` and returns the return value to its caller.
#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -42,10 +42,10 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::empty(),
callee_addr,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
callee_input,
None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! This fixture calls the account_id with the flags and value.
#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::{input, u256_bytes};
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -40,10 +40,10 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::from_bits(flags).unwrap(),
callee_addr,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&u256_bytes(value), // Value transferred to the contract.
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&u256_bytes(value), // Value transferred to the contract.
forwarded_input,
None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
//! It returns the result of the call as output data.
#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -43,8 +43,8 @@ pub extern "C" fn call() {
callee_addr,
ref_time,
proof_size,
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // value transferred to the contract.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // value transferred to the contract.
forwarded_input,
None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::{input, u256_bytes};
use uapi::{HostFn, HostFnImpl as api, ReturnErrorCode};
use uapi::{input, u256_bytes, HostFn, HostFnImpl as api, ReturnErrorCode};

const INPUT: [u8; 8] = [0u8, 1, 34, 51, 68, 85, 102, 119];
const REVERTED_INPUT: [u8; 7] = [1u8, 34, 51, 68, 85, 102, 119];
Expand Down Expand Up @@ -122,9 +122,9 @@ pub extern "C" fn call() {
let res = api::call(
uapi::CallFlags::empty(),
&callee,
load_code_ref_time, // just enough to load the contract
load_code_ref_time, // just enough to load the contract
load_code_proof_size, // just enough to load the contract
&[u8::MAX; 32], // No deposit limit.
&[u8::MAX; 32], // No deposit limit.
&value,
&INPUT,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! Call chain extension by passing through input and output of this contract.
#![no_std]
#![no_main]
include!("../panic_handler.rs");

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{input, HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
Loading
Loading