Skip to content

Commit

Permalink
Contracts: use compiled rust tests (#2347)
Browse files Browse the repository at this point in the history
see #2189

This PR does the following:
- Bring the user api functions into a new pallet-contracts-uapi (They
are currently defined in ink!
[here])(https://github.com/paritytech/ink/blob/master/crates/env/src/engine/on_chain/ext.rs)
- Add older api versions and unstable to the user api trait.
- Remove pallet-contracts-primitives and bring the types it defined in
uapi / pallet-contracts
- Add the infrastructure to build fixtures from Rust files and test it
works by replacing `dummy.wat` and `call.wat`
- Move all the doc from wasm/runtime.rs to pallet-contracts-uapi.

This will be done in a follow up:
- convert the rest of the test from .wat to rust
- bring risc-v uapi up to date with wasm
- finalize the uapi host fns, making sure everything is codegen from the
source host fns in pallet-contracts

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
  • Loading branch information
pgherveou and athei authored Nov 29, 2023
1 parent f69069b commit 2135fa8
Show file tree
Hide file tree
Showing 38 changed files with 2,520 additions and 977 deletions.
92 changes: 66 additions & 26 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,9 @@ members = [
"substrate/frame/collective",
"substrate/frame/contracts",
"substrate/frame/contracts/fixtures",
"substrate/frame/contracts/fixtures/contracts/common",
"substrate/frame/contracts/uapi",
"substrate/frame/contracts/mock-network",
"substrate/frame/contracts/primitives",
"substrate/frame/contracts/proc-macro",
"substrate/frame/conviction-voting",
"substrate/frame/core-fellowship",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pallet-transaction-payment-rpc-runtime-api = { path = "../../../../../substrate/
pallet-utility = { path = "../../../../../substrate/frame/utility", default-features = false}
pallet-sudo = { path = "../../../../../substrate/frame/sudo", default-features = false}
pallet-contracts = { path = "../../../../../substrate/frame/contracts", default-features = false}
pallet-contracts-primitives = { path = "../../../../../substrate/frame/contracts/primitives", default-features = false}

# Polkadot
pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false }
Expand Down Expand Up @@ -102,7 +101,6 @@ std = [
"pallet-authorship/std",
"pallet-balances/std",
"pallet-collator-selection/std",
"pallet-contracts-primitives/std",
"pallet-contracts/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-message-queue/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ impl_runtime_apis! {
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_contracts_primitives::ContractExecResult<Balance, EventRecord> {
) -> pallet_contracts::ContractExecResult<Balance, EventRecord> {
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_call(
origin,
Expand All @@ -608,10 +608,10 @@ impl_runtime_apis! {
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
code: pallet_contracts_primitives::Code<Hash>,
code: pallet_contracts::Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, Balance, EventRecord> {
) -> pallet_contracts::ContractInstantiateResult<AccountId, Balance, EventRecord> {
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_instantiate(
origin,
Expand All @@ -631,7 +631,7 @@ impl_runtime_apis! {
code: Vec<u8>,
storage_deposit_limit: Option<Balance>,
determinism: pallet_contracts::Determinism,
) -> pallet_contracts_primitives::CodeUploadResult<Hash, Balance> {
) -> pallet_contracts::CodeUploadResult<Hash, Balance> {
Contracts::bare_upload_code(
origin,
code,
Expand All @@ -643,7 +643,7 @@ impl_runtime_apis! {
fn get_storage(
address: AccountId,
key: Vec<u8>,
) -> pallet_contracts_primitives::GetStorageResult {
) -> pallet_contracts::GetStorageResult {
Contracts::get_storage(address, key)
}
}
Expand Down
2 changes: 0 additions & 2 deletions substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ pallet-broker = { path = "../../../frame/broker", default-features = false}
pallet-child-bounties = { path = "../../../frame/child-bounties", default-features = false}
pallet-collective = { path = "../../../frame/collective", default-features = false}
pallet-contracts = { path = "../../../frame/contracts", default-features = false}
pallet-contracts-primitives = { path = "../../../frame/contracts/primitives", default-features = false}
pallet-conviction-voting = { path = "../../../frame/conviction-voting", default-features = false}
pallet-core-fellowship = { path = "../../../frame/core-fellowship", default-features = false}
pallet-democracy = { path = "../../../frame/democracy", default-features = false}
Expand Down Expand Up @@ -171,7 +170,6 @@ std = [
"pallet-broker/std",
"pallet-child-bounties/std",
"pallet-collective/std",
"pallet-contracts-primitives/std",
"pallet-contracts/std",
"pallet-conviction-voting/std",
"pallet-core-fellowship/std",
Expand Down
10 changes: 5 additions & 5 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,7 @@ impl_runtime_apis! {
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_contracts_primitives::ContractExecResult<Balance, EventRecord> {
) -> pallet_contracts::ContractExecResult<Balance, EventRecord> {
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_call(
origin,
Expand All @@ -2517,10 +2517,10 @@ impl_runtime_apis! {
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
code: pallet_contracts_primitives::Code<Hash>,
code: pallet_contracts::Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, Balance, EventRecord>
) -> pallet_contracts::ContractInstantiateResult<AccountId, Balance, EventRecord>
{
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_instantiate(
Expand All @@ -2541,7 +2541,7 @@ impl_runtime_apis! {
code: Vec<u8>,
storage_deposit_limit: Option<Balance>,
determinism: pallet_contracts::Determinism,
) -> pallet_contracts_primitives::CodeUploadResult<Hash, Balance>
) -> pallet_contracts::CodeUploadResult<Hash, Balance>
{
Contracts::bare_upload_code(
origin,
Expand All @@ -2554,7 +2554,7 @@ impl_runtime_apis! {
fn get_storage(
address: AccountId,
key: Vec<u8>,
) -> pallet_contracts_primitives::GetStorageResult {
) -> pallet_contracts::GetStorageResult {
Contracts::get_storage(
address,
key
Expand Down
4 changes: 1 addition & 3 deletions substrate/frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ frame-benchmarking = { path = "../benchmarking", default-features = false, optio
frame-support = { path = "../support", default-features = false}
frame-system = { path = "../system", default-features = false}
pallet-balances = { path = "../balances", default-features = false , optional = true}
pallet-contracts-primitives = { path = "primitives", default-features = false}
pallet-contracts-uapi = { path = "uapi" }
pallet-contracts-proc-macro = { path = "proc-macro" }
sp-api = { path = "../../primitives/api", default-features = false}
sp-core = { path = "../../primitives/core", default-features = false}
Expand Down Expand Up @@ -83,8 +83,6 @@ std = [
"frame-system/std",
"log/std",
"pallet-balances?/std",
"pallet-contracts-fixtures/std",
"pallet-contracts-primitives/std",
"pallet-contracts-proc-macro/full",
"pallet-insecure-randomness-collective-flip/std",
"pallet-proxy/std",
Expand Down
1 change: 0 additions & 1 deletion substrate/frame/contracts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
version - 1,
)?;

println!("cargo:rerun-if-changed=src/migration");
Ok(())
}
16 changes: 11 additions & 5 deletions substrate/frame/contracts/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ description = "Fixtures for testing contracts pallet."

[dependencies]
wat = "1"
frame-system = { path = "../../system", default-features = false}
sp-runtime = { path = "../../../primitives/runtime", default-features = false}
frame-system = { path = "../../system" }
sp-runtime = { path = "../../../primitives/runtime" }
anyhow = "1.0.0"

[build-dependencies]
parity-wasm = "0.45.0"
tempfile = "3.8.1"
toml = "0.8.8"
twox-hash = "1.6.3"
anyhow = "1.0.0"
cfg-if = { version = "1.0", default-features = false }

[features]
default = [ "std" ]
std = [ "frame-system/std", "sp-runtime/std" ]

Loading

0 comments on commit 2135fa8

Please sign in to comment.