-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathDepositHalfEth.test.ts
132 lines (114 loc) · 3.83 KB
/
DepositHalfEth.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
import {
expectButtonToBeEnabled,
getButtonByText,
hasText,
} from '@fuels/playwright-utils';
import type { FuelWalletTestHelper } from '@fuels/playwright-utils';
import { expect } from '@playwright/test';
import type { WalletUnlocked } from 'fuels';
import { bn } from 'fuels';
import '../../load.envs.js';
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('Deposit Half ETH', () => {
let fuelWalletTestHelper: FuelWalletTestHelper;
let fuelWallet: WalletUnlocked;
let masterWallet: WalletUnlocked;
const depositAmount = '0.010';
const halfDepositAmount = '0.005';
test.beforeEach(async ({ context, extensionId, page }) => {
({ fuelWalletTestHelper, fuelWallet, masterWallet } = await testSetup({
context,
page,
extensionId,
amountToFund: bn.parseUnits(depositAmount).mul(2),
}));
});
test.afterEach(async () => {
await transferMaxBalance({
fromWallet: fuelWallet,
toWallet: masterWallet,
});
});
test('e2e deposit half eth', async ({ page }) => {
await connect(page, fuelWalletTestHelper);
const depositHalfInput = page
.getByLabel('Deposit half eth card')
.getByRole('textbox');
await depositHalfInput.fill(depositAmount);
const depositHalfButton = getButtonByText(page, 'Deposit Half ETH', true);
await expectButtonToBeEnabled(depositHalfButton);
await depositHalfButton.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 forward asset name is shown
await expect
.poll(
async () =>
await hasText(walletNotificationPage, 'Ethereum')
.then(() => true)
.catch(() => false),
{ timeout: 15000 }
)
.toBeTruthy();
// test forward asset id is shown
await hasText(walletNotificationPage, shortAddress(await getBaseAssetId()));
// test forward eth amount is correct
await hasText(walletNotificationPage, `${depositAmount} ETH`);
// test return asset name is shown
await hasText(walletNotificationPage, 'Ethereum', 1);
// test return asset id is shown
await hasText(
walletNotificationPage,
shortAddress(await getBaseAssetId()),
1
);
// test return eth amount is correct
await hasText(walletNotificationPage, `${halfDepositAmount} ETH`);
// 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 preDepositBalanceEth = await fuelWallet.getBalance();
await fuelWalletTestHelper.walletApprove();
await waitSuccessTransaction(page);
const postDepositBalanceEth = await fuelWallet.getBalance();
expect(
Number.parseFloat(
preDepositBalanceEth.sub(postDepositBalanceEth).format({ precision: 3 })
)
).toBe(Number.parseFloat(halfDepositAmount));
});
});