Skip to content

Commit

Permalink
test: rename the GanacheContractAddressRegistry class in preparatio…
Browse files Browse the repository at this point in the history
…n for ganache migration (#28595)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
The Contract Registry class, is going to be used as it is, in Anvil too.
In the efforts of making [the migration
PR](https://github.com/MetaMask/metamask-extension/pull/27246/files#diff-06cb4d4aa42b7e7467cb49bd17a4282672cc4a352ee698d122e566f25e906692)
smaller, this PR tackles the re-naming of this class
`GanacheContractAddressRegistry` to a more generic name that can be used
both by Ganache and Anvil `ContractAddressRegistry`.

Note: this PR doesn't introduce any functional change in the tests, so
we can skip the quality gate for sparing ci credits.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28595?quickstart=1)

## **Related issues**

Fixes: MetaMask/MetaMask-planning#3662

## **Manual testing steps**

1. Check all tests continues to work fine

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
seaona authored Nov 22, 2024
1 parent 197c201 commit fe5f85c
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const convertETHToHexGwei = (eth) => convertToHexValue(eth * 10 ** 18);
/**
* @typedef {object} Fixtures
* @property {import('./webdriver/driver').Driver} driver - The driver number.
* @property {GanacheContractAddressRegistry | undefined} contractRegistry - The contract registry.
* @property {ContractAddressRegistry | undefined} contractRegistry - The contract registry.
* @property {Ganache | undefined} ganacheServer - The Ganache server.
* @property {Ganache | undefined} secondaryGanacheServer - The secondary Ganache server.
* @property {mockttp.MockedEndpoint[]} mockedEndpoint - The mocked endpoint.
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/json-rpc/eth_call.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defaultGanacheOptions, withFixtures } from '../helpers';
import { Driver } from '../webdriver/driver';
import FixtureBuilder from '../fixture-builder';
import { Ganache } from '../seeder/ganache';
import GanacheContractAddressRegistry from '../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../seeder/contract-address-registry';
import { SMART_CONTRACTS } from '../seeder/smart-contracts';
import { loginWithBalanceValidation } from '../page-objects/flows/login.flow';

Expand All @@ -28,7 +28,7 @@ describe('eth_call', function () {
}: {
driver: Driver;
ganacheServer?: Ganache;
contractRegistry: GanacheContractAddressRegistry;
contractRegistry: ContractAddressRegistry;
}) => {
const contract = contractRegistry.getContractAddress(smartContract);
await loginWithBalanceValidation(driver, ganacheServer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Use this class to store pre-deployed smart contract addresses of the contracts deployed to
* a local blockchain instance ran by Ganache.
* a local blockchain instance.
*/
class GanacheContractAddressRegistry {
class ContractAddressRegistry {
#addresses = {};

/**
Expand All @@ -25,4 +25,4 @@ class GanacheContractAddressRegistry {
}
}

module.exports = GanacheContractAddressRegistry;
module.exports = ContractAddressRegistry;
6 changes: 3 additions & 3 deletions test/e2e/seeder/ganache-seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const { ContractFactory, Contract } = require('@ethersproject/contracts');

const { ENTRYPOINT, GANACHE_ACCOUNT } = require('../constants');
const { SMART_CONTRACTS, contractConfiguration } = require('./smart-contracts');
const GanacheContractAddressRegistry = require('./ganache-contract-address-registry');
const ContractAddressRegistry = require('./contract-address-registry');

/*
* Ganache seeder is used to seed initial smart contract or set initial blockchain state.
*/
class GanacheSeeder {
constructor(ganacheProvider) {
this.smartContractRegistry = new GanacheContractAddressRegistry();
this.smartContractRegistry = new ContractAddressRegistry();
this.ganacheProvider = ganacheProvider;
}

Expand Down Expand Up @@ -125,7 +125,7 @@ class GanacheSeeder {
/**
* Return an instance of the currently used smart contract registry.
*
* @returns GanacheContractAddressRegistry
* @returns ContractAddressRegistry
*/
getContractRegistry() {
return this.smartContractRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Suite } from 'mocha';
import { Driver } from '../../webdriver/driver';
import FixtureBuilder from '../../fixture-builder';
import { Ganache } from '../../seeder/ganache';
import GanacheContractAddressRegistry from '../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../seeder/contract-address-registry';
import {
multipleGanacheOptionsForType2Transactions,
PRIVATE_KEY_TWO,
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('Snap Account Contract interaction @no-mmi', function (this: Suite) {
ganacheServer,
}: {
driver: Driver;
contractRegistry: GanacheContractAddressRegistry;
contractRegistry: ContractAddressRegistry;
ganacheServer?: Ganache;
}) => {
await loginWithBalanceValidation(driver, ganacheServer);
Expand All @@ -62,7 +62,7 @@ describe('Snap Account Contract interaction @no-mmi', function (this: Suite) {
// Open Dapp with contract
const testDapp = new TestDapp(driver);
const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(smartContract);
await testDapp.openTestDappPage({ contractAddress });
await testDapp.check_pageIsLoaded();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
openDAppWithContract,
TestSuiteArguments,
} from '../transactions/shared';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';

const FixtureBuilder = require('../../../fixture-builder');
const {
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('Queued Confirmations', function () {
await openDAppWithContract(driver, contractRegistry, smartContract);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(smartContract);

await connectToDappTwoAndSwitchBackToOne(driver, contractAddress);
Expand Down Expand Up @@ -317,7 +317,7 @@ describe('Queued Confirmations', function () {
await openDAppWithContract(driver, contractRegistry, smartContract);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(smartContract);

await connectToDappTwoAndSwitchBackToOne(driver, contractAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Mockttp } from 'mockttp';
import { openDapp, unlockWallet } from '../../../helpers';
import { createDappTransaction } from '../../../page-objects/flows/transaction';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
import { Driver } from '../../../webdriver/driver';
import { MockedEndpoint } from '../../../mock-e2e';
import {
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('Confirmation Redesign Contract Interaction Component', function () {
await createLayer2Transaction(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(smartContract);

await openDapp(driver, contractAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { unlockWallet, WINDOW_TITLES } from '../../../helpers';
import { Mockttp } from '../../../mock-e2e';
import SetApprovalForAllTransactionConfirmation from '../../../page-objects/pages/confirmations/redesign/set-approval-for-all-transaction-confirmation';
import TestDapp from '../../../page-objects/pages/test-dapp';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
import { Driver } from '../../../webdriver/driver';
import { withRedesignConfirmationFixtures } from '../helpers';
import { mocked4BytesSetApprovalForAll } from './erc721-revoke-set-approval-for-all-redesign';
Expand Down Expand Up @@ -47,12 +47,12 @@ async function mocks(server: Mockttp) {

async function createTransactionAndAssertDetails(
driver: Driver,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await unlockWallet(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(SMART_CONTRACTS.NFTS);

const testDapp = new TestDapp(driver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DAPP_URL, unlockWallet, WINDOW_TITLES } from '../../../helpers';
import { Mockttp } from '../../../mock-e2e';
import SetApprovalForAllTransactionConfirmation from '../../../page-objects/pages/confirmations/redesign/set-approval-for-all-transaction-confirmation';
import TestDapp from '../../../page-objects/pages/test-dapp';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
import { Driver } from '../../../webdriver/driver';
import { withRedesignConfirmationFixtures } from '../helpers';
import { TestSuiteArguments } from './shared';
Expand Down Expand Up @@ -75,12 +75,12 @@ export async function mocked4BytesSetApprovalForAll(mockServer: Mockttp) {

async function createTransactionAssertDetailsAndConfirm(
driver: Driver,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await unlockWallet(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(SMART_CONTRACTS.NFTS);

const testDapp = new TestDapp(driver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import TokenTransferTransactionConfirmation from '../../../page-objects/pages/co
import HomePage from '../../../page-objects/pages/homepage';
import SendTokenPage from '../../../page-objects/pages/send/send-token-page';
import TestDapp from '../../../page-objects/pages/test-dapp';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
import { Driver } from '../../../webdriver/driver';
import { withRedesignConfirmationFixtures } from '../helpers';
import { TestSuiteArguments } from './shared';
Expand Down Expand Up @@ -115,12 +115,12 @@ export async function mockedSourcifyTokenSend(mockServer: Mockttp) {

async function createWalletInitiatedTransactionAndAssertDetails(
driver: Driver,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await unlockWallet(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(SMART_CONTRACTS.HST);

const testDapp = new TestDapp(driver);
Expand Down Expand Up @@ -160,12 +160,12 @@ async function createWalletInitiatedTransactionAndAssertDetails(

async function createDAppInitiatedTransactionAndAssertDetails(
driver: Driver,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await unlockWallet(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(SMART_CONTRACTS.HST);

const testDapp = new TestDapp(driver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { unlockWallet, WINDOW_TITLES } from '../../../helpers';
import { Mockttp } from '../../../mock-e2e';
import SetApprovalForAllTransactionConfirmation from '../../../page-objects/pages/confirmations/redesign/set-approval-for-all-transaction-confirmation';
import TestDapp from '../../../page-objects/pages/test-dapp';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
import { Driver } from '../../../webdriver/driver';
import { withRedesignConfirmationFixtures } from '../helpers';
import { TestSuiteArguments } from './shared';
Expand Down Expand Up @@ -70,12 +70,12 @@ export async function mocked4BytesSetApprovalForAll(mockServer: Mockttp) {

async function createTransactionAndAssertDetails(
driver: Driver,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await unlockWallet(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(SMART_CONTRACTS.NFTS);

const testDapp = new TestDapp(driver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DAPP_URL, unlockWallet, WINDOW_TITLES } from '../../../helpers';
import { Mockttp } from '../../../mock-e2e';
import SetApprovalForAllTransactionConfirmation from '../../../page-objects/pages/confirmations/redesign/set-approval-for-all-transaction-confirmation';
import TestDapp from '../../../page-objects/pages/test-dapp';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
import { Driver } from '../../../webdriver/driver';
import { withRedesignConfirmationFixtures } from '../helpers';
import { TestSuiteArguments } from './shared';
Expand Down Expand Up @@ -75,12 +75,12 @@ export async function mocked4BytesSetApprovalForAll(mockServer: Mockttp) {

async function createTransactionAssertDetailsAndConfirm(
driver: Driver,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await unlockWallet(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(SMART_CONTRACTS.NFTS);

const testDapp = new TestDapp(driver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
withFixtures,
} from '../../../helpers';
import { Mockttp } from '../../../mock-e2e';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
import { SMART_CONTRACTS } from '../../../seeder/smart-contracts';
import { Driver } from '../../../webdriver/driver';
import { scrollAndConfirmAndAssertConfirm } from '../helpers';
Expand Down Expand Up @@ -111,7 +111,7 @@ function generateFixtureOptionsForEIP1559Tx(mochaContext: Mocha.Context) {
async function createAndAssertIncreaseAllowanceSubmission(
driver: Driver,
newSpendingCap: string,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await openDAppWithContract(driver, contractRegistry, SMART_CONTRACTS.HST);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import HomePage from '../../../page-objects/pages/homepage';
import NFTDetailsPage from '../../../page-objects/pages/nft-details-page';
import SendTokenPage from '../../../page-objects/pages/send/send-token-page';
import TestDapp from '../../../page-objects/pages/test-dapp';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
import { Driver } from '../../../webdriver/driver';
import { withRedesignConfirmationFixtures } from '../helpers';
import { TestSuiteArguments } from './shared';
Expand Down Expand Up @@ -184,12 +184,12 @@ export async function mockedERC11554BytesNFTTokenSend(mockServer: Mockttp) {

async function createERC721WalletInitiatedTransactionAndAssertDetails(
driver: Driver,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await unlockWallet(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(SMART_CONTRACTS.NFTS);

const testDapp = new TestDapp(driver);
Expand Down Expand Up @@ -231,12 +231,12 @@ async function createERC721WalletInitiatedTransactionAndAssertDetails(

async function createERC721DAppInitiatedTransactionAndAssertDetails(
driver: Driver,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await unlockWallet(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(SMART_CONTRACTS.NFTS);

const testDapp = new TestDapp(driver);
Expand Down Expand Up @@ -266,12 +266,12 @@ async function createERC721DAppInitiatedTransactionAndAssertDetails(

async function createERC1155WalletInitiatedTransactionAndAssertDetails(
driver: Driver,
contractRegistry?: GanacheContractAddressRegistry,
contractRegistry?: ContractAddressRegistry,
) {
await unlockWallet(driver);

const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(SMART_CONTRACTS.ERC1155);

const testDapp = new TestDapp(driver);
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/tests/confirmations/transactions/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { MockedEndpoint } from 'mockttp';
import { veryLargeDelayMs } from '../../../helpers';
import { Ganache } from '../../../seeder/ganache';
import GanacheContractAddressRegistry from '../../../seeder/ganache-contract-address-registry';
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
import { Driver } from '../../../webdriver/driver';

const {
Expand All @@ -15,17 +15,17 @@ const { scrollAndConfirmAndAssertConfirm } = require('../helpers');
export type TestSuiteArguments = {
driver: Driver;
ganacheServer?: Ganache;
contractRegistry?: GanacheContractAddressRegistry;
contractRegistry?: ContractAddressRegistry;
mockedEndpoint?: MockedEndpoint | MockedEndpoint[];
};

export async function openDAppWithContract(
driver: Driver,
contractRegistry: GanacheContractAddressRegistry | undefined,
contractRegistry: ContractAddressRegistry | undefined,
smartContract: string,
) {
const contractAddress = await (
contractRegistry as GanacheContractAddressRegistry
contractRegistry as ContractAddressRegistry
).getContractAddress(smartContract);

await logInWithBalanceValidation(driver);
Expand Down

0 comments on commit fe5f85c

Please sign in to comment.