-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathMintAsset.test.ts
185 lines (156 loc) · 5.58 KB
/
MintAsset.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import type { FuelWalletTestHelper } from '@fuels/playwright-utils';
import {
expectButtonToBeEnabled,
getButtonByText,
hasText,
} from '@fuels/playwright-utils';
import { expect } from '@playwright/test';
import { bn } from 'fuels';
import type { WalletUnlocked } from 'fuels';
import '../../load.envs.js';
import {
calculateAssetId,
getBaseAssetId,
shortAddress,
} from '../../src/utils';
import { testSetup, transferMaxBalance } from '../utils';
import { MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import {
checkAddresses,
checkAriaLabelsContainsText,
connect,
waitSuccessTransaction,
} from './utils';
useLocalCRX();
test.describe('Mint Assets', () => {
let fuelWalletTestHelper: FuelWalletTestHelper;
let fuelWallet: WalletUnlocked;
let masterWallet: WalletUnlocked;
test.beforeEach(async ({ context, extensionId, page }) => {
({ fuelWalletTestHelper, fuelWallet, masterWallet } = await testSetup({
context,
page,
extensionId,
amountToFund: bn.parseUnits('0.001'),
}));
});
test.afterEach(async () => {
await transferMaxBalance({
fromWallet: fuelWallet,
toWallet: masterWallet,
});
});
test('e2e mint unknown assets', async ({ page }) => {
await connect(page, fuelWalletTestHelper);
const mintAmount = '12345';
const formattedMintAmount = '12,345';
const mintInput = page.getByLabel('Mint asset card').getByRole('textbox');
await mintInput.fill(mintAmount);
const mintButton = getButtonByText(page, 'Mint', true);
await expectButtonToBeEnabled(mintButton);
await mintButton.click({
delay: 1000,
});
// test asset is correct
const assetId = calculateAssetId(MAIN_CONTRACT_ID, await getBaseAssetId());
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();
// short address function copied from app package
await hasText(walletNotificationPage, shortAddress(assetId), 0, 10000);
// test mint amount is correct
await hasText(walletNotificationPage, formattedMintAmount);
// test gas fee is shown and correct
await hasText(walletNotificationPage, 'Fee (network)');
await checkAddresses(
{ address: fuelWallet.address.toString(), isContract: false },
{ address: MAIN_CONTRACT_ID, isContract: true },
walletNotificationPage
);
await checkAddresses(
{ address: MAIN_CONTRACT_ID, isContract: true },
{ address: fuelWallet.address.toString(), isContract: false },
walletNotificationPage
);
const preMintBalanceTkn = await fuelWallet.getBalance(assetId);
await fuelWalletTestHelper.walletApprove();
await waitSuccessTransaction(page);
const postMintBalanceTkn = await fuelWallet.getBalance(assetId);
expect(
postMintBalanceTkn
.sub(preMintBalanceTkn)
.mul(10)
.format({ units: 1, precision: 0 })
).toBe(formattedMintAmount);
});
test('e2e mint known asset', async ({ page }) => {
await connect(page, fuelWalletTestHelper);
const subId =
'0x0000000000000000000000000000000000000000000000000000000000000001';
const name = 'Token';
const symbol = 'TKN';
const decimals = '6';
const assetId = calculateAssetId(MAIN_CONTRACT_ID, subId);
await fuelWalletTestHelper.addAssetThroughSettings(
assetId,
name,
symbol,
Number(decimals)
);
const mintAmount = '1.2345';
const mintAmountInput = page.getByLabel('Asset config amount');
await mintAmountInput.fill(mintAmount);
const subIdInput = page.getByLabel('Asset config subid');
await subIdInput.fill(subId);
const decimalsInput = page.getByLabel('Asset config decimals');
await decimalsInput.fill(decimals);
const mintButton = getButtonByText(page, 'Mint Asset configuration');
await expectButtonToBeEnabled(mintButton);
await mintButton.click({
delay: 1000,
});
// test asset is correct
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();
// Test if asset name is defined (not unknown)
checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
checkAriaLabelsContainsText(walletNotificationPage, 'Sender Name', '');
// scroll to bottom of page to ensure all text is visible
await walletNotificationPage.evaluate(() =>
window.scrollTo(0, document.body.scrollHeight)
);
await hasText(walletNotificationPage, name);
await hasText(walletNotificationPage, shortAddress(assetId), 0, 10000);
// test mint amount is correct
await hasText(walletNotificationPage, `1.2345 ${symbol}`);
// test gas fee is shown and correct
await hasText(walletNotificationPage, 'Fee (network)');
// test to and from addresses
await checkAddresses(
{ address: fuelWallet.address.toString(), isContract: false },
{ address: MAIN_CONTRACT_ID, isContract: true },
walletNotificationPage
);
await checkAddresses(
{ address: MAIN_CONTRACT_ID, isContract: true },
{ address: fuelWallet.address.toString(), isContract: false },
walletNotificationPage
);
const preMintBalanceTkn = await fuelWallet.getBalance(assetId);
await fuelWalletTestHelper.walletApprove();
await waitSuccessTransaction(page);
const postMintBalanceTkn = await fuelWallet.getBalance(assetId);
expect(
Number.parseFloat(
postMintBalanceTkn
.sub(preMintBalanceTkn)
.format({ precision: 6, units: 6 })
)
).toBe(Number.parseFloat(mintAmount));
});
});