From 3b35c438a5a757de478d575062c8ac4eec710937 Mon Sep 17 00:00:00 2001 From: chungquantin <56880684+chungquantin@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:47:10 +0700 Subject: [PATCH 1/3] chore: README.md --- README.md | 183 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 150 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 2e17b48..d505c29 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,185 @@ -

Pop DRink! (forked from DRink!)

-

Dechained Ready-to-play ink! playground

+
+

Pop DRink!

-> [!IMPORTANT] -> This repository is customized and maintained for Pop API contract end-to-end testing. -> -> Quasi tests must be run with `cargo test --release`. +R0GUE Logo -# Pop Sandbox +[![Twitter URL](https://img.shields.io/twitter/follow/Pop?style=social)](https://x.com/onpopio/) +[![Twitter URL](https://img.shields.io/twitter/follow/R0GUE?style=social)](https://twitter.com/gor0gue) +[![Telegram](https://img.shields.io/badge/Telegram-gray?logo=telegram)](https://t.me/onpopio) -Implementation of the [`pop_drink::Sandbox`](https://github.com/r0gue-io/pop-drink) struct for the Pop Network runtimes (located in `pop-node/runtime`) required for the quasi testing with `drink`. +Forked version of [inkdevhub/drink](https://github.com/inkdevhub/drink) for E2E testing smart contract using [Pop API](https://github.com/r0gue-io/pop-node/tree/main/pop-api) with [Pop Network runtimes](https://github.com/r0gue-io/pop-node/tree/main/runtime). -In the context of quasi-testing with pop-drink, a sandbox refers to an isolated runtime environment that simulates the behavior of a full node, without requiring an actual node. It can emulate key processes (where runtime `pallets` are involved) such as block initialization, execution, and block finalization. +
+ +## Overview + +About the repository folder structure: + +- `crates/drink` + - `drink`: DRink! is a toolbox for ink! developers that allows for a fully functional ink! contract development without any running node. + - `drink-cli`: Simple command line tool to help you play with your local contracts in a convenient way. + - `examples`: A collection of example contracts tested with DRink! +- `crates/ink-sandbox`: In the context of quasi-testing with pop-drink, a sandbox refers to an isolated runtime environment that simulates the behavior of a full node, without requiring an actual node. +- `crates/pop-drink`: Provides utility methods for testing contract methods with DRink! and Pop Network runtimes. ## Getting Started -### Installation +- Add `pop-drink` crate to your contract `Cargo.toml`: ```toml -pop_drink = { version = "1.0.0", package = "pop-drink" } +drink = { version = "1.0.0", package = "pop-drink" } ``` -### Import Sandbox for the specific runtime +### 1. Setup a testing environment -- For `devnet` runtime +Import required methods and types: + +```rs +use drink::{ + devnet::{AccounId, Balance}, + TestExternalities +}; +``` -Implementation of the sandbox runtime environment for `devnet` runtime located in `pop-node/runtime/devnet` +Add the below code at the top of your contract test file to setup sandbox and contract bundle provider for the **Pop Network Devnet** runtime: ```rs -use pop_sandbox::DevnetSandbox; +// Initialising useful variables for testing the contract. +const UNIT: Balance = 10_000_000_000; +const INIT_AMOUNT: Balance = 100_000_000 * UNIT; +const INIT_VALUE: Balance = 100 * UNIT; +const ALICE: AccountId = AccountId::new([1u8; 32]); +const BOB: AccountId = AccountId::new([2_u8; 32]); +const CHARLIE: AccountId = AccountId::new([3_u8; 32]); + +// The contract bundle provider. +// +// Reference: https://github.com/r0gue-io/pop-drink/blob/main/crates/drink/drink/test-macro/src/lib.rs +#[drink::contract_bundle_provider] +enum BundleProvider {} + +// Sandbox environment for Pop Devnet Runtime. +struct Pop { + ext: TestExternalities, +} + +impl Default for Pop { + fn default() -> Self { + // Initialising genesis state, providing accounts with an initial balance. + let balances: Vec<(AccountId, u128)> = + vec![(ALICE, INIT_AMOUNT), (BOB, INIT_AMOUNT), (CHARLIE, INIT_AMOUNT)]; + let ext = BlockBuilder::::new_ext(balances); + Self { ext } + } +} + +// Implement `Sandbox` environment for the Pop Network Devnet runtime. +drink::impl_sandbox!(Pop, Runtime, ALICE); ``` -- For `testnet` runtime +### 2. Deploy a new contract -Implementation of the sandbox runtime environment for `testnet` runtime located in `pop-node/runtime/testnet` +Import required methods and types: ```rs -use pop_sandbox::TestnetSandbox; +use drink::{assert_ok, deploy}; ``` -- For `mainnet` runtime - -Implementation of the sandbox runtime environment for `mainnet` runtime located in `pop-node/runtime/mainnet` +Instantiate and deploy a local contract with `new` constructor method: ```rs -use pop_sandbox::MainnetSandbox; +let local_contract = BundleProvider::local().unwrap(); +// Contract address is returned if a deployment succeeds. +assert_ok!(deploy( + &mut session, + local_contract, + "new", + vec![TOKEN.to_string(), MIN_BALANCE.to_string()], + vec![], + None +)); ``` -### Setup test environment for your contract +### 3. Test contract method that uses [Pop API](https://github.com/r0gue-io/pop-node/tree/main/pop-api) -Below is an example for the contract testing with `pop_drink` and `pop_sandbox` for `devnet` environment using `DevnetSandbox`. +Import required methods and types: ```rs -use pop_drink::session::Session; -use pop_sandbox::DevnetSandbox as Sandbox; +use drink::{call, session::Session}; +use pop_api::v0::fungibles::PSP22Error; +``` -#[drink::contract_bundle_provider] -enum BundleProvider {} +Example of interacting with the `transfer` method of the `Psp22` contract: -#[drink::test(sandbox = Sandbox)] -fn test(mut session: Session) { - // Your test case +```rs +// Example of a method to interact with contract via pop-drink. +fn transfer(session: &mut Session, to: AccountId, amount: Balance) -> Result<(), PSP22Error> { + // Initialising a string value of an empty array. + let empty_array = serde_json::to_string::<[u8; 0]>(&[]).unwrap(); + // Call to a contract method. + call::( + session, + "Psp22::transfer", + vec![to.to_string(), amount.to_string(), empty_array], + None, + ) } ``` -## Examples +#### If the contract throws a non-custom error: + +```rs +// Not enough balance. Failed with `InsufficientBalance`. +assert_eq!( + transfer_from(&mut session, ALICE, contract.clone(), AMOUNT + 1), + Err(PSP22Error::InsufficientBalance) +); +``` + +#### If the contract throws a custom error [`StatusCode`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/lib.rs#L33): + +[`StatusCode`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/lib.rs#L33) encapsulates a `u32` value that indicates the success or failure of a runtime call via Pop API. + +Test the contract call with `drink::Error` and `drink::assert_err`: + +- `Error`: Runtime error for testing. +- `assert_err`: Asserts that a `Result` with an error type convertible to `u32` matches the expected `Error` from pop-drink. + +```rs +use drink::{assert_err, v0::Error, Assets, AssetsError::NoAccount}; + +assert_err!( + transfer(&mut session, ALICE, AMOUNT), + Error::Module(Assets(NoAccount)) +); +``` + +## Development Guide + +To run the `examples` contracts for DRink! + +``` +cargo test --release +``` + +## Terminology + +- `crates/drink` + + - **[Session](https://github.com/r0gue-io/pop-drink/blob/main/crates/drink/drink/src/session.rs)**: Wrapper around [`Sandbox`](https://github.com/r0gue-io/pop-drink/blob/main/crates/ink-sandbox/src/lib.rs) that provides methods to interact with multiple contracts. + + - **[Sandbox](https://github.com/r0gue-io/pop-drink/blob/main/crates/ink-sandbox/src/lib.rs)**: In the context of quasi-testing with pop-drink, a sandbox refers to an isolated runtime environment that simulates the behavior of a full node, without requiring an actual node. + +- `crates/pop-drink` + + - Mentions of `API` in `crates/pop_drink` refer to `pop_api::Error`. + + - **Module Errors**: Errors returned by the Substrate runtime modules (or pallets). + + - **API Errors**: Errors returned by the Substrate runtime modules (or pallets). + +### Support -Please find more examples of `pop_drink` tests in the [`pop_drink/examples`](https://github.com/r0gue-io/pop-drink/tree/main/examples). +- Be part of our passionate community of Web3 pioneers. [Join our Telegram](https://t.me/onpopio)! +- Additionally, there are [GitHub issues](https://github.com/r0gue-io/pop-drink/issues) and + [Polkadot Stack Exchange](https://polkadot.stackexchange.com/). From fc7db5633adf0ed90e94bef3eb07601b1de1b87c Mon Sep 17 00:00:00 2001 From: chungquantin <56880684+chungquantin@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:14:50 +0700 Subject: [PATCH 2/3] chore: update readme.md --- README.md | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d505c29..c9cf0d8 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ drink = { version = "1.0.0", package = "pop-drink" } ### 1. Setup a testing environment -Import required methods and types: +- Import required methods and types: ```rs use drink::{ @@ -41,7 +41,7 @@ use drink::{ }; ``` -Add the below code at the top of your contract test file to setup sandbox and contract bundle provider for the **Pop Network Devnet** runtime: +- Add the below code at the top of your contract test file to setup sandbox and contract bundle provider for the **Pop Network Devnet** runtime: ```rs // Initialising useful variables for testing the contract. @@ -79,13 +79,13 @@ drink::impl_sandbox!(Pop, Runtime, ALICE); ### 2. Deploy a new contract -Import required methods and types: +- Import required methods and types: ```rs use drink::{assert_ok, deploy}; ``` -Instantiate and deploy a local contract with `new` constructor method: +- Instantiate and deploy a local contract with `new` constructor method: ```rs let local_contract = BundleProvider::local().unwrap(); @@ -102,14 +102,18 @@ assert_ok!(deploy( ### 3. Test contract method that uses [Pop API](https://github.com/r0gue-io/pop-node/tree/main/pop-api) -Import required methods and types: +This example interacts with a [PSP22](https://github.com/w3f/PSPs/blob/master/PSPs/psp-22.md) example contract that uses [Pop API](https://github.com/r0gue-io/pop-node/tree/main/pop-api). The contract method returns [`PSP22Error`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/v0/fungibles/errors.rs#L73C1-L73C22) which is provided by Pop API library. + +Learn more in the [PSP22 example contract](https://github.com/r0gue-io/pop-node/blob/main/pop-api/examples/fungibles/lib.rs). + +- Import required methods and types: ```rs use drink::{call, session::Session}; use pop_api::v0::fungibles::PSP22Error; ``` -Example of interacting with the `transfer` method of the `Psp22` contract: +- Example of interacting with the `transfer` method of the `Psp22` contract: ```rs // Example of a method to interact with contract via pop-drink. @@ -128,6 +132,8 @@ fn transfer(session: &mut Session, to: AccountId, amount: Balance) -> Resul #### If the contract throws a non-custom error: +Non-custom errors are fixed variants of the provided [`PSP22Error`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/v0/fungibles/errors.rs#L73C1-L73C22). + ```rs // Not enough balance. Failed with `InsufficientBalance`. assert_eq!( @@ -136,15 +142,18 @@ assert_eq!( ); ``` -#### If the contract throws a custom error [`StatusCode`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/lib.rs#L33): +#### If the contract throws a custom error: -[`StatusCode`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/lib.rs#L33) encapsulates a `u32` value that indicates the success or failure of a runtime call via Pop API. +A custom error is returned if the error doesn't conform to the [`PSP22Error`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/v0/fungibles/errors.rs#L73C1-L73C22) standard. +The custom error is represented by a [`StatusCode`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/lib.rs#L33), which encapsulates a `u32` value indicating the success or failure of a runtime call via the Pop API. -Test the contract call with `drink::Error` and `drink::assert_err`: +Pop DRink! provides an error type and a [macro](https://doc.rust-lang.org/book/ch19-06-macros.html) to simplify testing both runtime module errors and API errors. -- `Error`: Runtime error for testing. +- `drink::v0::Error`: Runtime error type for testing API V0. - `assert_err`: Asserts that a `Result` with an error type convertible to `u32` matches the expected `Error` from pop-drink. +Test the contract call if a custom error is the runtime module error: + ```rs use drink::{assert_err, v0::Error, Assets, AssetsError::NoAccount}; @@ -154,6 +163,17 @@ assert_err!( ); ``` +Test the contract call if a custom error is the API error: + +```rs +use drink::{assert_err, v0::{Error, Arithmetic, ArithmeticError::Overflow}}; + +assert_err!( + transfer(&mut session, ALICE, AMOUNT), + Error::Api(Arithmetic(Overflow)) +); +``` + ## Development Guide To run the `examples` contracts for DRink! From 2ba64df464ab31cab21796f71a001803b6c78346 Mon Sep 17 00:00:00 2001 From: chungquantin <56880684+chungquantin@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:10:46 +0700 Subject: [PATCH 3/3] fix: readme --- Cargo.lock | 23 +++++- README.md | 200 +++++++++++++++++++---------------------------------- 2 files changed, 93 insertions(+), 130 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b5fb1e..bfc9981 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3473,6 +3473,7 @@ dependencies = [ "frame-system", "log", "pallet-assets", + "pallet-nfts 31.0.0", "parity-scale-codec", "pop-chain-extension", "scale-info", @@ -3917,7 +3918,7 @@ dependencies = [ "frame-system", "log", "pallet-assets", - "pallet-nfts", + "pallet-nfts 30.0.0", "parity-scale-codec", "scale-info", "sp-runtime", @@ -3943,13 +3944,29 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-nfts" +version = "31.0.0" +dependencies = [ + "enumflags2", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", +] + [[package]] name = "pallet-nfts-runtime-api" version = "22.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0ca7a0446d2d3c27f726a016c6366218df2e0bfef9ed35886b252cfa9757f6c" dependencies = [ - "pallet-nfts", + "pallet-nfts 30.0.0", "parity-scale-codec", "sp-api", "sp-std", @@ -4737,7 +4754,7 @@ dependencies = [ "pallet-message-queue", "pallet-multisig", "pallet-nft-fractionalization", - "pallet-nfts", + "pallet-nfts 31.0.0", "pallet-nfts-runtime-api", "pallet-preimage", "pallet-proxy", diff --git a/README.md b/README.md index c9cf0d8..807895b 100644 --- a/README.md +++ b/README.md @@ -15,163 +15,125 @@ Forked version of [inkdevhub/drink](https://github.com/inkdevhub/drink) for E2E About the repository folder structure: -- `crates/drink` - - `drink`: DRink! is a toolbox for ink! developers that allows for a fully functional ink! contract development without any running node. - - `drink-cli`: Simple command line tool to help you play with your local contracts in a convenient way. - - `examples`: A collection of example contracts tested with DRink! -- `crates/ink-sandbox`: In the context of quasi-testing with pop-drink, a sandbox refers to an isolated runtime environment that simulates the behavior of a full node, without requiring an actual node. -- `crates/pop-drink`: Provides utility methods for testing contract methods with DRink! and Pop Network runtimes. +- [pop-drink](/crates/pop-drink): Provides utility methods for testing contract methods with DRink! and Pop Network runtimes. +- [examples](/crates/drink/examples): A collection of example contracts tested with DRink! +- [drink](/crates/drink/drink): DRink! is a toolbox for ink! developers that allows for a fully functional ink! contract development without any running node. +- [ink-sandbox](/crates/ink-sandbox): Sandbox refers to an isolated runtime environment that simulates the behavior of a full node, without requiring an actual node. +- [drink-cli](/crates/drink/drink-cli): Simple command line tool to help you play with your local contracts in a convenient way. ## Getting Started -- Add `pop-drink` crate to your contract `Cargo.toml`: +Add `pop-drink` crate to your contract `Cargo.toml`: ```toml drink = { version = "1.0.0", package = "pop-drink" } ``` -### 1. Setup a testing environment +### Setup a testing environment -- Import required methods and types: +Please see ["Quick start with DRink!"](/crates/drink/examples/quick-start-with-drink/README.md) for a detailed explanation. + +Add the below code at the top of your contract test file to setup [Sandbox](TODO) for the [**Pop Network Devnet**](https://github.com/r0gue-io/pop-node/tree/main/runtime/devnet) runtime. ```rs -use drink::{ - devnet::{AccounId, Balance}, - TestExternalities -}; +#[derive(Default)] +struct Sandbox; + +// Implement `Sandbox` environment for the Pop Network Devnet runtime. +drink::impl_sandbox!(Sandbox, drink::devnet::Runtime, ALICE); ``` -- Add the below code at the top of your contract test file to setup sandbox and contract bundle provider for the **Pop Network Devnet** runtime: +## Writing tests -```rs -// Initialising useful variables for testing the contract. -const UNIT: Balance = 10_000_000_000; -const INIT_AMOUNT: Balance = 100_000_000 * UNIT; -const INIT_VALUE: Balance = 100 * UNIT; -const ALICE: AccountId = AccountId::new([1u8; 32]); -const BOB: AccountId = AccountId::new([2_u8; 32]); -const CHARLIE: AccountId = AccountId::new([3_u8; 32]); - -// The contract bundle provider. -// -// Reference: https://github.com/r0gue-io/pop-drink/blob/main/crates/drink/drink/test-macro/src/lib.rs -#[drink::contract_bundle_provider] -enum BundleProvider {} +### Writing tests -// Sandbox environment for Pop Devnet Runtime. -struct Pop { - ext: TestExternalities, -} +Your typical test module will look like (See ["Quick start with DRink!"](/crates/drink/examples/quick-start-with-drink/README.md) example tests): -impl Default for Pop { - fn default() -> Self { - // Initialising genesis state, providing accounts with an initial balance. - let balances: Vec<(AccountId, u128)> = - vec![(ALICE, INIT_AMOUNT), (BOB, INIT_AMOUNT), (CHARLIE, INIT_AMOUNT)]; - let ext = BlockBuilder::::new_ext(balances); - Self { ext } - } -} +```rust +#[cfg(test)] +mod tests { + use drink::session::{Session, NO_ARGS, None, NO_SALT}; -// Implement `Sandbox` environment for the Pop Network Devnet runtime. -drink::impl_sandbox!(Pop, Runtime, ALICE); -``` + #[drink::contract_bundle_provider] + enum BundleProvider {} -### 2. Deploy a new contract + #[drink::test] + fn deploy_and_call_a_contract(mut session: Session) -> Result<(), Box> { + let result: bool = session + .deploy_bundle_and(BundleProvider::local(), "new", &["true"], NO_SALT, None)? + .call_and("flip", NO_ARGS, None)? + .call_and("flip", NO_ARGS, None)? + .call_and("flip", NO_ARGS, None)? + .call("get", NO_ARGS, None)??; + assert_eq!(result, false); + } +} +``` -- Import required methods and types: +So, firstly, you declare a bundle provider like: -```rs -use drink::{assert_ok, deploy}; +```rust +#[drink::contract_bundle_provider] +enum BundleProvider {} ``` -- Instantiate and deploy a local contract with `new` constructor method: +It will take care of building all contract dependencies in the compilation phase and gather all contract bundles into a single registry. +Then, you will be able to get a contract bundle by calling: -```rs -let local_contract = BundleProvider::local().unwrap(); -// Contract address is returned if a deployment succeeds. -assert_ok!(deploy( - &mut session, - local_contract, - "new", - vec![TOKEN.to_string(), MIN_BALANCE.to_string()], - vec![], - None -)); +```rust +let bundle = BundleProvider::local()?; // for the contract from the current crate +let bundle = BundleProvider::Flipper.bundle()?; // for the contract from the `flipper` crate ``` -### 3. Test contract method that uses [Pop API](https://github.com/r0gue-io/pop-node/tree/main/pop-api) +We mark each testcase with `#[drink::test]` attribute and declare return type as `Result` so that we can use the `?` operator: -This example interacts with a [PSP22](https://github.com/w3f/PSPs/blob/master/PSPs/psp-22.md) example contract that uses [Pop API](https://github.com/r0gue-io/pop-node/tree/main/pop-api). The contract method returns [`PSP22Error`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/v0/fungibles/errors.rs#L73C1-L73C22) which is provided by Pop API library. +```rust +#[drink::test] +fn testcase() -> Result<(), Box> { + // ... +} +``` + +Then, we can use the `Session` API to interact with both contracts and the whole runtime. +For details, check out testcases in [lib.rs](lib.rs). -Learn more in the [PSP22 example contract](https://github.com/r0gue-io/pop-node/blob/main/pop-api/examples/fungibles/lib.rs). +### Writing tests for methods using [Pop API](https://github.com/r0gue-io/pop-node/tree/main/pop-api) -- Import required methods and types: +Pop DRink! also provides [utilitiy methods](/crates/pop-drink/src/lib.rs) that you can use to test your contracts. This example interacts with a [PSP22 example contract](https://github.com/r0gue-io/pop-node/blob/main/pop-api/examples/fungibles/lib.rs) that uses [Pop API](https://github.com/r0gue-io/pop-node/tree/main/pop-api). The contract method returns [`PSP22Error`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/v0/fungibles/errors.rs#L73C1-L73C22) custom error which is provided by Pop API library. ```rs +// Import required methods and types. use drink::{call, session::Session}; use pop_api::v0::fungibles::PSP22Error; -``` - -- Example of interacting with the `transfer` method of the `Psp22` contract: -```rs -// Example of a method to interact with contract via pop-drink. +// Interact with `transfer` method of the `Psp22` contract. fn transfer(session: &mut Session, to: AccountId, amount: Balance) -> Result<(), PSP22Error> { - // Initialising a string value of an empty array. let empty_array = serde_json::to_string::<[u8; 0]>(&[]).unwrap(); - // Call to a contract method. - call::( - session, - "Psp22::transfer", - vec![to.to_string(), amount.to_string(), empty_array], - None, - ) -} -``` + let input = vec![to.to_string(), amount.to_string(), empty_array]; -#### If the contract throws a non-custom error: - -Non-custom errors are fixed variants of the provided [`PSP22Error`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/v0/fungibles/errors.rs#L73C1-L73C22). - -```rs -// Not enough balance. Failed with `InsufficientBalance`. -assert_eq!( - transfer_from(&mut session, ALICE, contract.clone(), AMOUNT + 1), - Err(PSP22Error::InsufficientBalance) -); + call::(session, "Psp22::transfer", input, None) +} ``` -#### If the contract throws a custom error: - -A custom error is returned if the error doesn't conform to the [`PSP22Error`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/v0/fungibles/errors.rs#L73C1-L73C22) standard. -The custom error is represented by a [`StatusCode`](https://github.com/r0gue-io/pop-node/blob/main/pop-api/src/lib.rs#L33), which encapsulates a `u32` value indicating the success or failure of a runtime call via the Pop API. - -Pop DRink! provides an error type and a [macro](https://doc.rust-lang.org/book/ch19-06-macros.html) to simplify testing both runtime module errors and API errors. - -- `drink::v0::Error`: Runtime error type for testing API V0. -- `assert_err`: Asserts that a `Result` with an error type convertible to `u32` matches the expected `Error` from pop-drink. - -Test the contract call if a custom error is the runtime module error: +Asserts the returned error to an [`Error`](TODO) type using [`assert_err!`](TODO) to test errors of a runtime call. ```rs use drink::{assert_err, v0::Error, Assets, AssetsError::NoAccount}; -assert_err!( - transfer(&mut session, ALICE, AMOUNT), - Error::Module(Assets(NoAccount)) -); +#[drink::test(sandbox = Pop)] +fn test_transfer_to_no_account() { + // Test the contract call if a custom error is the runtime module error. + assert_err!( + transfer(&mut session, ALICE, AMOUNT), + Error::Module(Assets(NoAccount)) + ); +} ``` -Test the contract call if a custom error is the API error: +We need to specify the sandbox of Pop Network runtime for a testcase if the contract is using Pop API. ```rs -use drink::{assert_err, v0::{Error, Arithmetic, ArithmeticError::Overflow}}; - -assert_err!( - transfer(&mut session, ALICE, AMOUNT), - Error::Api(Arithmetic(Overflow)) -); +#[drink::test(sandbox = Pop)] ``` ## Development Guide @@ -182,22 +144,6 @@ To run the `examples` contracts for DRink! cargo test --release ``` -## Terminology - -- `crates/drink` - - - **[Session](https://github.com/r0gue-io/pop-drink/blob/main/crates/drink/drink/src/session.rs)**: Wrapper around [`Sandbox`](https://github.com/r0gue-io/pop-drink/blob/main/crates/ink-sandbox/src/lib.rs) that provides methods to interact with multiple contracts. - - - **[Sandbox](https://github.com/r0gue-io/pop-drink/blob/main/crates/ink-sandbox/src/lib.rs)**: In the context of quasi-testing with pop-drink, a sandbox refers to an isolated runtime environment that simulates the behavior of a full node, without requiring an actual node. - -- `crates/pop-drink` - - - Mentions of `API` in `crates/pop_drink` refer to `pop_api::Error`. - - - **Module Errors**: Errors returned by the Substrate runtime modules (or pallets). - - - **API Errors**: Errors returned by the Substrate runtime modules (or pallets). - ### Support - Be part of our passionate community of Web3 pioneers. [Join our Telegram](https://t.me/onpopio)!