Skip to content

Commit

Permalink
Merge pull request #1310 from Phala-Network/fix-e2e
Browse files Browse the repository at this point in the history
e2e: Fix delegate call types
  • Loading branch information
kvinwang authored Jun 15, 2023
2 parents 54615cd + 2a3ebd5 commit c8fda69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 58 deletions.
2 changes: 2 additions & 0 deletions e2e/contracts/check_system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ scale = { package = "parity-scale-codec", version = "3", default-features = fals
scale-info = { version = "2", 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.1", default-features = false }

[dependencies.indeterministic_functions]
version = "0.1"
Expand All @@ -34,6 +35,7 @@ default = ["std"]
std = [
"ink/std",
"scale/std",
"phat_js/std",
"scale-info/std",
"pink-extension/std",
"indeterministic_functions/std",
Expand Down
63 changes: 5 additions & 58 deletions e2e/contracts/check_system/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod check_system {
use pink::system::{ContractDeposit, DriverError, Result, SystemRef};
use pink::PinkEnvironment;

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

Expand Down Expand Up @@ -83,10 +83,10 @@ mod check_system {
call::ExecutionInput::new(call::Selector::new(0xafead99e_u32.to_be_bytes()))
.push_arg(json),
)
.returns::<ink::MessageResult<Option<Usd>>>()
.returns::<Option<Usd>>()
.invoke();
pink::info!("parse_usd result: {result:?}");
result.unwrap()
result
}

#[ink(message)]
Expand All @@ -96,7 +96,7 @@ mod check_system {
script: String,
args: Vec<String>,
) -> Result<js::Output, String> {
js::eval(delegate, &script, args)
js::eval_with(delegate, &script, &args)
}

#[ink(message)]
Expand All @@ -106,7 +106,7 @@ mod check_system {
script: Vec<u8>,
args: Vec<String>,
) -> Result<js::Output, String> {
js::eval_bytecode(delegate, script, args)
js::eval_bytecode_with(delegate, script, &args)
}

#[ink(message)]
Expand Down Expand Up @@ -156,56 +156,3 @@ mod check_system {
}
}
}

// Haven't much thought on the API shape so far. So it isn't turned into a crate yet.
mod js {
use super::*;
use alloc::string::String;
use alloc::vec::Vec;
use ink::primitives::Hash;
use scale::{Decode, Encode};

#[derive(Debug, Encode, Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum Output {
String(String),
Bytes(Vec<u8>),
Undefined,
}

pub fn eval(delegate: Hash, script: &str, args: Vec<String>) -> Result<Output, String> {
use ink::env::call;

let result = call::build_call::<pink::PinkEnvironment>()
.call_type(call::DelegateCall::new(delegate))
.exec_input(
call::ExecutionInput::new(call::Selector::new(0x49bfcd24_u32.to_be_bytes()))
.push_arg(script)
.push_arg(args),
)
.returns::<ink::MessageResult<Result<Output, String>>>()
.invoke();
pink::info!("eval result: {result:?}");
result.unwrap()
}

pub fn eval_bytecode(
delegate: Hash,
script: alloc::vec::Vec<u8>,
args: Vec<String>,
) -> Result<Output, String> {
use ink::env::call;

let result = call::build_call::<pink::PinkEnvironment>()
.call_type(call::DelegateCall::new(delegate))
.exec_input(
call::ExecutionInput::new(call::Selector::new(0xbf0ec203_u32.to_be_bytes()))
.push_arg(script)
.push_arg(args),
)
.returns::<ink::MessageResult<Result<Output, String>>>()
.invoke();
pink::info!("eval result: {result:?}");
result.unwrap()
}
}

0 comments on commit c8fda69

Please sign in to comment.