-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathgas-fee-tokens-eip-7702-sponsored.spec.ts
More file actions
325 lines (305 loc) · 9.65 KB
/
gas-fee-tokens-eip-7702-sponsored.spec.ts
File metadata and controls
325 lines (305 loc) · 9.65 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/* eslint-disable jest/no-disabled-tests -- E2E skipped; covered by component view tests */
import FixtureBuilder, {
DEFAULT_FIXTURE_ACCOUNT,
} from '../../../framework/fixtures/FixtureBuilder';
import FooterActions from '../../../page-objects/Browser/Confirmations/FooterActions';
import SendView from '../../../page-objects/Send/RedesignedSendView';
import TabBarComponent from '../../../page-objects/wallet/TabBarComponent';
import WalletView from '../../../page-objects/wallet/WalletView';
import {
Assertions,
LocalNode,
LocalNodeType,
Utilities,
} from '../../../framework';
import { SmokeConfirmations } from '../../../tags';
import { AnvilPort } from '../../../framework/fixtures/FixtureUtils';
import { loginToApp } from '../../../flows/wallet.flow';
import { withFixtures } from '../../../framework/fixtures/FixtureHelper';
import RowComponents from '../../../page-objects/Browser/Confirmations/RowComponents';
import { AnvilManager, Hardfork } from '../../../seeder/anvil-manager';
import {
setupMockRequest,
setupMockPostRequest,
} from '../../../api-mocking/helpers/mockHelpers';
import { SIMULATION_ENABLED_NETWORKS_MOCK } from '../../../api-mocking/mock-responses/simulations';
import { setupRemoteFeatureFlagsMock } from '../../../api-mocking/helpers/remoteFeatureFlagsHelper';
import { remoteFeatureEip7702 } from '../../../api-mocking/mock-responses/feature-flags-mocks';
import { Mockttp } from 'mockttp';
import {
TRANSACTION_RELAY_STATUS_NETWORKS_MOCK,
TRANSACTION_RELAY_SUBMIT_NETWORKS_MOCK,
} from '../../../api-mocking/mock-responses/transaction-relay-mocks';
import { RelayStatus } from '../../../../app/util/transactions/transaction-relay';
const TRANSACTION_UUID_MOCK = '1234-5678';
const SENDER_ADDRESS_MOCK = '0x76cf1cdd1fcc252442b50d6e97207228aa4aefc3';
const RECIPIENT_ADDRESS_MOCK = '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb';
/** Match {@link gas-fee-tokens-eip-7702.spec.ts} and {@link transaction-relay-mocks} for proxy URL matching. */
const LOCALHOST_SENTINEL_URL =
device.getPlatform() === 'android'
? 'https://tx-sentinel-127.0.0.1.api.cx.metamask.io/'
: 'https://tx-sentinel-localhost.api.cx.metamask.io/';
const SEND_ETH_TRANSACTION_MOCK = {
data: '0x',
from: SENDER_ADDRESS_MOCK,
to: RECIPIENT_ADDRESS_MOCK,
value: '0xde0b6B3a7640000',
};
const SIMULATION_ENABLED_NETWORKS_WITH_RELAY = {
...SIMULATION_ENABLED_NETWORKS_MOCK,
response: {
...SIMULATION_ENABLED_NETWORKS_MOCK.response,
1337: {
...SIMULATION_ENABLED_NETWORKS_MOCK.response[1337],
relayTransactions: true,
sendBundle: true,
},
1: {
network: 'ethereum-mainnet',
confirmations: true,
relayTransactions: true,
sendBundle: true,
},
},
};
const SIMULATION_SPONSORED_REQUEST_BODY = {
jsonrpc: '2.0',
method: 'infura_simulateTransactions',
params: [
{
transactions: [SEND_ETH_TRANSACTION_MOCK],
suggestFees: {
withFeeTransfer: true,
withTransfer: true,
with7702: true,
},
},
],
};
const SIMULATION_SPONSORED_IGNORE_FIELDS = [
'params.0.blockOverrides',
'id',
'params.0.transactions',
'params.0.suggestFees',
];
const SIMULATION_RESPONSE = {
jsonrpc: '2.0',
result: {
transactions: [
{
return:
'0x0000000000000000000000000000000000000000000000000000000000000000',
status: '0x1',
gasUsed: '0x5de2',
gasLimit: '0x5f34',
fees: [
{
maxFeePerGas: '0xf19b9f48d',
maxPriorityFeePerGas: '0x9febc9',
balanceNeeded: '0x59d9d3b865ed8',
currentBalance: '0x77f9fd8d99e7e0',
error: '',
tokenFees: [],
},
],
stateDiff: {},
feeEstimate: 972988071597550,
baseFeePerGas: 40482817574,
},
],
blockNumber: '0x1293669',
id: 'faaab4c5-edf5-4077-ac75-8d26278ca2c5',
sponsorship: { isSponsored: true },
},
};
const setupCommonMocks = async (mockServer: Mockttp) => {
await setupMockRequest(
mockServer,
{
requestMethod: 'GET',
url: SIMULATION_ENABLED_NETWORKS_WITH_RELAY.urlEndpoint,
response: SIMULATION_ENABLED_NETWORKS_WITH_RELAY.response,
responseCode: 200,
},
1000,
);
await setupMockRequest(mockServer, {
requestMethod: 'GET',
url: `${LOCALHOST_SENTINEL_URL}/network`,
response: SIMULATION_ENABLED_NETWORKS_WITH_RELAY.response,
responseCode: 200,
});
// Mock infura_simulateTransactions (align body + ignoreFields with gas-fee-tokens-eip-7702.spec.ts)
await setupMockPostRequest(
mockServer,
LOCALHOST_SENTINEL_URL,
SIMULATION_SPONSORED_REQUEST_BODY,
SIMULATION_RESPONSE,
{
statusCode: 200,
ignoreFields: SIMULATION_SPONSORED_IGNORE_FIELDS,
priority: 1000,
},
);
await setupRemoteFeatureFlagsMock(
mockServer,
Object.assign({}, ...remoteFeatureEip7702),
);
await setupMockRequest(mockServer, {
url: /accounts\.api\.cx\.metamask\.io\/v4\/multiaccount\/balances/,
response: {
balances: [
{
object: 'token',
address: '0x0000000000000000000000000000000000000000',
symbol: 'ETH',
name: 'Ether',
type: 'native',
decimals: 18,
chainId: 1337,
balance: '10.000000000000000000',
accountAddress: `eip155:1337:${DEFAULT_FIXTURE_ACCOUNT}`,
},
],
unprocessedNetworks: [],
},
requestMethod: 'GET',
responseCode: 200,
});
};
const createFixture = ({ localNodes }: { localNodes?: LocalNode[] }) => {
const node = localNodes?.[0] as unknown as AnvilManager;
const rpcPort =
node instanceof AnvilManager ? (node.getPort() ?? AnvilPort()) : undefined;
return new FixtureBuilder()
.withNetworkController({
chainId: '0x539',
rpcUrl: `http://localhost:${rpcPort ?? AnvilPort()}`,
type: 'custom',
nickname: 'Local RPC',
ticker: 'ETH',
})
.withDisabledSmartTransactions()
.build();
};
const localNodeOptions = [
{
type: LocalNodeType.anvil,
options: {
hardfork: 'prague' as Hardfork,
loadState:
'./tests/smoke/confirmations/transactions/7702/withDelegatorContracts.json',
},
},
];
const performSendTransaction = async () => {
await loginToApp();
await device.disableSynchronization();
await WalletView.tapWalletSendButton();
await SendView.selectEthereumToken();
await SendView.pressAmountFiveButton();
await SendView.pressContinueButton();
await SendView.inputRecipientAddress(RECIPIENT_ADDRESS_MOCK);
await SendView.pressReviewButton();
await Assertions.expectElementToBeVisible(RowComponents.GasFeesDetails, {
description: 'gas fees row is present on review screen',
timeout: 30000,
});
await Assertions.expectElementToBeVisible(
RowComponents.NetworkFeePaidByMetaMask,
{
description:
'network fee shows MetaMask-sponsored gas after relay + simulation settle',
timeout: 60000,
},
);
await Utilities.waitForElementToBeVisible(FooterActions.confirmButton);
await Utilities.waitForElementToStopMoving(FooterActions.confirmButton, {
timeout: 5000,
interval: 500,
stableCount: 6,
});
await FooterActions.tapConfirmButton();
await TabBarComponent.tapActivity();
};
describe(
SmokeConfirmations('Send native asset using EIP-7702 - Success Case'),
() => {
beforeAll(async () => {
jest.setTimeout(2500000);
});
it('sends ETH sponsored', async () => {
await withFixtures(
{
fixture: createFixture,
restartDevice: true,
localNodeOptions,
testSpecificMock: async (mockServer: Mockttp) => {
await setupCommonMocks(mockServer);
// Mock eth_sendRelayTransaction
await setupMockPostRequest(
mockServer,
LOCALHOST_SENTINEL_URL,
{
jsonrpc: '2.0',
method: 'eth_sendRelayTransaction',
},
TRANSACTION_RELAY_SUBMIT_NETWORKS_MOCK.response,
{
statusCode: 200,
ignoreFields: ['id', 'params'],
priority: 999,
},
);
// Status check mock
await setupMockRequest(mockServer, {
requestMethod: 'GET',
url: `${LOCALHOST_SENTINEL_URL}/smart-transactions/${TRANSACTION_UUID_MOCK}`,
response: {
transactions: [
{
hash: TRANSACTION_RELAY_STATUS_NETWORKS_MOCK.response
.transactions[0].hash,
status: RelayStatus.Success,
},
],
},
responseCode: 200,
});
},
},
async () => {
await performSendTransaction();
await Assertions.expectTextDisplayed('Confirmed');
await device.enableSynchronization();
},
);
});
},
);
describe(
SmokeConfirmations('Send native asset using EIP-7702 - Failure Case'),
() => {
beforeAll(async () => {
jest.setTimeout(2500000);
});
// Also implemented in cv tests (eip-7702-sponsored-relay-api-failure.view.test.tsx)
it('fails transaction if error occurs on API', async () => {
await withFixtures(
{
fixture: createFixture,
restartDevice: true,
localNodeOptions,
testSpecificMock: async (mockServer: Mockttp) => {
await setupCommonMocks(mockServer);
},
},
async () => {
await performSendTransaction();
await Assertions.expectTextDisplayed('Failed');
await device.enableSynchronization();
},
);
});
},
);