diff --git a/src/example/app_backend/src/lib.rs b/src/example/app_backend/src/lib.rs index b30b86b..c472e89 100644 --- a/src/example/app_backend/src/lib.rs +++ b/src/example/app_backend/src/lib.rs @@ -1,6 +1,6 @@ use candid::Principal; use ic_cdk::api::call::call_with_payment128; -use ic_cdk_macros::{update, export_candid}; +use ic_cdk_macros::{export_candid, update}; use ic_papi_api::PaymentError; /// Calls an arbitrary method on an arbitrary canister with an arbitrary amount of cycles attached. @@ -17,5 +17,4 @@ async fn call_with_attached_cycles( ans } - export_candid!(); diff --git a/src/example/paid_service/src/lib.rs b/src/example/paid_service/src/lib.rs index 39fcd09..67e4c45 100644 --- a/src/example/paid_service/src/lib.rs +++ b/src/example/paid_service/src/lib.rs @@ -1,4 +1,4 @@ -use ic_cdk_macros::{update, export_candid}; +use ic_cdk_macros::{export_candid, update}; use ic_papi_api::PaymentError; use ic_papi_guard::guards::attached_cycles::AttachedCyclesPayment; use ic_papi_guard::guards::PaymentGuard; diff --git a/src/example/paid_service/tests/it/attached_cycles.rs b/src/example/paid_service/tests/it/attached_cycles.rs index d65fb13..69e0e39 100644 --- a/src/example/paid_service/tests/it/attached_cycles.rs +++ b/src/example/paid_service/tests/it/attached_cycles.rs @@ -1,12 +1,13 @@ +use crate::util::pic_canister::{PicCanister, PicCanisterTrait}; use candid::Principal; use ic_papi_api::PaymentError; -use crate::util::pic_canister::{PicCanister, PicCanisterTrait}; use pocket_ic::PocketIc; use std::sync::Arc; pub struct AttachedCyclesTestSetup { /// The PocketIC instance. - #[allow(dead_code)] // The Arc is used; this makes it accessible without having to refer to a specific canister. + #[allow(dead_code)] + // The Arc is used; this makes it accessible without having to refer to a specific canister. pic: Arc, /// The canister providing the API. api_canister: PicCanister, @@ -71,4 +72,4 @@ fn inter_canister_call_succeeds_with_sufficient_cycles_only() { ); } } -} \ No newline at end of file +} diff --git a/src/example/paid_service/tests/it/icrc2.rs b/src/example/paid_service/tests/it/icrc2.rs index a303071..e46d281 100644 --- a/src/example/paid_service/tests/it/icrc2.rs +++ b/src/example/paid_service/tests/it/icrc2.rs @@ -1,13 +1,14 @@ +use crate::util::cycles_ledger::CyclesLedgerPic; +use crate::util::pic_canister::{PicCanister, PicCanisterBuilder, PicCanisterTrait}; use candid::{encode_one, Principal}; use ic_papi_api::PaymentError; -use crate::util::pic_canister::{PicCanister, PicCanisterBuilder, PicCanisterTrait}; use pocket_ic::PocketIc; use std::sync::Arc; -use crate::util::cycles_ledger::CyclesLedgerPic; pub struct CallerPaysWithIcRc2TestSetup { /// The PocketIC instance. - #[allow(dead_code)] // The Arc is used; this makes it accessible without having to refer to a specific canister. + #[allow(dead_code)] + // The Arc is used; this makes it accessible without having to refer to a specific canister. pic: Arc, /// The canister providing the API. paid_service: PicCanister, @@ -21,11 +22,10 @@ impl Default for CallerPaysWithIcRc2TestSetup { pic.clone(), &PicCanister::cargo_wasm_path("example_paid_service"), ); - let ledger = - PicCanisterBuilder::default() - .with_wasm(&PicCanister::cargo_wasm_path("example_paid_service")) - .with_arg(encode_one(9).expect("Failed to encode ledger init arg")) - .deploy_to(pic.clone()); + let ledger = PicCanisterBuilder::default() + .with_wasm(&PicCanister::cargo_wasm_path("example_paid_service")) + .with_arg(encode_one(9).expect("Failed to encode ledger init arg")) + .deploy_to(pic.clone()); Self { pic, paid_service: api_canister, @@ -37,4 +37,4 @@ impl Default for CallerPaysWithIcRc2TestSetup { #[test] fn icrc2_test_setup_works() { let _setup = CallerPaysWithIcRc2TestSetup::default(); -} \ No newline at end of file +} diff --git a/src/example/paid_service/tests/it/util/cycles_ledger.rs b/src/example/paid_service/tests/it/util/cycles_ledger.rs index 102da41..2f8a7c4 100644 --- a/src/example/paid_service/tests/it/util/cycles_ledger.rs +++ b/src/example/paid_service/tests/it/util/cycles_ledger.rs @@ -7,422 +7,524 @@ use candid::{self, decode_one, encode_args, encode_one, CandidType, Deserialize, use pocket_ic::{PocketIc, WasmResult}; #[derive(CandidType, Deserialize, Debug)] -pub enum ChangeIndexId { SetTo(Principal), Unset } +pub enum ChangeIndexId { + SetTo(Principal), + Unset, +} #[derive(CandidType, Deserialize, Debug)] pub struct UpgradeArgs { - pub change_index_id: Option, - pub max_blocks_per_request: Option, + pub change_index_id: Option, + pub max_blocks_per_request: Option, } #[derive(CandidType, Deserialize, Debug)] pub struct InitArgs { - pub index_id: Option, - pub max_blocks_per_request: u64, + pub index_id: Option, + pub max_blocks_per_request: u64, } #[derive(CandidType, Deserialize, Debug)] -pub enum LedgerArgs { Upgrade(Option), Init(InitArgs) } +pub enum LedgerArgs { + Upgrade(Option), + Init(InitArgs), +} #[derive(CandidType, Deserialize, Debug)] -pub struct SubnetFilter { pub subnet_type: Option } +pub struct SubnetFilter { + pub subnet_type: Option, +} #[derive(CandidType, Deserialize, Debug)] pub enum SubnetSelection { - Filter(SubnetFilter), - Subnet{ subnet: Principal }, + Filter(SubnetFilter), + Subnet { subnet: Principal }, } #[derive(CandidType, Deserialize, Debug)] pub struct CanisterSettings { - pub freezing_threshold: Option, - pub controllers: Option>, - pub reserved_cycles_limit: Option, - pub memory_allocation: Option, - pub compute_allocation: Option, + pub freezing_threshold: Option, + pub controllers: Option>, + pub reserved_cycles_limit: Option, + pub memory_allocation: Option, + pub compute_allocation: Option, } #[derive(CandidType, Deserialize, Debug)] pub struct CmcCreateCanisterArgs { - pub subnet_selection: Option, - pub settings: Option, + pub subnet_selection: Option, + pub settings: Option, } #[derive(CandidType, Deserialize, Debug)] pub struct CreateCanisterArgs { - pub from_subaccount: Option, - pub created_at_time: Option, - pub amount: candid::Nat, - pub creation_args: Option, + pub from_subaccount: Option, + pub created_at_time: Option, + pub amount: candid::Nat, + pub creation_args: Option, } pub type BlockIndex = candid::Nat; #[derive(CandidType, Deserialize, Debug)] pub struct CreateCanisterSuccess { - pub block_id: BlockIndex, - pub canister_id: Principal, + pub block_id: BlockIndex, + pub canister_id: Principal, } #[derive(CandidType, Deserialize, Debug)] pub enum CreateCanisterError { - GenericError{ message: String, error_code: candid::Nat }, - TemporarilyUnavailable, - Duplicate{ duplicate_of: candid::Nat, canister_id: Option }, - CreatedInFuture{ ledger_time: u64 }, - FailedToCreate{ - error: String, - refund_block: Option, - fee_block: Option, - }, - TooOld, - InsufficientFunds{ balance: candid::Nat }, + GenericError { + message: String, + error_code: candid::Nat, + }, + TemporarilyUnavailable, + Duplicate { + duplicate_of: candid::Nat, + canister_id: Option, + }, + CreatedInFuture { + ledger_time: u64, + }, + FailedToCreate { + error: String, + refund_block: Option, + fee_block: Option, + }, + TooOld, + InsufficientFunds { + balance: candid::Nat, + }, } #[derive(CandidType, Deserialize, Debug)] pub struct Account { - pub owner: Principal, - pub subaccount: Option, + pub owner: Principal, + pub subaccount: Option, } #[derive(CandidType, Deserialize, Debug)] pub struct CreateCanisterFromArgs { - pub spender_subaccount: Option, - pub from: Account, - pub created_at_time: Option, - pub amount: candid::Nat, - pub creation_args: Option, + pub spender_subaccount: Option, + pub from: Account, + pub created_at_time: Option, + pub amount: candid::Nat, + pub creation_args: Option, } #[derive(CandidType, Deserialize, Debug)] pub enum RejectionCode { - NoError, - CanisterError, - SysTransient, - DestinationInvalid, - Unknown, - SysFatal, - CanisterReject, + NoError, + CanisterError, + SysTransient, + DestinationInvalid, + Unknown, + SysFatal, + CanisterReject, } #[derive(CandidType, Deserialize, Debug)] pub enum CreateCanisterFromError { - FailedToCreateFrom{ - create_from_block: Option, - rejection_code: RejectionCode, - refund_block: Option, - approval_refund_block: Option, - rejection_reason: String, - }, - GenericError{ message: String, error_code: candid::Nat }, - TemporarilyUnavailable, - InsufficientAllowance{ allowance: candid::Nat }, - Duplicate{ duplicate_of: candid::Nat, canister_id: Option }, - CreatedInFuture{ ledger_time: u64 }, - TooOld, - InsufficientFunds{ balance: candid::Nat }, + FailedToCreateFrom { + create_from_block: Option, + rejection_code: RejectionCode, + refund_block: Option, + approval_refund_block: Option, + rejection_reason: String, + }, + GenericError { + message: String, + error_code: candid::Nat, + }, + TemporarilyUnavailable, + InsufficientAllowance { + allowance: candid::Nat, + }, + Duplicate { + duplicate_of: candid::Nat, + canister_id: Option, + }, + CreatedInFuture { + ledger_time: u64, + }, + TooOld, + InsufficientFunds { + balance: candid::Nat, + }, } #[derive(CandidType, Deserialize, Debug)] pub struct DepositArgs { - pub to: Account, - pub memo: Option, + pub to: Account, + pub memo: Option, } #[derive(CandidType, Deserialize, Debug)] pub struct DepositResult { - pub balance: candid::Nat, - pub block_index: BlockIndex, + pub balance: candid::Nat, + pub block_index: BlockIndex, } #[derive(CandidType, Deserialize, Debug)] pub struct HttpRequest { - pub url: String, - pub method: String, - pub body: serde_bytes::ByteBuf, - pub headers: Vec<(String,String,)>, + pub url: String, + pub method: String, + pub body: serde_bytes::ByteBuf, + pub headers: Vec<(String, String)>, } #[derive(CandidType, Deserialize, Debug)] pub struct HttpResponse { - pub body: serde_bytes::ByteBuf, - pub headers: Vec<(String,String,)>, - pub status_code: u16, + pub body: serde_bytes::ByteBuf, + pub headers: Vec<(String, String)>, + pub status_code: u16, } #[derive(CandidType, Deserialize, Debug)] pub enum MetadataValue { - Int(candid::Int), - Nat(candid::Nat), - Blob(serde_bytes::ByteBuf), - Text(String), + Int(candid::Int), + Nat(candid::Nat), + Blob(serde_bytes::ByteBuf), + Text(String), } #[derive(CandidType, Deserialize, Debug)] pub struct SupportedStandard { - pub url: String, - pub name: String, + pub url: String, + pub name: String, } #[derive(CandidType, Deserialize, Debug)] pub struct TransferArgs { - pub to: Account, - pub fee: Option, - pub memo: Option, - pub from_subaccount: Option, - pub created_at_time: Option, - pub amount: candid::Nat, + pub to: Account, + pub fee: Option, + pub memo: Option, + pub from_subaccount: Option, + pub created_at_time: Option, + pub amount: candid::Nat, } #[derive(CandidType, Deserialize, Debug)] pub enum TransferError { - GenericError{ message: String, error_code: candid::Nat }, - TemporarilyUnavailable, - BadBurn{ min_burn_amount: candid::Nat }, - Duplicate{ duplicate_of: candid::Nat }, - BadFee{ expected_fee: candid::Nat }, - CreatedInFuture{ ledger_time: u64 }, - TooOld, - InsufficientFunds{ balance: candid::Nat }, + GenericError { + message: String, + error_code: candid::Nat, + }, + TemporarilyUnavailable, + BadBurn { + min_burn_amount: candid::Nat, + }, + Duplicate { + duplicate_of: candid::Nat, + }, + BadFee { + expected_fee: candid::Nat, + }, + CreatedInFuture { + ledger_time: u64, + }, + TooOld, + InsufficientFunds { + balance: candid::Nat, + }, } #[derive(CandidType, Deserialize, Debug)] pub struct AllowanceArgs { - pub account: Account, - pub spender: Account, + pub account: Account, + pub spender: Account, } #[derive(CandidType, Deserialize, Debug)] pub struct Allowance { - pub allowance: candid::Nat, - pub expires_at: Option, + pub allowance: candid::Nat, + pub expires_at: Option, } #[derive(CandidType, Deserialize, Debug)] pub struct ApproveArgs { - pub fee: Option, - pub memo: Option, - pub from_subaccount: Option, - pub created_at_time: Option, - pub amount: candid::Nat, - pub expected_allowance: Option, - pub expires_at: Option, - pub spender: Account, + pub fee: Option, + pub memo: Option, + pub from_subaccount: Option, + pub created_at_time: Option, + pub amount: candid::Nat, + pub expected_allowance: Option, + pub expires_at: Option, + pub spender: Account, } #[derive(CandidType, Deserialize, Debug)] pub enum ApproveError { - GenericError{ message: String, error_code: candid::Nat }, - TemporarilyUnavailable, - Duplicate{ duplicate_of: candid::Nat }, - BadFee{ expected_fee: candid::Nat }, - AllowanceChanged{ current_allowance: candid::Nat }, - CreatedInFuture{ ledger_time: u64 }, - TooOld, - Expired{ ledger_time: u64 }, - InsufficientFunds{ balance: candid::Nat }, + GenericError { + message: String, + error_code: candid::Nat, + }, + TemporarilyUnavailable, + Duplicate { + duplicate_of: candid::Nat, + }, + BadFee { + expected_fee: candid::Nat, + }, + AllowanceChanged { + current_allowance: candid::Nat, + }, + CreatedInFuture { + ledger_time: u64, + }, + TooOld, + Expired { + ledger_time: u64, + }, + InsufficientFunds { + balance: candid::Nat, + }, } #[derive(CandidType, Deserialize, Debug)] pub struct TransferFromArgs { - pub to: Account, - pub fee: Option, - pub spender_subaccount: Option, - pub from: Account, - pub memo: Option, - pub created_at_time: Option, - pub amount: candid::Nat, + pub to: Account, + pub fee: Option, + pub spender_subaccount: Option, + pub from: Account, + pub memo: Option, + pub created_at_time: Option, + pub amount: candid::Nat, } #[derive(CandidType, Deserialize, Debug)] pub enum TransferFromError { - GenericError{ message: String, error_code: candid::Nat }, - TemporarilyUnavailable, - InsufficientAllowance{ allowance: candid::Nat }, - BadBurn{ min_burn_amount: candid::Nat }, - Duplicate{ duplicate_of: candid::Nat }, - BadFee{ expected_fee: candid::Nat }, - CreatedInFuture{ ledger_time: u64 }, - TooOld, - InsufficientFunds{ balance: candid::Nat }, + GenericError { + message: String, + error_code: candid::Nat, + }, + TemporarilyUnavailable, + InsufficientAllowance { + allowance: candid::Nat, + }, + BadBurn { + min_burn_amount: candid::Nat, + }, + Duplicate { + duplicate_of: candid::Nat, + }, + BadFee { + expected_fee: candid::Nat, + }, + CreatedInFuture { + ledger_time: u64, + }, + TooOld, + InsufficientFunds { + balance: candid::Nat, + }, +} +#[derive(CandidType, Deserialize, Debug)] +pub struct GetArchivesArgs { + pub from: Option, } #[derive(CandidType, Deserialize, Debug)] -pub struct GetArchivesArgs { pub from: Option } -#[derive(CandidType, Deserialize, Debug)] pub struct GetArchivesResultItem { - pub end: candid::Nat, - pub canister_id: Principal, - pub start: candid::Nat, + pub end: candid::Nat, + pub canister_id: Principal, + pub start: candid::Nat, } pub type GetArchivesResult = Vec; #[derive(CandidType, Deserialize, Debug)] pub struct GetBlocksArgsItem { - pub start: candid::Nat, - pub length: candid::Nat, + pub start: candid::Nat, + pub length: candid::Nat, } pub type GetBlocksArgs = Vec; #[derive(CandidType, Deserialize, Debug)] pub enum Value { - Int(candid::Int), - Map(Vec<(String,Box,)>), - Nat(candid::Nat), - Nat64(u64), - Blob(serde_bytes::ByteBuf), - Text(String), - Array(Vec>), + Int(candid::Int), + Map(Vec<(String, Box)>), + Nat(candid::Nat), + Nat64(u64), + Blob(serde_bytes::ByteBuf), + Text(String), + Array(Vec>), } #[derive(CandidType, Deserialize, Debug)] pub struct GetBlocksResultBlocksItem { - pub id: candid::Nat, - pub block: Box, + pub id: candid::Nat, + pub block: Box, } candid::define_function!(pub GetBlocksResultArchivedBlocksItemCallback : ( GetBlocksArgs, ) -> (GetBlocksResult) query); #[derive(CandidType, Deserialize, Debug)] pub struct GetBlocksResultArchivedBlocksItem { - pub args: GetBlocksArgs, - pub callback: GetBlocksResultArchivedBlocksItemCallback, + pub args: GetBlocksArgs, + pub callback: GetBlocksResultArchivedBlocksItemCallback, } #[derive(CandidType, Deserialize, Debug)] pub struct GetBlocksResult { - pub log_length: candid::Nat, - pub blocks: Vec, - pub archived_blocks: Vec, + pub log_length: candid::Nat, + pub blocks: Vec, + pub archived_blocks: Vec, } #[derive(CandidType, Deserialize, Debug)] pub struct DataCertificate { - pub certificate: serde_bytes::ByteBuf, - pub hash_tree: serde_bytes::ByteBuf, + pub certificate: serde_bytes::ByteBuf, + pub hash_tree: serde_bytes::ByteBuf, } #[derive(CandidType, Deserialize, Debug)] pub struct SupportedBlockType { - pub url: String, - pub block_type: String, + pub url: String, + pub block_type: String, } #[derive(CandidType, Deserialize, Debug)] pub struct WithdrawArgs { - pub to: Principal, - pub from_subaccount: Option, - pub created_at_time: Option, - pub amount: candid::Nat, + pub to: Principal, + pub from_subaccount: Option, + pub created_at_time: Option, + pub amount: candid::Nat, } #[derive(CandidType, Deserialize, Debug)] pub enum WithdrawError { - FailedToWithdraw{ - rejection_code: RejectionCode, - fee_block: Option, - rejection_reason: String, - }, - GenericError{ message: String, error_code: candid::Nat }, - TemporarilyUnavailable, - Duplicate{ duplicate_of: candid::Nat }, - BadFee{ expected_fee: candid::Nat }, - InvalidReceiver{ receiver: Principal }, - CreatedInFuture{ ledger_time: u64 }, - TooOld, - InsufficientFunds{ balance: candid::Nat }, + FailedToWithdraw { + rejection_code: RejectionCode, + fee_block: Option, + rejection_reason: String, + }, + GenericError { + message: String, + error_code: candid::Nat, + }, + TemporarilyUnavailable, + Duplicate { + duplicate_of: candid::Nat, + }, + BadFee { + expected_fee: candid::Nat, + }, + InvalidReceiver { + receiver: Principal, + }, + CreatedInFuture { + ledger_time: u64, + }, + TooOld, + InsufficientFunds { + balance: candid::Nat, + }, } #[derive(CandidType, Deserialize, Debug)] pub struct WithdrawFromArgs { - pub to: Principal, - pub spender_subaccount: Option, - pub from: Account, - pub created_at_time: Option, - pub amount: candid::Nat, + pub to: Principal, + pub spender_subaccount: Option, + pub from: Account, + pub created_at_time: Option, + pub amount: candid::Nat, } #[derive(CandidType, Deserialize, Debug)] pub enum WithdrawFromError { - GenericError{ message: String, error_code: candid::Nat }, - TemporarilyUnavailable, - InsufficientAllowance{ allowance: candid::Nat }, - Duplicate{ duplicate_of: BlockIndex }, - InvalidReceiver{ receiver: Principal }, - CreatedInFuture{ ledger_time: u64 }, - TooOld, - FailedToWithdrawFrom{ - withdraw_from_block: Option, - rejection_code: RejectionCode, - refund_block: Option, - approval_refund_block: Option, - rejection_reason: String, - }, - InsufficientFunds{ balance: candid::Nat }, + GenericError { + message: String, + error_code: candid::Nat, + }, + TemporarilyUnavailable, + InsufficientAllowance { + allowance: candid::Nat, + }, + Duplicate { + duplicate_of: BlockIndex, + }, + InvalidReceiver { + receiver: Principal, + }, + CreatedInFuture { + ledger_time: u64, + }, + TooOld, + FailedToWithdrawFrom { + withdraw_from_block: Option, + rejection_code: RejectionCode, + refund_block: Option, + approval_refund_block: Option, + rejection_reason: String, + }, + InsufficientFunds { + balance: candid::Nat, + }, } -pub struct CyclesLedgerPic{pub pic: Arc, pub canister_id: Principal} +pub struct CyclesLedgerPic { + pub pic: Arc, + pub canister_id: Principal, +} impl CyclesLedgerPic { - fn update( - &self, - caller: Principal, - method: &str, - arg: impl CandidType, -) -> Result -where - T: for<'a> Deserialize<'a> + CandidType, -{ - self.pic - .update_call(self.canister_id, caller, method, encode_one(arg).unwrap()) - .map_err(|e| { - format!( - "Update call error. RejectionCode: {:?}, Error: {}", - e.code, e.description - ) - }) - .and_then(|reply| match reply { - WasmResult::Reply(reply) => { - decode_one(&reply).map_err(|e| format!("Decoding failed: {e}")) - } - WasmResult::Reject(error) => Err(error), - }) -} + fn update(&self, caller: Principal, method: &str, arg: impl CandidType) -> Result + where + T: for<'a> Deserialize<'a> + CandidType, + { + self.pic + .update_call(self.canister_id, caller, method, encode_one(arg).unwrap()) + .map_err(|e| { + format!( + "Update call error. RejectionCode: {:?}, Error: {}", + e.code, e.description + ) + }) + .and_then(|reply| match reply { + WasmResult::Reply(reply) => { + decode_one(&reply).map_err(|e| format!("Decoding failed: {e}")) + } + WasmResult::Reject(error) => Err(error), + }) + } } impl CyclesLedgerPic { -/* - pub fn create_canister(&self, caller: Principal, arg0: &CreateCanisterArgs) -> Result<(std::result::Result,)> { - self.pic.update_call(self.canister_id, caller, "create_canister", (arg0,)) - } - pub fn create_canister_from(&self, caller: Principal, arg0: &CreateCanisterFromArgs) -> Result<(std::result::Result,)> { - self.pic.update_call(self.canister_id, caller, "create_canister_from", (arg0,)) - } - */ - pub fn deposit(&self, caller: Principal, arg0: &DepositArgs) -> Result { - self.update(caller, "deposit", (arg0,)) - } - /* - pub fn http_request(&self, caller: Principal, arg0: &HttpRequest) -> Result<(HttpResponse,)> { - self.pic.update_call(self.canister_id, caller, "http_request", (arg0,)) - } - pub fn icrc_1_balance_of(&self, caller: Principal, arg0: &Account) -> Result<(candid::Nat,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_balance_of", (arg0,)) - } - pub fn icrc_1_decimals(&self, caller: Principal) -> Result<(u8,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_decimals", ()) - } - pub fn icrc_1_fee(&self, caller: Principal) -> Result<(candid::Nat,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_fee", ()) - } - pub fn icrc_1_metadata(&self, caller: Principal) -> Result<(Vec<(String,MetadataValue,)>,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_metadata", ()) - } - pub fn icrc_1_minting_account(&self, caller: Principal) -> Result<(Option,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_minting_account", ()) - } - pub fn icrc_1_name(&self, caller: Principal) -> Result<(String,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_name", ()) - } - pub fn icrc_1_supported_standards(&self, caller: Principal) -> Result<(Vec,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_supported_standards", ()) - } - pub fn icrc_1_symbol(&self, caller: Principal) -> Result<(String,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_symbol", ()) - } - pub fn icrc_1_total_supply(&self, caller: Principal) -> Result<(candid::Nat,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_total_supply", ()) - } - pub fn icrc_1_transfer(&self, caller: Principal, arg0: &TransferArgs) -> Result<(std::result::Result,)> { - self.pic.update_call(self.canister_id, caller, "icrc1_transfer", (arg0,)) - } - pub fn icrc_2_allowance(&self, caller: Principal, arg0: &AllowanceArgs) -> Result<(Allowance,)> { - self.pic.update_call(self.canister_id, caller, "icrc2_allowance", (arg0,)) - } - pub fn icrc_2_approve(&self, caller: Principal, arg0: &ApproveArgs) -> Result<(std::result::Result,)> { - self.pic.update_call(self.canister_id, caller, "icrc2_approve", (arg0,)) - } - pub fn icrc_2_transfer_from(&self, caller: Principal, arg0: &TransferFromArgs) -> Result<(std::result::Result,)> { - self.pic.update_call(self.canister_id, caller, "icrc2_transfer_from", (arg0,)) - } - pub fn icrc_3_get_archives(&self, caller: Principal, arg0: &GetArchivesArgs) -> Result<(GetArchivesResult,)> { - self.pic.update_call(self.canister_id, caller, "icrc3_get_archives", (arg0,)) - } - pub fn icrc_3_get_blocks(&self, caller: Principal, arg0: &GetBlocksArgs) -> Result<(GetBlocksResult,)> { - self.pic.update_call(self.canister_id, caller, "icrc3_get_blocks", (arg0,)) - } - pub fn icrc_3_get_tip_certificate(&self, caller: Principal) -> Result<(Option,)> { - self.pic.update_call(self.canister_id, caller, "icrc3_get_tip_certificate", ()) - } - pub fn icrc_3_supported_block_types(&self, caller: Principal) -> Result<(Vec,)> { - self.pic.update_call(self.canister_id, caller, "icrc3_supported_block_types", encode_args(())) - } - pub fn withdraw(&self, caller: Principal, arg0: &WithdrawArgs) -> Result<(std::result::Result,)> { - self.pic.update_call(self.canister_id, caller, "withdraw", encode_args((arg0,)).unwrap()) - } - */ - pub fn withdraw_from(&self, caller: Principal, arg0: &WithdrawFromArgs) -> Result<(std::result::Result,), String> { - self.update(caller, "withdraw_from", encode_args((arg0,)).unwrap()) - } + /* + pub fn create_canister(&self, caller: Principal, arg0: &CreateCanisterArgs) -> Result<(std::result::Result,)> { + self.pic.update_call(self.canister_id, caller, "create_canister", (arg0,)) + } + pub fn create_canister_from(&self, caller: Principal, arg0: &CreateCanisterFromArgs) -> Result<(std::result::Result,)> { + self.pic.update_call(self.canister_id, caller, "create_canister_from", (arg0,)) + } + */ + pub fn deposit(&self, caller: Principal, arg0: &DepositArgs) -> Result { + self.update(caller, "deposit", (arg0,)) + } + /* + pub fn http_request(&self, caller: Principal, arg0: &HttpRequest) -> Result<(HttpResponse,)> { + self.pic.update_call(self.canister_id, caller, "http_request", (arg0,)) + } + pub fn icrc_1_balance_of(&self, caller: Principal, arg0: &Account) -> Result<(candid::Nat,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_balance_of", (arg0,)) + } + pub fn icrc_1_decimals(&self, caller: Principal) -> Result<(u8,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_decimals", ()) + } + pub fn icrc_1_fee(&self, caller: Principal) -> Result<(candid::Nat,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_fee", ()) + } + pub fn icrc_1_metadata(&self, caller: Principal) -> Result<(Vec<(String,MetadataValue,)>,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_metadata", ()) + } + pub fn icrc_1_minting_account(&self, caller: Principal) -> Result<(Option,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_minting_account", ()) + } + pub fn icrc_1_name(&self, caller: Principal) -> Result<(String,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_name", ()) + } + pub fn icrc_1_supported_standards(&self, caller: Principal) -> Result<(Vec,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_supported_standards", ()) + } + pub fn icrc_1_symbol(&self, caller: Principal) -> Result<(String,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_symbol", ()) + } + pub fn icrc_1_total_supply(&self, caller: Principal) -> Result<(candid::Nat,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_total_supply", ()) + } + pub fn icrc_1_transfer(&self, caller: Principal, arg0: &TransferArgs) -> Result<(std::result::Result,)> { + self.pic.update_call(self.canister_id, caller, "icrc1_transfer", (arg0,)) + } + pub fn icrc_2_allowance(&self, caller: Principal, arg0: &AllowanceArgs) -> Result<(Allowance,)> { + self.pic.update_call(self.canister_id, caller, "icrc2_allowance", (arg0,)) + } + pub fn icrc_2_approve(&self, caller: Principal, arg0: &ApproveArgs) -> Result<(std::result::Result,)> { + self.pic.update_call(self.canister_id, caller, "icrc2_approve", (arg0,)) + } + pub fn icrc_2_transfer_from(&self, caller: Principal, arg0: &TransferFromArgs) -> Result<(std::result::Result,)> { + self.pic.update_call(self.canister_id, caller, "icrc2_transfer_from", (arg0,)) + } + pub fn icrc_3_get_archives(&self, caller: Principal, arg0: &GetArchivesArgs) -> Result<(GetArchivesResult,)> { + self.pic.update_call(self.canister_id, caller, "icrc3_get_archives", (arg0,)) + } + pub fn icrc_3_get_blocks(&self, caller: Principal, arg0: &GetBlocksArgs) -> Result<(GetBlocksResult,)> { + self.pic.update_call(self.canister_id, caller, "icrc3_get_blocks", (arg0,)) + } + pub fn icrc_3_get_tip_certificate(&self, caller: Principal) -> Result<(Option,)> { + self.pic.update_call(self.canister_id, caller, "icrc3_get_tip_certificate", ()) + } + pub fn icrc_3_supported_block_types(&self, caller: Principal) -> Result<(Vec,)> { + self.pic.update_call(self.canister_id, caller, "icrc3_supported_block_types", encode_args(())) + } + pub fn withdraw(&self, caller: Principal, arg0: &WithdrawArgs) -> Result<(std::result::Result,)> { + self.pic.update_call(self.canister_id, caller, "withdraw", encode_args((arg0,)).unwrap()) + } + */ + pub fn withdraw_from( + &self, + caller: Principal, + arg0: &WithdrawFromArgs, + ) -> Result<(std::result::Result,), String> { + self.update(caller, "withdraw_from", encode_args((arg0,)).unwrap()) + } } - diff --git a/src/example/paid_service/tests/it/util/mod.rs b/src/example/paid_service/tests/it/util/mod.rs index 573f1dc..b768c4c 100644 --- a/src/example/paid_service/tests/it/util/mod.rs +++ b/src/example/paid_service/tests/it/util/mod.rs @@ -1,2 +1,2 @@ pub mod cycles_ledger; -pub mod pic_canister; \ No newline at end of file +pub mod pic_canister;