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

Default accounts in integration test implementation #1955

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
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 @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Fail when decoding from storage and not all bytes consumed - [#1897](https://github.com/paritytech/ink/pull/1897)
- Make the `default_accounts` in integration test and e2e the same addresses. - [#1955](https://github.com/paritytech/ink/pull/1955)

### Added
- Linter: `storage_never_freed` lint - [#1932](https://github.com/paritytech/ink/pull/1932)
Expand Down
1 change: 1 addition & 0 deletions crates/env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ schnorrkel = { version = "0.11.2", optional = true }
scale-decode = { workspace = true, optional = true }
scale-encode = { workspace = true, optional = true }
scale-info = { workspace = true, features = ["derive"], optional = true }
sp-keyring = { workspace = true }

[dev-dependencies]
ink = { path = "../ink" }
Expand Down
50 changes: 32 additions & 18 deletions crates/env/src/engine/off_chain/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,42 +306,52 @@ where
instance.engine.set_callee(encoded_alice.clone());

// set up the funds for the default accounts
let substantial = 1_000_000;
let some = 1_000;
let substantial = 1_u128 << 60;
instance.engine.set_balance(encoded_alice, substantial);
instance
.engine
.set_balance(scale::Encode::encode(&default_accounts.bob), some);
.set_balance(scale::Encode::encode(&default_accounts.bob), substantial);
instance.engine.set_balance(
scale::Encode::encode(&default_accounts.charlie),
substantial,
);
instance
.engine
.set_balance(scale::Encode::encode(&default_accounts.charlie), some);
.set_balance(scale::Encode::encode(&default_accounts.dave), substantial);
instance
.engine
.set_balance(scale::Encode::encode(&default_accounts.django), 0);
.set_balance(scale::Encode::encode(&default_accounts.eve), substantial);
instance
.engine
.set_balance(scale::Encode::encode(&default_accounts.eve), 0);
.set_balance(scale::Encode::encode(&default_accounts.ferdie), substantial);
instance
.engine
.set_balance(scale::Encode::encode(&default_accounts.frank), 0);
.set_balance(scale::Encode::encode(&default_accounts.one), substantial);
instance
.engine
.set_balance(scale::Encode::encode(&default_accounts.two), substantial);
});
f(default_accounts)
}

/// Returns the default accounts for testing purposes:
/// Alice, Bob, Charlie, Django, Eve and Frank.
/// Alice, Bob, Charlie, Dave, Eve, Ferdie, One and Two.
pub fn default_accounts<T>() -> DefaultAccounts<T>
where
T: Environment,
<T as Environment>::AccountId: From<[u8; 32]>,
{
DefaultAccounts {
alice: T::AccountId::from([0x01; 32]),
bob: T::AccountId::from([0x02; 32]),
charlie: T::AccountId::from([0x03; 32]),
django: T::AccountId::from([0x04; 32]),
eve: T::AccountId::from([0x05; 32]),
frank: T::AccountId::from([0x06; 32]),
alice: T::AccountId::from(sp_keyring::sr25519::Keyring::Alice.to_raw_public()),
bob: T::AccountId::from(sp_keyring::sr25519::Keyring::Bob.to_raw_public()),
charlie: T::AccountId::from(
sp_keyring::sr25519::Keyring::Charlie.to_raw_public(),
),
dave: T::AccountId::from(sp_keyring::sr25519::Keyring::Dave.to_raw_public()),
eve: T::AccountId::from(sp_keyring::sr25519::Keyring::Eve.to_raw_public()),
ferdie: T::AccountId::from(sp_keyring::sr25519::Keyring::Ferdie.to_raw_public()),
one: T::AccountId::from(sp_keyring::sr25519::Keyring::One.to_raw_public()),
two: T::AccountId::from(sp_keyring::sr25519::Keyring::Two.to_raw_public()),
}
}

Expand All @@ -356,12 +366,16 @@ where
pub bob: T::AccountId,
/// The predefined `CHARLIE` account holding some amounts of value.
pub charlie: T::AccountId,
/// The predefined `DJANGO` account holding no value.
pub django: T::AccountId,
/// The predefined `DAVE` account holding no value.
pub dave: T::AccountId,
/// The predefined `EVE` account holding no value.
pub eve: T::AccountId,
/// The predefined `FRANK` account holding no value.
pub frank: T::AccountId,
/// The predefined `FERDIE` account holding no value.
pub ferdie: T::AccountId,
/// The predefined `ONE` account holding no value.
pub one: T::AccountId,
/// The predefined `TWO` account holding no value.
pub two: T::AccountId,
}

/// Returns the recorded emitted events in order.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

use super::TraitDefinition;
use crate::{
generator::{self,},
generator::{
self,
},
traits::GenerateCode,
EnforcedErrors,
};
Expand Down
4 changes: 3 additions & 1 deletion crates/ink/ir/src/ir/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ use syn::{
};

