Skip to content

Commit

Permalink
Merge branch 'develop' into revert/3da34f4
Browse files Browse the repository at this point in the history
  • Loading branch information
gantunesr authored Nov 6, 2024
2 parents 7e6511e + e5b415f commit dbbc9e3
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@
"@metamask/phishing-warning": "^4.1.0",
"@metamask/preferences-controller": "^13.0.2",
"@metamask/test-bundler": "^1.0.0",
"@metamask/test-dapp": "8.7.0",
"@metamask/test-dapp": "8.13.0",
"@octokit/core": "^3.6.0",
"@open-rpc/meta-schema": "^1.14.6",
"@open-rpc/mock-server": "^1.7.5",
Expand Down
1 change: 1 addition & 0 deletions privacy-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"localhost:8000",
"localhost:8545",
"mainnet.infura.io",
"metamask-sdk.api.cx.metamask.io",
"metamask.eth",
"metamask.github.io",
"metametrics.metamask.test",
Expand Down
187 changes: 187 additions & 0 deletions test/e2e/tests/confirmations/signatures/nft-permit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import { strict as assert } from 'assert';
import { TransactionEnvelopeType } from '@metamask/transaction-controller';
import { Suite } from 'mocha';
import { MockedEndpoint } from 'mockttp';
import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers';
import { Ganache } from '../../../seeder/ganache';
import { Driver } from '../../../webdriver/driver';
import {
mockSignatureApproved,
mockSignatureRejected,
scrollAndConfirmAndAssertConfirm,
withRedesignConfirmationFixtures,
} from '../helpers';
import { TestSuiteArguments } from '../transactions/shared';
import {
assertAccountDetailsMetrics,
assertPastedAddress,
assertSignatureConfirmedMetrics,
assertSignatureRejectedMetrics,
clickHeaderInfoBtn,
copyAddressAndPasteWalletAddress,
openDappAndTriggerDeploy,
SignatureType,
triggerSignature,
} from './signature-helpers';

describe('Confirmation Signature - NFT Permit @no-mmi', function (this: Suite) {
it('initiates and confirms and emits the correct events', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
TransactionEnvelopeType.legacy,
async ({
driver,
ganacheServer,
mockedEndpoint: mockedEndpoints,
}: TestSuiteArguments) => {
const addresses = await (ganacheServer as Ganache).getAccounts();
const publicAddress = addresses?.[0] as string;

await openDappAndTriggerDeploy(driver);
await driver.delay(1000);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement('[data-testid="confirm-footer-button"]');

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.delay(1000);
await triggerSignature(driver, SignatureType.NFTPermit);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await clickHeaderInfoBtn(driver);
await copyAddressAndPasteWalletAddress(driver);
await assertPastedAddress(driver);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await assertInfoValues(driver);
await scrollAndConfirmAndAssertConfirm(driver);
await driver.delay(1000);

await assertAccountDetailsMetrics(
driver,
mockedEndpoints as MockedEndpoint[],
'eth_signTypedData_v4',
);

await assertSignatureConfirmedMetrics({
driver,
mockedEndpoints: mockedEndpoints as MockedEndpoint[],
signatureType: 'eth_signTypedData_v4',
primaryType: 'Permit',
uiCustomizations: ['redesigned_confirmation', 'permit'],
});

await assertVerifiedResults(driver, publicAddress);
},
mockSignatureApproved,
);
});

it('initiates and rejects and emits the correct events', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
TransactionEnvelopeType.legacy,
async ({
driver,
mockedEndpoint: mockedEndpoints,
}: TestSuiteArguments) => {
await openDappAndTriggerDeploy(driver);
await driver.delay(1000);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement('[data-testid="confirm-footer-button"]');

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.delay(1000);
await triggerSignature(driver, SignatureType.NFTPermit);

await driver.clickElementAndWaitForWindowToClose(
'[data-testid="confirm-footer-cancel-button"]',
);

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

await driver.waitForSelector({
tag: 'span',
text: 'Error: User rejected the request.',
});

await assertSignatureRejectedMetrics({
driver,
mockedEndpoints: mockedEndpoints as MockedEndpoint[],
signatureType: 'eth_signTypedData_v4',
primaryType: 'Permit',
uiCustomizations: ['redesigned_confirmation', 'permit'],
location: 'confirmation',
});
},
mockSignatureRejected,
);
});
});

async function assertInfoValues(driver: Driver) {
await driver.clickElement('[data-testid="sectionCollapseButton"]');
const origin = driver.findElement({ text: DAPP_HOST_ADDRESS });
const contractPetName = driver.findElement({
css: '.name__value',
text: '0x581c3...45947',
});

const title = driver.findElement({ text: 'Withdrawal request' });
const description = driver.findElement({
text: 'This site wants permission to withdraw your NFTs',
});
const primaryType = driver.findElement({ text: 'Permit' });
const spender = driver.findElement({
css: '.name__value',
text: '0x581c3...45947',
});
const tokenId = driver.findElement({ text: '3606393' });
const nonce = driver.findElement({ text: '0' });
const deadline = driver.findElement({ text: '23 December 2024, 23:03' });

assert.ok(await origin, 'origin');
assert.ok(await contractPetName, 'contractPetName');
assert.ok(await title, 'title');
assert.ok(await description, 'description');
assert.ok(await primaryType, 'primaryType');
assert.ok(await spender, 'spender');
assert.ok(await tokenId, 'tokenId');
assert.ok(await nonce, 'nonce');
assert.ok(await deadline, 'deadline');
}

