2022-10-14 14:33:36 +02:00
|
|
|
const { withFixtures } = require('../helpers');
|
2022-10-28 10:42:12 +02:00
|
|
|
const FixtureBuilder = require('../fixture-builder');
|
2022-10-14 14:33:36 +02:00
|
|
|
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(
|
|
|
|
{
|
2022-11-16 22:47:51 +01:00
|
|
|
fixtures: new FixtureBuilder().build(),
|
2022-10-14 14:33:36 +02:00
|
|
|
ganacheOptions,
|
2022-11-16 22:47:51 +01:00
|
|
|
failOnConsoleError: false,
|
2022-10-14 14:33:36 +02:00
|
|
|
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);
|
|
|
|
|
2022-10-24 13:49:41 +02:00
|
|
|
// navigate to test snaps page and connect
|
|
|
|
await driver.driver.get(TEST_SNAPS_WEBSITE_URL);
|
|
|
|
await driver.delay(1000);
|
2022-10-14 14:33:36 +02:00
|
|
|
|
2022-11-16 22:47:51 +01:00
|
|
|
// find and scroll to the bip32 test and connect
|
2023-07-21 23:32:51 +02:00
|
|
|
const snapButton1 = await driver.findElement('#connectbip32');
|
2022-11-16 22:47:51 +01:00
|
|
|
await driver.scrollToElement(snapButton1);
|
|
|
|
await driver.delay(1000);
|
2023-07-21 23:32:51 +02:00
|
|
|
await driver.clickElement('#connectbip32');
|
2023-01-10 20:11:15 +01:00
|
|
|
await driver.delay(1000);
|
2022-10-14 14:33:36 +02:00
|
|
|
|
2022-11-16 22:47:51 +01:00
|
|
|
// switch to metamask extension and click connect
|
2022-11-21 14:38:05 +01:00
|
|
|
let windowHandles = await driver.waitUntilXWindowHandles(
|
|
|
|
2,
|
|
|
|
1000,
|
|
|
|
10000,
|
|
|
|
);
|
2022-10-14 14:33:36 +02:00
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
2023-03-08 14:17:56 +01:00
|
|
|
await driver.clickElement({
|
|
|
|
text: 'Connect',
|
|
|
|
tag: 'button',
|
|
|
|
});
|
2022-11-16 22:47:51 +01:00
|
|
|
|
2023-06-06 12:15:20 +02:00
|
|
|
await driver.waitForSelector({ text: 'Install' });
|
2022-11-16 22:47:51 +01:00
|
|
|
|
2023-06-07 15:18:49 +02:00
|
|
|
await driver.clickElement('[data-testid="snap-install-scroll"]');
|
|
|
|
|
2022-10-14 14:33:36 +02:00
|
|
|
await driver.clickElement({
|
2023-06-06 12:15:20 +02:00
|
|
|
text: 'Install',
|
2022-10-14 14:33:36 +02:00
|
|
|
tag: 'button',
|
|
|
|
});
|
|
|
|
|
|
|
|
// wait for permissions popover, click checkboxes and confirm
|
2023-04-06 16:57:11 +02:00
|
|
|
await driver.delay(500);
|
2022-10-14 14:33:36 +02:00
|
|
|
await driver.clickElement('#key-access-bip32-m-44h-0h-secp256k1-0');
|
2023-03-29 21:17:57 +02:00
|
|
|
await driver.clickElement('#key-access-bip32-m-44h-0h-ed25519-1');
|
|
|
|
await driver.clickElement(
|
|
|
|
'#public-key-access-bip32-m-44h-0h-secp256k1-0',
|
|
|
|
);
|
2022-10-14 14:33:36 +02:00
|
|
|
await driver.clickElement({
|
|
|
|
text: 'Confirm',
|
|
|
|
tag: 'button',
|
|
|
|
});
|
|
|
|
|
2023-06-06 12:15:20 +02:00
|
|
|
await driver.waitForSelector({ text: 'OK' });
|
2023-03-17 12:00:05 +01:00
|
|
|
await driver.clickElement({
|
2023-06-06 12:15:20 +02:00
|
|
|
text: 'OK',
|
2023-03-17 12:00:05 +01:00
|
|
|
tag: 'button',
|
|
|
|
});
|
|
|
|
|
2022-10-14 14:33:36 +02:00
|
|
|
// switch back to test-snaps window
|
|
|
|
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
|
|
|
|
|
2023-03-15 18:03:01 +01:00
|
|
|
// wait for npm installation success
|
|
|
|
await driver.waitForSelector({
|
2023-07-21 23:32:51 +02:00
|
|
|
css: '#connectbip32',
|
2023-03-15 18:03:01 +01:00
|
|
|
text: 'Reconnect to BIP-32 Snap',
|
|
|
|
});
|
|
|
|
|
2022-11-16 22:47:51 +01:00
|
|
|
// scroll to and click get public key
|
|
|
|
await driver.delay(1000);
|
2023-04-06 16:57:11 +02:00
|
|
|
await driver.waitForSelector({ text: 'Get Public Key' });
|
2022-11-16 22:47:51 +01:00
|
|
|
await driver.clickElement('#bip32GetPublic');
|
|
|
|
|
2023-04-06 16:57:11 +02:00
|
|
|
// check for proper public key response using waitForSelector
|
|
|
|
await driver.waitForSelector({
|
|
|
|
css: '#bip32PublicKeyResult',
|
|
|
|
text: '"0x043e98d696ae15caef75fa8dd204a7c5c08d1272b2218ba3c20feeb4c691eec366606ece56791c361a2320e7fad8bcbb130f66d51c591fc39767ab2856e93f8dfb',
|
|
|
|
});
|
2022-11-16 22:47:51 +01:00
|
|
|
|
|
|
|
// scroll to and click get compressed public key
|
2023-04-06 16:57:11 +02:00
|
|
|
await driver.waitForSelector({ text: 'Get Compressed Public Key' });
|
2022-11-16 22:47:51 +01:00
|
|
|
await driver.clickElement('#bip32GetCompressedPublic');
|
|
|
|
|
2023-04-06 16:57:11 +02:00
|
|
|
// check for proper public key response using waitForSelector
|
|
|
|
await driver.waitForSelector({
|
|
|
|
css: '#bip32PublicKeyResult',
|
|
|
|
text: '"0x033e98d696ae15caef75fa8dd204a7c5c08d1272b2218ba3c20feeb4c691eec366',
|
|
|
|
});
|
2022-11-16 22:47:51 +01:00
|
|
|
|
2022-10-14 14:33:36 +02:00
|
|
|
// wait then run SECP256K1 test
|
2023-04-06 16:57:11 +02:00
|
|
|
await driver.fill('#bip32Message-secp256k1', 'foo bar');
|
2022-11-16 22:47:51 +01:00
|
|
|
await driver.clickElement('#sendBip32-secp256k1');
|
2022-10-14 14:33:36 +02:00
|
|
|
|
2023-04-06 16:57:11 +02:00
|
|
|
// hit 'approve' on the signature confirmation
|
2022-11-21 14:38:05 +01:00
|
|
|
windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000);
|
2022-10-14 14:33:36 +02:00
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
|
|
|
await driver.clickElement({
|
|
|
|
text: 'Approve',
|
|
|
|
tag: 'button',
|
|
|
|
});
|
|
|
|
|
2023-04-06 16:57:11 +02:00
|
|
|
// switch back to the test-snaps window
|
2022-11-21 14:38:05 +01:00
|
|
|
windowHandles = await driver.waitUntilXWindowHandles(1, 1000, 10000);
|
2022-10-14 14:33:36 +02:00
|
|
|
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
|
|
|
|
|
2023-04-06 16:57:11 +02:00
|
|
|
// check results of the secp256k1 signature with waitForSelector
|
|
|
|
await driver.waitForSelector({
|
|
|
|
css: '#bip32MessageResult-secp256k1',
|
|
|
|
text: '"0x3045022100b3ade2992ea3e5eb58c7550e9bddad356e9554233c8b099ebc3cb418e9301ae2022064746e15ae024808f0ba5d860e44dc4c97e65c8cba6f5ef9ea2e8c819930d2dc',
|
|
|
|
});
|
2022-10-14 14:33:36 +02:00
|
|
|
|
2022-11-16 22:47:51 +01:00
|
|
|
// scroll further into messages section
|
2023-04-06 16:57:11 +02:00
|
|
|
const snapButton4 = await driver.findElement('#sendBip32-ed25519');
|
2022-11-16 22:47:51 +01:00
|
|
|
await driver.scrollToElement(snapButton4);
|
|
|
|
|
2022-10-14 14:33:36 +02:00
|
|
|
// wait then run ed25519 test
|
2023-04-06 16:57:11 +02:00
|
|
|
await driver.delay(500);
|
|
|
|
await driver.fill('#bip32Message-ed25519', 'foo bar');
|
2022-11-16 22:47:51 +01:00
|
|
|
await driver.clickElement('#sendBip32-ed25519');
|
2022-10-14 14:33:36 +02:00
|
|
|
|
|
|
|
// hit 'approve' on the custom confirm
|
2022-11-21 14:38:05 +01:00
|
|
|
windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000);
|
2022-10-14 14:33:36 +02:00
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
|
|
|
await driver.clickElement({
|
|
|
|
text: 'Approve',
|
|
|
|
tag: 'button',
|
|
|
|
});
|
|
|
|
|
2022-11-21 14:38:05 +01:00
|
|
|
windowHandles = await driver.waitUntilXWindowHandles(1, 1000, 10000);
|
2022-10-14 14:33:36 +02:00
|
|
|
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
|
|
|
|
|
2023-04-06 16:57:11 +02:00
|
|
|
// check results of ed25519 signature with waitForSelector
|
|
|
|
await driver.waitForSelector({
|
|
|
|
css: '#bip32MessageResult-ed25519',
|
|
|
|
text: '"0xf3215b4d6c59aac7e01b4ceef530d1e2abf4857926b85a81aaae3894505699243768a887b7da4a8c2e0f25196196ba290b6531050db8dc15c252bdd508532a0a"',
|
|
|
|
});
|
2022-10-14 14:33:36 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|