Skip to content

Commit cd9b297

Browse files
committed
tests
1 parent 9b3444b commit cd9b297

3 files changed

Lines changed: 103 additions & 16 deletions

File tree

frontend/src/tests/lib/modals/accounts/IcrcTokenTransactionModal.spec.ts

Lines changed: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { renderModal } from "$tests/mocks/modal.mock";
1414
import { principal } from "$tests/mocks/sns-projects.mock";
1515
import { IcrcTokenTransactionModalPo } from "$tests/page-objects/IcrcTokenTransactionModal.page-object";
1616
import { JestPageObjectElement } from "$tests/page-objects/jest.page-object";
17+
import { runResolvedPromises } from "$tests/utils/timers.test-utils";
1718
import { TokenAmountV2 } from "@dfinity/utils";
1819
import { 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
});

frontend/src/tests/lib/pages/SnsWallet.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ describe("SnsWallet", () => {
7878
balance: 0n,
7979
});
8080
vi.spyOn(icrcLedgerApi, "icrcTransfer").mockResolvedValue(10n);
81+
vi.spyOn(icrcLedgerApi, "queryIcrcMintingAccount").mockResolvedValue(
82+
undefined
83+
);
8184
vi.spyOn(
8285
workerTransactionsServices,
8386
"initTransactionsWorker"

frontend/src/tests/page-objects/TransactionForm.page-object.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,12 @@ export class TransactionFormPo extends BasePageObject {
151151
async hasManualAddressLink(): Promise<boolean> {
152152
return this.getManualAddressLink().isPresent();
153153
}
154+
155+
hasBurnAddressLabel(): Promise<boolean> {
156+
return this.root.byTestId("burn-address-label").isPresent();
157+
}
158+
159+
async hasFee(): Promise<boolean> {
160+
return this.getTransactionFormFeePo().isPresent();
161+
}
154162
}

0 commit comments

Comments
 (0)