Skip to content

Commit

Permalink
Merge branch 'develop' into feat-permit-alert-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
digiwand committed Sep 9, 2024
2 parents 9d4c243 + 416d024 commit ad65b1c
Show file tree
Hide file tree
Showing 41 changed files with 740 additions and 31 deletions.
10 changes: 2 additions & 8 deletions test/e2e/accounts/create-watch-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ async function watchEoaAddress(
address: string = EOA_ADDRESS,
): Promise<void> {
await startCreateWatchAccountFlow(driver, unlockWalletFirst);
await driver.fill(
'[placeholder="Enter a public address or ENS name"]',
address,
);
await driver.fill('input#address-input[type="text"]', address);
await driver.clickElement({ text: 'Watch account', tag: 'button' });
await driver.clickElement('[data-testid="submit-add-account-with-name"]');
}
Expand Down Expand Up @@ -188,10 +185,7 @@ describe('Account-watcher snap', function (this: Suite) {
async ({ driver }: { driver: Driver }) => {
await startCreateWatchAccountFlow(driver);

await driver.fill(
'[placeholder="Enter a public address or ENS name"]',
input,
);
await driver.fill('input#address-input[type="text"]', input);
await driver.clickElement({ text: 'Watch account', tag: 'button' });

// error message should be displayed by the snap
Expand Down
140 changes: 140 additions & 0 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class FixtureBuilder {
onboarding === true ? onboardingFixture() : defaultFixture(inputChainId);
}

withAccountTracker(data) {
merge(this.fixture.data.AccountTracker, data);
return this;
}

withAddressBookController(data) {
merge(
this.fixture.data.AddressBookController
Expand Down Expand Up @@ -1791,6 +1796,141 @@ class FixtureBuilder {
return this.withNameController({ names: {} });
}

withTrezorAccount() {
return this.withAccountTracker({
accounts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
balance: '0x15af1d78b58c40000',
},
'0xf68464152d7289d7ea9a2bec2e0035c45188223c': {
address: '0xf68464152d7289d7ea9a2bec2e0035c45188223c',
balance: '0x100000000000000000000',
},
},
currentBlockGasLimit: '0x1c9c380',
accountsByChainId: {
'0x539': {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
balance: '0x15af1d78b58c40000',
},
'0xf68464152d7289d7ea9a2bec2e0035c45188223c': {
address: '0xf68464152d7289d7ea9a2bec2e0035c45188223c',
balance: '0x100000000000000000000',
},
},
},
currentBlockGasLimitByChainId: {
'0x539': '0x1c9c380',
},
})
.withAccountsController({
internalAccounts: {
accounts: {
'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4': {
id: 'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4',
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
options: {},
methods: [
'personal_sign',
'eth_sign',
'eth_signTransaction',
'eth_signTypedData_v1',
'eth_signTypedData_v3',
'eth_signTypedData_v4',
],
type: 'eip155:eoa',
metadata: {
name: 'Account 1',
importTime: 1724486724986,
lastSelected: 1665507600000,
keyring: {
type: 'HD Key Tree',
},
},
},
'221ecb67-0d29-4c04-83b2-dff07c263634': {
id: '221ecb67-0d29-4c04-83b2-dff07c263634',
address: '0xf68464152d7289d7ea9a2bec2e0035c45188223c',
options: {},
methods: [
'personal_sign',
'eth_sign',
'eth_signTransaction',
'eth_signTypedData_v1',
'eth_signTypedData_v3',
'eth_signTypedData_v4',
],
type: 'eip155:eoa',
metadata: {
name: 'Trezor 1',
importTime: 1724486729079,
keyring: {
type: 'Trezor Hardware',
},
lastSelected: 1724486729083,
},
},
},
selectedAccount: '221ecb67-0d29-4c04-83b2-dff07c263634',
},
})
.withKeyringController({
vault:
'{"data":"NPUZE4s9SQOrsw1GtJSnQ9ptC3J1nf3O+hWT3N8Oh5MDcyO0XojQfSBZL88FgjuAGMT+oFEnX8gzsd1x0/Z7iinNSOD+U22LJ6w37Pkfw4mqAYvKJDbnb2HAdjNbjGD99PKn1qe5eR0vohL5taFW2lTKdlE3dficITFM9wm9mQTegQVvYClTSktweumFS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hXtdOyc123sSghIPjC6RUlZE53skLx1cPaV5JJAkneQJ44QMWecLQjh3YyCzRQ8XCnFAL+Kmf7zW5t+l25PLCkcfuLE7zxvLsTz3w2TCIXzEJyw1vXjBzPTUdKCNSva0WGsbq5B93zYot6bmvK1RKHeje8Ed/4N/l8uwxulUAjYQ+94qDKkxTVxvAZ8ydoxwKuB8QCTXgbymDsF/Y5l+RDXmzMT8BdN/QtdjsCXJ2PjvBG+srQOPntOCZMS7FVMk9yc6MWE/DBDm7HtY5CiY3af4A5sOZmLSP3Ek91ijmYdr/nO32DnkV4NJ2/Hj8SWAK5OD8zq8q5uRlR8BDcj7oLnzJX4S+yJNJ/nZSleUyTsv5v6YZ8hno","iv":"6SgfUVcvgUDGbCuqmdZgbA==","keyMetadata":{"algorithm":"PBKDF2","params":{"iterations":600000}},"salt":"nk4xdpmMR+1s5BYe4Vnk++XAQwrISI2bCtbMg7V1wUA="}',
})
.withNameController({
names: {
ethereumAddress: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
'*': {
name: 'Account 1',
sourceId: null,
proposedNames: {},
origin: 'account-identity',
},
},
'0xf68464152d7289d7ea9a2bec2e0035c45188223c': {
'*': {
proposedNames: {},
name: 'Trezor 1',
sourceId: null,
origin: 'account-identity',
},
},
},
},
})
.withPreferencesController({
identities: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
lastSelected: 1665507600000,
name: 'Account 1',
},
'0xf68464152d7289d7ea9a2bec2e0035c45188223c': {
address: '0xf68464152d7289d7ea9a2bec2e0035c45188223c',
lastSelected: 1665507800000,
name: 'Trezor 1',
},
},
lostIdentities: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
name: 'Account 1',
lastSelected: 1665507600000,
},
'0xf68464152d7289d7ea9a2bec2e0035c45188223c': {
address: '0xf68464152d7289d7ea9a2bec2e0035c45188223c',
name: 'Trezor 1',
lastSelected: 1665507800000,
},
},
selectedAddress: '0xf68464152d7289d7ea9a2bec2e0035c45188223c',
});
}

