Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: runtime error #14

Merged
merged 27 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ddb5806
feat: add runtime error
chungquantin Oct 3, 2024
6f609f2
feat: into psp22 error
chungquantin Oct 3, 2024
4b9c94a
feat: u32 conversion
chungquantin Oct 4, 2024
a6c4b5c
feat: better runtime error
chungquantin Oct 4, 2024
6cf56a6
refactor: pop_primitive dispatch error conversion
chungquantin Oct 4, 2024
22732d3
Merge pull request #16 from r0gue-io/chungquantin/refactor-pop_primit…
chungquantin Oct 4, 2024
63ed93d
refactor: error module conversion
chungquantin Oct 7, 2024
0936849
Merge branch 'daan/feat-assets' into chungquantin/feat-runtime_error
chungquantin Oct 7, 2024
201a9b9
feat: add versioning
chungquantin Oct 8, 2024
5851852
feat: generic runtime error
chungquantin Oct 8, 2024
6cd8dbb
fix: comments
chungquantin Oct 8, 2024
b17157f
fix: resolve comments
chungquantin Oct 9, 2024
9450444
refactor: unwrap_or_else
chungquantin Oct 9, 2024
c1a6fea
fix: example
chungquantin Oct 9, 2024
c598eae
fix: comments
chungquantin Oct 10, 2024
c3a13c3
fix: update doc
chungquantin Oct 11, 2024
c4f6a87
fix: doc
chungquantin Oct 11, 2024
5ea730b
fix: doc
chungquantin Oct 11, 2024
30405b4
fix: doc
chungquantin Oct 15, 2024
364766f
fix: doc
chungquantin Oct 15, 2024
98244cd
fix: docs
chungquantin Oct 15, 2024
4ac3fab
docs: drink
Daanvdplas Oct 16, 2024
1a585d5
fix: comments
Daanvdplas Oct 17, 2024
aaf322c
fix: Cargo.lock
Daanvdplas Oct 17, 2024
dc38f73
refactor
Daanvdplas Oct 17, 2024
2710891
Merge pull request #22 from r0gue-io/daan/docs-drink
Daanvdplas Oct 18, 2024
59ae0eb
remove: pallet-api
Daanvdplas Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
[workspace]
resolver = "2"
members = [
"crates/ink-sandbox",
"crates/drink/drink",
"crates/drink/drink-cli",
"crates/drink/drink/test-macro",
"crates/pop-drink",
]
exclude = [
"crates/drink/examples",
"crates/ink-sandbox",
"crates/drink/drink",
"crates/drink/drink-cli",
"crates/drink/drink/test-macro",
"crates/pop-drink",
]
exclude = ["crates/drink/examples"]

[workspace.package]
edition = "2021"
Expand All @@ -32,7 +30,7 @@ proc-macro2 = { version = "1" }
quote = { version = "1" }
ratatui = { version = "0.21.0" }
scale = { package = "parity-scale-codec", version = "3.6.9", features = [
"derive",
"derive",
] }
scale-info = { version = "2.10.0" }
serde_json = { version = "1.0" }
Expand All @@ -56,6 +54,6 @@ sp-runtime-interface = { version = "28.0.0", features = ["std"] }
# Local
drink = { path = "crates/drink/drink" }
ink_sandbox = { path = "crates/ink-sandbox" }
pop-api = { path = "../pop-node/pop-api" }
pop-drink = { path = "crates/pop-drink" }
pop-runtime-devnet = { path = "../pop-node/runtime/devnet" }
pop-api = { path = "../pop-node/pop-api" }
99 changes: 58 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,85 @@
<h1 align="center"> Pop DRink! (forked from DRink!) </h1>
<p align="center"> <b>D</b>echained <b>R</b>eady-to-play <b>ink!</b> playground </p>
<div align="center">
<h1>Pop DRink!</h1>

> [!IMPORTANT]
> This repository is customized and maintained for Pop API contract end-to-end testing.
>
> Quasi tests must be run with `cargo test --release`.
<a href="r0gue.io"><img width="100px" style="border-radius:10px;" src="https://github.com/user-attachments/assets/96830651-c3db-412a-9cb4-6fcd8ea6231b" alt="R0GUE Logo" /></a>

# 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 of smart contract using the [Pop API](https://github.com/r0gue-io/pop-node/tree/main/pop-api) on Pop Network.

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.
</div>

## Overview

About the repository folder structure:

- [pop-drink](/crates/pop-drink): Library for testing contracts deployed on Pop Network using drink.
- [drink](/crates/drink/drink): drink is a toolbox for ink! developers to test contracts in a sandbox environment.
- [ink-sandbox](/crates/ink-sandbox): Creates a sandbox environment for a given runtime, without having to run a node.
- [examples](/crates/drink/examples): A collection of example contracts tested with drink.
- [drink-cli](/crates/drink/drink-cli): Simple command line tool to help you play with your local contracts in a convenient way.

