Skip to content

Commit

Permalink
Enable the Token Allowance flow by default for all users
Browse files Browse the repository at this point in the history
Fixing lint verify locales

changed add approve token tests

skipped approve token tests from metamask-ui file

added test for max spending cap

failOnConsoleError

removed tests from metamask-ui

fix

add delay

removed failOnConsoleError
  • Loading branch information
VSaric committed Dec 5, 2022
1 parent 08e8760 commit ad29194
Show file tree
Hide file tree
Showing 2 changed files with 489 additions and 544 deletions.
195 changes: 0 additions & 195 deletions test/e2e/metamask-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,136 +515,6 @@ describe('MetaMask', function () {
});
});

describe('Approves a custom token from dapp', function () {
it('approves an already created token', async function () {
const windowHandles = await driver.getAllWindowHandles();
const extension = windowHandles[0];
const dapp = await driver.switchToWindowWithTitle(
'E2E Test Dapp',
windowHandles,
);
await driver.closeAllWindowHandlesExcept([extension, dapp]);
await driver.delay(regularDelayMs);

await driver.switchToWindow(dapp);
await driver.delay(tinyDelayMs);

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

await driver.switchToWindow(extension);
await driver.delay(regularDelayMs);

await driver.wait(async () => {
const pendingTxes = await driver.findElements(
'.transaction-list__pending-transactions .transaction-list-item',
);
return pendingTxes.length === 1;
}, 10000);

await driver.waitForSelector({
// Selects only the very first transaction list item immediately following the 'Pending' header
css: '.transaction-list__pending-transactions .transaction-list__header + .transaction-list-item .list-item__heading',
text: 'Approve TST spend limit',
});

await driver.clickElement('.transaction-list-item');
await driver.delay(regularDelayMs);
});

it('displays the token approval data', async function () {
await driver.clickElement({
text: 'View full transaction details',
css: '.confirm-approve-content__small-blue-text',
});
const functionType = await driver.findElement(
'.confirm-approve-content__data .confirm-approve-content__small-text',
);
const functionTypeText = await functionType.getText();
assert.equal(functionTypeText, 'Function: Approve');

const confirmDataDiv = await driver.findElement(
'.confirm-approve-content__data__data-block',
);
const confirmDataText = await confirmDataDiv.getText();
assert(
confirmDataText.match(
/0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef4/u,
),
);
});

it('customizes gas', async function () {
await driver.clickElement('.confirm-approve-content__small-blue-text');
await driver.delay(regularDelayMs);
await driver.clickElement({
text: 'Edit suggested gas fee',
tag: 'button',
});
await driver.delay(regularDelayMs);

const [gasLimitInput, gasPriceInput] = await driver.findElements(
'input[type="number"]',
);

await gasPriceInput.fill('10');
await driver.delay(50);

await gasLimitInput.fill('60001');

await driver.delay(veryLargeDelayMs);

await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(veryLargeDelayMs);

const gasFeeInEth = await driver.findElement(
'.confirm-approve-content__transaction-details-content__secondary-fee',
);
assert.equal(await gasFeeInEth.getText(), '0.0006 ETH');
});

it('edits the permission', async function () {
const editButtons = await driver.findClickableElements(
'.confirm-approve-content__small-blue-text',
);
await editButtons[2].click();

// wait for permission modal to be visible
const permissionModal = await driver.findVisibleElement('span .modal');
const radioButtons = await driver.findClickableElements(
'.edit-approval-permission__edit-section__radio-button',
);
await radioButtons[1].click();

await driver.fill('input', '5');
await driver.delay(regularDelayMs);

await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(veryLargeDelayMs);

// wait for permission modal to be removed from DOM.
await permissionModal.waitForElementState('hidden');

const permissionInfo = await driver.findElements(
'.confirm-approve-content__medium-text',
);
const amountDiv = permissionInfo[0];
assert.equal(await amountDiv.getText(), '5 TST');
});

it('submits the transaction', async function () {
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.delay(regularDelayMs);
});

it('finds the transaction in the transactions list', async function () {
await driver.waitForSelector({
// Select only the heading of the first entry in the transaction list.
css: '.transaction-list__completed-transactions .transaction-list-item:first-child .list-item__heading',
text: 'Approve TST spend limit',
});
});
});

describe('Transfers a custom token from dapp when no gas value is specified', function () {
it('transfers an already created token, without specifying gas', async function () {
const windowHandles = await driver.getAllWindowHandles();
Expand Down Expand Up @@ -701,69 +571,4 @@ describe('MetaMask', function () {
});
});
});

describe('Approves a custom token from dapp when no gas value is specified', function () {
it('approves an already created token', async function () {
const windowHandles = await driver.getAllWindowHandles();
const extension = windowHandles[0];
const dapp = await driver.switchToWindowWithTitle(
'E2E Test Dapp',
windowHandles,
);
await driver.closeAllWindowHandlesExcept([extension, dapp]);
await driver.delay(regularDelayMs);

await driver.switchToWindow(dapp);
await driver.delay(tinyDelayMs);

await driver.clickElement({
text: 'Approve Tokens Without Gas',
tag: 'button',
});

await driver.switchToWindow(extension);
await driver.delay(regularDelayMs);

await driver.wait(async () => {
const pendingTxes = await driver.findElements(
'.transaction-list__pending-transactions .transaction-list-item',
);
return pendingTxes.length === 1;
}, 10000);

await driver.waitForSelector({
// Selects only the very first transaction list item immediately following the 'Pending' header
css: '.transaction-list__pending-transactions .transaction-list__header + .transaction-list-item .list-item__heading',
text: 'Approve TST spend limit',
});

await driver.clickElement('.transaction-list-item');
await driver.delay(regularDelayMs);
});

it('shows the correct recipient', async function () {
await driver.clickElement({
text: 'View full transaction details',
css: '.confirm-approve-content__small-blue-text',
});
const permissionInfo = await driver.findElements(
'.confirm-approve-content__medium-text',
);
const recipientDiv = permissionInfo[1];
assert.equal(await recipientDiv.getText(), '0x2f318C33...C970');
});

it('submits the transaction', async function () {
await driver.delay(veryLargeDelayMs);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.delay(regularDelayMs);
});

it('finds the transaction in the transactions list', async function () {
await driver.waitForSelector({
css: '.transaction-list__completed-transactions .transaction-list-item:first-child .list-item__heading',
text: 'Approve TST spend limit',
});
});
});
});
Loading

0 comments on commit ad29194

Please sign in to comment.