Skip to content

Commit

Permalink
Merge branch 'develop' into mikesposito/update-ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito authored Nov 6, 2024
2 parents 292b707 + 10102d0 commit 77d1ffa
Show file tree
Hide file tree
Showing 27 changed files with 296 additions and 64 deletions.
6 changes: 5 additions & 1 deletion .circleci/scripts/git-diff-develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type PRInfo = {
ref: string;
};
body: string;
labels: { name: string }[];
};

/**
Expand Down Expand Up @@ -123,7 +124,7 @@ async function storeGitDiffOutputAndPrBody() {
fs.mkdirSync(CHANGED_FILES_DIR, { recursive: true });

console.log(
`Determining whether this run is for a PR targeting ${MAIN_BRANCH}`,
`Determining whether to run git diff...`,
);
if (!PR_NUMBER) {
console.log('Not a PR, skipping git diff');
Expand All @@ -140,6 +141,9 @@ async function storeGitDiffOutputAndPrBody() {
console.log(`This is for a PR targeting '${baseRef}', skipping git diff`);
writePrBodyToFile(prInfo.body);
return;
} else if (prInfo.labels.some(label => label.name === 'skip-e2e-quality-gate')) {
console.log('PR has the skip-e2e-quality-gate label, skipping git diff');
return;
}

console.log('Attempting to get git diff...');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,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);
}
19 changes: 18 additions & 1 deletion test/e2e/tests/phishing-controller/phishing-detection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ describe('Phishing Detection', function () {
await unlockWallet(driver);
await openDapp(driver);
await driver.switchToWindowWithTitle('MetaMask Phishing Detection');

// we need to wait for this selector to mitigate a race condition on the phishing page site
// see more here https://github.com/MetaMask/phishing-warning/pull/173
await driver.waitForSelector({
testId: 'unsafe-continue-loaded',
});
await driver.clickElement({
text: 'Proceed anyway',
});
Expand Down Expand Up @@ -103,10 +109,15 @@ describe('Phishing Detection', function () {
}

await driver.switchToWindowWithTitle('MetaMask Phishing Detection');

// we need to wait for this selector to mitigate a race condition on the phishing page site
// see more here https://github.com/MetaMask/phishing-warning/pull/173
await driver.waitForSelector({
testId: 'unsafe-continue-loaded',
});
await driver.clickElement({
text: 'Proceed anyway',
});

await driver.wait(until.titleIs(WINDOW_TITLES.TestDApp), 10000);
};
}
Expand Down Expand Up @@ -169,6 +180,12 @@ describe('Phishing Detection', function () {
text: 'Open this warning in a new tab',
});
await driver.switchToWindowWithTitle('MetaMask Phishing Detection');

// we need to wait for this selector to mitigate a race condition on the phishing page site
// see more here https://github.com/MetaMask/phishing-warning/pull/173
await driver.waitForSelector({
testId: 'unsafe-continue-loaded',
});
await driver.clickElement({
text: 'Proceed anyway',
});
Expand Down
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
6 changes: 3 additions & 3 deletions ui/hooks/useMMICustodySendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export function useMMICustodySendTransaction() {
const accountType = useSelector(getAccountType);
const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage);

const { currentConfirmation } = useConfirmContext() as unknown as {
currentConfirmation: TransactionMeta | undefined;
};
const { currentConfirmation } = useConfirmContext<
TransactionMeta | undefined
>();
const { from } = getConfirmationSender(currentConfirmation);
const fromChecksumHexAddress = toChecksumHexAddress(from || '');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ exports[`ConfirmGasDisplay should match snapshot 1`] = `
class="mm-box mm-text transaction-detail-item__row-subText mm-text--body-sm mm-text--text-align-end mm-box--color-text-alternative"
>
<div
class="box gas-details-item__gasfee-label box--display-inline-flex box--flex-direction-row"
class="mm-box gas-details-item__gasfee-label mm-box--display-inline-flex"
>
<div
class="box box--flex-direction-row"
class="mm-box"
>
<p
class="mm-box mm-text mm-text--body-sm-medium mm-box--color-text-alternative"
Expand All @@ -105,8 +105,7 @@ exports[`ConfirmGasDisplay should match snapshot 1`] = `
</p>
</div>
<div
class="gas-details-item__currency-container"
paddingstart="1"
class="mm-box gas-details-item__currency-container mm-box--padding-inline-start-1"
>
<div
class="mm-box currency-display-component mm-box--display-flex mm-box--flex-wrap-wrap mm-box--align-items-center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import { useIsNFT } from '../hooks/use-is-nft';
export const ApproveStaticSimulation = () => {
const t = useI18nContext();

const { currentConfirmation: transactionMeta } = useConfirmContext() as {
currentConfirmation: TransactionMeta;
};
const { currentConfirmation: transactionMeta } =
useConfirmContext<TransactionMeta>();

const { decimals: initialDecimals } = useAssetDetails(
transactionMeta?.txParams?.to,
Expand Down
Loading

0 comments on commit 77d1ffa

Please sign in to comment.