Contracts: use compiled rust tests (#2347)

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>
This commit is contained in:
PG Herveou
2023-11-29 22:12:19 +01:00
committed by GitHub
parent f69069bd42
commit 2135fa872b
38 changed files with 2520 additions and 977 deletions
+12 -11
View File
@@ -24,13 +24,13 @@ mod runtime;
#[cfg(doc)]
pub use crate::wasm::runtime::api_doc;
#[cfg(test)]
pub use tests::MockExt;
pub use crate::wasm::runtime::{
AllowDeprecatedInterface, AllowUnstableInterface, CallFlags, Environment, ReturnCode, Runtime,
AllowDeprecatedInterface, AllowUnstableInterface, Environment, ReturnErrorCode, Runtime,
RuntimeCosts,
};
pub use pallet_contracts_uapi::ReturnFlags;
#[cfg(test)]
pub use tests::MockExt;
use crate::{
exec::{ExecResult, Executable, ExportedFunction, Ext},
@@ -436,6 +436,7 @@ mod tests {
use crate::{
exec::{AccountIdOf, ErrorOrigin, ExecError, Executable, Ext, Key, SeedOf},
gas::GasMeter,
primitives::ExecReturnValue,
storage::WriteOutcome,
tests::{RuntimeCall, Test, ALICE, BOB},
BalanceOf, CodeHash, Error, Origin, Pallet as Contracts,
@@ -445,7 +446,7 @@ mod tests {
assert_err, assert_ok, dispatch::DispatchResultWithPostInfo, weights::Weight,
};
use frame_system::pallet_prelude::BlockNumberFor;
use pallet_contracts_primitives::{ExecReturnValue, ReturnFlags};
use pallet_contracts_uapi::ReturnFlags;
use pretty_assertions::assert_eq;
use sp_core::H256;
use sp_runtime::DispatchError;
@@ -2739,7 +2740,7 @@ mod tests {
let result = execute(CODE, input, &mut ext).unwrap();
assert_eq!(
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
ReturnCode::KeyNotFound as u32
ReturnErrorCode::KeyNotFound as u32
);
// value exists
@@ -2747,7 +2748,7 @@ mod tests {
let result = execute(CODE, input, &mut ext).unwrap();
assert_eq!(
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
ReturnCode::Success as u32
ReturnErrorCode::Success as u32
);
assert_eq!(ext.storage.get(&[1u8; 64].to_vec()).unwrap(), &[42u8]);
assert_eq!(&result.data[4..], &[42u8]);
@@ -2757,7 +2758,7 @@ mod tests {
let result = execute(CODE, input, &mut ext).unwrap();
assert_eq!(
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
ReturnCode::Success as u32
ReturnErrorCode::Success as u32
);
assert_eq!(ext.storage.get(&[2u8; 19].to_vec()), Some(&vec![]));
assert_eq!(&result.data[4..], &([] as [u8; 0]));
@@ -2920,7 +2921,7 @@ mod tests {
let result = execute(CODE, input, &mut ext).unwrap();
assert_eq!(
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
ReturnCode::KeyNotFound as u32
ReturnErrorCode::KeyNotFound as u32
);
// value did exist -> value returned
@@ -2928,7 +2929,7 @@ mod tests {
let result = execute(CODE, input, &mut ext).unwrap();
assert_eq!(
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
ReturnCode::Success as u32
ReturnErrorCode::Success as u32
);
assert_eq!(ext.storage.get(&[1u8; 64].to_vec()), None);
assert_eq!(&result.data[4..], &[42u8]);
@@ -2938,7 +2939,7 @@ mod tests {
let result = execute(CODE, input, &mut ext).unwrap();
assert_eq!(
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
ReturnCode::Success as u32
ReturnErrorCode::Success as u32
);
assert_eq!(ext.storage.get(&[2u8; 19].to_vec()), None);
assert_eq!(&result.data[4..], &[0u8; 0]);
File diff suppressed because it is too large Load Diff