-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable STX only for ETH mainnet in production and for ETH mainnet and…
… Sepolia in non-prod Resolve linting
- Loading branch information
Showing
6 changed files
with
85 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { NETWORKS_CHAIN_ID } from './network'; | ||
import { isProduction } from '../util/environment'; | ||
import { getAllowedSmartTransactionsChainIds } from './smartTransactions'; | ||
|
||
jest.mock('../util/environment', () => ({ | ||
isProduction: jest.fn(() => false), // Initially mock isProduction to return false | ||
})); | ||
|
||
// Cast isProduction to jest.Mock to inform TypeScript about the mock type | ||
const mockIsProduction = isProduction as jest.Mock; | ||
|
||
describe('smartTransactions', () => { | ||
describe('getAllowedSmartTransactionsChainIds', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('returns the correct chain IDs for development environment', () => { | ||
mockIsProduction.mockReturnValue(false); | ||
const allowedChainIds = getAllowedSmartTransactionsChainIds(); | ||
expect(allowedChainIds).toStrictEqual([ | ||
NETWORKS_CHAIN_ID.MAINNET, | ||
NETWORKS_CHAIN_ID.SEPOLIA, | ||
]); | ||
}); | ||
|
||
it('returns the correct chain IDs for production environment', () => { | ||
mockIsProduction.mockReturnValue(true); | ||
const allowedChainIds = getAllowedSmartTransactionsChainIds(); | ||
expect(allowedChainIds).toStrictEqual([NETWORKS_CHAIN_ID.MAINNET]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
import { isProduction } from '../util/environment'; | ||
import { NETWORKS_CHAIN_ID } from './network'; | ||
|
||
const ALLOWED_SMART_TRANSACTIONS_CHAIN_IDS_DEVELOPMENT: string[] = [ | ||
NETWORKS_CHAIN_ID.MAINNET, | ||
NETWORKS_CHAIN_ID.SEPOLIA, | ||
]; | ||
|
||
const ALLOWED_SMART_TRANSACTIONS_CHAIN_IDS_PRODUCTION: string[] = [ | ||
NETWORKS_CHAIN_ID.MAINNET, | ||
]; | ||
|
||
export const getAllowedSmartTransactionsChainIds = (): string[] => | ||
isProduction() | ||
? ALLOWED_SMART_TRANSACTIONS_CHAIN_IDS_PRODUCTION | ||
: ALLOWED_SMART_TRANSACTIONS_CHAIN_IDS_DEVELOPMENT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { isProduction } from './environment'; | ||
|
||
const originalNodeEnvironment = process.env.NODE_ENV; | ||
|
||
describe('isProduction', () => { | ||
afterAll(() => { | ||
process.env.NODE_ENV = originalNodeEnvironment; | ||
}); | ||
|
||
it('returns true when NODE_ENV is "production"', () => { | ||
process.env.NODE_ENV = 'production'; | ||
expect(isProduction()).toBe(true); | ||
}); | ||
|
||
it('returns false when NODE_ENV is "development"', () => { | ||
process.env.NODE_ENV = 'development'; | ||
expect(isProduction()).toBe(false); | ||
}); | ||
|
||
it('returns false when NODE_ENV is "test"', () => { | ||
process.env.NODE_ENV = 'test'; | ||
expect(isProduction()).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
export const isProduction = (): boolean => | ||
// TODO: process.env.NODE_ENV === 'production' doesn't work with tests yet. Once we make it work, | ||
// we can remove the following line and use the code above instead. | ||
({ ...process.env }?.NODE_ENV === 'production'); |