Skip to content

Commit

Permalink
Merge pull request #26 from r0gue-io/chungquantin/feat-testnet
Browse files Browse the repository at this point in the history
feat(pop-drink): add testnet runtime environment
  • Loading branch information
chungquantin authored Nov 7, 2024
2 parents e131e72 + 7dcf51b commit cfbc763
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 82 deletions.
90 changes: 83 additions & 7 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
1 change: 1 addition & 0 deletions crates/pop-drink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
101 changes: 68 additions & 33 deletions crates/pop-drink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, *};

Expand All @@ -37,15 +54,33 @@ pub mod devnet {
}
}

// Types used in the pop runtime.
pub type Balance = BalanceFor<Runtime>;
pub type AccountId = AccountIdFor<Runtime>;
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<v0::Error, pop_runtime_testnet::RuntimeError, 3>;
}
}

define_runtime_utilities!(Runtime);
}

/// Deploy a contract with a given constructor, arguments, salt and an initial value. In
Expand All @@ -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<Pop, ContractError>(&mut session, bundle, "new", input, salt, init_value));
/// // Deploy contract.
/// //
/// // `ContractError` is the error type used by the contract.
/// assert_ok!(deploy<Pop, ContractError>(&mut session, bundle, "new", input, salt, init_value));
/// }
/// ```
pub fn deploy<S, E>(
Expand Down Expand Up @@ -116,19 +151,19 @@ where
/// ```rs
/// #[drink::test(sandbox = Pop)]
/// fn call_works(mut session: Session) {
/// let bundle = BundleProvider::local().unwrap();
/// assert_ok!(deploy<Pop, ContractError>(&mut session, bundle, "new", input, salt, init_value));
/// let bundle = BundleProvider::local().unwrap();
/// assert_ok!(deploy<Pop, ContractError>(&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::<Pop, (), ContractError>(
/// 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::<Pop, (), ContractError>(
/// session,

Check warning on line 162 in crates/pop-drink/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

using tabs in doc comments is not recommended

warning: using tabs in doc comments is not recommended --> crates/pop-drink/src/lib.rs:162:8 | 162 | /// session, | ^^^^ help: consider using four spaces per tab | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
/// "transfer",

Check warning on line 163 in crates/pop-drink/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

using tabs in doc comments is not recommended

warning: using tabs in doc comments is not recommended --> crates/pop-drink/src/lib.rs:163:8 | 163 | /// "transfer", | ^^^^ help: consider using four spaces per tab | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
/// input,

Check warning on line 164 in crates/pop-drink/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

using tabs in doc comments is not recommended

warning: using tabs in doc comments is not recommended --> crates/pop-drink/src/lib.rs:164:8 | 164 | /// input, | ^^^^ help: consider using four spaces per tab | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
/// init_value,

Check warning on line 165 in crates/pop-drink/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

using tabs in doc comments is not recommended

warning: using tabs in doc comments is not recommended --> crates/pop-drink/src/lib.rs:165:8 | 165 | /// init_value, | ^^^^ help: consider using four spaces per tab | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
/// )
/// }
/// ```
pub fn call<S, O, E>(
Expand Down Expand Up @@ -171,12 +206,12 @@ where
/// use drink::last_contract_event;
///
/// assert_eq!(
/// last_contract_event::<Pop>(&session).unwrap(),
/// ContractEvent {
/// value: 42,
/// }
/// .encode()
/// .as_slice()
/// last_contract_event::<Pop>(&session).unwrap(),
/// ContractEvent {
/// value: 42,

Check warning on line 211 in crates/pop-drink/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

using tabs in doc comments is not recommended

warning: using tabs in doc comments is not recommended --> crates/pop-drink/src/lib.rs:211:8 | 211 | /// value: 42, | ^^^^ help: consider using four spaces per tab | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments
/// }
/// .encode()
/// .as_slice()
/// );
/// ```
pub fn last_contract_event<S>(session: &Session<S>) -> Option<Vec<u8>>
Expand Down
Loading

0 comments on commit cfbc763

Please sign in to comment.