Skip to content

chore: update examples dependencies #77

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

Open
wants to merge 4 commits into
base: main
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
6 changes: 3 additions & 3 deletions basic-contract-caller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "basic-contract-caller"
version = "5.1.0"
version = "6.0.0"
authors = ["Use Ink <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
ink = { version = "5.1.0", default-features = false }
ink = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false, features = ["unstable-hostfn"] }

# Note: We **need** to specify the `ink-as-dependency` feature.
#
# If we don't we will end up with linking errors!
other-contract = { path = "other-contract", default-features = false, features = ["ink-as-dependency"] }

[dev-dependencies]
ink_e2e = { version = "5.1.0" }
ink_e2e = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false }

[lib]
path = "lib.rs"
Expand Down
7 changes: 4 additions & 3 deletions basic-contract-caller/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod basic_contract_caller {
/// Note that the other contract must have re-exported it (`pub use
/// OtherContractRef`) for us to have access to it.
use other_contract::OtherContractRef;
use ink::{H256, U256};

#[ink(storage)]
pub struct BasicContractCaller {
Expand All @@ -19,11 +20,11 @@ mod basic_contract_caller {
///
/// To do this we will use the uploaded `code_hash` of `OtherContract`.
#[ink(constructor)]
pub fn new(other_contract_code_hash: Hash) -> Self {
pub fn new(other_contract_code_hash: H256) -> Self {
let other_contract = OtherContractRef::new(true)
.code_hash(other_contract_code_hash)
.endowment(0)
.salt_bytes([0xDE, 0xAD, 0xBE, 0xEF])
.endowment(U256::from(0))
.salt_bytes(Some([1;32]))
.instantiate();

Self { other_contract }
Expand Down
6 changes: 3 additions & 3 deletions basic-contract-caller/other-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "other-contract"
version = "5.1.0"
version = "6.0.0"
authors = ["Use Ink <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
ink = { version = "5.1.0", default-features = false }
ink = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false, features = ["unstable-hostfn"] }

[dev-dependencies]
ink_e2e = { version = "5.1.0" }
ink_e2e = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false }

[lib]
path = "lib.rs"
Expand Down
17 changes: 9 additions & 8 deletions call-runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[package]
name = "call-runtime"
version = "5.1.0"
version = "6.0.0-alpha"
authors = ["Use Ink <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
ink = { version = "5.1.0", default-features = false }
ink = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false, features = ["unstable-hostfn"] }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", rev = "f8c90b2a01ec77579bccd21ae17bd6ff2eeffd6a", default-features = false }

# Substrate
#
# We need to explicitly turn off some of the `sp-io` features, to avoid conflicts
# (especially for global allocator).
#
# See also: https://substrate.stackexchange.com/questions/4733/error-when-compiling-a-contract-using-the-xcm-chain-extension.
sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] }
sp-runtime = { version = "24.0.0", default-features = false }
#
# For `sp-runtime-interface` we need to turn off static asserts.
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", rev = "f8c90b2a01ec77579bccd21ae17bd6ff2eeffd6a", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] }
sp-runtime-interface = { git = "https://github.com/paritytech/polkadot-sdk", rev = "f8c90b2a01ec77579bccd21ae17bd6ff2eeffd6a", default-features = false, features = ["disable_target_static_assertions"] }

[dev-dependencies]
ink_e2e = { version = "5.1.0" }
ink_e2e = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false }

[lib]
path = "lib.rs"
Expand All @@ -28,6 +28,7 @@ default = ["std"]
std = [
"ink/std",
"sp-runtime/std",
"sp-runtime-interface/std",
"sp-io/std",
]
ink-as-dependency = []
Expand Down
6 changes: 3 additions & 3 deletions call-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ It demonstrates how to call a runtime dispatchable from an ink! contract.
To integrate this example into Substrate you need to adjust pallet contracts configuration in your runtime:
```rust
// In your node's runtime configuration file (runtime.rs)
impl pallet_contracts::Config for Runtime {
impl pallet_revive::Config for Runtime {
// `Everything` or anything that will allow for the `Balances::transfer` extrinsic.
type CallFilter = frame_support::traits::Everything;
type CallFilter = frame_support::traits::Everything;
type UnsafeUnstableInterface = ConstBool<true>;
}
Expand All @@ -21,7 +21,7 @@ To integrate this example into Substrate you need to adjust pallet contracts con
## Comparison to `ChainExtension`

Just as a chain extension, `call_runtime` API allows contracts for direct calling to the runtime.
You can trigger any extrinsic that is not forbidden by `pallet_contracts::Config::CallFilter`.
You can trigger any extrinsic that is not forbidden by `pallet_revive::Config::CallFilter`.
Consider writing a chain extension if you need to perform one of the following tasks:
- Return data.
- Provide functionality **exclusively** to contracts.
Expand Down
36 changes: 24 additions & 12 deletions call-runtime/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod runtime_call {
EnvError::ReturnError(ReturnErrorCode::CallRuntimeFailed) => {
RuntimeError::CallRuntimeFailed
}
_ => panic!("Unexpected error from `pallet-contracts`."),
_ => panic!("Unexpected error from `pallet-revive`."),
}
}
}
Expand Down Expand Up @@ -112,6 +112,13 @@ mod runtime_call {
pub fn call_nonexistent_extrinsic(&mut self) -> Result<(), RuntimeError> {
self.env().call_runtime(&()).map_err(Into::into)
}

/// todo
/// Returns the `AccountId` of this contract.
#[ink(message)]
pub fn account_id(&mut self) -> AccountId {
self.env().account_id()
}
}

#[cfg(all(test, feature = "e2e-tests"))]
Expand All @@ -122,13 +129,7 @@ mod runtime_call {
ContractsBackend,
};

use ink::{
env::{
test::default_accounts,
DefaultEnvironment,
},
primitives::AccountId,
};
use ink::primitives::AccountId;

type E2EResult<T> = Result<T, Box<dyn std::error::Error>>;

Expand Down Expand Up @@ -167,10 +168,20 @@ mod runtime_call {
.expect("instantiate failed");
let mut call_builder = contract.call_builder::<RuntimeCaller>();

let receiver: AccountId = default_accounts::<DefaultEnvironment>().bob;
// todo
let acc = call_builder.account_id();
let call_res = client
.call(&ink_e2e::alice(), &acc)
.submit()
.await
.expect("call failed");
let account_id: AccountId = call_res.return_value();

//let receiver: AccountId = default_accounts().bob;
let receiver = AccountId::from([0x02; 32]);

let contract_balance_before = client
.free_balance(contract.account_id)
.free_balance(account_id)
.await
.expect("Failed to get account balance");
let receiver_balance_before = client
Expand All @@ -192,7 +203,7 @@ mod runtime_call {

// then
let contract_balance_after = client
.free_balance(contract.account_id)
.free_balance(account_id)
.await
.expect("Failed to get account balance");
let receiver_balance_after = client
Expand Down Expand Up @@ -231,7 +242,8 @@ mod runtime_call {
.expect("instantiate failed");
let mut call_builder = contract.call_builder::<RuntimeCaller>();

let receiver: AccountId = default_accounts::<DefaultEnvironment>().bob;
//let receiver: ink::H160 = default_accounts().bob;
let receiver = AccountId::from([0x02; 32]);

// when
let transfer_message = call_builder
Expand Down
4 changes: 2 additions & 2 deletions combined-extension/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "combined_extension"
version = "5.1.0"
version = "6.0.0-alpha"
authors = ["Use Ink <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
ink = { version = "5.1.0", default-features = false }
ink = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false, features = ["unstable-hostfn"] }
psp22_extension = { path = "../psp22-extension", default-features = false, features = ["ink-as-dependency"] }
rand_extension = { path = "../rand-extension", default-features = false, features = ["ink-as-dependency"] }

Expand Down
22 changes: 14 additions & 8 deletions combined-extension/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

use ink::env::{
DefaultEnvironment,
Environment,
use ink::{
env::{
DefaultEnvironment,
Environment,
},
U256,
};
use psp22_extension::Psp22Extension;
use rand_extension::{
Expand Down Expand Up @@ -42,6 +45,7 @@ impl Environment for CustomEnvironment {
type Hash = <DefaultEnvironment as Environment>::Hash;
type Timestamp = <DefaultEnvironment as Environment>::Timestamp;
type BlockNumber = <DefaultEnvironment as Environment>::BlockNumber;
type EventRecord = <DefaultEnvironment as Environment>::EventRecord;

/// Setting up the combined chain extension as a primary extension.
///
Expand Down Expand Up @@ -78,7 +82,7 @@ mod combined_extension {

/// Returns the total supply from PSP22 extension.
#[ink(message)]
pub fn get_total_supply(&self) -> Result<Balance, Psp22Error> {
pub fn get_total_supply(&self) -> Result<U256, Psp22Error> {
self.env().extension().psp22.total_supply(0)
}
}
Expand Down Expand Up @@ -126,7 +130,9 @@ mod combined_extension {
assert_eq!(contract.get_rand(), Ok(RANDOM_VALUE));
}

const TOTAL_SUPPLY: u128 = 1377;
fn total_supply() -> U256 {
U256::from(1337)
}

/// Mocking the PSP22 extension to return results that we want in the tests.
///
Expand All @@ -143,7 +149,7 @@ mod combined_extension {
fn call(&mut self, func_id: u16, _input: &[u8], output: &mut Vec<u8>) -> u32 {
match func_id {
0x162d /* `func_id` of the `total_supply` function */ => {
ink::scale::Encode::encode_to(&TOTAL_SUPPLY, output);
ink::scale::Encode::encode_to(&total_supply(), output);
0
}
_ => {
Expand All @@ -166,7 +172,7 @@ mod combined_extension {
ink::env::test::register_chain_extension(MockedPSP22Extension);

// then
assert_eq!(contract.get_total_supply(), Ok(TOTAL_SUPPLY));
assert_eq!(contract.get_total_supply(), Ok(total_supply()));
}

#[ink::test]
Expand All @@ -183,7 +189,7 @@ mod combined_extension {

// then
assert_eq!(contract.get_rand(), Ok(RANDOM_VALUE));
assert_eq!(contract.get_total_supply(), Ok(TOTAL_SUPPLY));
assert_eq!(contract.get_total_supply(), Ok(total_supply()));
}
}
}
6 changes: 3 additions & 3 deletions conditional-compilation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "conditional-compilation"
version = "5.1.0"
version = "6.0.0-alpha"
authors = ["Use Ink <[email protected]>"]
edition = "2021"

[dependencies]
ink = { version = "5.1.0", default-features = false }
ink = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false, features = ["unstable-hostfn"] }

[dev-dependencies]
ink_e2e = { version = "5.1.0" }
ink_e2e = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false }

[lib]
path = "lib.rs"
Expand Down
4 changes: 2 additions & 2 deletions conditional-compilation/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod conditional_compilation {
// attributing event field with `cfg` is not allowed
new_value: bool,
#[ink(topic)]
by: AccountId,
by: ink::H160,
}

/// Feature gated event
Expand All @@ -37,7 +37,7 @@ pub mod conditional_compilation {
// attributing event field with `cfg` is not allowed
new_value: bool,
#[ink(topic)]
by: AccountId,
by: ink::H160,
when: BlockNumber,
}

Expand Down
6 changes: 3 additions & 3 deletions contract-storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "contract-storage"
version = "5.1.0"
version = "6.0.0-alpha"
authors = ["Use Ink <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
ink = { version = "5.1.0", default-features = false }
ink = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false, features = ["unstable-hostfn"] }

[dev-dependencies]
ink_e2e = { version = "5.1.0" }
ink_e2e = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false }

[lib]
path = "lib.rs"
Expand Down
7 changes: 4 additions & 3 deletions contract-terminate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "contract_terminate"
version = "5.1.0"
version = "6.0.0-alpha"
authors = ["Use Ink <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
ink = { version = "5.1.0", default-features = false }
ink = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false, features = ["unstable-hostfn"] }

[dev-dependencies]
ink_e2e = { version = "5.1.0" }
ink_e2e = { git = "https://github.com/use-ink/ink", branch = "master", default-features = false }

[lib]
path = "lib.rs"
Expand All @@ -19,5 +19,6 @@ default = ["std"]
std = [
"ink/std",
]

ink-as-dependency = []
e2e-tests = []
Loading