Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracts: use compiled rust tests #2347

Merged
merged 84 commits into from
Nov 29, 2023
Merged
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
50d39a6
Add uapi and tests-contracts pallets
pgherveou Nov 15, 2023
5396bf6
wip
pgherveou Nov 15, 2023
2fbc2c3
Add prelude
pgherveou Nov 15, 2023
c2712f2
Add build.rs file
pgherveou Nov 17, 2023
b6dbd52
fmt
pgherveou Nov 17, 2023
28bc1e2
nit
pgherveou Nov 17, 2023
c396af7
fix
pgherveou Nov 17, 2023
974f33c
fixes
pgherveou Nov 17, 2023
03910c7
Update substrate/frame/contracts/fixtures/build.rs
pgherveou Nov 17, 2023
c4a8bb6
nit
pgherveou Nov 17, 2023
4f895ec
rm dummy.wat
pgherveou Nov 17, 2023
ce4f1ed
fixes
pgherveou Nov 17, 2023
ccbd83e
fix
pgherveou Nov 17, 2023
9016b63
fix
pgherveou Nov 17, 2023
f02512e
test
pgherveou Nov 17, 2023
11990ce
use encoded rust_flags
pgherveou Nov 17, 2023
46c4844
Update substrate/frame/contracts/fixtures/contracts/dummy.rs
pgherveou Nov 17, 2023
d0e18a1
Update substrate/frame/contracts/fixtures/Cargo.toml
pgherveou Nov 17, 2023
0cd6b90
Review part 1
pgherveou Nov 17, 2023
01550ba
Clean up Ptr stuff
pgherveou Nov 17, 2023
eb61dd7
smarter hashing
pgherveou Nov 17, 2023
a539a87
cleanup warnings
pgherveou Nov 17, 2023
2d321fd
add common
pgherveou Nov 17, 2023
2eb6227
Merge branch 'master' into pg/contracts_rust_tests
pgherveou Nov 18, 2023
697f7e1
clippy fix
pgherveou Nov 18, 2023
8da3043
fix clippy 2
pgherveou Nov 18, 2023
d9889e1
rm missing ink! stuff
pgherveou Nov 18, 2023
fe32a96
add back rm code
pgherveou Nov 20, 2023
a4451fc
Add call.wat
pgherveou Nov 20, 2023
db39e91
Adds Api trait
pgherveou Nov 21, 2023
68430f9
Refactoring primitives & uapi
pgherveou Nov 21, 2023
dad8fec
Move types to uapi and add docs
pgherveou Nov 22, 2023
cf47609
update call.rs
pgherveou Nov 22, 2023
a98e7af
fix lints
pgherveou Nov 22, 2023
213a01f
fix sys funcs
pgherveou Nov 24, 2023
eefde89
sort & clean up
pgherveou Nov 24, 2023
89aa067
fix fixture
pgherveou Nov 24, 2023
47fba86
Fix doc tests
pgherveou Nov 24, 2023
6cfb441
fix comments
pgherveou Nov 24, 2023
d999682
fix cargo doc links
pgherveou Nov 24, 2023
3336bb6
Compile with warning flags
pgherveou Nov 24, 2023
ea67819
fix some doc
pgherveou Nov 24, 2023
b976c17
add more docs
pgherveou Nov 24, 2023
09e8a59
fix runtime-benchmarks build
pgherveou Nov 24, 2023
84ba07b
Fix substrate-node
pgherveou Nov 24, 2023
153fe9f
fix dep
pgherveou Nov 24, 2023
56c6f25
fix primitives
pgherveou Nov 24, 2023
619d9a4
Merge branch 'master' into pg/contracts_rust_tests
pgherveou Nov 27, 2023
992e967
fix wasm32 legacy
pgherveou Nov 27, 2023
77c23ba
Remove features std from fixtures
pgherveou Nov 27, 2023
01261c7
PR review remove unused cargo dep
pgherveou Nov 27, 2023
a9a8e50
PR review Make sure fixtures are formatted
pgherveou Nov 27, 2023
04dbc5e
Fix fmt & lock
pgherveou Nov 27, 2023
d3871f3
rm println from build.rs
pgherveou Nov 27, 2023
d2d6e0c
fix formatting
pgherveou Nov 27, 2023
2ced8ea
Rename ptr_and_len_from_slice
pgherveou Nov 27, 2023
308c42f
Rename fn ptr_from_slice
pgherveou Nov 27, 2023
8907f0a
rm todo comment
pgherveou Nov 27, 2023
835d26f
Apply suggestions from code review
pgherveou Nov 27, 2023
c997c88
Update unstable comments
pgherveou Nov 27, 2023
8e9f317
rm inline
pgherveou Nov 27, 2023
a33ce94
rm unneeded uapi dep
pgherveou Nov 27, 2023
f3a2a21
rm legacy call uapi
pgherveou Nov 27, 2023
9c22f77
rm pub on legacy_compile_module
pgherveou Nov 27, 2023
4c15e5b
leftover
pgherveou Nov 27, 2023
b55b370
moved riscv32 and wasm32 under api
pgherveou Nov 27, 2023
f14996e
remove extern crate uapi
pgherveou Nov 27, 2023
c1e60bd
rm unneeded dep
pgherveou Nov 27, 2023
2a42b9f
move common inside contracts
pgherveou Nov 27, 2023
a8efa67
fmt
pgherveou Nov 27, 2023
08a6325
print both stdout & stderr
pgherveou Nov 28, 2023
887b70f
Fix format - skip on macos CI
pgherveou Nov 28, 2023
f5a5427
nit
pgherveou Nov 28, 2023
683e687
move cfg attribute to crate
pgherveou Nov 28, 2023
b978822
Update conditional compilation
pgherveou Nov 28, 2023
7fb1943
Update substrate/frame/contracts/fixtures/build.rs
pgherveou Nov 28, 2023
66c140d
Apply suggestions from code review
pgherveou Nov 28, 2023
6ef2866
fix tab / space mixed ups
pgherveou Nov 28, 2023
8922251
rm deps reserved for risc-v
pgherveou Nov 28, 2023
78f8ddf
rm leftover
pgherveou Nov 28, 2023
97f22a4
fix doc links
pgherveou Nov 28, 2023
39e423f
Add back scale to uapi
pgherveou Nov 29, 2023
b188eca
Merge branch 'master' into pg/contracts_rust_tests
pgherveou Nov 29, 2023
7c9322b
fix merge - rm call.wat
pgherveou Nov 29, 2023
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
Prev Previous commit
Next Next commit
Move types to uapi and add docs
pgherveou committed Nov 22, 2023
commit dad8fecd37e818eef9f93b2dfa0c22c186fa412e
1 change: 1 addition & 0 deletions substrate/frame/contracts/fixtures/build.rs
athei marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Compile contracts to wasm and RISC-V binaries.
use anyhow::Result;
use parity_wasm::elements::{deserialize_file, serialize_to_file, Internal};
use std::{
24 changes: 12 additions & 12 deletions substrate/frame/contracts/fixtures/contracts/call.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@

extern crate common;
extern crate uapi;
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
use uapi::{Api, CallFlags, ApiImpl as api};
use uapi::{Api, ApiImpl as api, CallFlags};

#[no_mangle]
pub fn deploy() {}
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
@@ -32,15 +32,15 @@ pub fn call() {
let mut out = [0u8; 0]; // No output data.

// Read the input data.
api::input(&mut &mut buffer[..]);

// xx Call the callee.
api::call(
CallFlags::empty(),
&buffer[4..36], // callee address.
0u64, // How much gas to devote for the execution. 0 = all.
&buffer[36..], // Pointer to value to transfer.
&buffer[0..4], // Pointer to input data buffer address.
Some(&mut out[..]), // Pointer to output data buffer address.
);
api::input(&mut &mut buffer[..]);

// Call the callee
api::call(
CallFlags::empty(),
&buffer[4..36], // callee address.
0u64, // How much gas to devote for the execution. 0 = all.
&buffer[36..], // Pointer to value to transfer.
&buffer[0..4], // Pointer to input data buffer address.
Some(&mut out[..]), // Pointer to output data buffer address.
);
}
4 changes: 2 additions & 2 deletions substrate/frame/contracts/proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -271,7 +271,7 @@ impl HostFn {
// process return type
let msg = r#"Should return one of the following:
- Result<(), TrapReason>,
- Result<ReturnCode, TrapReason>,
- Result<ReturnErrorCode, TrapReason>,
- Result<u64, TrapReason>,
- Result<u32, TrapReason>"#;
let ret_ty = match item.clone().sig.output {
@@ -336,7 +336,7 @@ impl HostFn {
"()" => Ok(HostFnReturn::Unit),
"u32" => Ok(HostFnReturn::U32),
"u64" => Ok(HostFnReturn::U64),
"ReturnCode" => Ok(HostFnReturn::ReturnCode),
"ReturnErrorCode" => Ok(HostFnReturn::ReturnCode),
_ => Err(err(arg1.span(), &msg)),
}?;

4 changes: 2 additions & 2 deletions substrate/frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
@@ -30,9 +30,10 @@ use crate::{
},
exec::{Frame, Key},
migration::codegen::LATEST_MIGRATION_VERSION,
primitives::CodeUploadReturnValue,
storage::DeletionQueueManager,
tests::test_utils::{get_contract, get_contract_checked},
wasm::{Determinism, ReturnCode as RuntimeReturnCode},
wasm::{Determinism, ReturnErrorCode as RuntimeReturnCode},
weights::WeightInfo,
BalanceOf, Code, CodeHash, CodeInfoOf, CollectEvents, Config, ContractInfo, ContractInfoOf,
DebugInfo, DefaultAddressGenerator, DeletionQueueCounter, Error, HoldReason,
@@ -54,7 +55,6 @@ use frame_support::{
};
use frame_system::{EventRecord, Phase};
use pallet_contracts_fixtures::compile_module;
use crate::primitives::CodeUploadReturnValue;
use pretty_assertions::{assert_eq, assert_ne};
use sp_core::ByteArray;
use sp_io::hashing::blake2_256;
22 changes: 11 additions & 11 deletions substrate/frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
@@ -24,13 +24,13 @@ mod runtime;
#[cfg(doc)]
pub use crate::wasm::runtime::api_doc;

#[cfg(test)]
pub use tests::MockExt;
pub use pallet_contracts_uapi::ReturnFlags;
pub use crate::wasm::runtime::{
AllowDeprecatedInterface, AllowUnstableInterface, 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,6 @@ mod tests {
assert_err, assert_ok, dispatch::DispatchResultWithPostInfo, weights::Weight,
};
use frame_system::pallet_prelude::BlockNumberFor;
use crate::primitives::ExecReturnValue;
use pallet_contracts_uapi::ReturnFlags;
use pretty_assertions::assert_eq;
use sp_core::H256;
@@ -2740,15 +2740,15 @@ 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
let input = (64, [1u8; 64]).encode();
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]);
@@ -2758,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]));
@@ -2921,15 +2921,15 @@ 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
let input = (64, [1u8; 64]).encode();
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]);
@@ -2939,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]);
Loading