use crate::{
ast::{self,},
ast::{
self,
},
error::ExtError as _,
ir,
ir::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ error[E0277]: the trait bound `NonCodecType: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
sp_core::Bytes
Rc<T>
Arc<T>
= note: required for `NonCodecType` to implement `ink::parity_scale_codec::Decode`
Expand All @@ -26,6 +27,7 @@ error[E0277]: the trait bound `NonCodecType: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
sp_core::Bytes
Rc<T>
Arc<T>
= note: required for `NonCodecType` to implement `ink::parity_scale_codec::Decode`
Expand All @@ -41,14 +43,14 @@ error[E0277]: the trait bound `NonCodecType: WrapperTypeEncode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeEncode`:
Box<T>
bytes::bytes::Bytes
Cow<'a, T>
ink::parity_scale_codec::Ref<'a, T, U>
sp_core::Bytes
Rc<T>
Arc<T>
Vec<T>
String
&T
&mut T
and $N others
= note: required for `NonCodecType` to implement `Encode`
note: required by a bound in `ExecutionInput::<ArgumentList<ArgumentListEnd, ArgumentListEnd>>::push_arg`
--> $WORKSPACE/crates/env/src/call/execution_input.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ error[E0277]: the trait bound `contract::Error: WrapperTypeDecode` is not satisf
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
sp_core::Bytes
Rc<T>
Arc<T>
= note: required for `contract::Error` to implement `ink::parity_scale_codec::Decode`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ error[E0277]: the trait bound `&Contract: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
sp_core::Bytes
Rc<T>
Arc<T>
= note: required for `&Contract` to implement `ink::parity_scale_codec::Decode`
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ error[E0277]: the trait bound `NonCodecType: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
sp_core::Bytes
Rc<T>
Arc<T>
= note: required for `NonCodecType` to implement `ink::parity_scale_codec::Decode`
Expand All @@ -26,6 +27,7 @@ error[E0277]: the trait bound `NonCodecType: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
sp_core::Bytes
Rc<T>
Arc<T>
= note: required for `NonCodecType` to implement `ink::parity_scale_codec::Decode`
Expand All @@ -41,14 +43,14 @@ error[E0277]: the trait bound `NonCodecType: WrapperTypeEncode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeEncode`:
Box<T>
bytes::bytes::Bytes
Cow<'a, T>
ink::parity_scale_codec::Ref<'a, T, U>
sp_core::Bytes
Rc<T>
Arc<T>
Vec<T>
String
&T
&mut T
and $N others
= note: required for `NonCodecType` to implement `Encode`
note: required by a bound in `ExecutionInput::<ArgumentList<ArgumentListEnd, ArgumentListEnd>>::push_arg`
--> $WORKSPACE/crates/env/src/call/execution_input.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ error[E0277]: the trait bound `NonCodecType: WrapperTypeEncode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeEncode`:
Box<T>
bytes::bytes::Bytes
Cow<'a, T>
ink::parity_scale_codec::Ref<'a, T, U>
sp_core::Bytes
Rc<T>
Arc<T>
Vec<T>
String
&T
&mut T
and $N others
= note: required for `NonCodecType` to implement `Encode`
note: required by a bound in `DispatchOutput`
--> src/codegen/dispatch/type_check.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ error[E0277]: the trait bound `NonPacked: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
sp_core::Bytes
Rc<T>
Arc<T>
= note: required for `NonPacked` to implement `ink::parity_scale_codec::Decode`
Expand All @@ -24,14 +25,14 @@ error[E0277]: the trait bound `NonPacked: WrapperTypeEncode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeEncode`:
Box<T>
bytes::bytes::Bytes
Cow<'a, T>
ink::parity_scale_codec::Ref<'a, T, U>
sp_core::Bytes
Rc<T>
Arc<T>
Vec<T>
String
&T
&mut T
and $N others
= note: required for `NonPacked` to implement `Encode`
= note: required for `NonPacked` to implement `Packed`
note: required by a bound in `consume_packed`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ error[E0277]: the trait bound `NonCodec: WrapperTypeDecode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeDecode`:
Box<T>
sp_core::Bytes
Rc<T>
Arc<T>
= note: required for `NonCodec` to implement `ink::parity_scale_codec::Decode`
Expand All @@ -29,14 +30,14 @@ error[E0277]: the trait bound `NonCodec: WrapperTypeEncode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeEncode`:
Box<T>
bytes::bytes::Bytes
Cow<'a, T>
ink::parity_scale_codec::Ref<'a, T, U>
sp_core::Bytes
Rc<T>
Arc<T>
Vec<T>
String
&T
&mut T
and $N others
= note: required for `NonCodec` to implement `Encode`
note: required by a bound in `ExecutionInput::<ArgumentList<ArgumentListEnd, ArgumentListEnd>>::push_arg`
--> $WORKSPACE/crates/env/src/call/execution_input.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ error[E0277]: the trait bound `NonCodec: WrapperTypeEncode` is not satisfied
|
= help: the following other types implement trait `WrapperTypeEncode`:
Box<T>
bytes::bytes::Bytes
Cow<'a, T>
ink::parity_scale_codec::Ref<'a, T, U>
sp_core::Bytes
Rc<T>
Arc<T>
Vec<T>
String
&T
&mut T
and $N others
= note: required for `NonCodec` to implement `Encode`
note: required by a bound in `DispatchOutput`
--> src/codegen/dispatch/type_check.rs
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/default-accounts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore build artifacts from the local tests sub-crate.
/target/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk

# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
26 changes: 26 additions & 0 deletions integration-tests/default-accounts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "default-accounts"
version = "4.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
publish = false

[dependencies]
ink = { path = "../../crates/ink", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.5", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
ink_e2e = { path = "../../crates/e2e" }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
]
ink-as-dependency = []
e2e-tests = []
Loading