Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make sure to use static constant variables for accounts in fixture-builder.js #29786

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const GANACHE_PRIVATE_KEY =
export const DEFAULT_FIXTURE_ACCOUNT =
'0x5CfE73b6021E818B776b421B1c4Db2474086a7e1';

/** Address of the second default account derived from onboarding fixture. */
export const DEFAULT_FIXTURE_ACCOUNT_2 =
'0x09781764c08de8ca82e156bbf156a3ca217c7950';

/* Address of the 4337 entrypoint smart contract. */
export const ENTRYPOINT = '0x18b06605539dc02ecD3f7AB314e38eB7c1dA5c9b';

Expand Down
71 changes: 34 additions & 37 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const {
ETHERSCAN_SUPPORTED_CHAIN_IDS,
} = require('@metamask/preferences-controller');
const { mockNetworkStateOld } = require('../stub/networks');

const { CHAIN_IDS } = require('../../shared/constants/network');
const { SMART_CONTRACTS } = require('./seeder/smart-contracts');
const {
DAPP_URL,
DAPP_URL_LOCALHOST,
DAPP_ONE_URL,
DEFAULT_FIXTURE_ACCOUNT,
DEFAULT_FIXTURE_ACCOUNT_2,
} = require('./constants');
const {
defaultFixture,
Expand Down Expand Up @@ -358,7 +358,7 @@ class FixtureBuilder {
withNftControllerERC1155() {
return this.withNftController({
allNftContracts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[DEFAULT_FIXTURE_ACCOUNT]: {
[toHex(1337)]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.ERC1155}`,
Expand All @@ -367,7 +367,7 @@ class FixtureBuilder {
},
},
allNfts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[DEFAULT_FIXTURE_ACCOUNT]: {
[toHex(1337)]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.ERC1155}`,
Expand All @@ -390,7 +390,7 @@ class FixtureBuilder {
withNftControllerERC721() {
return this.withNftController({
allNftContracts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[DEFAULT_FIXTURE_ACCOUNT]: {
[toHex(1337)]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.NFTS}`,
Expand All @@ -401,7 +401,7 @@ class FixtureBuilder {
},
},
allNfts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[DEFAULT_FIXTURE_ACCOUNT]: {
[toHex(1337)]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.NFTS}`,
Expand Down Expand Up @@ -535,10 +535,7 @@ class FixtureBuilder {
caveats: [
{
type: 'restrictReturnedAccounts',
value: [
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
'0x09781764c08de8ca82e156bbf156a3ca217c7950',
],
value: [DEFAULT_FIXTURE_ACCOUNT, DEFAULT_FIXTURE_ACCOUNT_2],
},
],
date: 1664388714636,
Expand All @@ -564,7 +561,7 @@ class FixtureBuilder {
caveats: [
{
type: 'restrictReturnedAccounts',
value: ['0x09781764c08de8ca82e156bbf156a3ca217c7950'],
value: [DEFAULT_FIXTURE_ACCOUNT_2],
},
],
date: 1664388714636,
Expand All @@ -588,7 +585,7 @@ class FixtureBuilder {
caveats: [
{
type: 'restrictReturnedAccounts',
value: ['0x5cfe73b6021e818b776b421b1c4db2474086a7e1'],
value: [DEFAULT_FIXTURE_ACCOUNT],
},
],
date: 1664388714636,
Expand All @@ -605,7 +602,7 @@ class FixtureBuilder {
caveats: [
{
type: 'restrictReturnedAccounts',
value: ['0x5cfe73b6021e818b776b421b1c4db2474086a7e1'],
value: [DEFAULT_FIXTURE_ACCOUNT],
},
],
date: 1664388714636,
Expand Down Expand Up @@ -664,13 +661,13 @@ class FixtureBuilder {
withPreferencesControllerAdditionalAccountIdentities() {
return this.withPreferencesController({
identities: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
[DEFAULT_FIXTURE_ACCOUNT]: {
address: DEFAULT_FIXTURE_ACCOUNT,
lastSelected: 1665507600000,
name: 'Account 1',
},
'0x09781764c08de8ca82e156bbf156a3ca217c7950': {
address: '0x09781764c08de8ca82e156bbf156a3ca217c7950',
[DEFAULT_FIXTURE_ACCOUNT_2]: {
address: DEFAULT_FIXTURE_ACCOUNT_2,
lastSelected: 1665507800000,
name: 'Account 2',
},
Expand Down Expand Up @@ -818,7 +815,7 @@ class FixtureBuilder {
accounts: {
'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4': {
id: 'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4',
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
address: DEFAULT_FIXTURE_ACCOUNT,
options: {},
methods: [
'personal_sign',
Expand All @@ -838,7 +835,7 @@ class FixtureBuilder {
},
'e9976a84-110e-46c3-9811-e2da7b5528d3': {
id: 'e9976a84-110e-46c3-9811-e2da7b5528d3',
address: '0x09781764c08de8ca82e156bbf156a3ca217c7950',
address: DEFAULT_FIXTURE_ACCOUNT_2,
options: {},
methods: [
'personal_sign',
Expand Down Expand Up @@ -940,7 +937,7 @@ class FixtureBuilder {
detectedTokens: [],
allTokens: {
[toHex(chainId)]: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': [
[DEFAULT_FIXTURE_ACCOUNT]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.HST}`,
symbol: 'TST',
Expand Down Expand Up @@ -983,7 +980,7 @@ class FixtureBuilder {
status: 'unapproved',
time: 1617228030067,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: DEFAULT_FIXTURE_ACCOUNT,
gas: '0x61a8',
maxFeePerGas: '0x59682f0c',
maxPriorityFeePerGas: '0x59682f00',
Expand Down Expand Up @@ -1023,7 +1020,7 @@ class FixtureBuilder {
status: 'approved',
time: 1617228030067,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: DEFAULT_FIXTURE_ACCOUNT,
gas: '0x61a8',
maxFeePerGas: '0x59682f0c',
maxPriorityFeePerGas: '0x59682f00',
Expand All @@ -1036,7 +1033,7 @@ class FixtureBuilder {
status: 'approved',
time: 1617228030067,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: DEFAULT_FIXTURE_ACCOUNT,
gas: '0x61a8',
maxFeePerGas: '0x59682f0c',
maxPriorityFeePerGas: '0x59682f00',
Expand Down Expand Up @@ -1064,7 +1061,7 @@ class FixtureBuilder {
status: 'unapproved',
time: 1671635506502,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: DEFAULT_FIXTURE_ACCOUNT,
gas: '0x5208',
maxFeePerGas: '0x4c03c96f8',
maxPriorityFeePerGas: '0x59682f00',
Expand Down Expand Up @@ -1151,7 +1148,7 @@ class FixtureBuilder {
path: '/txReceipt',
value: {
blockNumber: '7cbf95',
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: DEFAULT_FIXTURE_ACCOUNT,
gasUsed: '5208',
status: '0x1',
to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
Expand All @@ -1176,7 +1173,7 @@ class FixtureBuilder {
submittedTime: 1671635510753,
time: 1671635506502,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: DEFAULT_FIXTURE_ACCOUNT,
gas: '0x5208',
to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
type: '0x2',
Expand All @@ -1189,7 +1186,7 @@ class FixtureBuilder {
negative: 0,
words: [8175509, null],
},
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: DEFAULT_FIXTURE_ACCOUNT,
status: '0x1',
to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
type: '0x2',
Expand All @@ -1214,7 +1211,7 @@ class FixtureBuilder {
from: '0xc87261ba337be737fa744f50e7aaf4a920bdfcd6',
gas: '0x5208',
gasPrice: '0x329af9707',
to: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
to: DEFAULT_FIXTURE_ACCOUNT,
value: '0xDE0B6B3A7640000',
},
type: 'incoming',
Expand Down Expand Up @@ -1388,8 +1385,8 @@ class FixtureBuilder {
withTrezorAccount() {
return this.withAccountTracker({
accounts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
[DEFAULT_FIXTURE_ACCOUNT]: {
address: DEFAULT_FIXTURE_ACCOUNT,
balance: '0x15af1d78b58c40000',
},
'0xf68464152d7289d7ea9a2bec2e0035c45188223c': {
Expand All @@ -1400,8 +1397,8 @@ class FixtureBuilder {
currentBlockGasLimit: '0x1c9c380',
accountsByChainId: {
'0x539': {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
[DEFAULT_FIXTURE_ACCOUNT]: {
address: DEFAULT_FIXTURE_ACCOUNT,
balance: '0x15af1d78b58c40000',
},
'0xf68464152d7289d7ea9a2bec2e0035c45188223c': {
Expand All @@ -1419,7 +1416,7 @@ class FixtureBuilder {
accounts: {
'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4': {
id: 'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4',
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
address: DEFAULT_FIXTURE_ACCOUNT,
options: {},
methods: [
'personal_sign',
Expand Down Expand Up @@ -1472,7 +1469,7 @@ class FixtureBuilder {
.withNameController({
names: {
ethereumAddress: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[DEFAULT_FIXTURE_ACCOUNT]: {
'*': {
name: 'Account 1',
sourceId: null,
Expand All @@ -1493,8 +1490,8 @@ class FixtureBuilder {
})
.withPreferencesController({
identities: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
[DEFAULT_FIXTURE_ACCOUNT]: {
address: DEFAULT_FIXTURE_ACCOUNT,
lastSelected: 1665507600000,
name: 'Account 1',
},
Expand All @@ -1505,8 +1502,8 @@ class FixtureBuilder {
},
},
lostIdentities: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
[DEFAULT_FIXTURE_ACCOUNT]: {
address: DEFAULT_FIXTURE_ACCOUNT,
name: 'Account 1',
lastSelected: 1665507600000,
},
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const { Bundler } = require('./bundler');
const { SMART_CONTRACTS } = require('./seeder/smart-contracts');
const { setManifestFlags } = require('./set-manifest-flags');
const {
DEFAULT_FIXTURE_ACCOUNT_2,
ERC_4337_ACCOUNT,
DEFAULT_GANACHE_ETH_BALANCE_DEC,
} = require('./constants');
Expand Down Expand Up @@ -456,7 +457,7 @@ const PRIVATE_KEY_TWO =
'0xf444f52ea41e3a39586d7069cb8e8233e9f6b9dea9cbb700cce69ae860661cc8';

const ACCOUNT_1 = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can replace this with DEFAULT_FIXTURE_ACCOUNT?

const ACCOUNT_2 = '0x09781764c08de8ca82e156bbf156a3ca217c7950';
const ACCOUNT_2 = DEFAULT_FIXTURE_ACCOUNT_2;

const defaultGanacheOptions = {
accounts: [
Expand Down
Loading