-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put contract back at workspace root again
- Loading branch information
Showing
5 changed files
with
100 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[workspace] | ||
members = [ "flipper", "sandbox-runtime", "traits"] | ||
members = ["sandbox-runtime", "traits"] | ||
|
||
[workspace.package] | ||
authors = ["Parity Technologies <[email protected]>"] | ||
|
@@ -25,12 +25,15 @@ publish = false | |
|
||
[dependencies] | ||
ink = { path = "../../../crates/ink", default-features = false } | ||
ink_e2e = { path = "../../../crates/e2e", features = ["sandbox"] } | ||
flipper-traits = { path = "traits", default-features = false } | ||
flipper = { path = "flipper", default-features = false, features = ["ink-as-dependency"] } | ||
|
||
[dev-dependencies] | ||
ink_e2e = { path = "../../../crates/e2e", features = ["sandbox"] } | ||
sandbox-runtime = { path = "sandbox-runtime", default-features = false } | ||
scale-value = "0.14.1" | ||
frame-support = { workspace = true } | ||
# can't use workspace dependency because of `cargo-contract` build not | ||
# working with workspace dependencies | ||
frame-support = { version = "31.0.0", default-features = false } | ||
|
||
[lib] | ||
path = "lib.rs" | ||
|
@@ -40,6 +43,6 @@ default = ["std"] | |
std = [ | ||
"ink/std", | ||
"sandbox-runtime/std", | ||
"flipper/std", | ||
"flipper-traits/std", | ||
] | ||
ink-as-dependency = [] |
60 changes: 60 additions & 0 deletions
60
integration-tests/public/runtime-call-contract/e2e_tests.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use super::{ | ||
Flipper, | ||
FlipperRef, | ||
}; | ||
use ink_e2e::{ | ||
ChainBackend, | ||
ContractsBackend, | ||
}; | ||
|
||
type E2EResult<T> = Result<T, Box<dyn std::error::Error>>; | ||
|
||
/// Just instantiate a contract using non-default runtime. | ||
#[ink_e2e::test(backend(runtime_only(sandbox = sandbox_runtime::ContractCallerSandbox)))] | ||
async fn instantiate_and_get<Client: E2EBackend>(mut client: Client) -> E2EResult<()> { | ||
use flipper_traits::Flip; | ||
|
||
let initial_value = false; | ||
let mut constructor = FlipperRef::new(initial_value); | ||
|
||
let contract = client | ||
.instantiate("runtime-call-contract", &ink_e2e::alice(), &mut constructor) | ||
.submit() | ||
.await | ||
.expect("instantiate failed"); | ||
|
||
let mut call_builder = contract.call_builder::<Flipper>(); | ||
let flip_dry_run = client | ||
.call(&ink_e2e::bob(), &call_builder.flip()) | ||
.dry_run() | ||
.await?; | ||
let gas_required = flip_dry_run.exec_result.gas_required; | ||
|
||
// call pallet dispatchable | ||
client | ||
.runtime_call( | ||
&ink_e2e::alice(), | ||
"ContractCaller", | ||
"contract_call_flip", | ||
vec![ | ||
scale_value::Value::from_bytes(contract.account_id), | ||
scale_value::serde::to_value(frame_support::weights::Weight::from_parts( | ||
gas_required.ref_time(), | ||
gas_required.proof_size(), | ||
)) | ||
.unwrap(), | ||
], | ||
) | ||
.await | ||
.expect("runtime call failed"); | ||
|
||
// now check that the flip was executed via the pallet | ||
let get_result = client | ||
.call(&ink_e2e::alice(), &call_builder.get()) | ||
.dry_run() | ||
.await?; | ||
|
||
assert_eq!(get_result.return_value(), !initial_value); | ||
|
||
Ok(()) | ||
} |
20 changes: 0 additions & 20 deletions
20
integration-tests/public/runtime-call-contract/flipper/Cargo.toml
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
integration-tests/public/runtime-call-contract/flipper/lib.rs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,36 @@ | ||
#[cfg(test)] | ||
mod e2e_tests{ | ||
use flipper::{Flipper, FlipperRef}; | ||
use ink_e2e::{ | ||
ChainBackend, | ||
ContractsBackend, | ||
}; | ||
|
||
type E2EResult<T> = Result<T, Box<dyn std::error::Error>>; | ||
|
||
/// Just instantiate a contract using non-default runtime. | ||
#[ink_e2e::test(backend(runtime_only(sandbox = sandbox_runtime::ContractCallerSandbox)))] | ||
async fn instantiate_and_get<Client: E2EBackend>(mut client: Client) -> E2EResult<()> { | ||
use flipper_traits::Flip; | ||
|
||
let initial_value = false; | ||
let mut constructor = FlipperRef::new(initial_value); | ||
|
||
let contract = client | ||
.instantiate("flipper", &ink_e2e::alice(), &mut constructor) | ||
.submit() | ||
.await | ||
.expect("instantiate failed"); | ||
|
||
let mut call_builder = contract.call_builder::<Flipper>(); | ||
let flip_dry_run = client | ||
.call(&ink_e2e::bob(), &call_builder.flip()) | ||
.dry_run() | ||
.await?; | ||
let gas_required = flip_dry_run.exec_result.gas_required; | ||
|
||
// call pallet dispatchable | ||
client | ||
.runtime_call( | ||
&ink_e2e::alice(), | ||
"ContractCaller", | ||
"contract_call_flip", | ||
vec![ | ||
scale_value::Value::from_bytes(contract.account_id), | ||
scale_value::serde::to_value(frame_support::weights::Weight::from_parts( | ||
gas_required.ref_time(), | ||
gas_required.proof_size(), | ||
)) | ||
.unwrap(), | ||
], | ||
) | ||
.await | ||
.expect("runtime call failed"); | ||
#![cfg_attr(not(feature = "std"), no_std, no_main)] | ||
|
||
pub use flipper::{ | ||
Flipper, | ||
FlipperRef, | ||
}; | ||
|
||
#[ink::contract] | ||
mod flipper { | ||
#[ink(storage)] | ||
pub struct Flipper { | ||
value: bool, | ||
} | ||
|
||
// now check that the flip was executed via the pallet | ||
let get_result = client | ||
.call(&ink_e2e::alice(), &call_builder.get()) | ||
.dry_run() | ||
.await?; | ||
impl Flipper { | ||
#[ink(constructor)] | ||
pub fn new(init_value: bool) -> Self { | ||
Self { value: init_value } | ||
} | ||
} | ||
|
||
assert_eq!(get_result.return_value(), !initial_value); | ||
impl flipper_traits::Flip for Flipper { | ||
#[ink(message)] | ||
fn flip(&mut self) { | ||
self.value = !self.value; | ||
} | ||
|
||
Ok(()) | ||
#[ink(message)] | ||
fn get(&self) -> bool { | ||
self.value | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod e2e_tests; |