## 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

- For `devnet` runtime

Implementation of the sandbox runtime environment for `devnet` runtime located in `pop-node/runtime/devnet`
Set up your pop-drink test environment and write your first test.

```rs
use pop_sandbox::DevnetSandbox;
```
use drink::{
devnet::{AccountId, Balance, Runtime},
TestExternalities,
deploy, call,
};

- For `testnet` runtime

Implementation of the sandbox runtime environment for `testnet` runtime located in `pop-node/runtime/testnet`
// Builds your contract(s).
#[drink::contract_bundle_provider]
enum BundleProvider {}

```rs
use pop_sandbox::TestnetSandbox;
```
/// Sandbox environment for Pop Devnet Runtime.
pub struct Pop {
ext: TestExternalities,
}

- For `mainnet` runtime
// Initialising genesis state.
impl Default for Pop {
fn default() -> Self {
let balances: Vec<(AccountId, Balance)> = vec![(ALICE, 100u128)];
let ext = BlockBuilder::<Runtime>::new_ext(balances);
Self { ext }
}
}

Implementation of the sandbox runtime environment for `mainnet` runtime located in `pop-node/runtime/mainnet`
// Implement core functionalities for the `Pop` sandbox.
drink::impl_sandbox!(Pop, Runtime, ALICE);

```rs
use pop_sandbox::MainnetSandbox;
// Write your first pop-drink test!
#[drink::test(sandbox = Pop)]
fn test(mut session: Session) { ... }
```

### Setup test environment for your contract
Important: run your tests with `--release`
```
cargo test --release
```

Below is an example for the contract testing with `pop_drink` and `pop_sandbox` for `devnet` environment using `DevnetSandbox`.
## Learn more

```rs
use pop_drink::session::Session;
use pop_sandbox::DevnetSandbox as Sandbox;
Dive into the ["quick start with drink!"](/crates/drink/examples/quick-start-with-drink/README.md) to learn more about drink. Also check out the other examples provided by drink.

#[drink::contract_bundle_provider]
enum BundleProvider {}
If you are interested in learning more about testing contracts using the Pop API, check out the [example contracts](https://github.com/r0gue-io/pop-node/tree/main/pop-api/examples) tested with pop-drink!

#[drink::test(sandbox = Sandbox)]
fn test(mut session: Session) {
// Your test case
}
```
## Support

Be part of our passionate community of Web3 builders. [Join our Telegram](https://t.me/onpopio)!

## Examples
Feel free to contribute to `drink` or `pop-drink` to help improve testing ink! smart contracts!

Please find more examples of `pop_drink` tests in the [`pop_drink/examples`](https://github.com/r0gue-io/pop-drink/tree/main/examples).
For any questions related to ink! you can also go to [Polkadot Stack Exchange](https://polkadot.stackexchange.com/) or ask the [ink! community](https://t.me/inkathon/1).
8 changes: 4 additions & 4 deletions crates/drink/drink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub use drink_test_macro::{contract_bundle_provider, test};
pub use errors::Error;
pub use frame_support;
pub use ink_sandbox::{
self, api as sandbox_api, create_sandbox, impl_sandbox,
pallet_balances, pallet_contracts, pallet_timestamp, sp_externalities, AccountId32,
DispatchError, Sandbox, Ss58Codec, Weight,
self, api as sandbox_api, create_sandbox, impl_sandbox, pallet_assets, pallet_balances,
pallet_contracts, pallet_timestamp, sp_externalities, AccountId32, DispatchError, Sandbox,
Ss58Codec, Weight,
};
#[cfg(feature = "session")]
pub use session::mock::{mock_message, ContractMock, MessageMock, MockedCallResult, Selector};
Expand All @@ -28,4 +28,4 @@ pub mod minimal {

// create_sandbox!(MinimalSandbox);
create_sandbox!(MinimalSandbox, (), crate::pallet_contracts_debugging::DrinkDebug);
}
}
8 changes: 7 additions & 1 deletion crates/pop-drink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ edition = "2021"
[dependencies]
drink.workspace = true
ink_sandbox.workspace = true
pop-runtime-devnet.workspace = true
pallet-contracts.workspace = true
pop-runtime-devnet.workspace = true
frame-system.workspace = true
frame-support.workspace = true
sp-io.workspace = true
scale.workspace = true
pop-api.workspace = true

[dev-dependencies]
scale-info = { workspace = true, features = ["derive"] }
pallet-assets.workspace = true
pallet-balances.workspace = true
pallet-timestamp.workspace = true
Loading
Loading