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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
71 changes: 34 additions & 37 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const {
ETHERSCAN_SUPPORTED_CHAIN_IDS,
} = require('@metamask/preferences-controller');
const { mockNetworkStateOld } = require('../stub/networks');

const { CHAIN_IDS } = require('../../shared/constants/network');
const { ACCOUNT_1, ACCOUNT_2 } = require('./helpers');
Copy link
Member

Choose a reason for hiding this comment

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

Ah, this import is causing problems. It seems that this file is being pulled into the build somehow, and adding this import is resulting in some environment variables being referenced that are not defined, causing a build failure.

Why is this part of the build 🤔

Copy link
Member

Choose a reason for hiding this comment

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

We could resolve the error by moving these account constants from helpers to a constants file. That will ensure no additional environment variable references are brought in.

But this file being in the application bundle seems like a mistake.

Copy link
Member Author

Choose a reason for hiding this comment

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

Did suggested change in 73b8c72 🤞🏾

const { SMART_CONTRACTS } = require('./seeder/smart-contracts');
const {
DAPP_URL,
Expand Down Expand Up @@ -359,7 +359,7 @@ class FixtureBuilder {
withNftControllerERC1155() {
return this.withNftController({
allNftContracts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[ACCOUNT_1]: {
[toHex(1337)]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.ERC1155}`,
Expand All @@ -368,7 +368,7 @@ class FixtureBuilder {
},
},
allNfts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[ACCOUNT_1]: {
[toHex(1337)]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.ERC1155}`,
Expand All @@ -391,7 +391,7 @@ class FixtureBuilder {
withNftControllerERC721() {
return this.withNftController({
allNftContracts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[ACCOUNT_1]: {
[toHex(1337)]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.NFTS}`,
Expand All @@ -402,7 +402,7 @@ class FixtureBuilder {
},
},
allNfts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[ACCOUNT_1]: {
[toHex(1337)]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.NFTS}`,
Expand Down Expand Up @@ -538,10 +538,7 @@ class FixtureBuilder {
caveats: [
{
type: 'restrictReturnedAccounts',
value: [
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
'0x09781764c08de8ca82e156bbf156a3ca217c7950',
],
value: [ACCOUNT_1, ACCOUNT_2],
},
],
date: 1664388714636,
Expand All @@ -567,7 +564,7 @@ class FixtureBuilder {
caveats: [
{
type: 'restrictReturnedAccounts',
value: ['0x09781764c08de8ca82e156bbf156a3ca217c7950'],
value: [ACCOUNT_2],
},
],
date: 1664388714636,
Expand All @@ -591,7 +588,7 @@ class FixtureBuilder {
caveats: [
{
type: 'restrictReturnedAccounts',
value: ['0x5cfe73b6021e818b776b421b1c4db2474086a7e1'],
value: [ACCOUNT_1],
},
],
date: 1664388714636,
Expand All @@ -608,7 +605,7 @@ class FixtureBuilder {
caveats: [
{
type: 'restrictReturnedAccounts',
value: ['0x5cfe73b6021e818b776b421b1c4db2474086a7e1'],
value: [ACCOUNT_1],
},
],
date: 1664388714636,
Expand Down Expand Up @@ -667,13 +664,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',
[ACCOUNT_2]: {
address: ACCOUNT_2,
lastSelected: 1665507800000,
name: 'Account 2',
},
Expand Down Expand Up @@ -821,7 +818,7 @@ class FixtureBuilder {
accounts: {
'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4': {
id: 'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4',
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
address: ACCOUNT_1,
options: {},
methods: [
'personal_sign',
Expand All @@ -841,7 +838,7 @@ class FixtureBuilder {
},
'e9976a84-110e-46c3-9811-e2da7b5528d3': {
id: 'e9976a84-110e-46c3-9811-e2da7b5528d3',
address: '0x09781764c08de8ca82e156bbf156a3ca217c7950',
address: ACCOUNT_2,
options: {},
methods: [
'personal_sign',
Expand Down Expand Up @@ -943,7 +940,7 @@ class FixtureBuilder {
detectedTokens: [],
allTokens: {
[toHex(chainId)]: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': [
[ACCOUNT_1]: [
{
address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.HST}`,
symbol: 'TST',
Expand Down Expand Up @@ -986,7 +983,7 @@ class FixtureBuilder {
status: 'unapproved',
time: 1617228030067,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: ACCOUNT_1,
gas: '0x61a8',
maxFeePerGas: '0x59682f0c',
maxPriorityFeePerGas: '0x59682f00',
Expand Down Expand Up @@ -1026,7 +1023,7 @@ class FixtureBuilder {
status: 'approved',
time: 1617228030067,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: ACCOUNT_1,
gas: '0x61a8',
maxFeePerGas: '0x59682f0c',
maxPriorityFeePerGas: '0x59682f00',
Expand All @@ -1039,7 +1036,7 @@ class FixtureBuilder {
status: 'approved',
time: 1617228030067,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: ACCOUNT_1,
gas: '0x61a8',
maxFeePerGas: '0x59682f0c',
maxPriorityFeePerGas: '0x59682f00',
Expand Down Expand Up @@ -1067,7 +1064,7 @@ class FixtureBuilder {
status: 'unapproved',
time: 1671635506502,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: ACCOUNT_1,
gas: '0x5208',
maxFeePerGas: '0x4c03c96f8',
maxPriorityFeePerGas: '0x59682f00',
Expand Down Expand Up @@ -1154,7 +1151,7 @@ class FixtureBuilder {
path: '/txReceipt',
value: {
blockNumber: '7cbf95',
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: ACCOUNT_1,
gasUsed: '5208',
status: '0x1',
to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
Expand All @@ -1179,7 +1176,7 @@ class FixtureBuilder {
submittedTime: 1671635510753,
time: 1671635506502,
txParams: {
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: ACCOUNT_1,
gas: '0x5208',
to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
type: '0x2',
Expand All @@ -1192,7 +1189,7 @@ class FixtureBuilder {
negative: 0,
words: [8175509, null],
},
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: ACCOUNT_1,
status: '0x1',
to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
type: '0x2',
Expand All @@ -1217,7 +1214,7 @@ class FixtureBuilder {
from: '0xc87261ba337be737fa744f50e7aaf4a920bdfcd6',
gas: '0x5208',
gasPrice: '0x329af9707',
to: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
to: ACCOUNT_1,
value: '0xDE0B6B3A7640000',
},
type: 'incoming',
Expand Down Expand Up @@ -1391,8 +1388,8 @@ class FixtureBuilder {
withTrezorAccount() {
return this.withAccountTracker({
accounts: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
[ACCOUNT_1]: {
address: ACCOUNT_1,
balance: '0x15af1d78b58c40000',
},
'0xf68464152d7289d7ea9a2bec2e0035c45188223c': {
Expand All @@ -1403,8 +1400,8 @@ class FixtureBuilder {
currentBlockGasLimit: '0x1c9c380',
accountsByChainId: {
'0x539': {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
[ACCOUNT_1]: {
address: ACCOUNT_1,
balance: '0x15af1d78b58c40000',
},
'0xf68464152d7289d7ea9a2bec2e0035c45188223c': {
Expand All @@ -1422,7 +1419,7 @@ class FixtureBuilder {
accounts: {
'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4': {
id: 'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4',
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
address: ACCOUNT_1,
options: {},
methods: [
'personal_sign',
Expand Down Expand Up @@ -1475,7 +1472,7 @@ class FixtureBuilder {
.withNameController({
names: {
ethereumAddress: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
[ACCOUNT_1]: {
'*': {
name: 'Account 1',
sourceId: null,
Expand All @@ -1496,8 +1493,8 @@ class FixtureBuilder {
})
.withPreferencesController({
identities: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
[ACCOUNT_1]: {
address: ACCOUNT_1,
lastSelected: 1665507600000,
name: 'Account 1',
},
Expand All @@ -1508,8 +1505,8 @@ class FixtureBuilder {
},
},
lostIdentities: {
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1': {
address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
[ACCOUNT_1]: {
address: ACCOUNT_1,
name: 'Account 1',
lastSelected: 1665507600000,
},
Expand Down
Loading