Skip to content

Commit

Permalink
Merge pull request #22 from r0gue-io/daan/docs-drink
Browse files Browse the repository at this point in the history
docs: drink
  • Loading branch information
Daanvdplas authored Oct 18, 2024
2 parents 98244cd + dc38f73 commit 2710891
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 353 deletions.
23 changes: 3 additions & 20 deletions Cargo.lock

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

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).
5 changes: 1 addition & 4 deletions crates/pop-drink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
scale-info = { workspace = true, default-features = false, features = [
"derive",
] }

drink.workspace = true
ink_sandbox.workspace = true
pallet-contracts.workspace = true
Expand All @@ -19,6 +15,7 @@ scale.workspace = true
pop-api.workspace = true

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

0 comments on commit 2710891

Please sign in to comment.