Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions integration_tests/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ pub fn default_get_deposit_address_args() -> GetDepositAddressArgs {
}
}

pub fn default_update_balance_args() -> cksol_types::UpdateBalanceArgs {
cksol_types::UpdateBalanceArgs {
owner: None,
subaccount: None,
}
}

pub fn default_process_deposit_args() -> ProcessDepositArgs {
ProcessDepositArgs {
owner: None,
Expand Down
62 changes: 21 additions & 41 deletions integration_tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cksol_int_tests::{
DEFAULT_CALLER_ACCOUNT, DEFAULT_CALLER_DEPOSIT_ADDRESS, DEPOSIT_AMOUNT,
EXPECTED_MINT_AMOUNT, MockBuilder, SharedMockHttpOutcalls,
default_get_deposit_address_args, default_process_deposit_args,
default_update_balance_args, deposit_transaction_signature,
deposit_transaction_signature,
},
};
use cksol_types::{
Expand Down Expand Up @@ -1022,47 +1022,29 @@ mod update_balance_tests {
let setup = SetupBuilder::new().build().await;
let minter = setup.minter();

// Register the same accounts as used in get_deposit_address_tests
let accounts = vec![
Account {
owner: Setup::DEFAULT_CALLER,
subaccount: None,
},
Account {
owner: Principal::from_slice(&[1]),
subaccount: None,
},
Account {
owner: Setup::DEFAULT_CALLER,
subaccount: Some([1; 32]),
},
Account {
owner: Setup::DEFAULT_CALLER,
subaccount: Some([2; 32]),
},
];
let subaccounts: Vec<Option<Subaccount>> = vec![None, Some([1; 32]), Some([2; 32])];

for account in &accounts {
for subaccount in &subaccounts {
let result = minter
.update_balance(UpdateBalanceArgs {
owner: Some(account.owner),
subaccount: account.subaccount,
subaccount: *subaccount,
})
.await;
assert_eq!(result, Ok(()));
}

// Calling again for an already-monitored account is idempotent — no new event
let result = minter
.update_balance(UpdateBalanceArgs {
owner: None,
subaccount: None,
})
.await;
let result = minter.update_balance(UpdateBalanceArgs::default()).await;
assert_eq!(result, Ok(()));

// Exactly one StartedMonitoringAccount event per account, no duplicates
let expected_accounts = accounts.clone();
// Exactly one StartedMonitoringAccount event per subaccount, no duplicates
let expected_accounts: Vec<Account> = subaccounts
.iter()
.map(|subaccount| Account {
owner: Setup::DEFAULT_CALLER,
subaccount: *subaccount,
})
.collect();
minter.assert_that_events().await.satisfy(|events| {
let monitoring_events: Vec<&Account> = events
.iter()
Expand Down Expand Up @@ -1105,15 +1087,6 @@ mod anonymous_caller_tests {
.await;
assert_matches!(result, Err(s) => s.contains("the owner must be non-anonymous"));

// `update_balance` endpoint
let result = minter
.try_update_balance(UpdateBalanceArgs {
owner,
subaccount: None,
})
.await;
assert_matches!(result, Err(s) => s.contains("the owner must be non-anonymous"));

// `process_deposit` endpoint
let result = minter
.try_process_deposit(ProcessDepositArgs {
Expand All @@ -1125,6 +1098,13 @@ mod anonymous_caller_tests {
assert_matches!(result, Err(s) => s.contains("the owner must be non-anonymous"));
}

// `update_balance` endpoint (no `owner` field, only anonymous caller applies)
let minter = setup.minter_with_caller(Principal::anonymous());
let result = minter
.try_update_balance(UpdateBalanceArgs::default())
.await;
assert_matches!(result, Err(s) => s.contains("the owner must be non-anonymous"));

// `withdraw` endpoint (no `owner` field, only anonymous caller applies)
let minter = setup.minter_with_caller(Principal::anonymous());
let result = minter
Expand Down Expand Up @@ -1308,7 +1288,7 @@ mod automated_deposit_flow_tests {
DEFAULT_CALLER_DEPOSIT_ADDRESS
);
minter
.update_balance(default_update_balance_args())
.update_balance(UpdateBalanceArgs::default())
.await
.expect("update_balance should succeed");

Expand Down
9 changes: 3 additions & 6 deletions libs/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,11 @@ pub enum ProcessDepositError {
}

/// Arguments for a request to the `update_balance` ckSOL minter endpoint.
#[derive(Clone, Eq, PartialEq, Debug, CandidType, Deserialize, Serialize)]
#[derive(Clone, Eq, PartialEq, Debug, Default, CandidType, Deserialize, Serialize)]
pub struct UpdateBalanceArgs {
/// The principal to register for automated deposit monitoring.
///
/// If not set, defaults to the caller's principal.
/// The resolved owner must be a non-anonymous principal.
pub owner: Option<Principal>,
/// The subaccount to register for automated deposit monitoring.
///
/// The owner is always the caller.
pub subaccount: Option<Subaccount>,
}

Expand Down
6 changes: 1 addition & 5 deletions minter/cksol_minter.did
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,8 @@ type ProcessDepositError = variant {

// Arguments for a request to the `update_balance` endpoint.
type UpdateBalanceArgs = record {
// If provided, register this principal's deposit address for monitoring.
//
// If not set, defaults to the caller's principal.
// The resolved owner must be a non-anonymous principal.
owner: opt principal;
// The subaccount to register for automated deposit monitoring.
// The owner is always the caller.
subaccount: opt blob;
};

Expand Down
2 changes: 1 addition & 1 deletion minter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn get_deposit_address(args: GetDepositAddressArgs) -> Address {

#[ic_cdk::update]
fn update_balance(args: UpdateBalanceArgs) -> Result<(), UpdateBalanceError> {
let account = assert_non_anonymous_account(args.owner, args.subaccount);
let account = assert_non_anonymous_account(None, args.subaccount);
cksol_minter::deposit::automatic::update_balance(&IcCanisterRuntime::new(), account)
}

Expand Down
Loading