Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[e2e] Refactor for custom token add approve action using Ganache seeder #15728

Closed
wants to merge 1 commit into from

Conversation

mirjanaKukic
Copy link
Contributor

@mirjanaKukic mirjanaKukic commented Aug 30, 2022

Explanation

We need to refactor these tests in order to use the smart contract deployer, instead of deploying each contract manually, using the Dapp UI.
Tests which will be refactored are in custom-token-add-approve.spec.js file

Resolves #15417

More Information

The main goal is to deploy the e2e smart contracts directly on Ganache, instead of using the Dapp Test interface for achieving the same actions.
These smart contracts can be used later within the e2e tests in order to reduce the amount of code needed to be written in order to execute the same action every time for each of the tests (i.e. contract deployment). This would also reduce the time needed for e2e tests execution because waiting for the UI action response will be eliminated.

Manual Testing Steps

Run testcase locally or check ci pipeline and ensure that it continues to work normally:
yarn test:e2e:single test/e2e/tests/custom-token-add-approve.spec.js

Pre-Merge Checklist

  • PR template is filled out
  • IF this PR fixes a bug, a test that would have caught the bug has been added
  • PR is linked to the appropriate GitHub issue
  • PR has been added to the appropriate release Milestone

+ If there are functional changes:

  • Manual testing complete & passed
  • "Extension QA Board" label has been applied

@mirjanaKukic mirjanaKukic added the needs-qa Label will automate into QA workspace label Aug 30, 2022
@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@mirjanaKukic mirjanaKukic added the PS-team PS MM extension team issues label Aug 31, 2022
@mirjanaKukic mirjanaKukic self-assigned this Aug 31, 2022
@mirjanaKukic mirjanaKukic changed the title [fix] e2e test for custom token add approve action Refactor e2e test for custom token add approve action using Ganache seeder Aug 31, 2022
@mirjanaKukic mirjanaKukic changed the title Refactor e2e test for custom token add approve action using Ganache seeder [e2e] Refactor for custom token add approve action using Ganache seeder Aug 31, 2022
@metamaskbot
Copy link
Collaborator

