diff --git a/test/e2e/snaps/enums.js b/test/e2e/snaps/enums.js index 7df5887ba..d18f41755 100644 --- a/test/e2e/snaps/enums.js +++ b/test/e2e/snaps/enums.js @@ -1,3 +1,3 @@ module.exports = { - TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/test-snaps/3.0.1', + TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/test-snaps/3.1.0', }; diff --git a/test/e2e/snaps/test-snap-bip-32.spec.js b/test/e2e/snaps/test-snap-bip-32.spec.js new file mode 100644 index 000000000..6cffbbb4e --- /dev/null +++ b/test/e2e/snaps/test-snap-bip-32.spec.js @@ -0,0 +1,169 @@ +const { strict: assert } = require('assert'); +const { withFixtures } = require('../helpers'); +const { TEST_SNAPS_WEBSITE_URL } = require('./enums'); + +describe('Test Snap bip-32', function () { + it('tests various functions of bip-32', async function () { + const ganacheOptions = { + accounts: [ + { + secretKey: + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', + }, + ], + }; + await withFixtures( + { + fixtures: 'imported-account', + ganacheOptions, + title: this.test.title, + }, + async ({ driver }) => { + await driver.navigate(); + + // enter pw into extension + await driver.fill('#password', 'correct horse battery staple'); + await driver.press('#password', driver.Key.ENTER); + + // open a new tab and navigate to test snaps page and connect + await driver.openNewPage(TEST_SNAPS_WEBSITE_URL); + + // find and scroll to the correct card and click first + const snapButton = await driver.findElement('#sendUpdateHello'); + await driver.scrollToElement(snapButton); + await driver.delay(500); + await driver.fill('#snapId6', 'npm:@metamask/test-snap-bip32'); + await driver.clickElement('#connectBip32'); + + // switch to metamask extension and click connect + await driver.waitUntilXWindowHandles(3, 5000, 10000); + let windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + await driver.clickElement( + { + text: 'Connect', + tag: 'button', + }, + 10000, + ); + + await driver.delay(1000); + + // approve install of snap + windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + await driver.clickElement({ + text: 'Approve & install', + tag: 'button', + }); + + // wait for permissions popover, click checkboxes and confirm + await driver.delay(1000); + await driver.clickElement('#key-access-bip32-m-44h-0h-secp256k1-0'); + await driver.clickElement('#key-access-bip32-m-44h-0h-ed25519-0'); + await driver.clickElement({ + text: 'Confirm', + tag: 'button', + }); + + // switch back to test-snaps window + await driver.waitUntilXWindowHandles(2, 5000, 10000); + windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle('Test Snaps', windowHandles); + + // wait then run SECP256K1 test + await driver.delay(1000); + await driver.fill('#bip32SignMessage', 'foo bar'); + await driver.clickElement('#sendBip32Secp256k1'); + + // hit 'approve' on the custom confirm + await driver.waitUntilXWindowHandles(2, 5000, 10000); + windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + await driver.clickElement({ + text: 'Approve', + tag: 'button', + }); + + await driver.waitUntilXWindowHandles(2, 5000, 10000); + windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle('Test Snaps', windowHandles); + + // check result + await driver.delay(1000); + const secp256k1Result = await driver.findElement( + '#bip32Secp256k1Result', + ); + assert.equal( + await secp256k1Result.getText(), + 'Signature: "0xd30561eb9e3195e47d49198fb0bc66eda867a7dff4c5e8b60c2ec13851aa7d8cc3d485da177de63dad331f315d440cbb693a629efe228389c4693ea90465b101"', + ); + + // wait then run ed25519 test + await driver.delay(1000); + await driver.clickElement('#sendBip32Ed25519'); + + // hit 'approve' on the custom confirm + await driver.waitUntilXWindowHandles(2, 5000, 10000); + windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + await driver.clickElement({ + text: 'Approve', + tag: 'button', + }); + + await driver.waitUntilXWindowHandles(2, 5000, 10000); + windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle('Test Snaps', windowHandles); + + // check result + await driver.delay(1000); + const ed25519Result = await driver.findElement('#bip32Ed25519Result'); + assert.equal( + await ed25519Result.getText(), + 'Signature: "0xf3215b4d6c59aac7e01b4ceef530d1e2abf4857926b85a81aaae3894505699243768a887b7da4a8c2e0f25196196ba290b6531050db8dc15c252bdd508532a0a"', + ); + + const publicKeyButton = await driver.findElement('#sendBip32PublicKey'); + await driver.scrollToElement(publicKeyButton); + // wait then run public key test + await driver.delay(1000); + await driver.clickElement('#sendBip32PublicKey'); + // check result + await driver.delay(1000); + const publicKeyResult = await driver.findElement( + '#bip32PublicKeyResult', + ); + assert.equal( + await publicKeyResult.getText(), + 'Public key: "043e98d696ae15caef75fa8dd204a7c5c08d1272b2218ba3c20feeb4c691eec366606ece56791c361a2320e7fad8bcbb130f66d51c591fc39767ab2856e93f8dfb"', + ); + + // wait then run compressed public key test + await driver.delay(1000); + await driver.clickElement('#sendBip32CompressedPublicKey'); + // check result + await driver.delay(1000); + const compressedPublicKeyResult = await driver.findElement( + '#bip32CompressedPublicKeyResult', + ); + assert.equal( + await compressedPublicKeyResult.getText(), + 'Public key: "033e98d696ae15caef75fa8dd204a7c5c08d1272b2218ba3c20feeb4c691eec366"', + ); + }, + ); + }); +}); diff --git a/test/e2e/snaps/test-snap-bip-44.spec.js b/test/e2e/snaps/test-snap-bip-44.spec.js index 448557aff..743fee4a9 100644 --- a/test/e2e/snaps/test-snap-bip-44.spec.js +++ b/test/e2e/snaps/test-snap-bip-44.spec.js @@ -31,8 +31,7 @@ describe('Test Snap bip-44', function () { await driver.delay(1000); await driver.fill('#snapId3', 'npm:@metamask/test-snap-bip44'); - // reveal snapId3 by finding and scrolling to #snapId4 - const snapButton = await driver.findElement('#snapId4'); + const snapButton = await driver.findElement('#snapId3'); await driver.scrollToElement(snapButton); await driver.delay(500); @@ -67,9 +66,10 @@ describe('Test Snap bip-44', function () { text: 'Approve & install', tag: 'button', }); + // deal with permissions popover await driver.delay(1000); - await driver.press('#key-access-bip44-1-0', driver.Key.SPACE); + await driver.clickElement('#key-access-bip44-1-0'); await driver.clickElement({ text: 'Confirm', tag: 'button', @@ -87,7 +87,7 @@ describe('Test Snap bip-44', function () { const bip44Result = await driver.findElement('#bip44Result'); assert.equal( await bip44Result.getText(), - 'Public key: "0x86debb44fb3a984d93f326131d4c1db0bc39644f1a67b673b3ab45941a1cea6a385981755185ac4594b6521e4d1e8d1"', + 'Public key: "0x86debb44fb3a984d93f326131d4c1db0bc39644f1a67b673b3ab45941a1cea6a385981755185ac4594b6521e4d1e08d1"', ); }, ); diff --git a/test/e2e/snaps/test-snap-confirm.spec.js b/test/e2e/snaps/test-snap-confirm.spec.js index c6a35657a..1722dd93f 100644 --- a/test/e2e/snaps/test-snap-confirm.spec.js +++ b/test/e2e/snaps/test-snap-confirm.spec.js @@ -64,6 +64,10 @@ describe('Test Snap Confirm', function () { await driver.waitUntilXWindowHandles(1, 5000, 10000); windowHandles = await driver.getAllWindowHandles(); await driver.switchToWindowWithTitle('Test Snaps', windowHandles); + + const snapButton = await driver.findElement('#sendConfirmButton'); + await driver.scrollToElement(snapButton); + await driver.delay(1000); await driver.clickElement('#sendConfirmButton'); diff --git a/test/e2e/snaps/test-snap-error.spec.js b/test/e2e/snaps/test-snap-error.spec.js index 177184727..406daba7d 100644 --- a/test/e2e/snaps/test-snap-error.spec.js +++ b/test/e2e/snaps/test-snap-error.spec.js @@ -30,6 +30,11 @@ describe('Test Snap Error', function () { // navigate to test snaps page and connect await driver.driver.get(TEST_SNAPS_WEBSITE_URL); await driver.fill('#snapId2', 'npm:@metamask/test-snap-error'); + + const snapButton = await driver.findElement('#connectError'); + await driver.scrollToElement(snapButton); + await driver.delay(500); + await driver.clickElement('#connectError'); // switch to metamask extension and click connect diff --git a/ui/pages/permissions-connect/flask/util.js b/ui/pages/permissions-connect/flask/util.js index ce9f82551..3f7fbe4cf 100644 --- a/ui/pages/permissions-connect/flask/util.js +++ b/ui/pages/permissions-connect/flask/util.js @@ -17,7 +17,9 @@ export function getSnapInstallWarnings(permissions, targetSubjectMetadata, t) { return [ ...flatMap(bip32EntropyPermissions, (permission, i) => permission.caveats[0].value.map(({ path, curve }) => ({ - id: `key-access-bip32-${path.join('/')}-${curve}-${i}`, + id: `key-access-bip32-${path + .join('-') + .replace(/'/gu, 'h')}-${curve}-${i}`, message: t('snapInstallWarningKeyAccess', [ targetSubjectMetadata.name, `${path.join('/')} (${curve})`,