From bf8f4aa4199f9894c0cdaedc15fbf560aec56e89 Mon Sep 17 00:00:00 2001 From: Plasma Corral <32695229+plasmacorral@users.noreply.github.com> Date: Thu, 27 Jun 2024 08:47:06 -0400 Subject: [PATCH 1/5] add e2e to swap with snap account --- .../accounts/snap-account-eth-swap.spec.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/e2e/accounts/snap-account-eth-swap.spec.ts diff --git a/test/e2e/accounts/snap-account-eth-swap.spec.ts b/test/e2e/accounts/snap-account-eth-swap.spec.ts new file mode 100644 index 000000000000..08e9ab7345f9 --- /dev/null +++ b/test/e2e/accounts/snap-account-eth-swap.spec.ts @@ -0,0 +1,41 @@ +import { withFixtures, WINDOW_TITLES } from '../helpers'; +import { Driver } from '../webdriver/driver'; +import { accountSnapFixtures, installSnapSimpleKeyring } from './common'; + +const { + buildQuote, + reviewQuote, + waitForTransactionToComplete, + checkActivityTransaction, +} = require('../tests/swaps/shared'); + +describe('Snap account swap', function () { + it('exchanges native token (ETH) for DAI with snap account', async function () { + await withFixtures( + accountSnapFixtures(this.test?.fullTitle()), + async ({ driver }: { driver: Driver }) => { + await installSnapSimpleKeyring(driver, false); + await driver.switchToWindowWithTitle( + WINDOW_TITLES.ExtensionInFullScreenView, + ); + await buildQuote(driver, { + amount: 0.001, + swapTo: 'DAI', + }); + await reviewQuote(driver, { + amount: 0.001, + swapFrom: 'TESTETH', + swapTo: 'DAI', + }); + await driver.clickElement({ text: 'Swap', tag: 'button' }); + await waitForTransactionToComplete(driver, { tokenName: 'DAI' }); + await checkActivityTransaction(driver, { + index: 0, + amount: '0.001', + swapFrom: 'TESTETH', + swapTo: 'DAI', + }); + }, + ); + }); +}); From 0f2f79deb7a2ca26caa42633cdc947de604be3cd Mon Sep 17 00:00:00 2001 From: Plasma Corral <32695229+plasmacorral@users.noreply.github.com> Date: Thu, 27 Jun 2024 09:13:44 -0400 Subject: [PATCH 2/5] fix: linting --- test/e2e/accounts/snap-account-eth-swap.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/accounts/snap-account-eth-swap.spec.ts b/test/e2e/accounts/snap-account-eth-swap.spec.ts index 08e9ab7345f9..79b2751c4e28 100644 --- a/test/e2e/accounts/snap-account-eth-swap.spec.ts +++ b/test/e2e/accounts/snap-account-eth-swap.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */ import { withFixtures, WINDOW_TITLES } from '../helpers'; import { Driver } from '../webdriver/driver'; import { accountSnapFixtures, installSnapSimpleKeyring } from './common'; From 56337456335932d9d500b4f5cc03ab5e00ed28a6 Mon Sep 17 00:00:00 2001 From: Plasma Corral <32695229+plasmacorral@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:59:30 -0400 Subject: [PATCH 3/5] Simply test fixtures per suggestion --- test/e2e/accounts/snap-account-eth-swap.spec.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/e2e/accounts/snap-account-eth-swap.spec.ts b/test/e2e/accounts/snap-account-eth-swap.spec.ts index 79b2751c4e28..8770c0674b4a 100644 --- a/test/e2e/accounts/snap-account-eth-swap.spec.ts +++ b/test/e2e/accounts/snap-account-eth-swap.spec.ts @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */ -import { withFixtures, WINDOW_TITLES } from '../helpers'; +import { withFixtures, defaultGanacheOptions, WINDOW_TITLES } from '../helpers'; import { Driver } from '../webdriver/driver'; -import { accountSnapFixtures, installSnapSimpleKeyring } from './common'; +import { installSnapSimpleKeyring } from './common'; +const FixtureBuilder = require('../fixture-builder'); const { buildQuote, reviewQuote, @@ -11,9 +12,13 @@ const { } = require('../tests/swaps/shared'); describe('Snap account swap', function () { - it('exchanges native token (ETH) for DAI with snap account', async function () { + it('exchanges native token (ETH) for DAI', async function () { await withFixtures( - accountSnapFixtures(this.test?.fullTitle()), + { + fixtures: new FixtureBuilder().build(), + ganacheOptions: defaultGanacheOptions, + title: this.test.fullTitle(), + }, async ({ driver }: { driver: Driver }) => { await installSnapSimpleKeyring(driver, false); await driver.switchToWindowWithTitle( From b5c46014714cb33c52109e2fdb5758dabb687335 Mon Sep 17 00:00:00 2001 From: Plasma Corral <32695229+plasmacorral@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:40:35 -0400 Subject: [PATCH 4/5] Fix: linting --- test/e2e/accounts/snap-account-eth-swap.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/accounts/snap-account-eth-swap.spec.ts b/test/e2e/accounts/snap-account-eth-swap.spec.ts index 8770c0674b4a..f25c537ecc5d 100644 --- a/test/e2e/accounts/snap-account-eth-swap.spec.ts +++ b/test/e2e/accounts/snap-account-eth-swap.spec.ts @@ -17,7 +17,7 @@ describe('Snap account swap', function () { { fixtures: new FixtureBuilder().build(), ganacheOptions: defaultGanacheOptions, - title: this.test.fullTitle(), + title: this.test?.fullTitle(), }, async ({ driver }: { driver: Driver }) => { await installSnapSimpleKeyring(driver, false); From 49afa37d2d7c1f85321381e18f411b7dd7f81a74 Mon Sep 17 00:00:00 2001 From: Plasma Corral <32695229+plasmacorral@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:51:50 -0400 Subject: [PATCH 5/5] use import instead of require, and update names --- .../accounts/snap-account-eth-swap.spec.ts | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/test/e2e/accounts/snap-account-eth-swap.spec.ts b/test/e2e/accounts/snap-account-eth-swap.spec.ts index f25c537ecc5d..bb4c3c7a5770 100644 --- a/test/e2e/accounts/snap-account-eth-swap.spec.ts +++ b/test/e2e/accounts/snap-account-eth-swap.spec.ts @@ -1,18 +1,19 @@ -/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */ import { withFixtures, defaultGanacheOptions, WINDOW_TITLES } from '../helpers'; import { Driver } from '../webdriver/driver'; -import { installSnapSimpleKeyring } from './common'; - -const FixtureBuilder = require('../fixture-builder'); -const { +import FixtureBuilder from '../fixture-builder'; +import { buildQuote, reviewQuote, waitForTransactionToComplete, checkActivityTransaction, -} = require('../tests/swaps/shared'); +} from '../tests/swaps/shared'; +import { installSnapSimpleKeyring } from './common'; + +const DAI = 'DAI'; +const TEST_ETH = 'TESTETH'; -describe('Snap account swap', function () { - it('exchanges native token (ETH) for DAI', async function () { +describe('Snap Account - Swap', function () { + it('swaps ETH for DAI using a snap account', async function () { await withFixtures( { fixtures: new FixtureBuilder().build(), @@ -26,20 +27,20 @@ describe('Snap account swap', function () { ); await buildQuote(driver, { amount: 0.001, - swapTo: 'DAI', + swapTo: DAI, }); await reviewQuote(driver, { amount: 0.001, - swapFrom: 'TESTETH', - swapTo: 'DAI', + swapFrom: TEST_ETH, + swapTo: DAI, }); await driver.clickElement({ text: 'Swap', tag: 'button' }); await waitForTransactionToComplete(driver, { tokenName: 'DAI' }); await checkActivityTransaction(driver, { index: 0, amount: '0.001', - swapFrom: 'TESTETH', - swapTo: 'DAI', + swapFrom: TEST_ETH, + swapTo: DAI, }); }, );