Skip to content

Commit

Permalink
fix(ledger): Make the transfer fee optional
Browse files Browse the repository at this point in the history
  • Loading branch information
yanliu38 committed Jan 29, 2025
1 parent 54d3afa commit b3d2012
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ic-canister/src/canister_backend/icrc1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn _icrc1_transfer(arg: TransferArg) -> Result<Nat, Icrc1TransferError> {
let to: IcrcCompatibleAccount = arg.to.into();

LEDGER_MAP.with(|ledger| {
let fee = nat_to_balance(&arg.fee.unwrap_or_default());
let fee = nat_to_balance(&arg.fee.unwrap_or(Nat::from(DC_TOKEN_TRANSFER_FEE_E9S)));
let balance_to_after: TokenAmountE9s = if to.is_minting_account() {
if fee != 0 {
return Err(Icrc1TransferError::BadFee {
Expand Down
20 changes: 20 additions & 0 deletions ic-canister/tests/test_icrc1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,26 @@ fn test_fee_handling() {
Result<Nat, TransferError>
);
assert!(result.is_ok());

// Test with no fee
let transfer_arg = TransferArg {
from_subaccount: None,
to,
amount: 1_000_000u64.into(),
fee: None,
created_at_time: Some(ts),
memo: None,
};

let result = update_check_and_decode!(
ctx.pic,
ctx.canister_id,
from.owner,
"icrc1_transfer",
candid::encode_one(transfer_arg).unwrap(),
Result<Nat, TransferError>
);
assert!(result.is_ok());
}

#[test]
Expand Down

0 comments on commit b3d2012

Please sign in to comment.