-
Notifications
You must be signed in to change notification settings - Fork 390
feat(ic-icrc1): add ICRC-122 AuthorizedMint/AuthorizedBurn candid types, index-ng, and .did support #9694
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
feat(ic-icrc1): add ICRC-122 AuthorizedMint/AuthorizedBurn candid types, index-ng, and .did support #9694
Changes from all commits
72ca322
cecbc6a
c654057
bf4d440
e326c5f
aa4cfe1
2fc7c2b
c20cd4e
8c03d01
277600e
191ced0
baa4891
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -969,6 +969,8 @@ fn test_get_account_transactions_pagination() { | |
| approve: None, | ||
| timestamp: 0, | ||
| fee_collector: None, | ||
| authorized_mint: None, | ||
| authorized_burn: None, | ||
| }, | ||
| transaction, | ||
| ); | ||
|
|
@@ -1571,6 +1573,99 @@ fn test_block_with_no_btype_and_no_mthd() { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_authorized_mint_and_burn_indexing() { | ||
| let env = &StateMachine::new(); | ||
| let ledger_id = install_icrc3_test_ledger(env); | ||
| let index_id = install_index_ng(env, index_init_arg_without_interval(ledger_id)); | ||
|
|
||
| let account_1 = account(1, 0); | ||
| let account_2 = account(2, 0); | ||
| let caller = PrincipalId::new_user_test_id(99); | ||
|
|
||
| // Block 0: regular mint to give account_1 initial balance | ||
| let block0 = BlockBuilder::new(0, 1000) | ||
| .mint(account_1, Tokens::from(10_000_000_u64)) | ||
| .build(); | ||
| assert_eq!( | ||
| Nat::from(0u64), | ||
| add_block(env, ledger_id, &block0).expect("failed to add block 0") | ||
| ); | ||
|
|
||
| // Block 1: authorized mint to account_2 (ICRC-152 style, with caller/mthd/ts) | ||
| let block1 = BlockBuilder::new(1, 2000) | ||
| .authorized_mint(account_2, Tokens::from(5_000_000_u64)) | ||
| .with_caller(caller.0) | ||
| .with_mthd("152mint".to_string()) | ||
| .with_created_at_time(1500) | ||
| .build(); | ||
| assert_eq!( | ||
| Nat::from(1u64), | ||
| add_block(env, ledger_id, &block1).expect("failed to add block 1") | ||
| ); | ||
|
|
||
| // Block 2: authorized burn from account_1 | ||
| let block2 = BlockBuilder::new(2, 3000) | ||
| .authorized_burn(account_1, Tokens::from(3_000_000_u64)) | ||
| .with_caller(caller.0) | ||
| .with_mthd("152burn".to_string()) | ||
| .with_created_at_time(2500) | ||
| .with_reason("compliance".to_string()) | ||
| .build(); | ||
| assert_eq!( | ||
| Nat::from(2u64), | ||
| add_block(env, ledger_id, &block2).expect("failed to add block 2") | ||
| ); | ||
|
|
||
| wait_until_sync_is_completed(env, index_id, ledger_id); | ||
|
|
||
| // Verify balances | ||
| // account_1: 10_000_000 (mint) - 3_000_000 (authorized burn) = 7_000_000 | ||
| assert_eq!(icrc1_balance_of(env, index_id, account_1), 7_000_000); | ||
| // account_2: 5_000_000 (authorized mint) | ||
| assert_eq!(icrc1_balance_of(env, index_id, account_2), 5_000_000); | ||
|
|
||
| // Verify account_2 transactions (should have the authorized mint) | ||
| let txs = get_account_transactions(env, index_id, account_2, None, u64::MAX); | ||
| assert_eq!(txs.transactions.len(), 1); | ||
| assert_eq!(txs.transactions[0].id, Nat::from(1u64)); | ||
| let tx = &txs.transactions[0].transaction; | ||
| assert_eq!(tx.kind, "122mint"); | ||
| assert!(tx.authorized_mint.is_some()); | ||
|
|
||
| // Verify account_1 transactions (should have the mint and the authorized burn) | ||
| let txs = get_account_transactions(env, index_id, account_1, None, u64::MAX); | ||
| assert_eq!(txs.transactions.len(), 2); | ||
| // Transactions are in descending order | ||
| assert_eq!(txs.transactions[0].id, Nat::from(2u64)); | ||
| assert_eq!(txs.transactions[0].transaction.kind, "122burn"); | ||
| assert!(txs.transactions[0].transaction.authorized_burn.is_some()); | ||
| assert_eq!(txs.transactions[1].id, Nat::from(0u64)); | ||
| assert_eq!(txs.transactions[1].transaction.kind, "mint"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_authorized_mint_minimal_icrc122_block() { | ||
| // Test a minimal ICRC-122 block (no caller, no mthd — permissive schema) | ||
| let env = &StateMachine::new(); | ||
| let ledger_id = install_icrc3_test_ledger(env); | ||
| let index_id = install_index_ng(env, index_init_arg_without_interval(ledger_id)); | ||
|
|
||
| let account_1 = account(1, 0); | ||
|
|
||
| let block0 = BlockBuilder::new(0, 1000) | ||
| .authorized_mint(account_1, Tokens::from(1_000_000_u64)) | ||
| .build(); | ||
| assert_eq!( | ||
| Nat::from(0u64), | ||
| add_block(env, ledger_id, &block0).expect("failed to add block 0") | ||
| ); | ||
|
|
||
| wait_until_sync_is_completed(env, index_id, ledger_id); | ||
|
|
||
| assert_eq!(icrc1_balance_of(env, index_id, account_1), 1_000_000); | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to the comment regarding allowances in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added two unit tests in the
|
||
| #[test] | ||
| fn test_index_ledger_coherence() { | ||
| let mut runner = TestRunner::new(TestRunnerConfig::with_cases(1)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.