-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathForwardHalfCustomAsset.test.ts
143 lines (125 loc) · 4.48 KB
/
ForwardHalfCustomAsset.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
import type { FuelWalletTestHelper } from '@fuels/playwright-utils';
import {
expectButtonToBeEnabled,
getButtonByText,
hasText,
} from '@fuels/playwright-utils';
import { expect } from '@playwright/test';
import type { WalletUnlocked } from 'fuels';
import { bn } from 'fuels';
import '../../load.envs';
import type { IdentityInput } from '../../src/contracts/contracts/CustomAssetAbi';
import {
calculateAssetId,
getBaseAssetId,
shortAddress,
} from '../../src/utils';
import { testSetup, transferMaxBalance } from '../utils';
import { CustomAsset } from '../../src/contracts/contracts';
import { MAIN_CONTRACT_ID } from './config';
import { test, useLocalCRX } from './test';
import {
checkAddresses,
checkAriaLabelsContainsText,
connect,
waitSuccessTransaction,
} from './utils';
useLocalCRX();
test.describe('Forward Half Custom Asset', () => {
let fuelWallet: WalletUnlocked;
let fuelWalletTestHelper: FuelWalletTestHelper;
let masterWallet: WalletUnlocked;
const forwardCustomAssetAmount = '10000';
const formattedForwardCustomAssetAmount = '10,000';
const formattedHalfForwardCustomAssetAmount = '5,000';
test.beforeEach(async ({ context, extensionId, page }) => {
({ fuelWallet, fuelWalletTestHelper, masterWallet } = await testSetup({
context,
page,
extensionId,
amountToFund: bn.parseUnits('0.001'),
}));
});
test.afterEach(async () => {
await transferMaxBalance({
fromWallet: fuelWallet,
toWallet: masterWallet,
});
});
test('e2e forward half custom asset', async ({ page }) => {
await connect(page, fuelWalletTestHelper);
// Mint custom asset to wallet
const contract = new CustomAsset(MAIN_CONTRACT_ID, fuelWallet);
const recipient: IdentityInput = {
Address: {
bits: fuelWallet.address.toB256(),
},
};
const assetId = calculateAssetId(MAIN_CONTRACT_ID, await getBaseAssetId());
const { waitForResult } = await contract.functions
.mint(recipient, await getBaseAssetId(), bn(100_000_000_000))
.call();
await waitForResult();
const forwardHalfCustomAssetInput = page
.getByLabel('Forward half custom asset card')
.getByRole('textbox');
await forwardHalfCustomAssetInput.fill(forwardCustomAssetAmount);
const forwardHalfCustomAssetButton = getButtonByText(
page,
'Forward Half Custom Asset'
);
await expectButtonToBeEnabled(forwardHalfCustomAssetButton);
await forwardHalfCustomAssetButton.click({
delay: 1000,
});
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', '');
// test the forward asset name is shown
await hasText(walletNotificationPage, 'Unknown', 0, 5000, true);
// test forward asset id is correct
await hasText(walletNotificationPage, shortAddress(assetId));
// test forward custom asset amount is correct
await hasText(walletNotificationPage, formattedForwardCustomAssetAmount);
// test return asset name is shown
await hasText(walletNotificationPage, 'Unknown', 1, 5000, true);
// test return asset id is shown
await hasText(walletNotificationPage, shortAddress(assetId), 1);
// test return asset amount is correct
await hasText(
walletNotificationPage,
formattedHalfForwardCustomAssetAmount
);
// test gas fee is 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
);
// Test approve
const preDepositBalanceTkn = await fuelWallet.getBalance(assetId);
await fuelWalletTestHelper.walletApprove();
await waitSuccessTransaction(page);
const postDepositBalanceTkn = await fuelWallet.getBalance(assetId);
expect(
preDepositBalanceTkn
.sub(postDepositBalanceTkn)
.mul(10)
.format({ units: 1, precision: 0 })
).toBe(formattedHalfForwardCustomAssetAmount);
});
});