Builds ready [7699dce]
Page Load Metrics (1970 ± 120 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1142046318525252
domContentLoaded171725371959234112
load172626741970250120
domInteractive171725371959233112

@seaona seaona self-requested a review September 5, 2022 17:02

describe.skip('Create token, approve token and approve token without gas', function () {
describe('Create token, approve token and approve token without gas', function () {
describe('Add a custom token from a dapp', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we use it blocks instead of nested describes, we could improve test structure and declare variables like smartContract, ganacheOptions only once before the it blocks (now repeated on line 13, 115, 322).

Something like:

describe('Create token, approve token and approve token without gas', function () {
   const smartContract = ...
   const ganacheOptions = ...

   it('...')
   it('...')
   it('...')

You can take this example for more clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

assert.equal(await recipientDiv.getText(), '0x2f318C33...C970');

await driver.clickElement({ text: 'Confirm', tag: 'button' });

await driver.waitForSelector({
css: '.transaction-list__completed-transactions .transaction-list-item:first-child .list-item__heading',
text: 'Approve Token spend limit',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think finishing each test case with an assertion is a good convention. It could be added in this last testcase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -37,8 +41,17 @@ describe.skip('Create token, approve token and approve token without gas', funct
await driver.waitForSelector({ text: 'Create Token', tag: 'button' });
Copy link
Contributor

@seaona seaona Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove waitForSelector, as the below clickElement method will make sure to findClickableElement first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -49,7 +62,7 @@ describe.skip('Create token, approve token and approve token without gas', funct
await driver.clickElement({ text: 'Save', tag: 'button' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, we can remove the above line of waitForSelector, as the below clickElement method will make sure to findClickableElement first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -99,8 +112,7 @@ describe.skip('Create token, approve token and approve token without gas', funct
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on lines 83, 101 we can remove await driver.waitForSelector('...'); for same reason above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const extension = windowHandles[0];

await driver.findClickableElement('#deployButton');
// approve token from dapp
await driver.waitForSelector({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this await driver.waitForSelector('...'); for same reason above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// approve token from dapp
await driver.waitForSelector({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this await driver.waitForSelector('...'); for same reason above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -25,6 +27,8 @@ describe.skip('Create token, approve token and approve token without gas', funct
dapp: true,
fixtures: 'connected-state',
ganacheOptions,
smartContract,
failOnConsoleError: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure we need the failOnConsoleError on all the tests, as it looks like they do not throw any console errors naturally (at least in my local env), so in the case there is a console error might be that some "real" error is happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had failure in one test and I put failOnConsoleError just in that test. After I thought maybe it would be good to put it in all tests, but if that is not usual i can remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified and it's not failing for me without the failOnConsoleError. If they are not failing for you I guess we can remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I remove from all tests it fails on first one on pipeline(it doesn't fail locally) with an error so I left failOnConsoleError just in one test:
1) Create token, approve token and approve token without gas
imports and renders the balance for the new token:
Error: Errors found in browser console:
https://static.metaswap.codefi.network/api/v1/tokenIcons/1337/0x581c3c1a2a4ebde2a0df29b5cf4c116e42945947.png - Failed to load resource: the server responded with a status of 404 (Not Found)
at withFixtures (test/e2e/helpers.js:130:17)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Context. (test/e2e/tests/custom-token-add-approve.spec.js:20:5)

@metamaskbot
Copy link
Collaborator

Builds ready [6b91add]
Page Load Metrics (1704 ± 27 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint90135112157
domContentLoaded1598183316936129
load1599183317045727
domInteractive1598183316936129

@mirjanaKukic
Copy link
Contributor Author

I think we could mock the gasPrice and gasLimit values instead of setting them up manually (see lines 57-60 and 261-264). What do you think @PeterYinusa @mirjanaKukic ?

I saw this approach in metamask-ui.spec.js file so put it like this also here. But yes I agree we could change it.

@metamaskbot
Copy link
Collaborator

Builds ready [8ff007c]
Page Load Metrics (1862 ± 72 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint992241272914
domContentLoaded16482127183614369
load16482127186214972
domInteractive16482127183614369

@mirjanaKukic mirjanaKukic marked this pull request as ready for review October 6, 2022 11:44
@mirjanaKukic mirjanaKukic requested a review from a team as a code owner October 6, 2022 11:44
@mirjanaKukic mirjanaKukic requested a review from danjm October 6, 2022 11:44
await driver.press('#password', driver.Key.ENTER);

// create token
await driver.openNewPage(`http://127.0.0.1:8080/`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to navigate to the test dapp with the contract deployed:

const contractAddress = await contractRegistry.getContractAddress(
          smartContract,
        );
await driver.openNewPage(
          `http://127.0.0.1:8080/?contract=${contractAddress}`,
        );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to the tests below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// create token
await driver.openNewPage(`http://127.0.0.1:8080/`);
await driver.clickElement({ text: 'Create Token', tag: 'button' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to create the token, as its already created using the seeder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to the tests below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

],
};

it('creates, imports and renders the balance for the new token', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also remove creates from the test title

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@mirjanaKukic mirjanaKukic force-pushed the e2e/custom-token-add-approve-fix branch from e6e948b to 44ffd4b Compare October 7, 2022 13:52
@metamaskbot
Copy link
Collaborator

Builds ready [84ea775]
Page Load Metrics (2345 ± 91 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint88144115168
domContentLoaded19722743233218087
load19722769234518991
domInteractive19722743233218087

@mirjanaKukic mirjanaKukic force-pushed the e2e/custom-token-add-approve-fix branch from 4371d0e to 9ede8f2 Compare October 12, 2022 09:09
@metamaskbot
Copy link
Collaborator

Builds ready [deedd51]
Page Load Metrics (2191 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint86164101178
domContentLoaded20122409218010349
load20122452219111455
domInteractive20122409217910349

@metamaskbot
Copy link
Collaborator

Builds ready [e4711ba]
Page Load Metrics (2229 ± 122 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint882699240564271
domContentLoaded167527012217253121
load167527252229254122
domInteractive167527012217253121

@brad-decker
Copy link
Contributor

@seaona @PeterYinusa @mirjanaKukic should this be rebased and reviewed again, or dropped?

lint fix

small refactoring

removed describe blocks

added assert

removed waitForSelectors

fix

added click for View full transaction details

removed faildOnConsoleError

added failOnConsoleError in one test

lint fix

added fixture builder
@mirjanaKukic mirjanaKukic force-pushed the e2e/custom-token-add-approve-fix branch from e4711ba to 17efda2 Compare November 22, 2022 08:27
@metamaskbot
Copy link
Collaborator

Builds ready [17efda2]
Page Load Metrics (2426 ± 147 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1081193194234112
domContentLoaded196235382411313150
load196235382426305147
domInteractive196235382411313150
Bundle size diffs
  • background: 0 bytes
  • ui: 0 bytes
  • common: 0 bytes

@mirjanaKukic
Copy link
Contributor Author

@seaona @PeterYinusa @mirjanaKukic should this be rebased and reviewed again, or dropped?

I've done rebase.

@mirjanaKukic
Copy link
Contributor Author

This one should not be merged since new screen for token allowance will be merged soon and tests for new screen are also done on this PR: #16740

@mirjanaKukic mirjanaKukic added the DO-NOT-MERGE Pull requests that should not be merged label Dec 9, 2022
@dzfjz dzfjz closed this Jan 31, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DO-NOT-MERGE Pull requests that should not be merged needs-qa Label will automate into QA workspace PS-team PS MM extension team issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor e2e testcases for implement smart contract deployment on the background using ganache seeder
6 participants