Skip to content

Commit

Permalink
Sepolia support (#1041)
Browse files Browse the repository at this point in the history
BREAKING: This update adds support for Sepolia (so that mobile can support it), and removes support for deprecated test networks Rinkeby, Kovan and Ropsten.

The test cases were changed to use Sepolia and Goerli instead of the deprecated networks, and test coverage for NetworkController was increased.

Finally the package `ethereumjs-common` was upgraded to version 2.6.1, which adds support for Sepolia (see changelog: <https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common/CHANGELOG.md#261---2022-02-01>).

Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
  • Loading branch information
2 people authored and MajorLift committed Oct 11, 2023
1 parent 28fc859 commit ab59d45
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mockedQuery = query as jest.Mock<
>;

const provider = new HttpProvider(
'https://ropsten.infura.io/v3/341eacb578dd44a1a049cbc5f6fd4035',
'https://goerli.infura.io/v3/341eacb578dd44a1a049cbc5f6fd4035',
);

describe('AccountTrackerController', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ describe('CurrencyRateController', () => {

expect(controller.state.conversionRate).toStrictEqual(1);

await controller.setNativeCurrency(TESTNET_TICKER_SYMBOLS.RINKEBY);
await controller.setNativeCurrency(TESTNET_TICKER_SYMBOLS.GOERLI);

expect(controller.state.conversionRate).toStrictEqual(10);

Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/CurrencyRateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class CurrencyRateController extends BaseControllerV2<
const currentCurrency = pendingCurrentCurrency ?? stateCurrentCurrency;
const nativeCurrency = pendingNativeCurrency ?? stateNativeCurrency;

// For preloaded testnets (Rinkeby, Ropsten, Goerli, Kovan) we want to fetch exchange rate for real ETH.
// For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.
const nativeCurrencyForExchangeRate = Object.values(
TESTNET_TICKER_SYMBOLS,
).includes(nativeCurrency)
Expand Down
12 changes: 6 additions & 6 deletions packages/assets-controllers/src/NftController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,8 @@ describe('NftController', () => {

it('should add NFT by provider type', async () => {
const { nftController, network, messenger } = setupController();
const firstNetworkType = 'rinkeby';
const secondNetworkType = 'ropsten';
const firstNetworkType = 'sepolia';
const secondNetworkType = 'goerli';
const { selectedAddress } = nftController.config;
sinon
.stub(nftController, 'getNftInformation' as any)
Expand Down Expand Up @@ -1365,8 +1365,8 @@ describe('NftController', () => {
sinon
.stub(nftController, 'getNftInformation' as any)
.returns({ name: 'name', image: 'url', description: 'description' });
const firstNetworkType = 'rinkeby';
const secondNetworkType = 'ropsten';
const firstNetworkType = 'sepolia';
const secondNetworkType = 'goerli';
network.setProviderType(firstNetworkType);
await nftController.addNft('0x02', '4321');
network.setProviderType(secondNetworkType);
Expand Down Expand Up @@ -1961,8 +1961,8 @@ describe('NftController', () => {
it('should check whether the passed NFT is still owned by the the selectedAddress/chainId combination passed in the accountParams argument and update its isCurrentlyOwned property in state, when the currently configured selectedAddress/chainId are different from those passed', async () => {
const { nftController, network, preferences, messenger } =
setupController();
const firstNetworkType = 'rinkeby';
const secondNetworkType = 'ropsten';
const firstNetworkType = 'sepolia';
const secondNetworkType = 'goerli';

preferences.update({ selectedAddress: OWNER_ADDRESS });
network.setProviderType(firstNetworkType);
Expand Down
13 changes: 0 additions & 13 deletions packages/assets-controllers/src/NftController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import {
BNToHex,
fetchWithErrorHandling,
MAINNET,
RINKEBY_CHAIN_ID,
IPFS_DEFAULT_GATEWAY_URL,
ERC721,
ERC1155,
OPENSEA_API_URL,
OPENSEA_PROXY_URL,
OPENSEA_TEST_API_URL,
NetworkType,
} from '@metamask/controller-utils';
import type {
Expand Down Expand Up @@ -180,11 +178,6 @@ export class NftController extends BaseController<NftConfig, NftState> {
tokenId: string;
useProxy: boolean;
}) {
const { chainId } = this.config;

if (chainId === RINKEBY_CHAIN_ID) {
return `${OPENSEA_TEST_API_URL}/asset/${contractAddress}/${tokenId}`;
}
return useProxy
? `${OPENSEA_PROXY_URL}/asset/${contractAddress}/${tokenId}`
: `${OPENSEA_API_URL}/asset/${contractAddress}/${tokenId}`;
Expand All @@ -197,12 +190,6 @@ export class NftController extends BaseController<NftConfig, NftState> {
contractAddress: string;
useProxy: boolean;
}) {
const { chainId } = this.config;

if (chainId === RINKEBY_CHAIN_ID) {
return `${OPENSEA_TEST_API_URL}/asset_contract/${contractAddress}`;
}

return useProxy
? `${OPENSEA_PROXY_URL}/asset_contract/${contractAddress}`
: `${OPENSEA_API_URL}/asset_contract/${contractAddress}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NftDetectionController } from './NftDetectionController';

const DEFAULT_INTERVAL = 180000;
const MAINNET = 'mainnet';
const ROPSTEN = 'ropsten';
const GOERLI = 'goerli';

describe('NftDetectionController', () => {
let nftDetection: NftDetectionController;
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('NftDetectionController', () => {
it('should detect mainnet correctly', () => {
nftDetection.configure({ networkType: MAINNET });
expect(nftDetection.isMainnet()).toStrictEqual(true);
nftDetection.configure({ networkType: ROPSTEN });
nftDetection.configure({ networkType: GOERLI });
expect(nftDetection.isMainnet()).toStrictEqual(false);
});

Expand All @@ -279,7 +279,7 @@ describe('NftDetectionController', () => {
addNft: nftController.addNft.bind(nftController),
getNftState: () => nftController.state,
},
{ interval: 10, networkType: ROPSTEN },
{ interval: 10, networkType: GOERLI },
);
expect(mockNfts.called).toBe(false);
resolve('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('TokenDetectionController', () => {
expect(
isTokenDetectionSupportedForNetwork(tokenDetection.config.chainId),
).toStrictEqual(true);
tokenDetection.configure({ chainId: NetworksChainId.ropsten });
tokenDetection.configure({ chainId: NetworksChainId.goerli });
expect(
isTokenDetectionSupportedForNetwork(tokenDetection.config.chainId),
).toStrictEqual(false);
Expand Down
12 changes: 6 additions & 6 deletions packages/assets-controllers/src/TokenListController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,8 @@ describe('TokenListController', () => {
nock(TOKEN_END_POINT_API)
.get(`/tokens/${NetworksChainId.mainnet}`)
.reply(200, sampleMainnetTokenList)
.get(`/tokens/${NetworksChainId.ropsten}`)
.reply(200, { error: 'ChainId 3 is not supported' })
.get(`/tokens/${NetworksChainId.goerli}`)
.reply(200, { error: 'ChainId 5 is not supported' })
.get(`/tokens/56`)
.reply(200, sampleBinanceTokenList)
.persist();
Expand All @@ -1097,7 +1097,7 @@ describe('TokenListController', () => {
sampleTwoChainState.tokensChainsCache[NetworksChainId.mainnet].data,
);

network.setProviderType('ropsten');
network.setProviderType('goerli');

await new Promise<void>((resolve) => setTimeout(() => resolve(), 500));

Expand Down Expand Up @@ -1157,8 +1157,8 @@ describe('TokenListController', () => {
nock(TOKEN_END_POINT_API)
.get(`/tokens/${NetworksChainId.mainnet}`)
.reply(200, sampleMainnetTokenList)
.get(`/tokens/${NetworksChainId.ropsten}`)
.reply(200, { error: 'ChainId 3 is not supported' })
.get(`/tokens/${NetworksChainId.goerli}`)
.reply(200, { error: 'ChainId 5 is not supported' })
.get(`/tokens/56`)
.reply(200, sampleBinanceTokenList)
.persist();
Expand All @@ -1167,7 +1167,7 @@ describe('TokenListController', () => {
const { network } = setupNetworkController(controllerMessenger);
const messenger = getRestrictedMessenger(controllerMessenger);
const controller = new TokenListController({
chainId: NetworksChainId.ropsten,
chainId: NetworksChainId.goerli,
preventPollingOnNetworkRestart: true,
messenger,
interval: 100,
Expand Down
36 changes: 18 additions & 18 deletions packages/assets-controllers/src/TokensController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ describe('TokensController', () => {
it('should add token by network', async () => {
const stub = stubCreateEthers(tokensController, false);

const firstNetworkType = 'rinkeby';
const secondNetworkType = 'ropsten';
const firstNetworkType = 'sepolia';
const secondNetworkType = 'goerli';
network.setProviderType(firstNetworkType);
await tokensController.addToken('0x01', 'bar', 2);
network.setProviderType(secondNetworkType);
Expand All @@ -275,7 +275,7 @@ describe('TokensController', () => {
address: '0x01',
decimals: 2,
image:
'https://static.metaswap.codefi.network/api/v1/tokenIcons/4/0x01.png',
'https://static.metaswap.codefi.network/api/v1/tokenIcons/11155111/0x01.png',
symbol: 'bar',
isERC721: false,
aggregators: [],
Expand Down Expand Up @@ -317,8 +317,8 @@ describe('TokensController', () => {

it('should remove token by provider type', async () => {
const stub = stubCreateEthers(tokensController, false);
const firstNetworkType = 'rinkeby';
const secondNetworkType = 'ropsten';
const firstNetworkType = 'sepolia';
const secondNetworkType = 'goerli';

network.setProviderType(firstNetworkType);
await tokensController.addToken('0x02', 'baz', 2);
Expand All @@ -332,7 +332,7 @@ describe('TokensController', () => {
address: '0x02',
decimals: 2,
image:
'https://static.metaswap.codefi.network/api/v1/tokenIcons/4/0x02.png',
'https://static.metaswap.codefi.network/api/v1/tokenIcons/11155111/0x02.png',
symbol: 'baz',
isERC721: false,
aggregators: [],
Expand All @@ -341,7 +341,7 @@ describe('TokensController', () => {
});

it('should subscribe to new sibling preference controllers', async () => {
const networkType = 'rinkeby';
const networkType = 'sepolia';
const address = '0x123';
preferences.update({ selectedAddress: address });
expect(preferences.state.selectedAddress).toStrictEqual(address);
Expand All @@ -350,7 +350,7 @@ describe('TokensController', () => {
});

describe('ignoredTokens', () => {
const defaultSelectedNetwork: NetworkType = 'rinkeby';
const defaultSelectedNetwork: NetworkType = 'sepolia';
const defaultSelectedAddress = '0x0001';

let createEthersStub: sinon.SinonStub;
Expand Down Expand Up @@ -380,7 +380,7 @@ describe('TokensController', () => {

it('should remove a token from the ignoredTokens/allIgnoredTokens lists if re-added as part of a bulk addTokens add', async () => {
const selectedAddress = '0x0001';
const chain = 'rinkeby';
const chain = 'sepolia';
preferences.setSelectedAddress(selectedAddress);
network.setProviderType(chain);
await tokensController.addToken('0x01', 'bar', 2);
Expand Down Expand Up @@ -425,8 +425,8 @@ describe('TokensController', () => {
it('should ignore tokens by [chainID][accountAddress]', async () => {
const selectedAddress1 = '0x0001';
const selectedAddress2 = '0x0002';
const chain1 = 'rinkeby';
const chain2 = 'ropsten';
const chain1 = 'sepolia';
const chain2 = 'goerli';

preferences.setSelectedAddress(selectedAddress1);
network.setProviderType(chain1);
Expand Down Expand Up @@ -714,7 +714,7 @@ describe('TokensController', () => {
const DETECTED_CHAINID = '0xDetectedChainId';

const CONFIGURED_ADDRESS = '0xabc';
const CONFIGURED_NETWORK = 'rinkeby';
const CONFIGURED_NETWORK = 'sepolia';
preferences.update({ selectedAddress: CONFIGURED_ADDRESS });
network.setProviderType(CONFIGURED_NETWORK);

Expand Down Expand Up @@ -1127,8 +1127,8 @@ describe('TokensController', () => {
it('should remove a token from its state on corresponding network', async function () {
const stub = stubCreateEthers(tokensController, false);

const firstNetworkType = 'rinkeby';
const secondNetworkType = 'ropsten';
const firstNetworkType = 'sepolia';
const secondNetworkType = 'goerli';
network.setProviderType(firstNetworkType);

await tokensController.addToken('0x01', 'A', 4);
Expand All @@ -1149,7 +1149,7 @@ describe('TokensController', () => {
address: '0x01',
decimals: 4,
image:
'https://static.metaswap.codefi.network/api/v1/tokenIcons/4/0x01.png',
'https://static.metaswap.codefi.network/api/v1/tokenIcons/11155111/0x01.png',
isERC721: false,
symbol: 'A',
aggregators: [],
Expand All @@ -1158,7 +1158,7 @@ describe('TokensController', () => {
address: '0x02',
decimals: 5,
image:
'https://static.metaswap.codefi.network/api/v1/tokenIcons/4/0x02.png',
'https://static.metaswap.codefi.network/api/v1/tokenIcons/11155111/0x02.png',
isERC721: false,
symbol: 'B',
aggregators: [],
Expand All @@ -1170,7 +1170,7 @@ describe('TokensController', () => {
address: '0x03',
decimals: 4,
image:
'https://static.metaswap.codefi.network/api/v1/tokenIcons/3/0x03.png',
'https://static.metaswap.codefi.network/api/v1/tokenIcons/5/0x03.png',
isERC721: false,
symbol: 'C',
aggregators: [],
Expand All @@ -1179,7 +1179,7 @@ describe('TokensController', () => {
address: '0x04',
decimals: 5,
image:
'https://static.metaswap.codefi.network/api/v1/tokenIcons/3/0x04.png',
'https://static.metaswap.codefi.network/api/v1/tokenIcons/5/0x04.png',
isERC721: false,
symbol: 'D',
aggregators: [],
Expand Down
8 changes: 4 additions & 4 deletions packages/assets-controllers/src/assetsUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ describe('assetsUtil', () => {
).toBe(true);
});

it('returns false for testnets such as Ropsten', () => {
expect(assetsUtil.isTokenDetectionSupportedForNetwork('3')).toBe(false);
it('returns false for testnets such as Goerli', () => {
expect(assetsUtil.isTokenDetectionSupportedForNetwork('5')).toBe(false);
});
});

Expand Down Expand Up @@ -296,9 +296,9 @@ describe('assetsUtil', () => {
).toBe(true);
});

it('returns false for testnets such as Ropsten', () => {
it('returns false for testnets such as Goerli', () => {
expect(
assetsUtil.isTokenListSupportedForNetwork(NetworksChainId.ropsten),
assetsUtil.isTokenListSupportedForNetwork(NetworksChainId.goerli),
).toBe(false);
});
});
Expand Down
9 changes: 2 additions & 7 deletions packages/controller-utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const FALL_BACK_VS_CURRENCY = 'ETH';
export const IPFS_DEFAULT_GATEWAY_URL = 'https://cloudflare-ipfs.com/ipfs/';

// NETWORKS ID
export const RINKEBY_CHAIN_ID = '4';
export const GANACHE_CHAIN_ID = '1337';

// TOKEN STANDARDS
Expand Down Expand Up @@ -35,19 +34,15 @@ export const ASSET_TYPES = {

// TICKER SYMBOLS
export const TESTNET_TICKER_SYMBOLS = {
RINKEBY: 'RinkebyETH',
GOERLI: 'GoerliETH',
ROPSTEN: 'RopstenETH',
KOVAN: 'KovanETH',
SEPOLIA: 'SepoliaETH',
};
// TYPED NetworkType TICKER SYMBOLS
export const TESTNET_NETWORK_TYPE_TO_TICKER_SYMBOL: {
[K in NetworkType]: string;
} = {
rinkeby: 'RinkebyETH',
goerli: 'GoerliETH',
ropsten: 'RopstenETH',
kovan: 'KovanETH',
sepolia: 'SepoliaETH',
mainnet: '',
rpc: '',
localhost: '',
Expand Down
8 changes: 2 additions & 6 deletions packages/controller-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
* Human-readable network name
*/
export type NetworkType =
| 'kovan'
| 'localhost'
| 'mainnet'
| 'rinkeby'
| 'goerli'
| 'ropsten'
| 'sepolia'
| 'rpc';

export enum NetworksChainId {
mainnet = '1',
kovan = '42',
rinkeby = '4',
goerli = '5',
ropsten = '3',
sepolia = '11155111',
localhost = '',
rpc = '',
}
Expand Down
6 changes: 1 addition & 5 deletions packages/controller-utils/src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ describe('util', () => {
expect(util.getBuyURL('1', 'foo', 1337)).toBe(
'https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=1337&address=foo&crypto_currency=ETH',
);
expect(util.getBuyURL('3')).toBe('https://faucet.metamask.io/');
expect(util.getBuyURL('4')).toBe('https://www.rinkeby.io/');
expect(util.getBuyURL('5')).toBe('https://goerli-faucet.slock.it/');
expect(util.getBuyURL('42')).toBe(
'https://github.com/kovan-testnet/faucet',
);
expect(util.getBuyURL('11155111')).toBe('https://sepoliafaucet.net/');
expect(util.getBuyURL('unrecognized network ID')).toBeUndefined();
});

Expand Down
Loading

0 comments on commit ab59d45

Please sign in to comment.