#pink #ink #phat-contract

drink-pink-runtime

A drink runtime implementation for Phat Contract

9 stable releases

1.2.16-dev.1 Feb 21, 2024
1.2.16-dev.0 Feb 20, 2024
1.2.15 Jan 30, 2024
1.2.14 Dec 27, 2023
1.2.7 Nov 16, 2023

#3 in #phat-contract


Used in 2 crates

Apache-2.0

1MB
1.5K SLoC

drink-pink-runtime

Overview

drink-pink-runtime is a runtime implementation for drink framework for Pink contract environment. It extends Drink functionalities, offering a more convenient approach to writing strongly-typed tests for Pink contracts. This crate simplifies testing by simulating contract deployment, transaction execution, and queries in a Pink contract environment.

Installation

To include drink-pink-runtime in your project, add it to your Cargo.toml:

[dependencies]
pink-extension = "0.5"
drink = "0.8.0"
drink-pink-runtime = "1.2"

Usage

Here's an example demonstrating the basic usage of drink-pink-runtime. This includes setting up a test environment, deploying a contract bundle, and simulating transactions and queries.

#[cfg(test)]
mod tests {
    use drink_pink_runtime::{PinkRuntime, SessionExt, DeployBundle, Callable};
    use drink::session::Session;
    use super::YourContractRef;

    // This would compile all contracts dependended by your contract
    #[drink::contract_bundle_provider]
    enum BundleProvider {}

    #[test]
    fn example_test() -> Result<(), Box<dyn std::error::Error>> {
        let mut session = Session::<PinkRuntime>::new()?;

        // Deploy a contract bundle
        let contract_ref = YourContractRef::new().deploy_bundle(&BundleProvider::local()?, &mut session)?;

        // Set the deployed contract as a driver
        session.set_driver("YourDriverName", &contract_ref)?;

        // Simulate a transaction
        contract_ref.call_mut().your_transaction_method().submit_tx(&mut session)?;

        // Simulate a query
        let query_result = contract_ref.call().your_query_method().query(&mut session)?;

        Ok(())
    }
}

Dependencies

~93MB
~1.5M SLoC