@@ -14,6 +14,7 @@ import { renderModal } from "$tests/mocks/modal.mock";
1414import { principal } from "$tests/mocks/sns-projects.mock" ;
1515import { IcrcTokenTransactionModalPo } from "$tests/page-objects/IcrcTokenTransactionModal.page-object" ;
1616import { JestPageObjectElement } from "$tests/page-objects/jest.page-object" ;
17+ import { runResolvedPromises } from "$tests/utils/timers.test-utils" ;
1718import { TokenAmountV2 } from "@dfinity/utils" ;
1819import { encodeIcrcAccount } from "@icp-sdk/canisters/ledger/icrc" ;
1920
@@ -26,6 +27,8 @@ describe("IcrcTokenTransactionModal", () => {
2627 amount : token . fee ,
2728 token,
2829 } ) ;
30+ const mintingAccount = { owner : principal ( 99 ) } ;
31+ const mintingAccountAddress = encodeIcrcAccount ( mintingAccount ) ;
2932
3033 beforeEach ( ( ) => {
3134 resetIdentity ( ) ;
@@ -34,8 +37,19 @@ describe("IcrcTokenTransactionModal", () => {
3437 routeId : AppPath . Accounts ,
3538 } ) ;
3639 vi . spyOn ( ledgerApi , "icrcTransfer" ) . mockResolvedValue ( 1234n ) ;
40+ vi . spyOn ( ledgerApi , "queryIcrcMintingAccount" ) . mockResolvedValue ( undefined ) ;
3741 } ) ;
3842
43+ const setupAccount = ( ) => {
44+ icrcAccountsStore . set ( {
45+ ledgerCanisterId,
46+ accounts : {
47+ accounts : [ { ...mockIcrcMainAccount , balanceUlps : 1000n * 10n ** 18n } ] ,
48+ certified : true ,
49+ } ,
50+ } ) ;
51+ } ;
52+
3953 const renderModalComponent = async ( ) => {
4054 const { container } = await renderModal ( {
4155 component : IcrcTokenTransactionModal ,
@@ -47,6 +61,8 @@ describe("IcrcTokenTransactionModal", () => {
4761 } ,
4862 } ) ;
4963
64+ await runResolvedPromises ( ) ;
65+
5066 return IcrcTokenTransactionModalPo . under (
5167 new JestPageObjectElement ( container )
5268 ) ;
@@ -59,25 +75,11 @@ describe("IcrcTokenTransactionModal", () => {
5975 } ) ;
6076
6177 it ( "should transfer tokens" , async ( ) => {
62- // Used to choose the source account
63- icrcAccountsStore . set ( {
64- ledgerCanisterId,
65- accounts : {
66- accounts : [
67- {
68- ...mockIcrcMainAccount ,
69- balanceUlps : 1000n * 10n ** 18n ,
70- } ,
71- ] ,
72- certified : true ,
73- } ,
74- } ) ;
78+ setupAccount ( ) ;
7579
7680 const po = await renderModalComponent ( ) ;
7781
78- const toAccount = {
79- owner : principal ( 2 ) ,
80- } ;
82+ const toAccount = { owner : principal ( 2 ) } ;
8183 const amount = 10 ;
8284
8385 await po . transferToAddress ( {
@@ -94,4 +96,78 @@ describe("IcrcTokenTransactionModal", () => {
9496 fee : token . fee ,
9597 } ) ;
9698 } ) ;
99+
100+ describe ( "burn address" , ( ) => {
101+ beforeEach ( ( ) => {
102+ vi . spyOn ( ledgerApi , "queryIcrcMintingAccount" ) . mockResolvedValue (
103+ mintingAccount
104+ ) ;
105+ } ) ;
106+
107+ it ( "should show burn address label when destination is the minting account" , async ( ) => {
108+ setupAccount ( ) ;
109+ const po = await renderModalComponent ( ) ;
110+ const formPo = po . getTransactionFormPo ( ) ;
111+
112+ expect ( await formPo . hasBurnAddressLabel ( ) ) . toBe ( false ) ;
113+
114+ await formPo . enterAddress ( mintingAccountAddress ) ;
115+
116+ expect ( await formPo . hasBurnAddressLabel ( ) ) . toBe ( true ) ;
117+ } ) ;
118+
119+ it ( "should not show burn address label for a regular address" , async ( ) => {
120+ setupAccount ( ) ;
121+ const po = await renderModalComponent ( ) ;
122+ const formPo = po . getTransactionFormPo ( ) ;
123+
124+ await formPo . enterAddress ( encodeIcrcAccount ( { owner : principal ( 2 ) } ) ) ;
125+
126+ expect ( await formPo . hasBurnAddressLabel ( ) ) . toBe ( false ) ;
127+ } ) ;
128+
129+ it ( "should hide the fee when destination is the minting account" , async ( ) => {
130+ setupAccount ( ) ;
131+ const po = await renderModalComponent ( ) ;
132+ const formPo = po . getTransactionFormPo ( ) ;
133+
134+ expect ( await formPo . hasFee ( ) ) . toBe ( true ) ;
135+
136+ await formPo . enterAddress ( mintingAccountAddress ) ;
137+
138+ expect ( await formPo . hasFee ( ) ) . toBe ( false ) ;
139+ } ) ;
140+
141+ it ( "should transfer with fee 0 when destination is the minting account" , async ( ) => {
142+ setupAccount ( ) ;
143+ const po = await renderModalComponent ( ) ;
144+
145+ await po . transferToAddress ( {
146+ destinationAddress : mintingAccountAddress ,
147+ amount : 1 ,
148+ } ) ;
149+
150+ expect ( ledgerApi . icrcTransfer ) . toHaveBeenCalledTimes ( 1 ) ;
151+ expect ( ledgerApi . icrcTransfer ) . toHaveBeenCalledWith (
152+ expect . objectContaining ( {
153+ fee : 0n ,
154+ to : mintingAccount ,
155+ } )
156+ ) ;
157+ } ) ;
158+
159+ it ( "should transfer with normal fee for a regular address" , async ( ) => {
160+ setupAccount ( ) ;
161+ const po = await renderModalComponent ( ) ;
162+
163+ await po . transferToAddress ( {
164+ destinationAddress : encodeIcrcAccount ( { owner : principal ( 2 ) } ) ,
165+ amount : 1 ,
166+ } ) ;
167+
168+ expect ( ledgerApi . icrcTransfer ) . toHaveBeenCalledWith (
169+ expect . objectContaining ( { fee : token . fee } )
170+ ) ;
171+ } ) ;
172+ } ) ;
97173} ) ;
0 commit comments