-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathForwardEth.test.ts
117 lines (99 loc) · 3.24 KB
/
ForwardEth.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
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';
import { 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('Forward Eth', () => {
let fuelWalletTestHelper: FuelWalletTestHelper;
let fuelWallet: WalletUnlocked;
let masterWallet: WalletUnlocked;
const forwardEthAmount = '0.0012';
test.beforeEach(async ({ context, extensionId, page }) => {
({ fuelWalletTestHelper, fuelWallet, masterWallet } = await testSetup({
context,
page,
extensionId,
amountToFund: bn.parseUnits(forwardEthAmount).mul(2),
}));
});
test.afterEach(async () => {
await transferMaxBalance({
fromWallet: fuelWallet,
toWallet: masterWallet,
});
});
test('e2e forward ETH', async ({ page }) => {
await connect(page, fuelWalletTestHelper);
const forwardEthInput = page
.getByLabel('Forward eth card')
.getByRole('textbox');
await forwardEthInput.fill(forwardEthAmount);
const forwardEthButton = getButtonByText(page, 'Forward ETH');
await expectButtonToBeEnabled(forwardEthButton);
await forwardEthButton.click({
delay: 1000,
});
const walletNotificationPage =
await fuelWalletTestHelper.getWalletPopupPage();
// Test if asset name is defined (not unknown)
await checkAriaLabelsContainsText(
walletNotificationPage,
'Asset Name',
'Ethereum'
);
// Test if sender name is defined (not unknown)
await checkAriaLabelsContainsText(
walletNotificationPage,
'Sender Name',
''
);
// test the asset name is shown
await expect
.poll(
async () =>
await hasText(walletNotificationPage, 'Ethereum')
.then(() => true)
.catch(() => false),
{ timeout: 15000 }
)
.toBeTruthy();
// test asset id is correct
await hasText(walletNotificationPage, shortAddress(await getBaseAssetId()));
// test forward eth amount is correct
await hasText(walletNotificationPage, `${forwardEthAmount} ETH`);
// 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
);
// Test approve
const preDepositBalanceEth = await fuelWallet.getBalance();
await fuelWalletTestHelper.walletApprove();
await waitSuccessTransaction(page);
const postDepositBalanceEth = await fuelWallet.getBalance();
expect(
Number.parseFloat(
preDepositBalanceEth.sub(postDepositBalanceEth).format({ precision: 4 })
)
).toBe(Number.parseFloat(forwardEthAmount));
});
});