diff --git a/Cargo.lock b/Cargo.lock index 76558a8..a863b67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3467,7 +3467,7 @@ dependencies = [ [[package]] name = "pallet-api" version = "0.1.0" -source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#52fb7f06a89955d462900e33d2b9c9170c4534a0" +source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#d642b4201c86290222c9e1806bf194bb0ee96feb" dependencies = [ "frame-benchmarking", "frame-support", @@ -4638,7 +4638,7 @@ dependencies = [ [[package]] name = "pop-api" version = "0.0.0" -source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#f2131648d775d845cfced8ed3e645102244acc7b" +source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#d642b4201c86290222c9e1806bf194bb0ee96feb" dependencies = [ "ink", "pop-primitives", @@ -4648,7 +4648,7 @@ dependencies = [ [[package]] name = "pop-chain-extension" version = "0.1.0" -source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#52fb7f06a89955d462900e33d2b9c9170c4534a0" +source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#d642b4201c86290222c9e1806bf194bb0ee96feb" dependencies = [ "frame-support", "frame-system", @@ -4676,6 +4676,7 @@ dependencies = [ "parity-scale-codec", "pop-api", "pop-runtime-devnet", + "pop-runtime-testnet", "scale-info", "sp-io", ] @@ -4683,7 +4684,7 @@ dependencies = [ [[package]] name = "pop-primitives" version = "0.0.0" -source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#52fb7f06a89955d462900e33d2b9c9170c4534a0" +source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#d642b4201c86290222c9e1806bf194bb0ee96feb" dependencies = [ "parity-scale-codec", "scale-info", @@ -4692,7 +4693,7 @@ dependencies = [ [[package]] name = "pop-runtime-common" version = "0.0.0" -source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#52fb7f06a89955d462900e33d2b9c9170c4534a0" +source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#d642b4201c86290222c9e1806bf194bb0ee96feb" dependencies = [ "frame-support", "parachains-common", @@ -4706,7 +4707,7 @@ dependencies = [ [[package]] name = "pop-runtime-devnet" version = "0.1.0" -source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#52fb7f06a89955d462900e33d2b9c9170c4534a0" +source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#d642b4201c86290222c9e1806bf194bb0ee96feb" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -4784,6 +4785,81 @@ dependencies = [ "substrate-wasm-builder", ] +[[package]] +name = "pop-runtime-testnet" +version = "0.4.2" +source = "git+https://github.com/r0gue-io/pop-node.git?branch=main#d642b4201c86290222c9e1806bf194bb0ee96feb" +dependencies = [ + "cumulus-pallet-aura-ext", + "cumulus-pallet-parachain-system", + "cumulus-pallet-session-benchmarking", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-aura", + "cumulus-primitives-core", + "cumulus-primitives-storage-weight-reclaim", + "cumulus-primitives-utility", + "frame-benchmarking", + "frame-executive", + "frame-metadata-hash-extension", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex-literal", + "log", + "pallet-api", + "pallet-assets", + "pallet-aura", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "pallet-contracts", + "pallet-message-queue", + "pallet-multisig", + "pallet-nft-fractionalization", + "pallet-nfts", + "pallet-nfts-runtime-api", + "pallet-preimage", + "pallet-proxy", + "pallet-scheduler", + "pallet-session", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-utility", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "pop-chain-extension", + "pop-primitives", + "pop-runtime-common", + "scale-info", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-aura", + "sp-core", + "sp-genesis-builder", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std", + "sp-transaction-pool", + "sp-version", + "staging-parachain-info", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "substrate-wasm-builder", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -7243,7 +7319,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2038b73..669b005 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,3 +57,4 @@ ink_sandbox = { path = "crates/ink-sandbox" } pop-api = { git = "https://github.com/r0gue-io/pop-node.git", branch = "main" } pop-drink = { path = "crates/pop-drink" } pop-runtime-devnet = { git = "https://github.com/r0gue-io/pop-node.git", branch = "main" } +pop-runtime-testnet = { git = "https://github.com/r0gue-io/pop-node.git", branch = "main" } diff --git a/crates/pop-drink/Cargo.toml b/crates/pop-drink/Cargo.toml index 5c7f26c..bc90015 100644 --- a/crates/pop-drink/Cargo.toml +++ b/crates/pop-drink/Cargo.toml @@ -8,6 +8,7 @@ drink.workspace = true ink_sandbox.workspace = true pallet-contracts.workspace = true pop-runtime-devnet.workspace = true +pop-runtime-testnet.workspace = true frame-system.workspace = true frame-support.workspace = true sp-io.workspace = true diff --git a/crates/pop-drink/src/lib.rs b/crates/pop-drink/src/lib.rs index cc379be..9303d02 100644 --- a/crates/pop-drink/src/lib.rs +++ b/crates/pop-drink/src/lib.rs @@ -15,20 +15,37 @@ pub mod macros; #[cfg(test)] mod mock; -/// Types and utilities for testing smart contracts interacting with Pop Network Devnet via the pop -/// api. +macro_rules! define_runtime_utilities { + ($runtime_type:ident) => { + /// Alias for the balance type. + pub type Balance = BalanceFor<$runtime_type>; + /// Alias for the account ID type. + pub type AccountId = AccountIdFor<$runtime_type>; + + /// Converts an AccountId from Pop's runtime to the account ID used in the contract + /// environment. + pub fn account_id_from_slice(s: &AccountId) -> pop_api::primitives::AccountId { + let account: [u8; 32] = s.clone().into(); + super::account_id_from_slice(&account) + } + }; +} + +/// Types and utilities for testing smart contracts interacting with Pop Network Devnet via the Pop +/// API. pub mod devnet { pub use pop_runtime_devnet::Runtime; use super::*; pub use crate::error::*; - /// Error related utilities for smart contracts using pop api. + /// Error related utilities for smart contracts using Pop API. pub mod error { pub use pop_runtime_devnet::RuntimeError::*; pub use crate::error::*; + /// Error types for smart contracts using Pop API V0. pub mod v0 { pub use pop_api::primitives::v0::{self, Error as ApiError, *}; @@ -37,15 +54,33 @@ pub mod devnet { } } - // Types used in the pop runtime. - pub type Balance = BalanceFor; - pub type AccountId = AccountIdFor; + define_runtime_utilities!(Runtime); +} + +/// Types and utilities for testing smart contracts interacting with Pop Network Testnet via the Pop +/// API. +pub mod testnet { + pub use pop_runtime_testnet::Runtime; - /// Converts an AccountId from Pop's runtime to the account ID used in the contract environment. - pub fn account_id_from_slice(s: &AccountId) -> pop_api::primitives::AccountId { - let account: [u8; 32] = s.clone().into(); - super::account_id_from_slice(&account) + use super::*; + pub use crate::error::*; + + /// Error related utilities for smart contracts using Pop API. + pub mod error { + pub use pop_runtime_testnet::RuntimeError::*; + + pub use crate::error::*; + + /// Error types for smart contracts using Pop API V0. + pub mod v0 { + pub use pop_api::primitives::v0::{self, Error as ApiError, *}; + + /// Error type for writing tests (see `error` module). + pub type Error = crate::error::Error; + } } + + define_runtime_utilities!(Runtime); } /// Deploy a contract with a given constructor, arguments, salt and an initial value. In @@ -68,12 +103,12 @@ pub mod devnet { /// ```rs /// #[drink::test(sandbox = Pop)] /// fn test_constructor_works(mut session: Session) { -/// let bundle = BundleProvider::local().unwrap(); +/// let bundle = BundleProvider::local().unwrap(); /// -/// // Deploy contract. -/// // -/// // `ContractError` is the error type used by the contract. -/// assert_ok!(deploy(&mut session, bundle, "new", input, salt, init_value)); +/// // Deploy contract. +/// // +/// // `ContractError` is the error type used by the contract. +/// assert_ok!(deploy(&mut session, bundle, "new", input, salt, init_value)); /// } /// ``` pub fn deploy( @@ -116,19 +151,19 @@ where /// ```rs /// #[drink::test(sandbox = Pop)] /// fn call_works(mut session: Session) { -/// let bundle = BundleProvider::local().unwrap(); -/// assert_ok!(deploy(&mut session, bundle, "new", input, salt, init_value)); +/// let bundle = BundleProvider::local().unwrap(); +/// assert_ok!(deploy(&mut session, bundle, "new", input, salt, init_value)); /// -/// // Call contract. -/// // -/// // `()` is the successful result type used by the contract. -/// // `ContractError` is the error type used by the contract. -/// call::( -/// session, -/// "transfer", -/// input, -/// init_value, -/// ) +/// // Call contract. +/// // +/// // `()` is the successful result type used by the contract. +/// // `ContractError` is the error type used by the contract. +/// call::( +/// session, +/// "transfer", +/// input, +/// init_value, +/// ) /// } /// ``` pub fn call( @@ -171,12 +206,12 @@ where /// use drink::last_contract_event; /// /// assert_eq!( -/// last_contract_event::(&session).unwrap(), -/// ContractEvent { -/// value: 42, -/// } -/// .encode() -/// .as_slice() +/// last_contract_event::(&session).unwrap(), +/// ContractEvent { +/// value: 42, +/// } +/// .encode() +/// .as_slice() /// ); /// ``` pub fn last_contract_event(session: &Session) -> Option> diff --git a/crates/pop-drink/src/macros.rs b/crates/pop-drink/src/macros.rs index a1f7436..3bfeb44 100644 --- a/crates/pop-drink/src/macros.rs +++ b/crates/pop-drink/src/macros.rs @@ -17,13 +17,13 @@ use crate::last_contract_event; /// /// ```rs /// use drink::devnet::{ -/// Assets, -/// AssetsError::BalanceLow, -/// v0::{ -/// Arithmetic, -/// ArithmeticError::Overflow, -/// BadOrigin -/// }, +/// Assets, +/// AssetsError::BalanceLow, +/// v0::{ +/// Arithmetic, +/// ArithmeticError::Overflow, +/// BadOrigin +/// }, /// }; /// ``` /// @@ -51,50 +51,50 @@ use crate::last_contract_event; /// /// /// Custom error in contract. /// pub enum CustomError { -/// ..., -/// /// Error with status code. -/// StatusCode(u32), +/// ..., +/// /// Error with status code. +/// StatusCode(u32), /// } /// /// impl From for CustomError { -/// /// Converts a `StatusCode` (returned by the api) to a `CustomError`. -/// fn from(value: StatusCode) -> Self { -/// match value { -/// ..., -/// _ => CustomError::StatusCode(value.0), -/// } -/// } +/// /// Converts a `StatusCode` (returned by the api) to a `CustomError`. +/// fn from(value: StatusCode) -> Self { +/// match value { +/// ..., +/// _ => CustomError::StatusCode(value.0), +/// } +/// } /// } /// /// impl From for u32 { -/// /// Converts a `CustomError to a `u32`. -/// // -/// // Required for the `assert_err` macro to assert to `Error`. -/// fn from(value: CustomError) -> Self { -/// match value { -/// ..., -/// CustomError::StatusCode(status_code) => status_code, -/// } -/// } +/// /// Converts a `CustomError to a `u32`. +/// // +/// // Required for the `assert_err` macro to assert to `Error`. +/// fn from(value: CustomError) -> Self { +/// match value { +/// ..., +/// CustomError::StatusCode(status_code) => status_code, +/// } +/// } /// } /// /// - Use `assert_err` in a test. /// /// #[drink::test(sandbox = Pop)] /// fn test_custom_error(mut session: Session) { -/// ... +/// ... /// -/// // Call a contract method that returns a `Result<(), CustomError>`. -/// let result = call::(session, "hello_world", vec![], None); +/// // Call a contract method that returns a `Result<(), CustomError>`. +/// let result = call::(session, "hello_world", vec![], None); /// -/// // Assert the result to the expected error. -/// assert_err!(result, Error::Raw(BadOrigin))); +/// // Assert the result to the expected error. +/// assert_err!(result, Error::Raw(BadOrigin))); /// -/// // Other assertions: -/// ... -/// assert_err!(result, Error::Raw(Arithmetic(Overflow))); -/// ... -/// assert_err!(result, Error::Module(Assets(BalanceLow))); +/// // Other assertions: +/// ... +/// assert_err!(result, Error::Raw(Arithmetic(Overflow))); +/// ... +/// assert_err!(result, Error::Module(Assets(BalanceLow))); /// } /// ``` /// @@ -135,12 +135,12 @@ where /// /// ```rs /// assert_last_contract_event!( -/// &session, -/// Transfer { -/// from: Some(account_id_from_slice(&contract)), -/// to: Some(account_id_from_slice(&BOB)), -/// value, -/// } +/// &session, +/// Transfer { +/// from: Some(account_id_from_slice(&contract)), +/// to: Some(account_id_from_slice(&BOB)), +/// value, +/// } /// ); /// ``` ///