build() {
this.fixture.meta = {
version: FIXTURE_STATE_METADATA_VERSION,
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/flask/btc/btc-account-overview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ describe('BTC Account - Overview', function (this: Suite) {
const buySellButton = await driver.waitForSelector(
'[data-testid="coin-overview-buy"]',
);
// Ramps now support buyable chains dynamically (https://github.com/MetaMask/metamask-extension/pull/24041) and has now been
// enabled to fully support the v12.2.0 release
assert.equal(await buySellButton.isEnabled(), true);

const portfolioButton = await driver.waitForSelector(
Expand Down
57 changes: 45 additions & 12 deletions test/e2e/flask/btc/common-btc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Mockttp } from 'mockttp';
import FixtureBuilder from '../../fixture-builder';
import { withFixtures, unlockWallet } from '../../helpers';
import { DEFAULT_BTC_ACCOUNT } from '../../constants';
import { MultichainNetworks } from '../../../../shared/constants/multichain/networks';
import { Driver } from '../../webdriver/driver';
import { createBtcAccount } from '../../accounts/common';

Expand All @@ -19,17 +20,43 @@ export async function mockBtcBalanceQuote(
mockServer: Mockttp,
address: string = DEFAULT_BTC_ACCOUNT,
) {
return [
await mockServer
.forGet(/https:\/\/api\.blockchair\.com\/bitcoin\/addresses\/balances/u)
.withQuery({
addresses: address,
})
.thenCallback(() => ({
statusCode: 200,
json: GENERATE_MOCK_BTC_BALANCE_CALL(address),
})),
];
return await mockServer
.forGet(/https:\/\/api\.blockchair\.com\/bitcoin\/addresses\/balances/u)
.withQuery({
addresses: address,
})
.thenCallback(() => ({
statusCode: 200,
json: GENERATE_MOCK_BTC_BALANCE_CALL(address),
}));
}

export async function mockRampsDynamicFeatureFlag(
mockServer: Mockttp,
subDomain: string,
) {
return await mockServer
.forGet(
`https://on-ramp-content.${subDomain}.cx.metamask.io/regions/networks`,
)
.withQuery({
context: 'extension',
})
.thenCallback(() => ({
statusCode: 200,
json: {
networks: [
{
active: true,
chainId: MultichainNetworks.BITCOIN,
chainName: 'Bitcoin',
shortName: 'Bitcoin',
nativeTokenSupported: true,
isEvm: false,
},
],
},
}));
}

export async function withBtcAccountSnap(
Expand All @@ -48,7 +75,13 @@ export async function withBtcAccountSnap(
.build(),
title,
dapp: true,
testSpecificMock: mockBtcBalanceQuote,
testSpecificMock: async (mockServer: Mockttp) => [
await mockBtcBalanceQuote(mockServer),
// See: PROD_RAMP_API_BASE_URL
await mockRampsDynamicFeatureFlag(mockServer, 'api'),
// See: UAT_RAMP_API_BASE_URL
await mockRampsDynamicFeatureFlag(mockServer, 'uat-api'),
],
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/seeder/ganache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export class Ganache {
return Number(fiatBalance);
}

async setAccountBalance(address: string, balance: string) {
return await this.getProvider()?.request({
method: 'evm_setAccountBalance',
params: [address, balance],
});
}

async quit() {
if (!this.#server) {
throw new Error('Server not running yet');
Expand Down
47 changes: 47 additions & 0 deletions test/e2e/tests/hardware-wallets/trezor-send.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Suite } from 'mocha';
import { Driver } from '../../webdriver/driver';
import { Ganache } from '../../seeder/ganache';
import FixtureBuilder from '../../fixture-builder';
import {
defaultGanacheOptions,
logInWithBalanceValidation,
sendTransaction,
withFixtures,
} from '../../helpers';
import { KNOWN_PUBLIC_KEY_ADDRESSES } from '../../../stub/keyring-bridge';

const RECIPIENT = '0x0Cc5261AB8cE458dc977078A3623E2BaDD27afD3';

describe('Trezor Hardware', function (this: Suite) {
it('send ETH', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder().withTrezorAccount().build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({
driver,
ganacheServer,
}: {
driver: Driver;
ganacheServer?: Ganache;
}) => {
// Seed the Trezor account with balance
await ganacheServer?.setAccountBalance(
KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
'0x100000000000000000000',
);
await logInWithBalanceValidation(driver);

await sendTransaction(driver, RECIPIENT, '1');

// Wait for transaction to be confirmed
await driver.waitForSelector({
css: '.transaction-status-label',
text: 'Confirmed',
});
},
);
});
});
Loading

0 comments on commit ad65b1c

Please sign in to comment.