async function assertVerifiedResults(driver: Driver, publicAddress: string) {
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.clickElement('#sign721PermitVerify');

await driver.waitForSelector({
css: '#sign721PermitVerifyResult',
text: publicAddress,
});

await driver.waitForSelector({
css: '#sign721PermitResult',
text: '0x572bc6300f6aa669e85e0a7792bc0b0803fb70c3c492226b30007ff7030b03600e390ef295a5a525d19f444943ae82697f0e5b5b0d77cc382cb2ea9486ec27801c',
});

await driver.waitForSelector({
css: '#sign721PermitResultR',
text: 'r: 0x572bc6300f6aa669e85e0a7792bc0b0803fb70c3c492226b30007ff7030b0360',
});

await driver.waitForSelector({
css: '#sign721PermitResultS',
text: 's: 0x0e390ef295a5a525d19f444943ae82697f0e5b5b0d77cc382cb2ea9486ec2780',
});

await driver.waitForSelector({
css: '#sign721PermitResultV',
text: 'v: 28',
});

await driver.waitForSelector({
css: '#sign721PermitVerifyResult',
text: publicAddress,
});
}
14 changes: 13 additions & 1 deletion test/e2e/tests/confirmations/signatures/signature-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const WALLET_ETH_BALANCE = '25';
export enum SignatureType {
PersonalSign = '#personalSign',
Permit = '#signPermit',
NFTPermit = '#sign721Permit',
SignTypedDataV3 = '#signTypedDataV3',
SignTypedDataV4 = '#signTypedDataV4',
SignTypedData = '#signTypedData',
Expand Down Expand Up @@ -240,12 +241,23 @@ export async function assertPastedAddress(driver: Driver) {
assert.equal(await formFieldEl.getAttribute('value'), WALLET_ADDRESS);
}

export async function triggerSignature(driver: Driver, type: string) {
await driver.clickElement(type);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
}

export async function openDappAndTriggerSignature(
driver: Driver,
type: string,
) {
await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement(type);
await triggerSignature(driver, type);
}

export async function openDappAndTriggerDeploy(driver: Driver) {
await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#deployNFTsButton');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
}
11 changes: 8 additions & 3 deletions test/e2e/tests/tokens/add-multiple-tokens.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ describe('Multiple ERC20 Watch Asset', function () {
await openDapp(driver, undefined, DAPP_URL);

// Create Token 1
const createToken = await driver.findElement({
text: 'Create Token',
tag: 'button',
});
await driver.scrollToElement(createToken);
await driver.clickElement({ text: 'Create Token', tag: 'button' });
await switchToNotificationWindow(driver);
await driver.findClickableElement({ text: 'Confirm', tag: 'button' });
Expand All @@ -37,7 +42,7 @@ describe('Multiple ERC20 Watch Asset', function () {
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.wait(async () => {
const tokenAddressesElement = await driver.findElement(
'#tokenAddresses',
'#erc20TokenAddresses',
);
const tokenAddresses = await tokenAddressesElement.getText();
return tokenAddresses !== '';
Expand All @@ -53,7 +58,7 @@ describe('Multiple ERC20 Watch Asset', function () {
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.wait(async () => {
const tokenAddressesElement = await driver.findElement(
'#tokenAddresses',
'#erc20TokenAddresses',
);
const tokenAddresses = await tokenAddressesElement.getText();
return tokenAddresses.split(',').length === 2;
Expand All @@ -69,7 +74,7 @@ describe('Multiple ERC20 Watch Asset', function () {
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.wait(async () => {
const tokenAddressesElement = await driver.findElement(
'#tokenAddresses',
'#erc20TokenAddresses',
);
const tokenAddresses = await tokenAddressesElement.getText();
return tokenAddresses.split(',').length === 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const BaseTransactionInfo = () => {
<SimulationDetails
transaction={transactionMeta}
isTransactionsRedesign
enableMetrics
/>
</ConfirmInfoSection>
<TransactionDetails />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const NativeTransferInfo = () => {
<SimulationDetails
transaction={transactionMeta}
isTransactionsRedesign
enableMetrics
/>
</ConfirmInfoSection>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const NFTTokenTransferInfo = () => {
<SimulationDetails
transaction={transactionMeta}
isTransactionsRedesign
enableMetrics
/>
</ConfirmInfoSection>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const TokenTransferInfo = () => {
<SimulationDetails
transaction={transactionMeta}
isTransactionsRedesign
enableMetrics
/>
</ConfirmInfoSection>
)}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6386,10 +6386,10 @@ __metadata:
languageName: node
linkType: hard

"@metamask/test-dapp@npm:8.7.0":
version: 8.7.0
resolution: "@metamask/test-dapp@npm:8.7.0"
checksum: 10/c2559179d3372e5fc8d67a60c1e4056fad9809486eaff6a2aa9c351a2a613eeecc15885a5fd9b71b8f4139058fe168abeac06bd6bdb6d4a47fe0b9b4146923ab
"@metamask/test-dapp@npm:8.13.0":
version: 8.13.0
resolution: "@metamask/test-dapp@npm:8.13.0"
checksum: 10/b588e562ce81d94e22e8c19b6b160b6dc1c5f68314edaeeb3c886a0676d4bd21205c741d039a1a8ad2dfc1e87109239d18da17c322fbaa99f527b543b0032786
languageName: node
linkType: hard

Expand Down Expand Up @@ -26470,7 +26470,7 @@ __metadata:
"@metamask/snaps-sdk": "npm:^6.10.0"
"@metamask/snaps-utils": "npm:^8.5.1"
"@metamask/test-bundler": "npm:^1.0.0"
"@metamask/test-dapp": "npm:8.7.0"
"@metamask/test-dapp": "npm:8.13.0"
"@metamask/transaction-controller": "npm:^38.1.0"
"@metamask/user-operation-controller": "npm:^13.0.0"
"@metamask/utils": "npm:^9.3.0"
Expand Down

0 comments on commit dbbc9e3

Please sign in to comment.