Skip to content

Commit

Permalink
Merge pull request #1427 from Phala-Network/drink
Browse files Browse the repository at this point in the history
Example for testing with drink
  • Loading branch information
kvinwang authored Nov 20, 2023
2 parents 521fd07 + bb6e777 commit 1232a43
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 32 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/pink-drivers/log_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink = { version = "4", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"], optional = true }

pink-extension = { version = "0.4", default-features = false, path = "../../pink/pink-extension", features = ["ink-as-dependency"] }
pink-extension = { default-features = false, path = "../../pink/pink-extension" }
this-crate = { path = "../../this-crate" }

[build-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/pink-drivers/sidevm_deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ink = { version = "4", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"], optional = true }

pink-extension = { version = "0.4", default-features = false, path = "../../pink/pink-extension", features = ["ink-as-dependency"] }
system = { version = "1.0", default-features = false, path = "../system", features = ["ink-as-dependency"] }
pink-extension = { default-features = false, path = "../../pink/pink-extension" }
system = { version = "1.0", default-features = false, path = "../system" }
this-crate = { path = "../../this-crate" }

[lib]
Expand Down
2 changes: 1 addition & 1 deletion crates/pink-drivers/system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ink = { version = "4", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"], optional = true }

pink-extension = { version = "0.4", default-features = false, path = "../../pink/pink-extension" }
pink-extension = { default-features = false, path = "../../pink/pink-extension" }
this-crate = { path = "../../this-crate" }

[lib]
Expand Down
2 changes: 1 addition & 1 deletion crates/pink-drivers/tokenomic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ink = { version = "4", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"], optional = true }

pink-extension = { version = "0.4", default-features = false, path = "../../../crates/pink/pink-extension" }
pink-extension = { default-features = false, path = "../../../crates/pink/pink-extension" }
this-crate = { path = "../../this-crate" }

[build-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/pink-libs/s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ description = "Simple S3 client for Phala's pink"
homepage = "https://github.com/Phala-Network/phala-blockchain"
license = "Apache-2.0"
name = "pink-s3"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
keywords = ["phat-contract", "pink", "ink", "S3"]

[dependencies]
pink-extension = { version = "0.4.0", default-features = false, path = "../../pink/pink-extension" }
pink-extension = { version = "0.5.0", default-features = false, path = "../../pink/pink-extension" }
scale = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"], optional = true }
sha2 = { version = "0.10.2", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions crates/pink-libs/subrpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pink-subrpc"
version = "0.4.3"
version = "0.5.0"
authors = ["Phala Network"]
edition = "2021"
license = "Apache-2.0"
Expand All @@ -21,7 +21,7 @@ hex-literal = "0.4.1"
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
impl-serde = { version = "0.4.0", optional = true }

pink-extension = { version = "0.4", path = "../../pink/pink-extension", default-features = false, features = ["ink-as-dependency"] }
pink-extension = { version = "0.5", path = "../../pink/pink-extension", default-features = false }
sp-core-hashing = { version = "9", default-features = false }

serde = { version = "1.0.140", default-features = false, features = ["derive", "alloc"]}
Expand All @@ -31,7 +31,7 @@ ss58-registry = { version = "1.33.0", default-features = false }
base58 = { version = "0.2.0", default-features = false }

[dev-dependencies]
pink-extension-runtime = { version = "0.4", path = "../../pink/pink-extension-runtime" }
pink-extension-runtime = { path = "../../pink/pink-extension-runtime" }
xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false, features = ["std"] }

[features]
Expand Down
4 changes: 2 additions & 2 deletions crates/pink-libs/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pink-utils"
version = "0.4.1"
version = "0.5.0"
edition = "2021"
description = "Useful utilities for pink"
homepage = "https://github.com/Phala-Network/phala-blockchain"
Expand All @@ -13,7 +13,7 @@ ink = { version = "4", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"], optional = true }

pink-extension = { version = "0.4.0", default-features = false, path = "../../pink/pink-extension" }
pink-extension = { version = "0.5.0", default-features = false, path = "../../pink/pink-extension" }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/pink/pink-extension-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ description = "Mock pink chain extension for Phala pink contract"
homepage = "https://github.com/Phala-Network/phala-blockchain"
license = "Apache-2.0"
name = "pink-extension-runtime"
version = "0.4.6"
version = "0.5.0"
edition = "2021"

[dependencies]
pink-extension = { version = "0.4.5", path = "../pink-extension" }
pink-extension = { version = "0.5.0", path = "../pink-extension" }
reqwest-env-proxy = { version = "0.1", path = "../../reqwest-env-proxy" }
sp-core = { version = "21", features = ["full_crypto"] }
sp-runtime-interface = { version = "17", features = ["disable_target_static_assertions"] }
Expand Down
5 changes: 2 additions & 3 deletions crates/pink/pink-extension/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pink-extension"
version = "0.4.6"
version = "0.5.0"
edition = "2018"
description = "Phala's ink! for writing phat contracts"
license = "Apache-2.0"
Expand All @@ -20,7 +20,7 @@ num_enum = { version = "0.6", default-features = false }
insta = "1.7.2"

[features]
default = ["std", "runtime_utils", "ink-as-dependency"]
default = ["std", "runtime_utils"]
std = [
"ink/std",
"scale/std",
Expand All @@ -29,4 +29,3 @@ std = [
]
runtime_utils = ["std"]
dlmalloc = ["ink/no-allocator", "dep:dlmalloc"]
ink-as-dependency = []
2 changes: 1 addition & 1 deletion crates/pink/pink-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To get started with Pink!, add the following dependency to your `Cargo.toml`:
```toml
[dependencies]
ink = { version = "4", default-features = false }
pink = { package = "pink-extension", version = "0.4", default-features = false }
pink = { package = "pink-extension", version = "0.5", default-features = false }

[features]
std = [
Expand Down
2 changes: 1 addition & 1 deletion crates/pink/pink-extension/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ink::env::{emit_event, topics::state::HasRemainingTopics, Environment, Topic
use ink::EnvAccess;
use scale::{Decode, Encode};

pub use pink_extension_macro::contract;
pub use pink_extension_macro::{contract, driver};

pub mod chain_extension;
pub use chain_extension::pink_extension_instance as ext;
Expand Down
10 changes: 7 additions & 3 deletions e2e/contracts/check_system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ ink = { version = "4", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"], optional = true }

pink-extension = { version = "0.4", default-features = false, path = "../../../crates/pink/pink-extension" }
phat_js = { version = "0.1.5", default-features = false }
pink-extension = { default-features = false, path = "../../../crates/pink/pink-extension" }
phat_js = { version = "0.2.0", default-features = false }

[dependencies.indeterministic_functions]
version = "0.1"
default-features = false
path = "../indeterministic_functions"
features = ["ink-as-dependency"]

[dev-dependencies]
drink = "0.8.0"
drink-pink-runtime = "1.2.5"

[build-dependencies]
sp-core = "7"
sp-core = "25"

[lib]
name = "check_system"
Expand Down
52 changes: 51 additions & 1 deletion e2e/contracts/check_system/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ mod check_system {
use pink::system::{ContractDeposit, DriverError, Result, SystemRef};
use pink::PinkEnvironment;

use phat_js as js;
use alloc::string::String;
use indeterministic_functions::Usd;
use phat_js as js;

#[ink(storage)]
pub struct CheckSystem {
on_block_end_called: bool,
flag: u32,
}

impl CheckSystem {
Expand All @@ -26,6 +27,7 @@ mod check_system {
pub fn default() -> Self {
Self {
on_block_end_called: false,
flag: 0,
}
}

Expand Down Expand Up @@ -153,6 +155,30 @@ mod check_system {
String::from_utf8(response.body).unwrap_or_default(),
)
}

#[ink(message)]
pub fn system_contract_version(&self) -> (u16, u16, u16) {
pink::system::SystemRef::instance().version()
}

#[ink(message)]
pub fn eval_javascript(
&self,
script: String,
args: Vec<String>,
) -> Result<js::Output, String> {
js::eval(&script, &args)
}

#[ink(message)]
pub fn set_flag(&mut self, flag: u32) {
self.flag = flag;
}

#[ink(message)]
pub fn get_flag(&self) -> u32 {
self.flag
}
}

impl ContractDeposit for CheckSystem {
Expand All @@ -169,4 +195,28 @@ mod check_system {
Ok(())
}
}

#[cfg(test)]
mod tests {
use drink::session::Session;
use drink_pink_runtime::{Callable, DeployBundle, PinkRuntime};
use ink::codegen::TraitCallBuilder;

use super::CheckSystemRef;

#[drink::contract_bundle_provider]
enum BundleProvider {}

#[test]
fn it_works() -> Result<(), Box<dyn std::error::Error>> {
let mut session = Session::<PinkRuntime>::new()?;
let mut checker = CheckSystemRef::default()
.deploy_bundle(&BundleProvider::local()?, &mut session)
.expect("Failed to deploy checker contract");
checker.call_mut().set_flag(42).submit_tx(&mut session)?;
let flag = checker.call().get_flag().query(&mut session)?;
assert_eq!(flag, 42);
Ok(())
}
}
}
4 changes: 2 additions & 2 deletions standalone/pruntime/Cargo.lock

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

0 comments on commit 1232a43

Please sign in to comment.