diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 400ac126..2e4a7918 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -188,16 +188,22 @@ jobs: - name: Download and run latest `substrate-contracts-node` binary if: runner.os == 'Linux' + env: + CONTRACTS_NODE_URL: https://github.com/paritytech/substrate-contracts-node/releases/latest/download/substrate-contracts-node- + CONTRACTS_NODE_OS: linux run: | - curl -L -o substrate-contracts-node.zip 'https://gitlab.parity.io/parity/mirrors/substrate-contracts-node/-/jobs/artifacts/main/download?job=build-linux' && \ + curl -L -o substrate-contracts-node.tar.gz "$CONTRACTS_NODE_URL$CONTRACTS_NODE_OS.tar.gz" unzip substrate-contracts-node.zip && \ chmod +x artifacts/substrate-contracts-node-linux/substrate-contracts-node && ./artifacts/substrate-contracts-node-linux/substrate-contracts-node -linfo,runtime::contracts=debug 2>&1 | tee /tmp/contracts-node.log & - name: Download and run latest `substrate-contracts-node` binary if: runner.os == 'macOS' + env: + CONTRACTS_NODE_URL: https://github.com/paritytech/substrate-contracts-node/releases/latest/download/substrate-contracts-node- + CONTRACTS_NODE_OS: mac-universal run: | - curl -L -o substrate-contracts-node.zip 'https://gitlab.parity.io/parity/mirrors/substrate-contracts-node/-/jobs/artifacts/main/download?job=build-mac' && \ + curl -L -o substrate-contracts-node.tar.gz "$CONTRACTS_NODE_URL$CONTRACTS_NODE_OS.tar.gz" unzip substrate-contracts-node.zip && \ chmod +x artifacts/substrate-contracts-node-mac/substrate-contracts-node && ./artifacts/substrate-contracts-node-mac/substrate-contracts-node -linfo,runtime::contracts=debug 2>&1 | tee /tmp/contracts-node.log & diff --git a/basic-contract-caller/Cargo.toml b/basic-contract-caller/Cargo.toml index 3b8fb17b..feb70f08 100755 --- a/basic-contract-caller/Cargo.toml +++ b/basic-contract-caller/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "basic-contract-caller" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } # Note: We **need** to specify the `ink-as-dependency` feature. # @@ -14,7 +14,7 @@ ink = { version = "5.0.0", default-features = false } other-contract = { path = "other-contract", default-features = false, features = ["ink-as-dependency"] } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/basic-contract-caller/other-contract/Cargo.toml b/basic-contract-caller/other-contract/Cargo.toml index b941a058..6eb419bd 100755 --- a/basic-contract-caller/other-contract/Cargo.toml +++ b/basic-contract-caller/other-contract/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "other-contract" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/call-runtime/Cargo.toml b/call-runtime/Cargo.toml index 8a65abac..bf6a8b09 100644 --- a/call-runtime/Cargo.toml +++ b/call-runtime/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "call-runtime" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } # Substrate # @@ -18,7 +18,7 @@ sp-io = { version = "23.0.0", default-features = false, features = ["disable_pan sp-runtime = { version = "24.0.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/combined-extension/Cargo.toml b/combined-extension/Cargo.toml index 90e9b781..1dcacfbe 100755 --- a/combined-extension/Cargo.toml +++ b/combined-extension/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "combined_extension" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } psp22_extension = { path = "../psp22-extension", default-features = false, features = ["ink-as-dependency"] } rand_extension = { path = "../rand-extension", default-features = false, features = ["ink-as-dependency"] } diff --git a/conditional-compilation/Cargo.toml b/conditional-compilation/Cargo.toml index f1b6241a..86afe242 100755 --- a/conditional-compilation/Cargo.toml +++ b/conditional-compilation/Cargo.toml @@ -1,14 +1,14 @@ [package] name = "conditional-compilation" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/contract-storage/Cargo.toml b/contract-storage/Cargo.toml index 6142bba7..13355ead 100755 --- a/contract-storage/Cargo.toml +++ b/contract-storage/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "contract-storage" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/contract-terminate/Cargo.toml b/contract-terminate/Cargo.toml index 06c001bb..3c96a74c 100644 --- a/contract-terminate/Cargo.toml +++ b/contract-terminate/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "contract_terminate" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/contract-transfer/Cargo.toml b/contract-transfer/Cargo.toml index 714dee5c..17154b49 100644 --- a/contract-transfer/Cargo.toml +++ b/contract-transfer/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "contract_transfer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/contract-xcm/Cargo.toml b/contract-xcm/Cargo.toml new file mode 100644 index 00000000..fcfb36bb --- /dev/null +++ b/contract-xcm/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "contract-xcm" +version = "5.1.0" +authors = ["Use Ink "] +edition = "2021" +publish = false + +[dependencies] +ink = { version = "5.1.0", default-features = false } +frame-support = { version = "32.0.0", default-features = false } +pallet-balances = { version = "33.0.0", default-features = false } + +[dev-dependencies] +ink_e2e = { version = "5.1.0", features = ["sandbox"] } + +[lib] +path = "lib.rs" + +[features] +default = ["std"] +std = [ + "ink/std", + "pallet-balances/std", + "frame-support/std", +] +ink-as-dependency = [] +e2e-tests = [] diff --git a/contract-xcm/lib.rs b/contract-xcm/lib.rs new file mode 100644 index 00000000..93cf0486 --- /dev/null +++ b/contract-xcm/lib.rs @@ -0,0 +1,272 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] + +#[ink::contract] +mod contract_xcm { + use ink::{ + env::Error as EnvError, + xcm::prelude::*, + }; + + /// A trivial contract used to exercise XCM API. + #[ink(storage)] + #[derive(Default)] + pub struct ContractXcm; + + #[derive(Debug, PartialEq, Eq)] + #[ink::scale_derive(Encode, Decode, TypeInfo)] + pub enum RuntimeError { + XcmExecuteFailed, + XcmSendFailed, + } + + impl From for RuntimeError { + fn from(e: EnvError) -> Self { + use ink::env::ReturnErrorCode; + match e { + EnvError::ReturnError(ReturnErrorCode::XcmExecutionFailed) => { + RuntimeError::XcmExecuteFailed + } + EnvError::ReturnError(ReturnErrorCode::XcmSendFailed) => { + RuntimeError::XcmSendFailed + } + _ => panic!("Unexpected error from `pallet-contracts`."), + } + } + } + + impl ContractXcm { + /// The constructor is `payable`, so that during instantiation it can be given + /// some tokens that will be further transferred when transferring funds through + /// XCM. + #[ink(constructor, payable)] + pub fn new() -> Self { + Default::default() + } + + /// Tries to transfer `value` from the contract's balance to `receiver`. + /// + /// Fails if: + /// - called in the off-chain environment + /// - the chain is not configured to support XCM + /// - the XCM program executed failed (e.g contract doesn't have enough balance) + #[ink(message)] + pub fn transfer_through_xcm( + &mut self, + receiver: AccountId, + value: Balance, + ) -> Result<(), RuntimeError> { + let asset: Asset = (Here, value).into(); + let beneficiary = AccountId32 { + network: None, + id: *receiver.as_ref(), + }; + + let message: Xcm<()> = Xcm::builder() + .withdraw_asset(asset.clone().into()) + .buy_execution(asset.clone(), Unlimited) + .deposit_asset(asset.into(), beneficiary.into()) + .build(); + + self.env() + .xcm_execute(&VersionedXcm::V4(message)) + .map_err(Into::into) + } + + /// Transfer some funds on the relay chain via XCM from the contract's derivative + /// account to the caller's account. + /// + /// Fails if: + /// - called in the off-chain environment + /// - the chain is not configured to support XCM + /// - the XCM program executed failed (e.g contract doesn't have enough balance) + #[ink(message)] + pub fn send_funds( + &mut self, + value: Balance, + fee: Balance, + ) -> Result { + let destination: Location = Parent.into(); + let asset: Asset = (Here, value).into(); + let beneficiary = AccountId32 { + network: None, + id: *self.env().caller().as_ref(), + }; + + let message: Xcm<()> = Xcm::builder() + .withdraw_asset(asset.clone().into()) + .buy_execution((Here, fee).into(), WeightLimit::Unlimited) + .deposit_asset(asset.into(), beneficiary.into()) + .build(); + + let hash = self.env().xcm_send( + &VersionedLocation::V4(destination), + &VersionedXcm::V4(message), + )?; + + Ok(hash) + } + } + + #[cfg(all(test, feature = "e2e-tests"))] + mod e2e_tests { + use frame_support::{ + sp_runtime::AccountId32, + traits::tokens::currency::Currency, + }; + use ink::{ + env::{ + test::default_accounts, + DefaultEnvironment, + }, + primitives::AccountId, + }; + use ink_e2e::{ + preset::mock_network::{ + self, + primitives::{ + CENTS, + UNITS, + }, + MockNetworkSandbox, + }, + ChainBackend, + ContractsBackend, + }; + use mock_network::{ + parachain::estimate_message_fee, + parachain_account_sovereign_account_id, + relay_chain, + Relay, + TestExt, + }; + + use super::*; + + /// The contract will be given 1000 tokens during instantiation. + pub const CONTRACT_BALANCE: u128 = 1_000 * UNITS; + + type E2EResult = Result>; + + #[ink_e2e::test(backend(runtime_only(sandbox = MockNetworkSandbox)))] + async fn xcm_execute_works( + mut client: Client, + ) -> E2EResult<()> { + // given + let mut constructor = ContractXcmRef::new(); + let contract = client + .instantiate("contract_xcm", &ink_e2e::alice(), &mut constructor) + .value(CONTRACT_BALANCE) + .submit() + .await + .expect("instantiate failed"); + let mut call_builder = contract.call_builder::(); + + let receiver: AccountId = default_accounts::().bob; + + let contract_balance_before = client + .free_balance(contract.account_id) + .await + .expect("Failed to get account balance"); + let receiver_balance_before = client + .free_balance(receiver) + .await + .expect("Failed to get account balance"); + + // when + let amount = 1000 * CENTS; + let transfer_message = call_builder.transfer_through_xcm(receiver, amount); + + let call_res = client + .call(&ink_e2e::alice(), &transfer_message) + .submit() + .await + .expect("call failed"); + + assert!(call_res.return_value().is_ok()); + + // then + let contract_balance_after = client + .free_balance(contract.account_id) + .await + .expect("Failed to get account balance"); + let receiver_balance_after = client + .free_balance(receiver) + .await + .expect("Failed to get account balance"); + + assert_eq!(contract_balance_before, contract_balance_after + amount); + assert_eq!(receiver_balance_before, receiver_balance_after - amount); + + Ok(()) + } + + #[ink_e2e::test(backend(runtime_only(sandbox = MockNetworkSandbox)))] + async fn incomplete_xcm_execute_works( + mut client: Client, + ) -> E2EResult<()> { + let mut constructor = ContractXcmRef::new(); + let contract = client + .instantiate("contract_xcm", &ink_e2e::alice(), &mut constructor) + .value(CONTRACT_BALANCE) + .submit() + .await + .expect("instantiate failed"); + let mut call_builder = contract.call_builder::(); + + // This will fail since we have insufficient balance + let transfer_message = call_builder.transfer_through_xcm( + default_accounts::().bob, + CONTRACT_BALANCE + 1, + ); + + let call_res = client + .call(&ink_e2e::alice(), &transfer_message) + .submit() + .await? + .return_value(); + + assert!(matches!(call_res, Err(RuntimeError::XcmExecuteFailed))); + Ok(()) + } + + #[ink_e2e::test(backend(runtime_only(sandbox = MockNetworkSandbox)))] + async fn xcm_send_works(mut client: Client) -> E2EResult<()> { + let mut constructor = ContractXcmRef::new(); + let contract = client + .instantiate("contract_xcm", &ink_e2e::alice(), &mut constructor) + .value(CONTRACT_BALANCE) + .submit() + .await + .expect("instantiate failed"); + + Relay::execute_with(|| { + let sovereign_account = parachain_account_sovereign_account_id( + 1u32, + AccountId32::from(contract.account_id.0), + ); + + // Fund the contract's derivative account, so we can use it as a sink, to + // transfer funds to the caller. + relay_chain::Balances::make_free_balance_be( + &sovereign_account, + CONTRACT_BALANCE, + ); + }); + + let amount = 1000 * CENTS; + let fee = estimate_message_fee(4); + + let mut call_builder = contract.call_builder::(); + let message = call_builder.send_funds(amount, fee); + let call_res = client.call(&ink_e2e::alice(), &message).submit().await?; + assert!(call_res.return_value().is_ok()); + + Relay::execute_with(|| { + let alice = AccountId32::from(ink_e2e::alice().public_key().0); + assert_eq!(relay_chain::Balances::free_balance(&alice), amount - fee); + }); + + Ok(()) + } + } +} diff --git a/cross-contract-calls/Cargo.toml b/cross-contract-calls/Cargo.toml index 984f7591..ef3c3d19 100755 --- a/cross-contract-calls/Cargo.toml +++ b/cross-contract-calls/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "cross-contract-calls" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } # Note: We **need** to specify the `ink-as-dependency` feature. # @@ -14,7 +14,7 @@ ink = { version = "5.0.0", default-features = false } other-contract = { path = "other-contract", default-features = false, features = ["ink-as-dependency"] } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/cross-contract-calls/other-contract/Cargo.toml b/cross-contract-calls/other-contract/Cargo.toml index b941a058..6eb419bd 100755 --- a/cross-contract-calls/other-contract/Cargo.toml +++ b/cross-contract-calls/other-contract/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "other-contract" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/custom-allocator/Cargo.toml b/custom-allocator/Cargo.toml index 9b98d51e..a962be71 100755 --- a/custom-allocator/Cargo.toml +++ b/custom-allocator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "custom-allocator" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false @@ -8,13 +8,13 @@ publish = false [dependencies] # We're going to use a different allocator than the one provided by ink!. To do that we # first need to disable the included memory allocator. -ink = { version = "5.0.0", default-features = false, features = ["no-allocator"] } +ink = { version = "5.1.0", default-features = false, features = ["no-allocator"] } # This is going to be our new global memory allocator. dlmalloc = {version = "0.2", default-features = false, features = ["global"] } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/custom-environment/Cargo.toml b/custom-environment/Cargo.toml index 1687ef58..e79f8a90 100644 --- a/custom-environment/Cargo.toml +++ b/custom-environment/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "custom-environment" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/dns/Cargo.toml b/dns/Cargo.toml index 99a926a6..c7eef8f6 100644 --- a/dns/Cargo.toml +++ b/dns/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "dns" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/e2e-call-runtime/Cargo.toml b/e2e-call-runtime/Cargo.toml index a20c8cdb..c3dc54f8 100644 --- a/e2e-call-runtime/Cargo.toml +++ b/e2e-call-runtime/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "e2e_call_runtime" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/e2e-runtime-only-backend/Cargo.toml b/e2e-runtime-only-backend/Cargo.toml index 18faa7fc..4bb5dcc2 100644 --- a/e2e-runtime-only-backend/Cargo.toml +++ b/e2e-runtime-only-backend/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "e2e-runtime-only-backend" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/erc1155/Cargo.toml b/erc1155/Cargo.toml index f6f0756b..73fb8df9 100644 --- a/erc1155/Cargo.toml +++ b/erc1155/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "erc1155" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/erc20/Cargo.toml b/erc20/Cargo.toml index bd2f7bee..848080d7 100644 --- a/erc20/Cargo.toml +++ b/erc20/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "erc20" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/erc721/Cargo.toml b/erc721/Cargo.toml index 0316c2e4..b07e5d50 100644 --- a/erc721/Cargo.toml +++ b/erc721/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "erc721" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/erc721/lib.rs b/erc721/lib.rs index 637836f9..5b2cbafd 100644 --- a/erc721/lib.rs +++ b/erc721/lib.rs @@ -226,6 +226,7 @@ mod erc721 { .ok_or(Error::CannotFetchValue)?; owned_tokens_count.insert(caller, &count); token_owner.remove(id); + self.clear_approval(id); self.env().emit_event(Transfer { from: Some(caller), @@ -635,6 +636,31 @@ mod erc721 { assert_eq!(erc721.burn(1), Err(Error::NotOwner)); } + #[ink::test] + fn burn_clears_approval() { + let accounts = + ink::env::test::default_accounts::(); + // Create a new contract instance. + let mut erc721 = Erc721::new(); + // Create token Id 1 for Alice + assert_eq!(erc721.mint(1), Ok(())); + // Alice gives approval to Bob to transfer token Id 1 + assert_eq!(erc721.approve(accounts.bob, 1), Ok(())); + // Alice burns token + assert_eq!(erc721.burn(1), Ok(())); + // Set caller to Frank + set_caller(accounts.frank); + // Frank mints token Id 1 + assert_eq!(erc721.mint(1), Ok(())); + // Set caller to Bob + set_caller(accounts.bob); + // Bob tries to transfer token Id 1 from Frank to himself + assert_eq!( + erc721.transfer_from(accounts.frank, accounts.bob, 1), + Err(Error::NotApproved) + ); + } + #[ink::test] fn transfer_from_fails_not_owner() { let accounts = diff --git a/events/Cargo.toml b/events/Cargo.toml index 62baa9ea..fc814e85 100644 --- a/events/Cargo.toml +++ b/events/Cargo.toml @@ -1,19 +1,19 @@ [package] name = "events" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } event-def = { path = "event-def", default-features = false } event-def2 = { path = "event-def2", default-features = false } event-def-unused = { path = "event-def-unused", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/events/event-def-unused/Cargo.toml b/events/event-def-unused/Cargo.toml index a41f0422..fe283ee0 100644 --- a/events/event-def-unused/Cargo.toml +++ b/events/event-def-unused/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [features] default = ["std"] diff --git a/events/event-def/Cargo.toml b/events/event-def/Cargo.toml index 78cbff7f..2e72cfc8 100644 --- a/events/event-def/Cargo.toml +++ b/events/event-def/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [features] default = ["std"] diff --git a/events/event-def2/Cargo.toml b/events/event-def2/Cargo.toml index d7ed2993..10956b53 100644 --- a/events/event-def2/Cargo.toml +++ b/events/event-def2/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [features] default = ["std"] diff --git a/flipper/Cargo.toml b/flipper/Cargo.toml index 6de3f9da..03556314 100644 --- a/flipper/Cargo.toml +++ b/flipper/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "flipper" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } hex = { version = "0.4.3" } [lib] diff --git a/flipper/lib.rs b/flipper/lib.rs index d2eb93ed..3730b8e2 100644 --- a/flipper/lib.rs +++ b/flipper/lib.rs @@ -131,7 +131,7 @@ pub mod flipper { /// # node process for each test. /// $ export CONTRACTS_NODE_URL=ws://127.0.0.1:9944 /// - /// $ export CONTRACT_HEX=0x2c75f0aa09dbfbfd49e6286a0f2edd3b4913f04a58b13391c79e96782f5713e3 + /// $ export CONTRACT_ADDR_HEX=0x2c75f0aa09dbfbfd49e6286a0f2edd3b4913f04a58b13391c79e96782f5713e3 /// $ cargo test --features e2e-tests e2e_test_deployed_contract -- --ignored /// ``` /// @@ -150,14 +150,19 @@ pub mod flipper { let acc_id = hex::decode(addr).unwrap(); let acc_id = AccountId::try_from(&acc_id[..]).unwrap(); + use std::str::FromStr; + let suri = ink_e2e::subxt_signer::SecretUri::from_str("//Alice").unwrap(); + let caller = ink_e2e::Keypair::from_uri(&suri).unwrap(); + // when - // Invoke `Flipper::get()` from Bob's account + // Invoke `Flipper::get()` from `caller`'s account let call_builder = ink_e2e::create_call_builder::(acc_id); let get = call_builder.get(); - let get_res = client.call(&ink_e2e::bob(), &get).dry_run().await?; + let get_res = client.call(&caller, &get).dry_run().await?; // then - assert!(matches!(get_res.return_value(), true)); + assert_eq!(get_res.return_value(), true); + Ok(()) } } diff --git a/incrementer/Cargo.toml b/incrementer/Cargo.toml index 542ba069..247cbc43 100644 --- a/incrementer/Cargo.toml +++ b/incrementer/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "incrementer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/lazyvec/Cargo.toml b/lazyvec/Cargo.toml index bd32ff07..e8e0e407 100755 --- a/lazyvec/Cargo.toml +++ b/lazyvec/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "lazyvec-integration-tests" -version = "5.0.0" +name = "lazyvec" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/lazyvec/lib.rs b/lazyvec/lib.rs index 7c146808..8c520680 100755 --- a/lazyvec/lib.rs +++ b/lazyvec/lib.rs @@ -3,7 +3,7 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] #[ink::contract] -mod lazyvec_integration_tests { +mod lazyvec { use ink::{ prelude::vec::Vec, storage::StorageVec, @@ -103,11 +103,7 @@ mod lazyvec_integration_tests { // given let mut constructor = LazyVectorRef::default(); let contract = client - .instantiate( - "lazyvec-integration-tests", - &ink_e2e::alice(), - &mut constructor, - ) + .instantiate("lazyvec", &ink_e2e::alice(), &mut constructor) .submit() .await .expect("instantiate failed"); diff --git a/mapping/Cargo.toml b/mapping/Cargo.toml index f7eebafa..767fe080 100755 --- a/mapping/Cargo.toml +++ b/mapping/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "mapping-integration-tests" -version = "5.0.0" +name = "mapping" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/mapping/lib.rs b/mapping/lib.rs index ccf07cf8..47caf9b8 100755 --- a/mapping/lib.rs +++ b/mapping/lib.rs @@ -3,7 +3,7 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] #[ink::contract] -mod mapping_integration_tests { +mod mapping { use ink::{ prelude::{ string::String, @@ -154,11 +154,7 @@ mod mapping_integration_tests { // given let mut constructor = MappingsRef::new(); let contract = client - .instantiate( - "mapping-integration-tests", - &ink_e2e::alice(), - &mut constructor, - ) + .instantiate("mapping", &ink_e2e::alice(), &mut constructor) .submit() .await .expect("instantiate failed"); @@ -194,11 +190,7 @@ mod mapping_integration_tests { // given let mut constructor = MappingsRef::new(); let contract = client - .instantiate( - "mapping-integration-tests", - &ink_e2e::bob(), - &mut constructor, - ) + .instantiate("mapping", &ink_e2e::bob(), &mut constructor) .submit() .await .expect("instantiate failed"); @@ -231,11 +223,7 @@ mod mapping_integration_tests { // given let mut constructor = MappingsRef::new(); let contract = client - .instantiate( - "mapping-integration-tests", - &ink_e2e::charlie(), - &mut constructor, - ) + .instantiate("mapping", &ink_e2e::charlie(), &mut constructor) .submit() .await .expect("instantiate failed"); @@ -280,11 +268,7 @@ mod mapping_integration_tests { // given let mut constructor = MappingsRef::new(); let contract = client - .instantiate( - "mapping-integration-tests", - &ink_e2e::dave(), - &mut constructor, - ) + .instantiate("mapping", &ink_e2e::dave(), &mut constructor) .submit() .await .expect("instantiate failed"); @@ -326,11 +310,7 @@ mod mapping_integration_tests { // given let mut constructor = MappingsRef::new(); let contract = client - .instantiate( - "mapping-integration-tests", - &ink_e2e::eve(), - &mut constructor, - ) + .instantiate("mapping", &ink_e2e::eve(), &mut constructor) .submit() .await .expect("instantiate failed"); @@ -375,11 +355,7 @@ mod mapping_integration_tests { // given let mut constructor = MappingsRef::new(); let contract = client - .instantiate( - "mapping-integration-tests", - &ink_e2e::ferdie(), - &mut constructor, - ) + .instantiate("mapping", &ink_e2e::ferdie(), &mut constructor) .submit() .await .expect("instantiate failed"); @@ -400,7 +376,7 @@ mod mapping_integration_tests { .await? .return_value(); let received_insert_result = - Err(crate::mapping_integration_tests::ContractError::ValueTooLarge); + Err(crate::mapping::ContractError::ValueTooLarge); assert_eq!(received_insert_result, expected_insert_result); // then there should be 4 entries (that's what fits into the 256kb buffer) diff --git a/multi-contract-caller/Cargo.toml b/multi-contract-caller/Cargo.toml index 4665182a..3d7ea172 100644 --- a/multi-contract-caller/Cargo.toml +++ b/multi-contract-caller/Cargo.toml @@ -1,19 +1,19 @@ [package] name = "multi-contract-caller" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } adder = { path = "adder", default-features = false, features = ["ink-as-dependency"] } subber = { path = "subber", default-features = false, features = ["ink-as-dependency"] } accumulator = { path = "accumulator", default-features = false, features = ["ink-as-dependency"] } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/multi-contract-caller/accumulator/Cargo.toml b/multi-contract-caller/accumulator/Cargo.toml index 37b42c67..4f570f5f 100644 --- a/multi-contract-caller/accumulator/Cargo.toml +++ b/multi-contract-caller/accumulator/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "accumulator" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/multi-contract-caller/adder/Cargo.toml b/multi-contract-caller/adder/Cargo.toml index 214d4026..3c6f1100 100644 --- a/multi-contract-caller/adder/Cargo.toml +++ b/multi-contract-caller/adder/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "adder" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } accumulator = { path = "../accumulator", default-features = false, features = ["ink-as-dependency"] } diff --git a/multi-contract-caller/subber/Cargo.toml b/multi-contract-caller/subber/Cargo.toml index 0779d509..2b8d683f 100644 --- a/multi-contract-caller/subber/Cargo.toml +++ b/multi-contract-caller/subber/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "subber" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } accumulator = { path = "../accumulator", default-features = false, features = ["ink-as-dependency"] } diff --git a/multisig/Cargo.toml b/multisig/Cargo.toml index 28b0b768..6731967a 100755 --- a/multisig/Cargo.toml +++ b/multisig/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "multisig" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/payment-channel/Cargo.toml b/payment-channel/Cargo.toml index 70d7b4cd..997dc257 100755 --- a/payment-channel/Cargo.toml +++ b/payment-channel/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "payment_channel" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] hex-literal = { version = "0.4.1" } diff --git a/psp22-extension/Cargo.toml b/psp22-extension/Cargo.toml index de0d23b3..ca264390 100755 --- a/psp22-extension/Cargo.toml +++ b/psp22-extension/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "psp22_extension" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/rand-extension/Cargo.toml b/rand-extension/Cargo.toml index ecbaa68d..cf2846a7 100755 --- a/rand-extension/Cargo.toml +++ b/rand-extension/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "rand_extension" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/runtime-call-contract/Cargo.toml b/runtime-call-contract/Cargo.toml new file mode 100644 index 00000000..152f1c0d --- /dev/null +++ b/runtime-call-contract/Cargo.toml @@ -0,0 +1,49 @@ +[workspace] +members = ["sandbox-runtime", "traits"] + +[workspace.package] +authors = ["Use Ink "] +edition = "2021" +homepage = "https://use.ink" +keywords = ["wasm", "ink", "webassembly", "blockchain", "edsl"] +license = "Apache-2.0" +repository = "https://github.com/use-ink/ink" + +[workspace.dependencies] +frame-support = { version = "32.0.0", default-features = false } +frame-system = { version = "32.0.0", default-features = false } +pallet-contracts = { version = "31.0.0", default-features = false } +sp-runtime = { version = "35.0.0", default-features = false } +codec = { package = "parity-scale-codec", version = "3.6.9", default-features = false } +scale-info = { version = "2.11.1", default-features = false } + +[package] +name = "runtime-call-contract" +version = "5.1.0" +authors = ["Use Ink "] +edition = "2021" +publish = false + +[dependencies] +ink = { version = "5.1.0", default-features = false } +flipper-traits = { path = "traits", default-features = false } + +[dev-dependencies] +ink_e2e = { version = "5.1.0", features = ["sandbox"] } +sandbox-runtime = { path = "sandbox-runtime", default-features = false } +scale-value = "0.14.1" +# can't use workspace dependency because of `cargo-contract` build not +# working with workspace dependencies +frame-support = { version = "32.0.0", default-features = false } + +[lib] +path = "lib.rs" + +[features] +default = ["std"] +std = [ + "ink/std", + "sandbox-runtime/std", + "flipper-traits/std", +] +ink-as-dependency = [] diff --git a/runtime-call-contract/e2e_tests.rs b/runtime-call-contract/e2e_tests.rs new file mode 100644 index 00000000..f4b73396 --- /dev/null +++ b/runtime-call-contract/e2e_tests.rs @@ -0,0 +1,61 @@ +use super::{ + Flipper, + FlipperRef, +}; +use ink_e2e::{ + ChainBackend, + ContractsBackend, +}; + +type E2EResult = Result>; + +/// Just instantiate a contract using non-default runtime. +#[ink_e2e::test(backend(runtime_only(sandbox = sandbox_runtime::ContractCallerSandbox)))] +async fn instantiate_and_get(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::(); + 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(), + scale_value::serde::to_value(None::).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(()) +} diff --git a/runtime-call-contract/lib.rs b/runtime-call-contract/lib.rs new file mode 100644 index 00000000..58435745 --- /dev/null +++ b/runtime-call-contract/lib.rs @@ -0,0 +1,36 @@ +#![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, + } + + impl Flipper { + #[ink(constructor)] + pub fn new(init_value: bool) -> Self { + Self { value: init_value } + } + } + + impl flipper_traits::Flip for Flipper { + #[ink(message)] + fn flip(&mut self) { + self.value = !self.value; + } + + #[ink(message)] + fn get(&self) -> bool { + self.value + } + } +} + +#[cfg(test)] +mod e2e_tests; diff --git a/runtime-call-contract/sandbox-runtime/Cargo.toml b/runtime-call-contract/sandbox-runtime/Cargo.toml new file mode 100644 index 00000000..fabffd81 --- /dev/null +++ b/runtime-call-contract/sandbox-runtime/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "sandbox-runtime" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +repository.workspace = true + +[dependencies] +ink_sandbox = { path = "../../../../crates/e2e/sandbox" } +pallet-contract-caller = { path = "pallet-contract-caller", default-features = false } +frame-support = { workspace = true } +frame-system = { workspace = true } +codec = { workspace = true } +scale-info = { workspace = true } + +[features] +default = ["std"] +std = [ + "pallet-contract-caller/std", +] diff --git a/runtime-call-contract/sandbox-runtime/pallet-contract-caller/Cargo.toml b/runtime-call-contract/sandbox-runtime/pallet-contract-caller/Cargo.toml new file mode 100644 index 00000000..2fd03162 --- /dev/null +++ b/runtime-call-contract/sandbox-runtime/pallet-contract-caller/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "pallet-contract-caller" +version = "0.1.0" +description = "Demonstrate calling an ink! contract from a pallet" +authors = ["Use Ink "] +homepage = "https://substrate.io" +edition.workspace = true +license = "MIT-0" +publish = false +repository = "https://github.com/use-ink/ink" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { workspace = true, default-features = false, features = ["derive"] } +scale-info = { workspace = true, default-features = false, features = ["derive"] } +frame-support = { workspace = true, default-features = false } +frame-system = { workspace = true, default-features = false } +sp-runtime = { workspace = true, default-features = false } + +pallet-contracts = { workspace = true, default-features = false } +flipper-traits = { path = "../../traits", default-features = false } +ink = { version = "5.1.0", features = ["no-panic-handler", "no-allocator"] } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "sp-runtime/std", + "scale-info/std", + "pallet-contracts/std", + "ink/std" +] +try-runtime = [] diff --git a/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/executor.rs b/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/executor.rs new file mode 100644 index 00000000..214cf5fd --- /dev/null +++ b/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/executor.rs @@ -0,0 +1,59 @@ +use crate::{ + AccountIdOf, + BalanceOf, +}; +use frame_support::pallet_prelude::Weight; +use ink::env::{ + call::{ + ExecutionInput, + Executor, + }, + Environment, +}; + +pub struct PalletContractsExecutor { + pub origin: AccountIdOf, + pub contract: AccountIdOf, + pub value: BalanceOf, + pub gas_limit: Weight, + pub storage_deposit_limit: Option>, + pub marker: core::marker::PhantomData, +} + +impl Executor for PalletContractsExecutor +where + E: Environment, + R: pallet_contracts::Config, +{ + type Error = sp_runtime::DispatchError; + + fn exec( + &self, + input: &ExecutionInput, + ) -> Result, Self::Error> + where + Args: codec::Encode, + Output: codec::Decode, + { + let data = codec::Encode::encode(&input); + + let result = pallet_contracts::Pallet::::bare_call( + self.origin.clone(), + self.contract.clone(), + self.value, + self.gas_limit, + self.storage_deposit_limit, + data, + pallet_contracts::DebugInfo::UnsafeDebug, + pallet_contracts::CollectEvents::Skip, + pallet_contracts::Determinism::Enforced, + ); + + let output = result.result?.data; + let result = codec::Decode::decode(&mut &output[..]).map_err(|_| { + sp_runtime::DispatchError::Other("Failed to decode contract output") + })?; + + Ok(result) + } +} diff --git a/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/lib.rs b/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/lib.rs new file mode 100644 index 00000000..cf7abdd4 --- /dev/null +++ b/runtime-call-contract/sandbox-runtime/pallet-contract-caller/src/lib.rs @@ -0,0 +1,76 @@ +//! # Contract Caller +//! +//! Demonstrates calling into an `ink!` contract from a pallet. + +#![cfg_attr(not(feature = "std"), no_std)] + +mod executor; + +use frame_support::{ + pallet_prelude::Weight, + traits::fungible::Inspect, +}; +pub use pallet::*; + +type AccountIdOf = ::AccountId; +type BalanceOf = <::Currency as Inspect< + ::AccountId, +>>::Balance; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use flipper_traits::Flip; + use frame_support::{ + pallet_prelude::*, + traits::fungible::Inspect, + }; + use frame_system::pallet_prelude::*; + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config + pallet_contracts::Config {} + + #[pallet::error] + pub enum Error {} + + #[pallet::call] + impl Pallet + where + [u8; 32]: From<::AccountId>, + <::Currency as Inspect< + ::AccountId, + >>::Balance: From, + { + /// Call the flip method on the contract at the given `contract` account. + #[pallet::call_index(0)] + #[pallet::weight(::call().saturating_add(*gas_limit))] + pub fn contract_call_flip( + origin: OriginFor, + contract: AccountIdOf, + gas_limit: Weight, + storage_deposit_limit: Option>, + ) -> DispatchResult { + let who = ensure_signed(origin)?; + + let executor = + executor::PalletContractsExecutor:: { + origin: who.clone(), + contract: contract.clone(), + value: 0.into(), + gas_limit, + storage_deposit_limit, + marker: Default::default(), + }; + + let mut flipper = ink::message_builder!(Flip); + let result = flipper.flip().exec(&executor)?; + + assert!(result.is_ok()); + + Ok(()) + } + } +} diff --git a/runtime-call-contract/sandbox-runtime/src/lib.rs b/runtime-call-contract/sandbox-runtime/src/lib.rs new file mode 100644 index 00000000..78a39d89 --- /dev/null +++ b/runtime-call-contract/sandbox-runtime/src/lib.rs @@ -0,0 +1,11 @@ +//! # Contract Caller +//! +//! Demonstrates calling into an `ink!` contract from a pallet. + +#![cfg_attr(not(feature = "std"), no_std)] + +ink_sandbox::create_sandbox!(ContractCallerSandbox, ContractCallerSandboxRuntime, (), (), { + ContractCaller: pallet_contract_caller, +}); + +impl pallet_contract_caller::Config for ContractCallerSandboxRuntime {} diff --git a/runtime-call-contract/traits/Cargo.toml b/runtime-call-contract/traits/Cargo.toml new file mode 100644 index 00000000..101fd590 --- /dev/null +++ b/runtime-call-contract/traits/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "flipper-traits" +version = "5.1.0" +authors = ["Use Ink "] +edition = "2021" +publish = false + +[dependencies] +ink = { version = "5.1.0", default-features = false } + +[lib] +path = "lib.rs" + +[features] +default = ["std"] +std = [ + "ink/std", +] diff --git a/runtime-call-contract/traits/lib.rs b/runtime-call-contract/traits/lib.rs new file mode 100644 index 00000000..294077a1 --- /dev/null +++ b/runtime-call-contract/traits/lib.rs @@ -0,0 +1,14 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] + +/// Allows to flip and get a bool value. +#[ink::trait_definition] +pub trait Flip { + /// Flip the value of the stored `bool` from `true` + /// to `false` and vice versa. + #[ink(message)] + fn flip(&mut self); + + /// Returns the current value of our `bool`. + #[ink(message)] + fn get(&self) -> bool; +} diff --git a/static-buffer/Cargo.toml b/static-buffer/Cargo.toml index 6a2abbd6..f88ff65c 100644 --- a/static-buffer/Cargo.toml +++ b/static-buffer/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "static-buffer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/trait-dyn-cross-contract-calls/Cargo.toml b/trait-dyn-cross-contract-calls/Cargo.toml index f442fe0c..77dc1219 100644 --- a/trait-dyn-cross-contract-calls/Cargo.toml +++ b/trait-dyn-cross-contract-calls/Cargo.toml @@ -1,17 +1,17 @@ [package] name = "trait-incrementer-caller" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } dyn-traits = { path = "./traits", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } trait-incrementer = { path = "./contracts/incrementer", default-features = false, features = ["ink-as-dependency"] } [lib] diff --git a/trait-dyn-cross-contract-calls/contracts/incrementer/Cargo.toml b/trait-dyn-cross-contract-calls/contracts/incrementer/Cargo.toml index 58d51c8c..64db9bfc 100644 --- a/trait-dyn-cross-contract-calls/contracts/incrementer/Cargo.toml +++ b/trait-dyn-cross-contract-calls/contracts/incrementer/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "trait-incrementer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } dyn-traits = { path = "../../traits", default-features = false } diff --git a/trait-dyn-cross-contract-calls/traits/Cargo.toml b/trait-dyn-cross-contract-calls/traits/Cargo.toml index 00eb9b2f..1685ae46 100644 --- a/trait-dyn-cross-contract-calls/traits/Cargo.toml +++ b/trait-dyn-cross-contract-calls/traits/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "dyn-traits" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" @@ -15,4 +15,4 @@ path = "lib.rs" default = ["std"] std = [ "ink/std", -] \ No newline at end of file +] diff --git a/trait-erc20/Cargo.toml b/trait-erc20/Cargo.toml index 0b9205ac..56d9d63d 100644 --- a/trait-erc20/Cargo.toml +++ b/trait-erc20/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "trait_erc20" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/trait-flipper/Cargo.toml b/trait-flipper/Cargo.toml index 8ef52455..b46735e2 100644 --- a/trait-flipper/Cargo.toml +++ b/trait-flipper/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "trait_flipper" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/trait-incrementer/Cargo.toml b/trait-incrementer/Cargo.toml index 6b87fc69..0a047617 100644 --- a/trait-incrementer/Cargo.toml +++ b/trait-incrementer/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "trait-incrementer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } traits = { path = "./traits", default-features = false } diff --git a/trait-incrementer/traits/Cargo.toml b/trait-incrementer/traits/Cargo.toml index daa725a9..4feb52b3 100644 --- a/trait-incrementer/traits/Cargo.toml +++ b/trait-incrementer/traits/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "traits" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] name = "traits" diff --git a/upgradeable-contracts/delegator/Cargo.toml b/upgradeable-contracts/delegator/Cargo.toml index 2a87568c..0c6f0514 100644 --- a/upgradeable-contracts/delegator/Cargo.toml +++ b/upgradeable-contracts/delegator/Cargo.toml @@ -1,17 +1,17 @@ [package] name = "delegator" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } delegatee = { path = "delegatee", default-features = false, features = ["ink-as-dependency"] } delegatee2 = { path = "delegatee2", default-features = false, features = ["ink-as-dependency"] } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/upgradeable-contracts/delegator/delegatee/Cargo.toml b/upgradeable-contracts/delegator/delegatee/Cargo.toml index 617522ac..56d26758 100644 --- a/upgradeable-contracts/delegator/delegatee/Cargo.toml +++ b/upgradeable-contracts/delegator/delegatee/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "delegatee" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/upgradeable-contracts/delegator/delegatee2/Cargo.toml b/upgradeable-contracts/delegator/delegatee2/Cargo.toml index 33629470..cf7c873b 100644 --- a/upgradeable-contracts/delegator/delegatee2/Cargo.toml +++ b/upgradeable-contracts/delegator/delegatee2/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "delegatee2" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/upgradeable-contracts/set-code-hash-migration/Cargo.toml b/upgradeable-contracts/set-code-hash-migration/Cargo.toml index e3d72691..be8024bd 100644 --- a/upgradeable-contracts/set-code-hash-migration/Cargo.toml +++ b/upgradeable-contracts/set-code-hash-migration/Cargo.toml @@ -1,18 +1,18 @@ [package] name = "incrementer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } migration = { path = "./migration", default-features = false, features = ["ink-as-dependency"] } updated-incrementer = { path = "./updated-incrementer", default-features = false, features = ["ink-as-dependency"] } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/upgradeable-contracts/set-code-hash-migration/migration/Cargo.toml b/upgradeable-contracts/set-code-hash-migration/migration/Cargo.toml index 7fa0f4f7..a9d918ec 100644 --- a/upgradeable-contracts/set-code-hash-migration/migration/Cargo.toml +++ b/upgradeable-contracts/set-code-hash-migration/migration/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "migration" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/upgradeable-contracts/set-code-hash-migration/updated-incrementer/Cargo.toml b/upgradeable-contracts/set-code-hash-migration/updated-incrementer/Cargo.toml index 7186e3f8..05590ada 100644 --- a/upgradeable-contracts/set-code-hash-migration/updated-incrementer/Cargo.toml +++ b/upgradeable-contracts/set-code-hash-migration/updated-incrementer/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "updated-incrementer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/upgradeable-contracts/set-code-hash/Cargo.toml b/upgradeable-contracts/set-code-hash/Cargo.toml index 021d0365..705455f2 100644 --- a/upgradeable-contracts/set-code-hash/Cargo.toml +++ b/upgradeable-contracts/set-code-hash/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "incrementer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } updated-incrementer = { path = "updated-incrementer", default-features = false, features = ["ink-as-dependency"] } [lib] diff --git a/upgradeable-contracts/set-code-hash/updated-incrementer/Cargo.toml b/upgradeable-contracts/set-code-hash/updated-incrementer/Cargo.toml index 7186e3f8..05590ada 100644 --- a/upgradeable-contracts/set-code-hash/updated-incrementer/Cargo.toml +++ b/upgradeable-contracts/set-code-hash/updated-incrementer/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "updated-incrementer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [lib] path = "lib.rs" diff --git a/vesting/Cargo.toml b/vesting/Cargo.toml index 78854270..8e9c45a0 100755 --- a/vesting/Cargo.toml +++ b/vesting/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "vesting" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] diff --git a/wildcard-selector/Cargo.toml b/wildcard-selector/Cargo.toml index e7e1240b..b3e9d0bf 100644 --- a/wildcard-selector/Cargo.toml +++ b/wildcard-selector/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "wildcard-selector" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false [dependencies] -ink = { version = "5.0.0", default-features = false } +ink = { version = "5.1.0", default-features = false } [dev-dependencies] -ink_e2e = { version = "5.0.0" } +ink_e2e = { version = "5.1.0" } [lib] path = "lib.rs" diff --git a/workspace-contracts/Cargo.toml b/workspace-contracts/Cargo.toml index 8e120b69..91f4fd9e 100644 --- a/workspace-contracts/Cargo.toml +++ b/workspace-contracts/Cargo.toml @@ -4,5 +4,5 @@ exclude = [".cargo", "target"] resolver = "2" [workspace.dependencies] -ink = { version = "5.0.0", default-features = false } -ink_e2e = "5.0.0" +ink = { version = "5.1.0", default-features = false } +ink_e2e = "5.1.0" diff --git a/workspace-contracts/flipper/Cargo.toml b/workspace-contracts/flipper/Cargo.toml index 47a5b1de..e7f52d67 100644 --- a/workspace-contracts/flipper/Cargo.toml +++ b/workspace-contracts/flipper/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flipper" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false diff --git a/workspace-contracts/incrementer/Cargo.toml b/workspace-contracts/incrementer/Cargo.toml index b7e5ec00..843afeab 100644 --- a/workspace-contracts/incrementer/Cargo.toml +++ b/workspace-contracts/incrementer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "incrementer" -version = "5.0.0" +version = "5.1.0" authors = ["Use Ink "] edition = "2021" publish = false