mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
E2e signing (#13507)
* Update personal-sign.spec.js * Update signature-request.spec.js * Add tests for eth_signTypedData and eth_signTypedData_v3 methods * Lint * Verify message * Verify message * Add test for eth_sign method
This commit is contained in:
parent
2b010710ae
commit
7bcd22d85f
@ -268,7 +268,7 @@ describe('MetaMask', function () {
|
|||||||
popup = windowHandles[2];
|
popup = windowHandles[2];
|
||||||
await driver.switchToWindow(popup);
|
await driver.switchToWindow(popup);
|
||||||
await driver.delay(regularDelayMs);
|
await driver.delay(regularDelayMs);
|
||||||
await driver.clickElement({ text: 'Edit', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Edit', tag: 'button' });
|
||||||
|
|
||||||
const inputs = await driver.findElements('input[type="number"]');
|
const inputs = await driver.findElements('input[type="number"]');
|
||||||
const gasLimitInput = inputs[0];
|
const gasLimitInput = inputs[0];
|
||||||
@ -276,8 +276,8 @@ describe('MetaMask', function () {
|
|||||||
await gasLimitInput.fill('4700000');
|
await gasLimitInput.fill('4700000');
|
||||||
await gasPriceInput.fill('20');
|
await gasPriceInput.fill('20');
|
||||||
await driver.delay(1000);
|
await driver.delay(1000);
|
||||||
await driver.clickElement({ text: 'Save', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Save', tag: 'button' });
|
||||||
await driver.clickElement({ text: 'Confirm', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Confirm', tag: 'button' });
|
||||||
|
|
||||||
await driver.delay(regularDelayMs);
|
await driver.delay(regularDelayMs);
|
||||||
|
|
||||||
@ -390,7 +390,7 @@ describe('MetaMask', function () {
|
|||||||
await gasLimitInput.fill('100000');
|
await gasLimitInput.fill('100000');
|
||||||
await gasPriceInput.fill('100');
|
await gasPriceInput.fill('100');
|
||||||
await driver.delay(1000);
|
await driver.delay(1000);
|
||||||
await driver.clickElement({ text: 'Save', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Save', tag: 'button' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('submits the transaction', async function () {
|
it('submits the transaction', async function () {
|
||||||
@ -465,7 +465,7 @@ describe('MetaMask', function () {
|
|||||||
await gasLimitInput.fill('60000');
|
await gasLimitInput.fill('60000');
|
||||||
await gasPriceInput.fill('10');
|
await gasPriceInput.fill('10');
|
||||||
await driver.delay(1000);
|
await driver.delay(1000);
|
||||||
await driver.clickElement({ text: 'Save', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Save', tag: 'button' });
|
||||||
await driver.findElement({ tag: 'span', text: '0.0006' });
|
await driver.findElement({ tag: 'span', text: '0.0006' });
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -591,7 +591,7 @@ describe('MetaMask', function () {
|
|||||||
|
|
||||||
await driver.delay(1000);
|
await driver.delay(1000);
|
||||||
|
|
||||||
await driver.clickElement({ text: 'Save', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Save', tag: 'button' });
|
||||||
|
|
||||||
const gasFeeInEth = await driver.findElement(
|
const gasFeeInEth = await driver.findElement(
|
||||||
'.confirm-approve-content__transaction-details-content__secondary-fee',
|
'.confirm-approve-content__transaction-details-content__secondary-fee',
|
||||||
|
67
test/e2e/tests/eth-sign.spec.js
Normal file
67
test/e2e/tests/eth-sign.spec.js
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
const { strict: assert } = require('assert');
|
||||||
|
const { convertToHexValue, withFixtures } = require('../helpers');
|
||||||
|
|
||||||
|
describe('Eth sign', function () {
|
||||||
|
it('can initiate and confirm a eth sign', async function () {
|
||||||
|
const ganacheOptions = {
|
||||||
|
accounts: [
|
||||||
|
{
|
||||||
|
secretKey:
|
||||||
|
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
|
||||||
|
balance: convertToHexValue(25000000000000000000),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const expectedPersonalMessage =
|
||||||
|
'0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0';
|
||||||
|
const expectedEthSignResult =
|
||||||
|
'"0x816ab6c5d5356548cc4e004ef35a37fdfab916742a2bbeda756cd064c3d3789a6557d41d49549be1de249e1937a8d048996dfcc70d0552111605dc7cc471e8531b"';
|
||||||
|
await withFixtures(
|
||||||
|
{
|
||||||
|
dapp: true,
|
||||||
|
fixtures: 'connected-state',
|
||||||
|
ganacheOptions,
|
||||||
|
title: this.test.title,
|
||||||
|
},
|
||||||
|
async ({ driver }) => {
|
||||||
|
await driver.navigate();
|
||||||
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
|
|
||||||
|
await driver.openNewPage('http://127.0.0.1:8080/');
|
||||||
|
await driver.clickElement('#ethSign');
|
||||||
|
|
||||||
|
await driver.waitUntilXWindowHandles(3);
|
||||||
|
let windowHandles = await driver.getAllWindowHandles();
|
||||||
|
await driver.switchToWindowWithTitle(
|
||||||
|
'MetaMask Notification',
|
||||||
|
windowHandles,
|
||||||
|
);
|
||||||
|
|
||||||
|
const title = await driver.findElement(
|
||||||
|
'.request-signature__header__text',
|
||||||
|
);
|
||||||
|
const origin = await driver.findElement('.request-signature__origin');
|
||||||
|
assert.equal(await title.getText(), 'Signature Request');
|
||||||
|
assert.equal(await origin.getText(), 'http://127.0.0.1:8080');
|
||||||
|
|
||||||
|
const personalMessageRow = await driver.findElement(
|
||||||
|
'.request-signature__row-value',
|
||||||
|
);
|
||||||
|
const personalMessage = await personalMessageRow.getText();
|
||||||
|
assert.equal(personalMessage, expectedPersonalMessage);
|
||||||
|
|
||||||
|
await driver.clickElement('[data-testid="request-signature__sign"]');
|
||||||
|
|
||||||
|
// Switch to the Dapp
|
||||||
|
await driver.waitUntilXWindowHandles(2);
|
||||||
|
windowHandles = await driver.getAllWindowHandles();
|
||||||
|
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
const result = await driver.findElement('#ethSignResult');
|
||||||
|
assert.equal(await result.getText(), expectedEthSignResult);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@ -1,5 +1,5 @@
|
|||||||
const { strict: assert } = require('assert');
|
const { strict: assert } = require('assert');
|
||||||
const { convertToHexValue, withFixtures } = require('../helpers');
|
const { convertToHexValue, withFixtures, largeDelayMs } = require('../helpers');
|
||||||
|
|
||||||
describe('Personal sign', function () {
|
describe('Personal sign', function () {
|
||||||
it('can initiate and confirm a personal sign', async function () {
|
it('can initiate and confirm a personal sign', async function () {
|
||||||
@ -12,6 +12,7 @@ describe('Personal sign', function () {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1';
|
||||||
await withFixtures(
|
await withFixtures(
|
||||||
{
|
{
|
||||||
dapp: true,
|
dapp: true,
|
||||||
@ -28,7 +29,7 @@ describe('Personal sign', function () {
|
|||||||
await driver.clickElement('#personalSign');
|
await driver.clickElement('#personalSign');
|
||||||
|
|
||||||
await driver.waitUntilXWindowHandles(3);
|
await driver.waitUntilXWindowHandles(3);
|
||||||
const windowHandles = await driver.getAllWindowHandles();
|
let windowHandles = await driver.getAllWindowHandles();
|
||||||
await driver.switchToWindowWithTitle(
|
await driver.switchToWindowWithTitle(
|
||||||
'MetaMask Notification',
|
'MetaMask Notification',
|
||||||
windowHandles,
|
windowHandles,
|
||||||
@ -42,7 +43,22 @@ describe('Personal sign', function () {
|
|||||||
|
|
||||||
await driver.clickElement('[data-testid="request-signature__sign"]');
|
await driver.clickElement('[data-testid="request-signature__sign"]');
|
||||||
|
|
||||||
|
// Switch to the Dapp
|
||||||
await driver.waitUntilXWindowHandles(2);
|
await driver.waitUntilXWindowHandles(2);
|
||||||
|
windowHandles = await driver.getAllWindowHandles();
|
||||||
|
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
await driver.clickElement('#personalSignVerify');
|
||||||
|
await driver.delay(largeDelayMs);
|
||||||
|
const verifySigUtil = await driver.findElement(
|
||||||
|
'#personalSignVerifySigUtilResult',
|
||||||
|
);
|
||||||
|
const verifyECRecover = await driver.findElement(
|
||||||
|
'#personalSignVerifyECRecoverResult',
|
||||||
|
);
|
||||||
|
assert.equal(await verifySigUtil.getText(), publicAddress);
|
||||||
|
assert.equal(await verifyECRecover.getText(), publicAddress);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -224,7 +224,7 @@ describe('Send ETH from dapp using advanced gas controls', function () {
|
|||||||
await driver.switchToWindow(dapp);
|
await driver.switchToWindow(dapp);
|
||||||
|
|
||||||
// initiates a send from the dapp
|
// initiates a send from the dapp
|
||||||
await driver.clickElement({ text: 'Send', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Send', tag: 'button' });
|
||||||
await driver.delay(2000);
|
await driver.delay(2000);
|
||||||
windowHandles = await driver.getAllWindowHandles();
|
windowHandles = await driver.getAllWindowHandles();
|
||||||
await driver.switchToWindowWithTitle(
|
await driver.switchToWindowWithTitle(
|
||||||
@ -243,8 +243,8 @@ describe('Send ETH from dapp using advanced gas controls', function () {
|
|||||||
const gasPriceInput = inputs[1];
|
const gasPriceInput = inputs[1];
|
||||||
await gasPriceInput.fill('100');
|
await gasPriceInput.fill('100');
|
||||||
await driver.delay(1000);
|
await driver.delay(1000);
|
||||||
await driver.clickElement({ text: 'Save', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Save', tag: 'button' });
|
||||||
await driver.clickElement({ text: 'Confirm', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Confirm', tag: 'button' });
|
||||||
await driver.waitUntilXWindowHandles(2);
|
await driver.waitUntilXWindowHandles(2);
|
||||||
await driver.switchToWindow(extension);
|
await driver.switchToWindow(extension);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const { strict: assert } = require('assert');
|
const { strict: assert } = require('assert');
|
||||||
const { convertToHexValue, withFixtures } = require('../helpers');
|
const { convertToHexValue, withFixtures } = require('../helpers');
|
||||||
|
|
||||||
describe('Signature Request', function () {
|
describe('Sign Typed Data V4 Signature Request', function () {
|
||||||
it('can initiate and confirm a Signature Request', async function () {
|
it('can initiate and confirm a Signature Request', async function () {
|
||||||
const ganacheOptions = {
|
const ganacheOptions = {
|
||||||
accounts: [
|
accounts: [
|
||||||
@ -28,7 +28,7 @@ describe('Signature Request', function () {
|
|||||||
await driver.openNewPage('http://127.0.0.1:8080/');
|
await driver.openNewPage('http://127.0.0.1:8080/');
|
||||||
|
|
||||||
// creates a sign typed data signature request
|
// creates a sign typed data signature request
|
||||||
await driver.clickElement('#signTypedDataV4', 10000);
|
await driver.clickElement('#signTypedDataV4');
|
||||||
|
|
||||||
await driver.waitUntilXWindowHandles(3);
|
await driver.waitUntilXWindowHandles(3);
|
||||||
let windowHandles = await driver.getAllWindowHandles();
|
let windowHandles = await driver.getAllWindowHandles();
|
||||||
@ -48,6 +48,9 @@ describe('Signature Request', function () {
|
|||||||
);
|
);
|
||||||
const origin = content[0];
|
const origin = content[0];
|
||||||
const address = content[1];
|
const address = content[1];
|
||||||
|
const message = await driver.findElement(
|
||||||
|
'.signature-request-message--node-value',
|
||||||
|
);
|
||||||
assert.equal(await title.getText(), 'Signature Request');
|
assert.equal(await title.getText(), 'Signature Request');
|
||||||
assert.equal(await name.getText(), 'Ether Mail');
|
assert.equal(await name.getText(), 'Ether Mail');
|
||||||
assert.equal(await origin.getText(), 'http://127.0.0.1:8080');
|
assert.equal(await origin.getText(), 'http://127.0.0.1:8080');
|
||||||
@ -57,15 +60,16 @@ describe('Signature Request', function () {
|
|||||||
publicAddress.length - 8,
|
publicAddress.length - 8,
|
||||||
)}`,
|
)}`,
|
||||||
);
|
);
|
||||||
|
assert.equal(await message.getText(), 'Hello, Bob!');
|
||||||
|
|
||||||
// Approve signing typed data
|
// Approve signing typed data
|
||||||
await driver.clickElement({ text: 'Sign', tag: 'button' }, 10000);
|
await driver.clickElement({ text: 'Sign', tag: 'button' });
|
||||||
await driver.waitUntilXWindowHandles(2);
|
await driver.waitUntilXWindowHandles(2);
|
||||||
windowHandles = await driver.getAllWindowHandles();
|
windowHandles = await driver.getAllWindowHandles();
|
||||||
|
|
||||||
// switch to the Dapp and verify the signed addressed
|
// switch to the Dapp and verify the signed addressed
|
||||||
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
||||||
await driver.clickElement('#signTypedDataV4Verify', 10000);
|
await driver.clickElement('#signTypedDataV4Verify');
|
||||||
const recoveredAddress = await driver.findElement(
|
const recoveredAddress = await driver.findElement(
|
||||||
'#signTypedDataV4VerifyResult',
|
'#signTypedDataV4VerifyResult',
|
||||||
);
|
);
|
||||||
@ -74,3 +78,146 @@ describe('Signature Request', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Sign Typed Data V3 Signature Request', function () {
|
||||||
|
it('can initiate and confirm a Signature Request', async function () {
|
||||||
|
const ganacheOptions = {
|
||||||
|
accounts: [
|
||||||
|
{
|
||||||
|
secretKey:
|
||||||
|
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
|
||||||
|
balance: convertToHexValue(25000000000000000000),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1';
|
||||||
|
await withFixtures(
|
||||||
|
{
|
||||||
|
dapp: true,
|
||||||
|
fixtures: 'connected-state',
|
||||||
|
ganacheOptions,
|
||||||
|
title: this.test.title,
|
||||||
|
},
|
||||||
|
async ({ driver }) => {
|
||||||
|
await driver.navigate();
|
||||||
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
|
|
||||||
|
await driver.openNewPage('http://127.0.0.1:8080/');
|
||||||
|
|
||||||
|
// creates a sign typed data signature request
|
||||||
|
await driver.clickElement('#signTypedDataV3');
|
||||||
|
|
||||||
|
await driver.waitUntilXWindowHandles(3);
|
||||||
|
let windowHandles = await driver.getAllWindowHandles();
|
||||||
|
await driver.switchToWindowWithTitle(
|
||||||
|
'MetaMask Notification',
|
||||||
|
windowHandles,
|
||||||
|
);
|
||||||
|
|
||||||
|
const title = await driver.findElement(
|
||||||
|
'.signature-request-content__title',
|
||||||
|
);
|
||||||
|
const name = await driver.findElement(
|
||||||
|
'.signature-request-content__info--bolded',
|
||||||
|
);
|
||||||
|
const content = await driver.findElements(
|
||||||
|
'.signature-request-content__info',
|
||||||
|
);
|
||||||
|
const origin = content[0];
|
||||||
|
const address = content[1];
|
||||||
|
const message = await driver.findElement(
|
||||||
|
'.signature-request-message--node-value',
|
||||||
|
);
|
||||||
|
assert.equal(await title.getText(), 'Signature Request');
|
||||||
|
assert.equal(await name.getText(), 'Ether Mail');
|
||||||
|
assert.equal(await origin.getText(), 'http://127.0.0.1:8080');
|
||||||
|
assert.equal(
|
||||||
|
await address.getText(),
|
||||||
|
`${publicAddress.slice(0, 8)}...${publicAddress.slice(
|
||||||
|
publicAddress.length - 8,
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
assert.equal(await message.getText(), 'Hello, Bob!');
|
||||||
|
|
||||||
|
// Approve signing typed data
|
||||||
|
await driver.clickElement({ text: 'Sign', tag: 'button' });
|
||||||
|
await driver.waitUntilXWindowHandles(2);
|
||||||
|
windowHandles = await driver.getAllWindowHandles();
|
||||||
|
|
||||||
|
// switch to the Dapp and verify the signed addressed
|
||||||
|
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
||||||
|
await driver.clickElement('#signTypedDataV3Verify');
|
||||||
|
const recoveredAddress = await driver.findElement(
|
||||||
|
'#signTypedDataV3VerifyResult',
|
||||||
|
);
|
||||||
|
assert.equal(await recoveredAddress.getText(), publicAddress);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Sign Typed Data Signature Request', function () {
|
||||||
|
it('can initiate and confirm a Signature Request', async function () {
|
||||||
|
const ganacheOptions = {
|
||||||
|
accounts: [
|
||||||
|
{
|
||||||
|
secretKey:
|
||||||
|
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
|
||||||
|
balance: convertToHexValue(25000000000000000000),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1';
|
||||||
|
await withFixtures(
|
||||||
|
{
|
||||||
|
dapp: true,
|
||||||
|
fixtures: 'connected-state',
|
||||||
|
ganacheOptions,
|
||||||
|
title: this.test.title,
|
||||||
|
},
|
||||||
|
async ({ driver }) => {
|
||||||
|
await driver.navigate();
|
||||||
|
await driver.fill('#password', 'correct horse battery staple');
|
||||||
|
await driver.press('#password', driver.Key.ENTER);
|
||||||
|
|
||||||
|
await driver.openNewPage('http://127.0.0.1:8080/');
|
||||||
|
|
||||||
|
// creates a sign typed data signature request
|
||||||
|
await driver.clickElement('#signTypedData');
|
||||||
|
|
||||||
|
await driver.waitUntilXWindowHandles(3);
|
||||||
|
let windowHandles = await driver.getAllWindowHandles();
|
||||||
|
await driver.switchToWindowWithTitle(
|
||||||
|
'MetaMask Notification',
|
||||||
|
windowHandles,
|
||||||
|
);
|
||||||
|
|
||||||
|
const title = await driver.findElement(
|
||||||
|
'.request-signature__header__text',
|
||||||
|
);
|
||||||
|
const origin = await driver.findElement('.request-signature__origin');
|
||||||
|
const message = await driver.findElements(
|
||||||
|
'.request-signature__row-value',
|
||||||
|
);
|
||||||
|
assert.equal(await title.getText(), 'Signature Request');
|
||||||
|
assert.equal(await origin.getText(), 'http://127.0.0.1:8080');
|
||||||
|
assert.equal(await message[0].getText(), 'Hi, Alice!');
|
||||||
|
assert.equal(await message[1].getText(), '1337');
|
||||||
|
|
||||||
|
// Approve signing typed data
|
||||||
|
await driver.clickElement({ text: 'Sign', tag: 'button' });
|
||||||
|
await driver.waitUntilXWindowHandles(2);
|
||||||
|
windowHandles = await driver.getAllWindowHandles();
|
||||||
|
|
||||||
|
// switch to the Dapp and verify the signed addressed
|
||||||
|
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
||||||
|
await driver.clickElement('#signTypedDataVerify');
|
||||||
|
const recoveredAddress = await driver.findElement(
|
||||||
|
'#signTypedDataVerifyResult',
|
||||||
|
);
|
||||||
|
assert.equal(await recoveredAddress.getText(), publicAddress);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user