Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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.

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
26 changes: 16 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,21 @@ 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().exec().expect("Failed to fetch cargo metadata");
let uapi_pkg = metadata.packages.iter().find(|pkg| pkg.name == "pallet-revive-uapi").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 = ["fixtures"], default-features = false }
hex-literal = { version = "0.4.1", default-features = false }
polkavm-derive = { version = "0.21.0" }

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

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
3 changes: 1 addition & 2 deletions substrate/frame/revive/fixtures/contracts/balance_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#![no_std]
#![no_main]

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
1 change: 0 additions & 1 deletion substrate/frame/revive/fixtures/contracts/base_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#![no_std]
#![no_main]

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

#[no_mangle]
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/fixtures/contracts/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#![no_std]
#![no_main]

extern crate common;
extern crate uapi;

use core::arch::asm;

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

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

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/revive/fixtures/contracts/block_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#![no_std]
#![no_main]

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

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

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 @@ -19,8 +19,7 @@
#![no_std]
#![no_main]

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 @@ -21,7 +21,6 @@
#![no_std]
#![no_main]

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 @@ -23,7 +23,6 @@
#![no_std]
#![no_main]

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 @@ -20,7 +20,6 @@
#![no_std]
#![no_main]

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 @@ -26,8 +26,6 @@
#![no_std]
#![no_main]

extern crate common;

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

const BUF_SIZE: usize = 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#![no_std]
#![no_main]

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 +41,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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![no_std]
#![no_main]

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

#[no_mangle]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#![no_std]
#![no_main]

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 +41,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 @@ -19,8 +19,7 @@
#![no_std]
#![no_main]

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 +39,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 @@ -20,8 +20,7 @@
#![no_std]
#![no_main]

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 +42,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 @@ -18,8 +18,7 @@
#![no_std]
#![no_main]

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 +121,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 @@ -20,7 +20,7 @@
#![no_std]
#![no_main]

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

#[no_mangle]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![no_std]
#![no_main]

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

#[no_mangle]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#![no_std]
#![no_main]

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

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
2 changes: 0 additions & 2 deletions substrate/frame/revive/fixtures/contracts/chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#![no_std]
#![no_main]

extern crate common;

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

#[no_mangle]
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/fixtures/contracts/code_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![no_std]
#![no_main]

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

#[no_mangle]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![no_std]
#![no_main]

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

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

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

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -43,10 +42,12 @@ pub extern "C" fn call() {
let ret = api::call(
uapi::CallFlags::empty(),
callee,
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all resources.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all resources.
u64::MAX, /* How much ref_time weight to devote for the execution. u64::MAX = use all
* resources. */
u64::MAX, /* How much proof_size weight to devote for the execution. u64::MAX = use all
* resources. */
deposit_limit,
&[0u8; 32], // Value transferred to the contract.
&[0u8; 32], // Value transferred to the contract.
input,
None,
);
Expand Down
Loading