forked from inkdevhub/drink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from r0gue-io/daan/docs-drink
docs: drink
- Loading branch information
Showing
5 changed files
with
296 additions
and
353 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.