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

Support caller_is_root #2310

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ See [the compatibility section](https://use.ink/faq/migrating-from-ink-4-to-5/#c
- [Drink backend] Backend choice ‒ [#1864](https://github.com/use-ink/ink/pull/1864)
- [Drink backend] Backend traits - [#1857](https://github.com/use-ink/ink/pull/1857)
- [Drink backend] Abstract error and result structs - [#1844](https://github.com/use-ink/ink/pull/1844)
- Added support for caller_is_root - [#2310] (https://github.com/use-ink/ink/pull/2310)

#### Changed
- Use name-only syntax for `anonymous` ink! event item configuration argument - [#2140](https://github.com/use-ink/ink/pull/2140)
Expand Down
22 changes: 8 additions & 14 deletions crates/allocator/src/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
//! is `64KiB`). We will request new pages of memory as needed until we run out of memory,
//! at which point we will crash with an `OOM` error instead of freeing any memory.

use core::alloc::{
GlobalAlloc,
Layout,
};
use core::alloc::{GlobalAlloc, Layout};

/// A page in Wasm is `64KiB`
const PAGE_SIZE: usize = 64 * 1024;
Expand Down Expand Up @@ -357,10 +354,7 @@ mod tests {
#[cfg(all(test, feature = "ink-fuzz-tests"))]
mod fuzz_tests {
use super::*;
use quickcheck::{
quickcheck,
TestResult,
};
use quickcheck::{quickcheck, TestResult};
use std::mem::size_of;

#[quickcheck]
Expand Down Expand Up @@ -449,13 +443,13 @@ mod fuzz_tests {
let mut inner = InnerAlloc::new();

if sequence.is_empty() {
return TestResult::discard()
return TestResult::discard();
}

// We don't want any negative numbers so we can be sure our conversions to `usize`
// later are valid
if !sequence.iter().all(|n| n.is_positive()) {
return TestResult::discard()
return TestResult::discard();
}

// We can't just use `required_pages(Iterator::sum())` here because it ends up
Expand All @@ -468,7 +462,7 @@ mod fuzz_tests {
// We know this is going to end up overflowing, we'll check this case in a
// different test
if pages_required > max_pages {
return TestResult::discard()
return TestResult::discard();
}

let mut expected_alloc_start = 0;
Expand Down Expand Up @@ -532,13 +526,13 @@ mod fuzz_tests {
let mut inner = InnerAlloc::new();

if sequence.is_empty() {
return TestResult::discard()
return TestResult::discard();
}

// We don't want any negative numbers so we can be sure our conversions to `usize`
// later are valid
if !sequence.iter().all(|n| n.is_positive()) {
return TestResult::discard()
return TestResult::discard();
}

// We can't just use `required_pages(Iterator::sum())` here because it ends up
Expand All @@ -551,7 +545,7 @@ mod fuzz_tests {
// We want to explicitly test for the case where a series of allocations
// eventually runs out of pages of memory
if pages_required <= max_pages {
return TestResult::discard()
return TestResult::discard();
}

let mut results = vec![];
Expand Down
5 changes: 1 addition & 4 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
// limitations under the License.

use crate::{
config::{
Backend,
Node,
},
config::{Backend, Node},
ir,
};
use derive_more::From;
Expand Down
13 changes: 5 additions & 8 deletions crates/e2e/macro/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ impl Node {
///
/// Returns `None` if [`Self::Auto`] and `CONTRACTS_NODE_URL` not specified.
pub fn url(&self) -> Option<String> {
std::env::var("CONTRACTS_NODE_URL").ok().or_else(|| {
match self {
std::env::var("CONTRACTS_NODE_URL")
.ok()
.or_else(|| match self {
Node::Auto => None,
Node::Url(url) => Some(url.clone()),
}
})
})
}
}

Expand Down Expand Up @@ -112,10 +112,7 @@ impl E2EConfig {
#[cfg(test)]
mod tests {
use super::*;
use darling::{
ast::NestedMeta,
FromMeta,
};
use darling::{ast::NestedMeta, FromMeta};
use quote::quote;

#[test]
Expand Down
5 changes: 1 addition & 4 deletions crates/e2e/macro/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
// limitations under the License.

use crate::config::E2EConfig;
use darling::{
ast::NestedMeta,
FromMeta,
};
use darling::{ast::NestedMeta, FromMeta};
use proc_macro2::TokenStream as TokenStream2;

/// The End-to-End test with all required information.
Expand Down
4 changes: 1 addition & 3 deletions crates/e2e/sandbox/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ pub mod timestamp_api;

pub mod prelude {
pub use super::{
balance_api::BalanceAPI,
contracts_api::ContractAPI,
system_api::SystemAPI,
balance_api::BalanceAPI, contracts_api::ContractAPI, system_api::SystemAPI,
timestamp_api::TimestampAPI,
};
}
10 changes: 2 additions & 8 deletions crates/e2e/sandbox/src/api/balance_api.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use crate::{
AccountIdFor,
Sandbox,
};
use frame_support::{
sp_runtime::DispatchError,
traits::fungible::Mutate,
};
use crate::{AccountIdFor, Sandbox};
use frame_support::{sp_runtime::DispatchError, traits::fungible::Mutate};

type BalanceOf<R> = <R as pallet_balances::Config>::Balance;

Expand Down
23 changes: 4 additions & 19 deletions crates/e2e/sandbox/src/api/contracts_api.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
use crate::{
AccountIdFor,
ContractExecResultFor,
ContractInstantiateResultFor,
EventRecordOf,
AccountIdFor, ContractExecResultFor, ContractInstantiateResultFor, EventRecordOf,
Sandbox,
};
use frame_support::{
traits::fungible::Inspect,
weights::Weight,
};
use frame_support::{traits::fungible::Inspect, weights::Weight};
use frame_system::Config as SysConfig;
use pallet_contracts::{
Code,
CodeUploadResult,
CollectEvents,
ContractInstantiateResult,
DebugInfo,
Code, CodeUploadResult, CollectEvents, ContractInstantiateResult, DebugInfo,
Determinism,
};
use scale::Decode as _;
Expand Down Expand Up @@ -244,12 +234,7 @@ pub fn decode_debug_buffer(buffer: &[u8]) -> Vec<String> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
api::prelude::*,
DefaultSandbox,
RuntimeEventOf,
RuntimeOf,
};
use crate::{api::prelude::*, DefaultSandbox, RuntimeEventOf, RuntimeOf};
use frame_support::sp_runtime::traits::Hash;
use pallet_contracts::Origin;

Expand Down
22 changes: 4 additions & 18 deletions crates/e2e/sandbox/src/api/system_api.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
use crate::{
EventRecordOf,
RuntimeCall,
Sandbox,
};
use crate::{EventRecordOf, RuntimeCall, Sandbox};
use frame_support::sp_runtime::{
traits::{
Dispatchable,
Saturating,
},
traits::{Dispatchable, Saturating},
DispatchResultWithInfo,
};
use frame_system::pallet_prelude::BlockNumberFor;
Expand Down Expand Up @@ -100,17 +93,10 @@ where
#[cfg(test)]
mod tests {
use crate::{
api::prelude::*,
DefaultSandbox,
RuntimeCall,
RuntimeEventOf,
RuntimeOf,
Sandbox,
api::prelude::*, DefaultSandbox, RuntimeCall, RuntimeEventOf, RuntimeOf, Sandbox,
};
use frame_support::sp_runtime::{
traits::Dispatchable,
AccountId32,
DispatchResultWithInfo,
traits::Dispatchable, AccountId32, DispatchResultWithInfo,
};

fn make_transfer(
Expand Down
5 changes: 1 addition & 4 deletions crates/e2e/sandbox/src/api/timestamp_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ where

#[cfg(test)]
mod tests {
use crate::{
api::prelude::*,
DefaultSandbox,
};
use crate::{api::prelude::*, DefaultSandbox};

#[test]
fn getting_and_setting_timestamp_works() {
Expand Down
36 changes: 7 additions & 29 deletions crates/e2e/sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,20 @@ pub mod macros;

pub use frame_metadata::RuntimeMetadataPrefixed;
pub use frame_support::weights::Weight;
use frame_support::{
sp_runtime::traits::Dispatchable,
traits::fungible::Inspect,
};
use frame_system::{
pallet_prelude::BlockNumberFor,
EventRecord,
};
pub use macros::{
BlockBuilder,
DefaultSandbox,
};
use pallet_contracts::{
ContractExecResult,
ContractInstantiateResult,
};
use frame_support::{sp_runtime::traits::Dispatchable, traits::fungible::Inspect};
use frame_system::{pallet_prelude::BlockNumberFor, EventRecord};
pub use macros::{BlockBuilder, DefaultSandbox};
use pallet_contracts::{ContractExecResult, ContractInstantiateResult};
/// Export pallets that are used in [`crate::create_sandbox`]
pub use {
frame_support::sp_runtime::testing::H256,
frame_support::{
self,
sp_runtime::{
AccountId32,
DispatchError,
},
sp_runtime::{AccountId32, DispatchError},
},
frame_system,
pallet_balances,
pallet_contracts,
pallet_timestamp,
paste,
frame_system, pallet_balances, pallet_contracts, pallet_timestamp, paste,
sp_core::crypto::Ss58Codec,
sp_externalities::{
self,
Extension,
},
sp_externalities::{self, Extension},
sp_io::TestExternalities,
};

Expand Down
5 changes: 1 addition & 4 deletions crates/e2e/sandbox/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use std::time::SystemTime;

use frame_support::{
sp_runtime::{
traits::{
Header,
One,
},
traits::{Header, One},
BuildStorage,
},
traits::Hooks,
Expand Down
26 changes: 5 additions & 21 deletions crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,14 @@

use super::Keypair;
use crate::{
backend_calls::{
InstantiateBuilder,
RemoveCodeBuilder,
UploadBuilder,
},
backend_calls::{InstantiateBuilder, RemoveCodeBuilder, UploadBuilder},
builders::CreateBuilderPartial,
contract_results::{
BareInstantiationResult,
InstantiateDryRunResult,
},
CallBuilder,
CallBuilderFinal,
CallDryRunResult,
UploadResult,
};
use ink_env::{
DefaultEnvironment,
Environment,
contract_results::{BareInstantiationResult, InstantiateDryRunResult},
CallBuilder, CallBuilderFinal, CallDryRunResult, UploadResult,
};
use ink_env::{DefaultEnvironment, Environment};
use jsonrpsee::core::async_trait;
use scale::{
Decode,
Encode,
};
use scale::{Decode, Encode};
use sp_weights::Weight;
use subxt::dynamic::Value;

Expand Down
17 changes: 4 additions & 13 deletions crates/e2e/src/backend_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,13 @@
// limitations under the License.

use ink_env::Environment;
use scale::{
Decode,
Encode,
};
use scale::{Decode, Encode};
use sp_weights::Weight;

use crate::{
backend::BuilderClient,
builders::CreateBuilderPartial,
CallBuilderFinal,
CallDryRunResult,
CallResult,
ContractsBackend,
InstantiateDryRunResult,
InstantiationResult,
UploadResult,
backend::BuilderClient, builders::CreateBuilderPartial, CallBuilderFinal,
CallDryRunResult, CallResult, ContractsBackend, InstantiateDryRunResult,
InstantiationResult, UploadResult,
};

use super::Keypair;
Expand Down
10 changes: 2 additions & 8 deletions crates/e2e/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@

use ink_env::{
call::{
utils::{
ReturnType,
Set,
Unset,
},
CreateBuilder,
ExecutionInput,
LimitParamsV2,
utils::{ReturnType, Set, Unset},
CreateBuilder, ExecutionInput, LimitParamsV2,
},
Environment,
};
Expand Down
Loading