Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(ICP_ledger): FI-1491: Add tests for existing ledger behavior regarding the anonymous principal #1550

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mbjorkqvist
Copy link
Member

Add tests for transfers to and from the account belonging to the anonymous principal.

@github-actions github-actions bot added the test label Sep 18, 2024
)
.expect("failed to transfer funds")
.bytes();
let string_from_bytes_result = String::from_utf8(encoded_transfer_result.clone());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When calling icrc1_transfer, we should get back a TransferError in case the transfer failed, but here we need special parsing since we just get back a String in this error case.

Comment on lines 248 to 258
let response = env.execute_ingress_as(
anon,
canister_id,
"transfer",
Encode!(&transfer_args).unwrap(),
);
assert!(response.is_err());
if let Err(err) = response {
assert_eq!(err.code(), ErrorCode::CanisterCalledTrap);
assert!(err.description().contains("Canister called `ic0.trap` with message: Panicked at 'Sending from 2vxsx-fae is not allowed'"));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, this response should be a WasmResult, in this case containing an icp_ledger::TransferError, but since the ledger traps, we instead get a UserError.

@mbjorkqvist mbjorkqvist marked this pull request as ready for review September 18, 2024 14:00
@mbjorkqvist mbjorkqvist requested a review from a team as a code owner September 18, 2024 14:00
rs/rosetta-api/icp_ledger/ledger/tests/tests.rs Outdated Show resolved Hide resolved
rs/rosetta-api/icp_ledger/ledger/tests/tests.rs Outdated Show resolved Hide resolved
assert_eq!(0u64, balance_of(&env, canister_id, anon.0));

// Transfer to the account of the anonymous principal succeeds
transfer(&env, canister_id, p1.0, anon.0, TRANSFER_AMOUNT).expect("transfer failed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not also fail?
Otherwise it's essentially an unregistered brun operation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that's TBD - here I'm only adding tests to verify the current behavior.

assert!(response.is_err());
if let Err(err) = response {
assert_eq!(err.code(), ErrorCode::CanisterCalledTrap);
assert!(err.description().contains("Canister called `ic0.trap` with message: Panicked at 'Sending from 2vxsx-fae is not allowed'"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also worth adding a check that approve by anonymous principal fails.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants