Prepare for upcoming deprecation of Ethereum testnets

* Remove references to Rinkeby, Ropsten, and Kovan testnets as they will
  be deprecated soon.

* Add Sepolia Ethereum testnet as a preloaded network

* Migrate test network used by Swap Service to Goerli

* Add migration to update selected ethereum network to mainnet if any of
  the deprecated testnets are selected
This commit is contained in:
Nick von Pentz
2022-10-03 13:53:48 -04:00
parent 2b07f1ad40
commit 143f28e1fb
34 changed files with 337 additions and 322 deletions
@@ -1420,7 +1420,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
mCurrentSwapToBlockchainToken = blockchainToken;
BlockchainToken token = buySend ? mCurrentBlockchainToken : mCurrentSwapToBlockchainToken;
// Replace USDC and DAI contract addresses for Ropsten network
// Replace USDC and DAI contract addresses for Goerli network
token.contractAddress = Utils.getContractAddress(
mSelectedNetwork.chainId, token.symbol, token.contractAddress);
String tokensPath = BlockchainRegistryFactory.getInstance().getTokensIconsLocation();
@@ -32,7 +32,7 @@ public class PendingTxHelper implements TxServiceObserverImplDelegate {
private HashMap<String, TransactionInfo[]> mTxInfos;
private boolean mReturnAll;
private String mFilterByContractAddress;
private String mRopstenContractAddress;
private String mGoerliContractAddress;
private final List<TransactionInfo> mTransactionInfos;
private final List<TransactionCacheRecord> mCacheTransactionInfos;
private boolean isFetchingTx;
@@ -84,7 +84,7 @@ public class TokenUtils {
}
/*
* Wrapper for BlockchainRegistry.getAllTokens with Ropsten contract address midifications.
* Wrapper for BlockchainRegistry.getAllTokens with Goerli contract address modifications.
*/
public static void getAllTokens(BlockchainRegistry blockchainRegistry, String chainId,
int coinType, Callbacks.Callback1<BlockchainToken[]> callback) {
@@ -899,24 +899,24 @@ public class Utils {
}
public static String getContractAddress(String chainId, String symbol, String contractAddress) {
if (!chainId.equals(BraveWalletConstants.ROPSTEN_CHAIN_ID)) {
if (!chainId.equals(BraveWalletConstants.GOERLI_CHAIN_ID)) {
return contractAddress;
}
if (symbol.equals("USDC")) {
return "0x07865c6e87b9f70255377e024ace6630c1eaa37f";
return "0x2f3a40a3db8a7e3d09b0adfefbce4f6f81927557";
} else if (symbol.equals("DAI")) {
return "0xad6d458402f60fd3bd25163575031acdce07538d";
return "0x73967c6a0904aa032c103b4104747e88c566b1a2";
}
return contractAddress;
}
public static String getRopstenContractAddress(String mainnetContractAddress) {
public static String getGoerliContractAddress(String mainnetContractAddress) {
String lowerCaseAddress = mainnetContractAddress.toLowerCase(Locale.getDefault());
if (lowerCaseAddress.equals("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")) {
return "0x07865c6e87b9f70255377e024ace6630c1eaa37f";
return "0x2f3a40a3db8a7e3d09b0adfefbce4f6f81927557";
} else if (lowerCaseAddress.equals("0x6b175474e89094c44da98b954eedeac495271d0f")) {
return "0xad6d458402f60fd3bd25163575031acdce07538d";
return "0x73967c6a0904aa032c103b4104747e88c566b1a2";
}
return "";
@@ -1031,7 +1031,7 @@ public class Utils {
return asset;
}
// Replace USDC and DAI contract addresses for Ropsten network
// Replace USDC and DAI contract addresses for Goerli network
public static BlockchainToken[] fixupTokensRegistry(BlockchainToken[] tokens, String chainId) {
for (BlockchainToken token : tokens) {
token.contractAddress =
@@ -57,5 +57,5 @@ public final class WalletConstants {
// BraveWalletConstants.FILECOIN_MAINNET); , /* not yet supported */
public static List<String> SWAP_SUPPORTED_NETWORKS = Arrays.asList(
BraveWalletConstants.MAINNET_CHAIN_ID, BraveWalletConstants.ROPSTEN_CHAIN_ID);
BraveWalletConstants.MAINNET_CHAIN_ID, BraveWalletConstants.GOERLI_CHAIN_ID);
}
@@ -223,29 +223,29 @@ public class BraveWalletUtilsTest {
@Test
@SmallTest
public void getContractAddressTest() {
assertEquals(Utils.getContractAddress(BraveWalletConstants.ROPSTEN_CHAIN_ID, "USDC",
assertEquals(Utils.getContractAddress(BraveWalletConstants.GOERLI_CHAIN_ID, "USDC",
"0xdef1c0ded9bec7f1a1670819833240f027b25eff"),
"0x07865c6e87b9f70255377e024ace6630c1eaa37f");
assertEquals(Utils.getContractAddress(BraveWalletConstants.ROPSTEN_CHAIN_ID, "DAI",
"0x2f3a40a3db8a7e3d09b0adfefbce4f6f81927557");
assertEquals(Utils.getContractAddress(BraveWalletConstants.GOERLI_CHAIN_ID, "DAI",
"0xdef1c0ded9bec7f1a1670819833240f027b25eff"),
"0xad6d458402f60fd3bd25163575031acdce07538d");
assertEquals(Utils.getContractAddress(BraveWalletConstants.ROPSTEN_CHAIN_ID, "BAT",
"0x73967c6a0904aa032c103b4104747e88c566b1a2");
assertEquals(Utils.getContractAddress(BraveWalletConstants.GOERLI_CHAIN_ID, "BAT",
"0xdef1c0ded9bec7f1a1670819833240f027b25eff"),
"0xdef1c0ded9bec7f1a1670819833240f027b25eff");
assertEquals(Utils.getContractAddress(BraveWalletConstants.RINKEBY_CHAIN_ID, "USDC",
assertEquals(Utils.getContractAddress(BraveWalletConstants.SEPOLIA_CHAIN_ID, "USDC",
"0xdef1c0ded9bec7f1a1670819833240f027b25eff"),
"0xdef1c0ded9bec7f1a1670819833240f027b25eff");
}
@Test
@SmallTest
public void getRopstenContractAddressTest() {
assertEquals(Utils.getRopstenContractAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"),
"0x07865c6e87b9f70255377e024ace6630c1eaa37f");
assertEquals(Utils.getRopstenContractAddress("0x6b175474e89094c44da98b954eedeac495271d0f"),
"0xad6d458402f60fd3bd25163575031acdce07538d");
public void getGoerliContractAddressTest() {
assertEquals(Utils.getGoerliContractAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"),
"0x2f3a40a3db8a7e3d09b0adfefbce4f6f81927557");
assertEquals(Utils.getGoerliContractAddress("0x6b175474e89094c44da98b954eedeac495271d0f"),
"0x73967c6a0904aa032c103b4104747e88c566b1a2");
assertEquals(
Utils.getRopstenContractAddress("0xdef1c0ded9bec7f1a1670819833240f027b25eff"), "");
Utils.getGoerliContractAddress("0xdef1c0ded9bec7f1a1670819833240f027b25eff"), "");
}
private static String getStackTrace(Exception ex) {
@@ -72,7 +72,7 @@ const char token_list_json[] = R"(
}
})";
const char ropsten_list_json[] = R"(
const char goerli_list_json[] = R"(
{
"0x6B175474E89094C44Da98b954EedeAC495271d0F": {
"name": "USD Coin",
@@ -81,7 +81,7 @@ const char ropsten_list_json[] = R"(
"erc721": false,
"symbol": "USDC",
"decimals": 6,
"chainId": "0x2a"
"chainId": "0x5"
},
"0x06012c8cf97BEaD5deAe237070F9587f8E7A266d": {
"name": "Crypto Kitties",
@@ -90,7 +90,7 @@ const char ropsten_list_json[] = R"(
"erc721": true,
"symbol": "CK",
"decimals": 0,
"chainId": "0x2a"
"chainId": "0x5"
},
"0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984": {
"name": "Uniswap",
@@ -98,7 +98,7 @@ const char ropsten_list_json[] = R"(
"erc20": true,
"symbol": "UNI",
"decimals": 18,
"chainId": "0x2a"
"chainId": "0x5"
}
})";
@@ -273,7 +273,7 @@ class BraveWalletServiceUnitTest : public testing::Test {
TokenListMap token_list_map;
ASSERT_TRUE(
ParseTokenList(token_list_json, &token_list_map, mojom::CoinType::ETH));
ASSERT_TRUE(ParseTokenList(ropsten_list_json, &token_list_map,
ASSERT_TRUE(ParseTokenList(goerli_list_json, &token_list_map,
mojom::CoinType::ETH));
ASSERT_TRUE(ParseTokenList(solana_token_list_json, &token_list_map,
mojom::CoinType::SOL));
@@ -656,7 +656,7 @@ class BraveWalletServiceUnitTest : public testing::Test {
EXPECT_EQ(requests[0]->token, expected_token);
if (run_switch_network) {
json_rpc_service_->SetNetwork(mojom::kRopstenChainId,
json_rpc_service_->SetNetwork(mojom::kGoerliChainId,
mojom::CoinType::ETH);
} else {
service_->NotifyAddSuggestTokenRequestsProcessed(
@@ -721,14 +721,14 @@ TEST_F(BraveWalletServiceUnitTest, GetUserAssets) {
EXPECT_EQ(tokens[0], GetEthToken());
EXPECT_EQ(tokens[1], GetBatToken());
// Create ETH token with 0x3 chain_id.
mojom::BlockchainTokenPtr eth_0x3_token = GetEthToken();
eth_0x3_token->chain_id = "0x3";
// Create ETH token with 0x5 chain_id.
mojom::BlockchainTokenPtr eth_0x5_token = GetEthToken();
eth_0x5_token->chain_id = "0x5";
// ETH should be returned before any token is added.
GetUserAssets("0x3", mojom::CoinType::ETH, &tokens);
GetUserAssets("0x5", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 1u);
EXPECT_EQ(tokens[0], eth_0x3_token);
EXPECT_EQ(tokens[0], eth_0x5_token);
// Prepare tokens to add.
mojom::BlockchainTokenPtr token1 = GetToken1();
@@ -741,15 +741,15 @@ TEST_F(BraveWalletServiceUnitTest, GetUserAssets) {
// Adding token with lower case contract address should be converted to
// checksum address.
auto unchecked_token = token1.Clone();
unchecked_token->chain_id = "0x4";
unchecked_token->chain_id = "0xaa36a7";
unchecked_token->contract_address =
base::ToLowerASCII(unchecked_token->contract_address);
AddUserAsset(std::move(unchecked_token), &success);
EXPECT_TRUE(success);
auto token2_0x4 = token2.Clone();
token2_0x4->chain_id = "0x4";
AddUserAsset(token2_0x4.Clone(), &success);
auto token2_0xaa36a7 = token2.Clone();
token2_0xaa36a7->chain_id = "0xaa36a7";
AddUserAsset(token2_0xaa36a7.Clone(), &success);
EXPECT_TRUE(success);
// Create Token1 with 0x1 chain_id.
@@ -762,23 +762,23 @@ TEST_F(BraveWalletServiceUnitTest, GetUserAssets) {
EXPECT_EQ(GetBatToken(), tokens[1]);
EXPECT_EQ(token1_0x1, tokens[2]);
// Create Tokens with 0x4 chain_id.
mojom::BlockchainTokenPtr eth_0x4_token = GetEthToken();
eth_0x4_token->chain_id = "0x4";
mojom::BlockchainTokenPtr token1_0x4 = token1.Clone();
token1_0x4->chain_id = "0x4";
// Create Tokens with 0xaa36a7 chain_id.
mojom::BlockchainTokenPtr eth_0xaa36a7_token = GetEthToken();
eth_0xaa36a7_token->chain_id = "0xaa36a7";
mojom::BlockchainTokenPtr token1_0xaa36a7 = token1.Clone();
token1_0xaa36a7->chain_id = "0xaa36a7";
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 3u);
EXPECT_EQ(eth_0x4_token, tokens[0]);
EXPECT_EQ(token1_0x4, tokens[1]);
EXPECT_EQ(token2_0x4, tokens[2]);
EXPECT_EQ(eth_0xaa36a7_token, tokens[0]);
EXPECT_EQ(token1_0xaa36a7, tokens[1]);
EXPECT_EQ(token2_0xaa36a7, tokens[2]);
// Remove token1 from "0x1" and token2 from "0x4" and test GetUserAssets.
// Remove token1 from "0x1" and token2 from "0xaa36a7" and test GetUserAssets.
RemoveUserAsset(token1_0x1.Clone(), &success);
EXPECT_TRUE(success);
RemoveUserAsset(token2_0x4.Clone(), &success);
RemoveUserAsset(token2_0xaa36a7.Clone(), &success);
EXPECT_TRUE(success);
GetUserAssets("0x1", mojom::CoinType::ETH, &tokens);
@@ -786,10 +786,10 @@ TEST_F(BraveWalletServiceUnitTest, GetUserAssets) {
EXPECT_EQ(tokens[0], GetEthToken());
EXPECT_EQ(tokens[1], GetBatToken());
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 2u);
EXPECT_EQ(eth_0x4_token, tokens[0]);
EXPECT_EQ(token1_0x4, tokens[1]);
EXPECT_EQ(eth_0xaa36a7_token, tokens[0]);
EXPECT_EQ(token1_0xaa36a7, tokens[1]);
}
TEST_F(BraveWalletServiceUnitTest, DefaultAssets) {
@@ -849,7 +849,7 @@ TEST_F(BraveWalletServiceUnitTest, AddUserAsset) {
// already should fail, in this case, it was eth.
auto token_with_empty_contract_address = token.Clone();
token_with_empty_contract_address->contract_address = "";
token_with_empty_contract_address->chain_id = "0x4";
token_with_empty_contract_address->chain_id = "0xaa36a7";
AddUserAsset(std::move(token_with_empty_contract_address), &success);
EXPECT_FALSE(success);
@@ -885,26 +885,26 @@ TEST_F(BraveWalletServiceUnitTest, AddUserAsset) {
AddUserAsset(token_with_unchecked_address.Clone(), &success);
EXPECT_FALSE(success);
// Create Tokens with 0x4 chain_id.
mojom::BlockchainTokenPtr eth_0x4_token = GetEthToken();
eth_0x4_token->chain_id = "0x4";
mojom::BlockchainTokenPtr token1_0x4 = GetToken1();
token1_0x4->chain_id = "0x4";
// Create Tokens with 0xaa36a7 chain_id.
mojom::BlockchainTokenPtr eth_0xaa36a7_token = GetEthToken();
eth_0xaa36a7_token->chain_id = "0xaa36a7";
mojom::BlockchainTokenPtr token1_0xaa36a7 = GetToken1();
token1_0xaa36a7->chain_id = "0xaa36a7";
// Adding token with same address in a different chain will succeed.
// And the address will be converted to checksum address.
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 1u);
EXPECT_EQ(tokens[0], eth_0x4_token);
EXPECT_EQ(tokens[0], eth_0xaa36a7_token);
token_with_unchecked_address->chain_id = "0x4";
token_with_unchecked_address->chain_id = "0xaa36a7";
AddUserAsset(token_with_unchecked_address.Clone(), &success);
EXPECT_TRUE(success);
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 2u);
EXPECT_EQ(tokens[0], eth_0x4_token);
EXPECT_EQ(tokens[1], token1_0x4);
EXPECT_EQ(tokens[0], eth_0xaa36a7_token);
EXPECT_EQ(tokens[1], token1_0xaa36a7);
}
TEST_F(BraveWalletServiceUnitTest, RemoveUserAsset) {
@@ -914,10 +914,10 @@ TEST_F(BraveWalletServiceUnitTest, RemoveUserAsset) {
token1_0x1->chain_id = "0x1";
mojom::BlockchainTokenPtr token2_0x1 = GetToken2();
token2_0x1->chain_id = "0x1";
mojom::BlockchainTokenPtr token2_0x4 = GetToken2();
token2_0x4->chain_id = "0x4";
mojom::BlockchainTokenPtr eth_0x4_token = GetEthToken();
eth_0x4_token->chain_id = "0x4";
mojom::BlockchainTokenPtr token2_0xaa36a7 = GetToken2();
token2_0xaa36a7->chain_id = "0xaa36a7";
mojom::BlockchainTokenPtr eth_0xaa36a7_token = GetEthToken();
eth_0xaa36a7_token->chain_id = "0xaa36a7";
bool success = false;
std::vector<mojom::BlockchainTokenPtr> tokens;
@@ -929,7 +929,7 @@ TEST_F(BraveWalletServiceUnitTest, RemoveUserAsset) {
AddUserAsset(token2.Clone(), &success);
EXPECT_TRUE(success);
AddUserAsset(token2_0x4.Clone(), &success);
AddUserAsset(token2_0xaa36a7.Clone(), &success);
EXPECT_TRUE(success);
GetUserAssets("0x1", mojom::CoinType::ETH, &tokens);
@@ -939,10 +939,10 @@ TEST_F(BraveWalletServiceUnitTest, RemoveUserAsset) {
EXPECT_EQ(tokens[2], token1_0x1);
EXPECT_EQ(tokens[3], token2_0x1);
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 2u);
EXPECT_EQ(tokens[0], eth_0x4_token);
EXPECT_EQ(tokens[1], token2_0x4);
EXPECT_EQ(tokens[0], eth_0xaa36a7_token);
EXPECT_EQ(tokens[1], token2_0xaa36a7);
// Remove token with invalid contract_address returns false.
auto invalid_eth_token = GetEthToken().Clone();
@@ -963,9 +963,9 @@ TEST_F(BraveWalletServiceUnitTest, RemoveUserAsset) {
EXPECT_FALSE(success);
// Remove non-exist token returns true.
auto token1_0x4 = token1.Clone();
token1_0x4->chain_id = "0x4";
RemoveUserAsset(std::move(token1_0x4), &success);
auto token1_0xaa36a7 = token1.Clone();
token1_0xaa36a7->chain_id = "0xaa36a7";
RemoveUserAsset(std::move(token1_0xaa36a7), &success);
EXPECT_TRUE(success);
// Remove existing token.
@@ -993,10 +993,10 @@ TEST_F(BraveWalletServiceUnitTest, SetUserAssetVisible) {
token1_0x1->chain_id = "0x1";
mojom::BlockchainTokenPtr token2_0x1 = GetToken2();
token2_0x1->chain_id = "0x1";
mojom::BlockchainTokenPtr token2_0x4 = GetToken2();
token2_0x4->chain_id = "0x4";
mojom::BlockchainTokenPtr eth_0x4_token = GetEthToken();
eth_0x4_token->chain_id = "0x4";
mojom::BlockchainTokenPtr token2_0xaa36a7 = GetToken2();
token2_0xaa36a7->chain_id = "0xaa36a7";
mojom::BlockchainTokenPtr eth_0xaa36a7_token = GetEthToken();
eth_0xaa36a7_token->chain_id = "0xaa36a7";
bool success = false;
std::vector<mojom::BlockchainTokenPtr> tokens;
@@ -1008,7 +1008,7 @@ TEST_F(BraveWalletServiceUnitTest, SetUserAssetVisible) {
AddUserAsset(token2.Clone(), &success);
EXPECT_TRUE(success);
AddUserAsset(token2_0x4.Clone(), &success);
AddUserAsset(token2_0xaa36a7.Clone(), &success);
EXPECT_TRUE(success);
GetUserAssets("0x1", mojom::CoinType::ETH, &tokens);
@@ -1018,10 +1018,10 @@ TEST_F(BraveWalletServiceUnitTest, SetUserAssetVisible) {
EXPECT_EQ(tokens[2], token1_0x1);
EXPECT_EQ(tokens[3], token2_0x1);
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 2u);
EXPECT_EQ(tokens[0], eth_0x4_token);
EXPECT_EQ(tokens[1], token2_0x4);
EXPECT_EQ(tokens[0], eth_0xaa36a7_token);
EXPECT_EQ(tokens[1], token2_0xaa36a7);
// Invalid contract_address return false.
auto invalid_eth = GetEthToken();
@@ -1036,18 +1036,18 @@ TEST_F(BraveWalletServiceUnitTest, SetUserAssetVisible) {
EXPECT_FALSE(success);
// List for this network_id is not existed should return false.
auto token1_0x3 = token1.Clone();
token1_0x3->chain_id = "0x3";
SetUserAssetVisible(std::move(token1_0x3), false, &success);
auto token1_0x5 = token1.Clone();
token1_0x5->chain_id = "0x5";
SetUserAssetVisible(std::move(token1_0x5), false, &success);
EXPECT_FALSE(success);
auto token1_0x4 = token1.Clone();
token1_0x4->chain_id = "0x4";
auto token1_0xaa36a7 = token1.Clone();
token1_0xaa36a7->chain_id = "0xaa36a7";
// No entry with this contract address exists in the list.
SetUserAssetVisible(token1_0x4.Clone(), false, &success);
SetUserAssetVisible(token1_0xaa36a7.Clone(), false, &success);
EXPECT_FALSE(success);
// Set visible to false for BAT & token1 in "0x1" and token2 in "0x4".
// Set visible to false for BAT & token1 in "0x1" and token2 in "0xaa36a7".
SetUserAssetVisible(token1.Clone(), false, &success);
EXPECT_TRUE(success);
@@ -1058,7 +1058,7 @@ TEST_F(BraveWalletServiceUnitTest, SetUserAssetVisible) {
SetUserAssetVisible(std::move(BAT_lower_case_addr), false, &success);
EXPECT_TRUE(success);
SetUserAssetVisible(token2_0x4.Clone(), false, &success);
SetUserAssetVisible(token2_0xaa36a7.Clone(), false, &success);
EXPECT_TRUE(success);
GetUserAssets("0x1", mojom::CoinType::ETH, &tokens);
@@ -1072,7 +1072,7 @@ TEST_F(BraveWalletServiceUnitTest, SetUserAssetVisible) {
EXPECT_EQ(tokens[3]->contract_address, token2->contract_address);
EXPECT_TRUE(tokens[3]->visible);
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 2u);
EXPECT_EQ(tokens[0]->contract_address, GetEthToken()->contract_address);
EXPECT_TRUE(tokens[0]->visible);
@@ -1189,47 +1189,47 @@ TEST_F(BraveWalletServiceUnitTest, SelectedCoin) {
}
TEST_F(BraveWalletServiceUnitTest, EthAddRemoveSetUserAssetVisible) {
mojom::BlockchainTokenPtr eth_0x4_token = GetEthToken();
eth_0x4_token->chain_id = "0x4";
mojom::BlockchainTokenPtr eth_0xaa36a7_token = GetEthToken();
eth_0xaa36a7_token->chain_id = "0xaa36a7";
bool success = false;
std::vector<mojom::BlockchainTokenPtr> tokens;
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 1u);
EXPECT_EQ(eth_0x4_token, tokens[0]);
EXPECT_EQ(eth_0xaa36a7_token, tokens[0]);
// Add ETH again will fail.
AddUserAsset(eth_0x4_token.Clone(), &success);
AddUserAsset(eth_0xaa36a7_token.Clone(), &success);
EXPECT_FALSE(success);
// Test setting visibility of ETH.
SetUserAssetVisible(eth_0x4_token.Clone(), false, &success);
SetUserAssetVisible(eth_0xaa36a7_token.Clone(), false, &success);
EXPECT_TRUE(success);
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 1u);
EXPECT_FALSE(tokens[0]->visible);
// Test removing ETH from user asset list.
RemoveUserAsset(eth_0x4_token.Clone(), &success);
RemoveUserAsset(eth_0xaa36a7_token.Clone(), &success);
EXPECT_TRUE(success);
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_TRUE(tokens.empty());
// Add ETH with eth as the contract address will fail.
auto invalid_eth = eth_0x4_token.Clone();
auto invalid_eth = eth_0xaa36a7_token.Clone();
invalid_eth->contract_address = "eth";
AddUserAsset(std::move(invalid_eth), &success);
EXPECT_FALSE(success);
// Add ETH with empty contract address.
AddUserAsset(eth_0x4_token.Clone(), &success);
AddUserAsset(eth_0xaa36a7_token.Clone(), &success);
EXPECT_TRUE(success);
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 1u);
EXPECT_EQ(eth_0x4_token, tokens[0]);
EXPECT_EQ(eth_0xaa36a7_token, tokens[0]);
}
TEST_F(BraveWalletServiceUnitTest, NetworkListChangedEvent) {
@@ -1304,7 +1304,7 @@ TEST_F(BraveWalletServiceUnitTest, ERC721TokenAddRemoveSetUserAssetVisible) {
std::vector<mojom::BlockchainTokenPtr> tokens;
auto erc721_token_with_empty_token_id = GetErc721Token();
erc721_token_with_empty_token_id->chain_id = "0x4";
erc721_token_with_empty_token_id->chain_id = "0xaa36a7";
auto erc721_token_1 = erc721_token_with_empty_token_id.Clone();
erc721_token_1->token_id = "0x1";
auto erc721_token_2 = erc721_token_with_empty_token_id.Clone();
@@ -1334,12 +1334,12 @@ TEST_F(BraveWalletServiceUnitTest, ERC721TokenAddRemoveSetUserAssetVisible) {
AddUserAsset(erc721_token_2.Clone(), &success);
EXPECT_TRUE(success);
mojom::BlockchainTokenPtr eth_0x4_token = GetEthToken();
eth_0x4_token->chain_id = "0x4";
mojom::BlockchainTokenPtr eth_0xaa36a7_token = GetEthToken();
eth_0xaa36a7_token->chain_id = "0xaa36a7";
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 3u);
EXPECT_EQ(eth_0x4_token, tokens[0]);
EXPECT_EQ(eth_0xaa36a7_token, tokens[0]);
EXPECT_EQ(erc721_token_1, tokens[1]);
EXPECT_EQ(erc721_token_2, tokens[2]);
@@ -1351,9 +1351,9 @@ TEST_F(BraveWalletServiceUnitTest, ERC721TokenAddRemoveSetUserAssetVisible) {
auto erc721_token_1_visible_false = erc721_token_1.Clone();
erc721_token_1_visible_false->visible = false;
GetUserAssets("0x4", mojom::CoinType::ETH, &tokens);
GetUserAssets("0xaa36a7", mojom::CoinType::ETH, &tokens);
EXPECT_EQ(tokens.size(), 2u);
EXPECT_EQ(eth_0x4_token, tokens[0]);
EXPECT_EQ(eth_0xaa36a7_token, tokens[0]);
EXPECT_EQ(erc721_token_1_visible_false, tokens[1]);
}
@@ -1450,13 +1450,13 @@ TEST_F(BraveWalletServiceUnitTest, MigrateUserAssetEthContractAddress) {
value.Set("decimals", 18);
value.Set("visible", true);
user_assets_list.Append(std::move(value));
user_assets_pref->Set("rinkeby", std::move(user_assets_list));
user_assets_pref->Set("goerli", std::move(user_assets_list));
}
const base::Value* pref =
GetPrefs()->GetDictionary(kBraveWalletUserAssetsDeprecated);
ASSERT_TRUE(pref);
const auto* user_assets_list = pref->GetDict().FindList("rinkeby");
const auto* user_assets_list = pref->GetDict().FindList("goerli");
ASSERT_TRUE(user_assets_list);
ASSERT_EQ(user_assets_list->size(), 1u);
EXPECT_EQ(*(*user_assets_list)[0].GetDict().FindString("contract_address"),
@@ -1898,7 +1898,7 @@ TEST_F(BraveWalletServiceUnitTest, SignMessage) {
TEST_F(BraveWalletServiceUnitTest, AddSuggestToken) {
std::vector<std::string> chain_ids = {mojom::kMainnetChainId,
mojom::kKovanChainId};
mojom::kGoerliChainId};
for (const std::string& chain_id : chain_ids) {
json_rpc_service_->SetNetwork(chain_id, mojom::CoinType::ETH);
mojom::BlockchainTokenPtr usdc_from_blockchain_registry =
@@ -2041,16 +2041,16 @@ TEST_F(BraveWalletServiceUnitTest, AddSuggestToken) {
TEST_F(BraveWalletServiceUnitTest, GetUserAsset) {
mojom::BlockchainTokenPtr usdc = mojom::BlockchainToken::New(
"0x6B175474E89094C44Da98b954EedeAC495271d0F", "USD Coin", "usdc.png",
true, false, "USDC", 6, true, "", "", mojom::kRopstenChainId,
true, false, "USDC", 6, true, "", "", mojom::kGoerliChainId,
mojom::CoinType::ETH);
ASSERT_TRUE(service_->AddUserAsset(usdc.Clone()));
EXPECT_EQ(usdc, service_->GetUserAsset(
usdc->contract_address, usdc->token_id, usdc->is_erc721,
mojom::kRopstenChainId, mojom::CoinType::ETH));
EXPECT_EQ(usdc, service_->GetUserAsset(usdc->contract_address, usdc->token_id,
usdc->is_erc721, mojom::kGoerliChainId,
mojom::CoinType::ETH));
EXPECT_EQ(usdc,
service_->GetUserAsset(
base::ToLowerASCII(usdc->contract_address), usdc->token_id,
usdc->is_erc721, mojom::kRopstenChainId, mojom::CoinType::ETH));
usdc->is_erc721, mojom::kGoerliChainId, mojom::CoinType::ETH));
EXPECT_FALSE(service_->GetUserAsset(usdc->contract_address, usdc->token_id,
usdc->is_erc721, mojom::kMainnetChainId,
mojom::CoinType::ETH));
@@ -2058,16 +2058,16 @@ TEST_F(BraveWalletServiceUnitTest, GetUserAsset) {
auto erc721_token_with_empty_token_id = GetErc721Token();
auto erc721_token_1 = erc721_token_with_empty_token_id.Clone();
erc721_token_1->token_id = "0x1";
erc721_token_1->chain_id = mojom::kRopstenChainId;
erc721_token_1->chain_id = mojom::kGoerliChainId;
ASSERT_TRUE(service_->AddUserAsset(erc721_token_1.Clone()));
EXPECT_EQ(erc721_token_1,
service_->GetUserAsset(
erc721_token_1->contract_address, erc721_token_1->token_id,
erc721_token_1->is_erc721, mojom::kRopstenChainId,
erc721_token_1->is_erc721, mojom::kGoerliChainId,
mojom::CoinType::ETH));
EXPECT_FALSE(service_->GetUserAsset(
erc721_token_1->contract_address, "0x2", erc721_token_1->is_erc721,
mojom::kRopstenChainId, mojom::CoinType::ETH));
mojom::kGoerliChainId, mojom::CoinType::ETH));
}
TEST_F(BraveWalletServiceUnitTest, Reset) {
@@ -1227,7 +1227,7 @@ TEST_F(EthereumProviderImplUnitTest, AddAndApprove1559TransactionNoChainId) {
AddAccount();
GURL url("https://brave.com");
Navigate(url);
SetNetwork("0x4");
SetNetwork("0xaa36a7");
// Wait for EthTxStateManager::ChainChangedEvent to be called.
browser_task_environment_.RunUntilIdle();
@@ -1283,8 +1283,10 @@ TEST_F(EthereumProviderImplUnitTest, AddAndApprove1559TransactionNoChainId) {
std::vector<mojom::TransactionInfoPtr> infos = GetAllTransactionInfo();
ASSERT_EQ(infos.size(), 2UL);
ASSERT_TRUE(infos[0]->tx_data_union->is_eth_tx_data_1559());
EXPECT_EQ(infos[0]->tx_data_union->get_eth_tx_data_1559()->chain_id, "0x4");
EXPECT_EQ(infos[1]->tx_data_union->get_eth_tx_data_1559()->chain_id, "0x4");
EXPECT_EQ(infos[0]->tx_data_union->get_eth_tx_data_1559()->chain_id,
"0xaa36a7");
EXPECT_EQ(infos[1]->tx_data_union->get_eth_tx_data_1559()->chain_id,
"0xaa36a7");
}
TEST_F(EthereumProviderImplUnitTest, AddAndApprove1559TransactionError) {
@@ -1731,8 +1733,8 @@ TEST_F(EthereumProviderImplUnitTest, SignTypedMessage) {
EXPECT_EQ(error_message,
l10n_util::GetStringUTF8(IDS_WALLET_INVALID_PARAMETERS));
domain.Set("chainId", 4);
std::string chain_id = "0x4";
domain.Set("chainId", 11155111);
std::string chain_id = "0xaa36a7";
// not active network
SignTypedMessage(absl::nullopt, address, "{...}", domain_hash, primary_hash,
domain.Clone(), &signature, &error, &error_message);
@@ -1913,9 +1915,9 @@ TEST_F(EthereumProviderImplUnitTest, SignMessageRequestQueue) {
TEST_F(EthereumProviderImplUnitTest, ChainChangedEvent) {
EXPECT_FALSE(observer_->ChainChangedFired());
SetNetwork(mojom::kRinkebyChainId);
SetNetwork(mojom::kGoerliChainId);
EXPECT_TRUE(observer_->ChainChangedFired());
EXPECT_EQ(mojom::kRinkebyChainId, observer_->GetChainId());
EXPECT_EQ(mojom::kGoerliChainId, observer_->GetChainId());
// Works a second time
observer_->Reset();
@@ -2142,7 +2144,7 @@ TEST_F(EthereumProviderImplUnitTest, SwitchEthereumChain) {
EXPECT_FALSE(brave_wallet_tab_helper()->IsShowingBubble());
// user rejected
SwitchEthereumChain("0x4", false, &error, &error_message);
SwitchEthereumChain("0xaa36a7", false, &error, &error_message);
EXPECT_EQ(error, mojom::ProviderError::kUserRejectedRequest);
EXPECT_EQ(error_message,
l10n_util::GetStringUTF8(IDS_WALLET_USER_REJECTED_REQUEST));
@@ -2151,13 +2153,13 @@ TEST_F(EthereumProviderImplUnitTest, SwitchEthereumChain) {
EXPECT_FALSE(brave_wallet_tab_helper()->IsShowingBubble());
// user approved
SwitchEthereumChain("0x4", true, &error, &error_message);
SwitchEthereumChain("0xaa36a7", true, &error, &error_message);
EXPECT_EQ(error, mojom::ProviderError::kSuccess);
EXPECT_TRUE(error_message.empty());
EXPECT_TRUE(brave_wallet_tab_helper()->IsShowingBubble());
brave_wallet_tab_helper()->CloseBubble();
EXPECT_FALSE(brave_wallet_tab_helper()->IsShowingBubble());
EXPECT_EQ(json_rpc_service()->GetChainId(mojom::CoinType::ETH), "0x4");
EXPECT_EQ(json_rpc_service()->GetChainId(mojom::CoinType::ETH), "0xaa36a7");
// one request per origin
base::RunLoop run_loop;
@@ -2188,9 +2190,9 @@ TEST_F(EthereumProviderImplUnitTest, AddEthereumChainSwitchesForInnactive) {
// AddEthereumChain switches for already added networks
std::string params = R"({"params": [{
"chainId": "0x3",
"chainName": "Ropsten",
"rpcUrls": ["https://ropsten-infura.brave.com/"]
"chainId": "0x5",
"chainName": "Goerli",
"rpcUrls": ["https://goerli-infura.brave.com/"]
}]})";
base::RunLoop run_loop;
provider()->AddEthereumChain(
@@ -2213,7 +2215,7 @@ TEST_F(EthereumProviderImplUnitTest, AddEthereumChainSwitchesForInnactive) {
run_loop.Run();
brave_wallet_tab_helper()->CloseBubble();
EXPECT_FALSE(brave_wallet_tab_helper()->IsShowingBubble());
EXPECT_EQ(json_rpc_service()->GetChainId(mojom::CoinType::ETH), "0x3");
EXPECT_EQ(json_rpc_service()->GetChainId(mojom::CoinType::ETH), "0x5");
}
TEST_F(EthereumProviderImplUnitTest, AddSuggestToken) {
@@ -449,10 +449,8 @@ bool ParseJSON(base::StringPiece json,
// Wallet
{ "name": "goerli-infura.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
{ "name": "kovan-infura.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
{ "name": "sepolia-infura.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
{ "name": "mainnet-infura.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
{ "name": "rinkeby-infura.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
{ "name": "ropsten-infura.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
{ "name": "mainnet-beta-solana.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
{ "name": "mainnet-polygon.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
@@ -40,7 +40,7 @@ TEST(ParseTokenListUnitTest, ParseTokenList) {
"erc20": true,
"symbol": "UNI",
"decimals": 18,
"chainId": "0x3"
"chainId": "0x5"
}
}
)");
@@ -49,7 +49,7 @@ TEST(ParseTokenListUnitTest, ParseTokenList) {
ASSERT_TRUE(ParseTokenList(json, &token_list_map, mojom::CoinType::ETH));
ASSERT_EQ(token_list_map["ethereum.0x1"].size(), 2UL);
EXPECT_EQ(token_list_map["ethereum.0x2"].size(), 0UL);
ASSERT_EQ(token_list_map["ethereum.0x3"].size(), 1UL);
ASSERT_EQ(token_list_map["ethereum.0x5"].size(), 1UL);
const auto& mainnet_token_list = token_list_map["ethereum.0x1"];
EXPECT_EQ(mainnet_token_list[0]->name, "Crypto Kitties");
@@ -72,15 +72,15 @@ TEST(ParseTokenListUnitTest, ParseTokenList) {
EXPECT_EQ(mainnet_token_list[1]->decimals, 18);
EXPECT_EQ(mainnet_token_list[1]->coingecko_id, "basic-attention-token");
const auto& ropsten_token_list = token_list_map["ethereum.0x3"];
EXPECT_EQ(ropsten_token_list[0]->name, "Uniswap");
EXPECT_EQ(ropsten_token_list[0]->contract_address,
const auto& goerli_token_list = token_list_map["ethereum.0x5"];
EXPECT_EQ(goerli_token_list[0]->name, "Uniswap");
EXPECT_EQ(goerli_token_list[0]->contract_address,
"0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984");
EXPECT_TRUE(ropsten_token_list[0]->is_erc20);
EXPECT_FALSE(ropsten_token_list[0]->is_erc721);
EXPECT_EQ(ropsten_token_list[0]->symbol, "UNI");
EXPECT_EQ(ropsten_token_list[0]->logo, "uni.svg");
EXPECT_EQ(ropsten_token_list[0]->decimals, 18);
EXPECT_TRUE(goerli_token_list[0]->is_erc20);
EXPECT_FALSE(goerli_token_list[0]->is_erc721);
EXPECT_EQ(goerli_token_list[0]->symbol, "UNI");
EXPECT_EQ(goerli_token_list[0]->logo, "uni.svg");
EXPECT_EQ(goerli_token_list[0]->decimals, 18);
EXPECT_TRUE(mainnet_token_list[0]->coingecko_id.empty());
std::string solana_json(R"(
@@ -43,7 +43,7 @@ const char token_list_json[] = R"(
"erc20": true,
"symbol": "UNI",
"decimals": 18,
"chainId": "0x3"
"chainId": "0x5"
},
"0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef": {
"name": "ENS Registrar",
@@ -233,7 +233,7 @@ TEST(BlockchainRegistryUnitTest, GetAllTokens) {
// Can get other chain tokens
base::RunLoop run_loop2;
registry->GetAllTokens(
mojom::kRopstenChainId, mojom::CoinType::ETH,
mojom::kGoerliChainId, mojom::CoinType::ETH,
base::BindLambdaForTesting(
[&](std::vector<mojom::BlockchainTokenPtr> token_list) {
ASSERT_EQ(token_list.size(), 1UL);
@@ -251,7 +251,7 @@ TEST(BlockchainRegistryUnitTest, GetAllTokens) {
// chainId which has no tokens
base::RunLoop run_loop3;
registry->GetAllTokens(
mojom::kRinkebyChainId, mojom::CoinType::ETH,
mojom::kSepoliaChainId, mojom::CoinType::ETH,
base::BindLambdaForTesting(
[&](std::vector<mojom::BlockchainTokenPtr> token_list) {
// ENS Registrar should not be parsed because it doesn't have
@@ -298,7 +298,7 @@ TEST(BlockchainRegistryUnitTest, GetTokenByAddress) {
// Can get other chain tokens
base::RunLoop run_loop2;
registry->GetTokenByAddress(
mojom::kRopstenChainId, mojom::CoinType::ETH,
mojom::kGoerliChainId, mojom::CoinType::ETH,
"0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
base::BindLambdaForTesting([&](mojom::BlockchainTokenPtr token) {
EXPECT_EQ(token->symbol, "UNI");
@@ -320,7 +320,7 @@ TEST(BlockchainRegistryUnitTest, GetTokenByAddress) {
// chainId which has no tokens
base::RunLoop run_loop4;
registry->GetTokenByAddress(
mojom::kRinkebyChainId, mojom::CoinType::ETH,
mojom::kGoerliChainId, mojom::CoinType::ETH,
"0xCCC775F648430679A709E98d2b0Cb6250d2887EF",
base::BindLambdaForTesting([&](mojom::BlockchainTokenPtr token) {
EXPECT_FALSE(token);
@@ -362,7 +362,7 @@ TEST(BlockchainRegistryUnitTest, GetTokenBySymbol) {
// Can get other chain tokens
base::RunLoop run_loop2;
registry->GetTokenBySymbol(
mojom::kRopstenChainId, mojom::CoinType::ETH, "UNI",
mojom::kGoerliChainId, mojom::CoinType::ETH, "UNI",
base::BindLambdaForTesting([&](mojom::BlockchainTokenPtr token) {
EXPECT_EQ(token->contract_address,
"0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984");
@@ -383,7 +383,7 @@ TEST(BlockchainRegistryUnitTest, GetTokenBySymbol) {
// chainId which has no tokens
base::RunLoop run_loop4;
registry->GetTokenBySymbol(
mojom::kRinkebyChainId, mojom::CoinType::ETH, "BRB",
mojom::kGoerliChainId, mojom::CoinType::ETH, "BRB",
base::BindLambdaForTesting([&](mojom::BlockchainTokenPtr token) {
EXPECT_FALSE(token);
run_loop4.Quit();
@@ -353,10 +353,8 @@ constexpr webui::LocalizedString kLocalizedStrings[] = {
{"braveWalletNetworkETH", IDS_BRAVE_WALLET_NETWORK_E_T_H},
{"braveWalletNetworkMain", IDS_BRAVE_WALLET_NETWORK_MAIN},
{"braveWalletNetworkTest", IDS_BRAVE_WALLET_NETWORK_TEST},
{"braveWalletNetworkRopsten", IDS_BRAVE_WALLET_NETWORK_ROPSTEN},
{"braveWalletNetworkKovan", IDS_BRAVE_WALLET_NETWORK_KOVAN},
{"braveWalletNetworkRinkeby", IDS_BRAVE_WALLET_NETWORK_RINKEBY},
{"braveWalletNetworkGoerli", IDS_BRAVE_WALLET_NETWORK_GOERLI},
{"braveWalletNetworkSepolia", IDS_BRAVE_WALLET_NETWORK_SEPOLIA},
{"braveWalletNetworkBinance", IDS_BRAVE_WALLET_NETWORK_BINANCE},
{"braveWalletNetworkBinanceAbbr", IDS_BRAVE_WALLET_NETWORK_BINANCE_ABBR},
{"braveWalletNetworkLocalhost", IDS_BRAVE_WALLET_NETWORK_LOCALHOST},
@@ -945,9 +943,9 @@ constexpr webui::LocalizedString kLocalizedStrings[] = {
IDS_BRAVE_WALLET_ADD_ASSET_NFT_TAB_TITLE}};
// 0x swap constants
constexpr char kRopstenSwapBaseAPIURL[] = "https://ropsten.api.0x.org/";
constexpr char kGoerliSwapBaseAPIURL[] = "https://goerli.api.0x.org/";
// As of 22-02-2022, this address is controlled by @onyb.
constexpr char kRopstenFeeRecipient[] =
constexpr char kGoerliFeeRecipient[] =
"0xa92D461a9a988A7f11ec285d39783A637Fdd6ba4";
constexpr char kPolygonSwapBaseAPIURL[] = "https://polygon.api.0x.org/";
constexpr char kBinanceSmartChainSwapBaseAPIURL[] = "https://bsc.api.0x.org/";
@@ -117,6 +117,10 @@ void RegisterProfilePrefsForMigration(
// Added 06/2022
registry->RegisterBooleanPref(
kBraveWalletUserAssetsAddPreloadingNetworksMigrated, false);
// Added 10/2022
registry->RegisterBooleanPref(
kBraveWalletDeprecateEthereumTestNetworksMigrated, false);
}
void ClearJsonRpcServiceProfilePrefs(PrefService* prefs) {
@@ -196,6 +200,9 @@ void MigrateObsoleteProfilePrefs(PrefService* prefs) {
}
prefs->SetBoolean(kBraveWalletEthereumTransactionsCoinTypeMigrated, true);
}
// Added 10/2022
JsonRpcService::MigrateDeprecatedEthereumTestnets(prefs);
}
} // namespace brave_wallet
@@ -209,38 +209,6 @@ const mojom::NetworkInfo* GetAuroraMainnet() {
return network_info.get();
}
const mojom::NetworkInfo* GetRinkebyTestNetwork() {
static base::NoDestructor<mojom::NetworkInfo> network_info(
{brave_wallet::mojom::kRinkebyChainId,
"Rinkeby Test Network",
{"https://rinkeby.etherscan.io"},
{},
0,
{},
"ETH",
"Ethereum",
18,
brave_wallet::mojom::CoinType::ETH,
true});
return network_info.get();
}
const mojom::NetworkInfo* GetRopstenTestNetwork() {
static base::NoDestructor<mojom::NetworkInfo> network_info(
{brave_wallet::mojom::kRopstenChainId,
"Ropsten Test Network",
{"https://ropsten.etherscan.io"},
{},
0,
{},
"ETH",
"Ethereum",
18,
brave_wallet::mojom::CoinType::ETH,
true});
return network_info.get();
}
const mojom::NetworkInfo* GetGoerliTestNetwork() {
static base::NoDestructor<mojom::NetworkInfo> network_info(
{brave_wallet::mojom::kGoerliChainId,
@@ -257,11 +225,11 @@ const mojom::NetworkInfo* GetGoerliTestNetwork() {
return network_info.get();
}
const mojom::NetworkInfo* GetKovanTestNetwork() {
const mojom::NetworkInfo* GetSepoliaTestNetwork() {
static base::NoDestructor<mojom::NetworkInfo> network_info(
{brave_wallet::mojom::kKovanChainId,
"Kovan Test Network",
{"https://kovan.etherscan.io"},
{brave_wallet::mojom::kSepoliaChainId,
"Sepolia Test Network",
{"https://sepolia.etherscan.io"},
{},
0,
{},
@@ -301,10 +269,8 @@ const std::vector<const mojom::NetworkInfo*>& GetKnownEthNetworks() {
GetFantomOperaMainnet(),
GetOptimismMainnet(),
GetAuroraMainnet(),
GetRinkebyTestNetwork(),
GetRopstenTestNetwork(),
GetGoerliTestNetwork(),
GetKovanTestNetwork(),
GetSepoliaTestNetwork(),
GetEthLocalhost(),
// clang-format on
});
@@ -449,20 +415,16 @@ const std::vector<const mojom::NetworkInfo*>& GetKnownFilNetworks() {
const base::flat_map<std::string, std::string> kInfuraSubdomains = {
{brave_wallet::mojom::kMainnetChainId, "mainnet"},
{brave_wallet::mojom::kRinkebyChainId, "rinkeby"},
{brave_wallet::mojom::kRopstenChainId, "ropsten"},
{brave_wallet::mojom::kGoerliChainId, "goerli"},
{brave_wallet::mojom::kKovanChainId, "kovan"}};
{brave_wallet::mojom::kSepoliaChainId, "sepolia"}};
const base::flat_set<std::string> kInfuraChains = {
brave_wallet::mojom::kMainnetChainId,
brave_wallet::mojom::kPolygonMainnetChainId,
brave_wallet::mojom::kOptimismMainnetChainId,
brave_wallet::mojom::kAuroraMainnetChainId,
brave_wallet::mojom::kRinkebyChainId,
brave_wallet::mojom::kRopstenChainId,
brave_wallet::mojom::kGoerliChainId,
brave_wallet::mojom::kKovanChainId};
brave_wallet::mojom::kSepoliaChainId,
brave_wallet::mojom::kGoerliChainId};
const base::flat_map<std::string, std::string> kSolanaSubdomains = {
{brave_wallet::mojom::kSolanaMainnet, "mainnet"},
@@ -711,7 +711,7 @@ TEST(BraveWalletUtilsUnitTest, KnownChainExists) {
UpdateCustomNetworks(&prefs, std::move(values), mojom::CoinType::ETH);
auto known_chains = GetAllKnownChains(&prefs, mojom::CoinType::ETH);
EXPECT_EQ(known_chains.size(), 13u);
EXPECT_EQ(known_chains.size(), 11u);
for (auto& known_chain : known_chains) {
EXPECT_TRUE(KnownChainExists(known_chain->chain_id, mojom::CoinType::ETH));
}
@@ -870,10 +870,8 @@ TEST(BraveWalletUtilsUnitTest, GetNetworkURLForKnownChains) {
brave_wallet::mojom::kPolygonMainnetChainId,
brave_wallet::mojom::kOptimismMainnetChainId,
brave_wallet::mojom::kAuroraMainnetChainId,
brave_wallet::mojom::kRinkebyChainId,
brave_wallet::mojom::kRopstenChainId,
brave_wallet::mojom::kGoerliChainId,
brave_wallet::mojom::kKovanChainId};
brave_wallet::mojom::kSepoliaChainId};
for (const auto& chain : GetAllKnownChains(&prefs, mojom::CoinType::ETH)) {
auto network_url =
@@ -996,8 +994,8 @@ TEST(BraveWalletUtilsUnitTest, GetAllKnownEthNetworkIds) {
{"mainnet", mojom::kPolygonMainnetChainId,
mojom::kBinanceSmartChainMainnetChainId, mojom::kCeloMainnetChainId,
mojom::kAvalancheMainnetChainId, mojom::kFantomMainnetChainId,
mojom::kOptimismMainnetChainId, mojom::kAuroraMainnetChainId, "rinkeby",
"ropsten", "goerli", "kovan", "http://localhost:7545/"});
mojom::kOptimismMainnetChainId, mojom::kAuroraMainnetChainId, "goerli",
"sepolia", "http://localhost:7545/"});
ASSERT_EQ(GetAllKnownNetworksForTesting().size(),
expected_network_ids.size());
EXPECT_EQ(GetAllKnownEthNetworkIds(), expected_network_ids);
@@ -1007,10 +1005,8 @@ TEST(BraveWalletUtilsUnitTest, GetKnownEthNetworkId) {
EXPECT_EQ(GetKnownEthNetworkId(mojom::kLocalhostChainId),
"http://localhost:7545/");
EXPECT_EQ(GetKnownEthNetworkId(mojom::kMainnetChainId), "mainnet");
EXPECT_EQ(GetKnownEthNetworkId(mojom::kRinkebyChainId), "rinkeby");
EXPECT_EQ(GetKnownEthNetworkId(mojom::kRopstenChainId), "ropsten");
EXPECT_EQ(GetKnownEthNetworkId(mojom::kGoerliChainId), "goerli");
EXPECT_EQ(GetKnownEthNetworkId(mojom::kKovanChainId), "kovan");
EXPECT_EQ(GetKnownEthNetworkId(mojom::kSepoliaChainId), "sepolia");
}
TEST(BraveWalletUtilsUnitTest, GetKnownSolNetworkId) {
@@ -174,8 +174,8 @@ TEST_F(EthTxStateManagerUnitTest, TxMetaAndValue) {
TEST_F(EthTxStateManagerUnitTest, GetTxPrefPathPrefix) {
EXPECT_EQ("ethereum.mainnet", eth_tx_state_manager_->GetTxPrefPathPrefix());
SetNetwork("0x3");
EXPECT_EQ("ethereum.ropsten", eth_tx_state_manager_->GetTxPrefPathPrefix());
SetNetwork("0x5");
EXPECT_EQ("ethereum.goerli", eth_tx_state_manager_->GetTxPrefPathPrefix());
SetNetwork(brave_wallet::mojom::kLocalhostChainId);
EXPECT_EQ("ethereum.http://localhost:7545/",
eth_tx_state_manager_->GetTxPrefPathPrefix());
@@ -228,6 +228,28 @@ void JsonRpcService::MigrateMultichainNetworks(PrefService* prefs) {
}
}
// static
void JsonRpcService::MigrateDeprecatedEthereumTestnets(PrefService* prefs) {
if (prefs->GetBoolean(kBraveWalletDeprecateEthereumTestNetworksMigrated))
return;
if (prefs->HasPrefPath(kBraveWalletSelectedNetworks)) {
DictionaryPrefUpdate update(prefs, kBraveWalletSelectedNetworks);
auto& selected_networks_pref = update.Get()->GetDict();
const std::string* selected_eth_network =
selected_networks_pref.FindString(kEthereumPrefKey);
if (!selected_eth_network) {
return;
}
if ((*selected_eth_network == "0x3") || (*selected_eth_network == "0x4") ||
(*selected_eth_network == "0x2a")) {
selected_networks_pref.Set(kEthereumPrefKey, mojom::kMainnetChainId);
}
}
prefs->SetBoolean(kBraveWalletDeprecateEthereumTestNetworksMigrated, true);
}
mojo::PendingRemote<mojom::JsonRpcService> JsonRpcService::MakeRemote() {
mojo::PendingRemote<mojom::JsonRpcService> remote;
receivers_.Add(this, remote.InitWithNewPipeAndPassReceiver());
@@ -60,6 +60,7 @@ class JsonRpcService : public KeyedService, public mojom::JsonRpcService {
~JsonRpcService() override;
static void MigrateMultichainNetworks(PrefService* prefs);
static void MigrateDeprecatedEthereumTestnets(PrefService* prefs);
mojo::PendingRemote<mojom::JsonRpcService> MakeRemote();
void Bind(mojo::PendingReceiver<mojom::JsonRpcService> receiver);
@@ -1227,10 +1227,10 @@ TEST_F(JsonRpcServiceUnitTest, GetKnownNetworks) {
values.push_back(NetworkInfoToValue(chain1));
UpdateCustomNetworks(prefs(), &values);
EXPECT_CALL(callback,
Run(ElementsAreArray({"0x1", "0x89", "0x38", "0xa4ec", "0xa86a",
"0xfa", "0xa", "0x4e454152", "0x4", "0x3",
"0x5", "0x2a", "0x539"})));
EXPECT_CALL(
callback,
Run(ElementsAreArray({"0x1", "0x89", "0x38", "0xa4ec", "0xa86a", "0xfa",
"0xa", "0x4e454152", "0x5", "0xaa36a7", "0x539"})));
json_rpc_service_->GetKnownNetworks(mojom::CoinType::ETH, callback.Get());
testing::Mock::VerifyAndClearExpectations(&callback);
}
@@ -1778,8 +1778,8 @@ TEST_F(JsonRpcServiceUnitTest, AddEthereumChainForOriginError) {
TEST_F(JsonRpcServiceUnitTest, StartWithNetwork) {
ValidateStartWithNetwork(std::string(), std::string());
ValidateStartWithNetwork("SomeBadChainId", std::string());
ValidateStartWithNetwork(brave_wallet::mojom::kRopstenChainId,
brave_wallet::mojom::kRopstenChainId);
ValidateStartWithNetwork(brave_wallet::mojom::kGoerliChainId,
brave_wallet::mojom::kGoerliChainId);
}
TEST_F(JsonRpcServiceUnitTest, Request) {
@@ -3711,6 +3711,75 @@ TEST_F(JsonRpcServiceUnitTest, GetSolanaLatestBlockhash) {
l10n_util::GetStringUTF8(IDS_WALLET_INTERNAL_ERROR));
}
TEST_F(JsonRpcServiceUnitTest, MigrateDeprecatedEthereumTestnets) {
// If Ropsten (0x3), Rinkeby (0x4), or Kovan (0x2a) is set as selected network
// it should be switched to mainnet after migration
const std::vector<std::string> deprecated_chain_ids = {"0x3", "0x4", "0x2a"};
for (const std::string& deprecated_chain_id : deprecated_chain_ids) {
// Set up test by setting migrated pref to false
prefs()->SetBoolean(kBraveWalletDeprecateEthereumTestNetworksMigrated,
false);
ASSERT_FALSE(
prefs()->GetBoolean(kBraveWalletDeprecateEthereumTestNetworksMigrated));
// Set selected network to deprecated network and validate
DictionaryPrefUpdate update(prefs(), kBraveWalletSelectedNetworks);
auto& selected_networks_pref = update.Get()->GetDict();
selected_networks_pref.Set(kEthereumPrefKey, deprecated_chain_id);
const base::Value* selected_networks =
prefs()->GetDictionary(kBraveWalletSelectedNetworks);
ASSERT_TRUE(selected_networks);
const std::string* selected_eth_network =
selected_networks->FindStringKey(kEthereumPrefKey);
ASSERT_TRUE(selected_eth_network);
EXPECT_EQ(*selected_eth_network, deprecated_chain_id);
// Run deprecation migration and validate network is set to mainnet and
// migrated pref flag is set to true
JsonRpcService::MigrateDeprecatedEthereumTestnets(prefs());
const base::Value* new_selected_networks =
prefs()->GetDictionary(kBraveWalletSelectedNetworks);
ASSERT_TRUE(new_selected_networks);
selected_eth_network =
new_selected_networks->FindStringKey(kEthereumPrefKey);
EXPECT_EQ(*selected_eth_network, mojom::kMainnetChainId);
EXPECT_TRUE(
prefs()->GetBoolean(kBraveWalletDeprecateEthereumTestNetworksMigrated));
EXPECT_EQ(GetCurrentChainId(prefs(), mojom::CoinType::ETH),
mojom::kMainnetChainId);
}
// Nothing happens if non deprecated network is selected
prefs()->SetBoolean(kBraveWalletDeprecateEthereumTestNetworksMigrated, false);
ASSERT_FALSE(
prefs()->GetBoolean(kBraveWalletDeprecateEthereumTestNetworksMigrated));
// Set selected network to deprecated network and validate
DictionaryPrefUpdate update(prefs(), kBraveWalletSelectedNetworks);
auto& selected_networks_pref = update.Get()->GetDict();
selected_networks_pref.Set(kEthereumPrefKey, mojom::kSepoliaChainId);
const base::Value* selected_networks =
prefs()->GetDictionary(kBraveWalletSelectedNetworks);
ASSERT_TRUE(selected_networks);
const std::string* selected_eth_network =
selected_networks->FindStringKey(kEthereumPrefKey);
ASSERT_TRUE(selected_eth_network);
EXPECT_EQ(*selected_eth_network, mojom::kSepoliaChainId);
// Run migration and validate network is unchanged and migrated
// pref flag is set to true
JsonRpcService::MigrateDeprecatedEthereumTestnets(prefs());
const base::Value* new_selected_networks =
prefs()->GetDictionary(kBraveWalletSelectedNetworks);
ASSERT_TRUE(new_selected_networks);
selected_eth_network = new_selected_networks->FindStringKey(kEthereumPrefKey);
EXPECT_EQ(*selected_eth_network, mojom::kSepoliaChainId);
EXPECT_TRUE(
prefs()->GetBoolean(kBraveWalletDeprecateEthereumTestNetworksMigrated));
EXPECT_EQ(GetCurrentChainId(prefs(), mojom::CoinType::ETH),
mojom::kSepoliaChainId);
}
TEST_F(JsonRpcServiceUnitTest, MigrateMultichainNetworks) {
prefs()->ClearPref(kBraveWalletCustomNetworks);
prefs()->ClearPref(kBraveWalletSelectedNetworks);
@@ -34,6 +34,8 @@ const char kBraveWalletUserAssetEthContractAddressMigrated[] =
"brave.wallet.user.asset.eth_contract_address_migrated";
const char kBraveWalletUserAssetsAddPreloadingNetworksMigrated[] =
"brave.wallet.user.assets.add_preloading_networks_migrated_2";
const char kBraveWalletDeprecateEthereumTestNetworksMigrated[] =
"brave.wallet.deprecated_ethereum_test_networks_migrated";
const char kBraveWalletAutoLockMinutes[] = "brave.wallet.auto_lock_minutes";
const char kSupportEip1559OnLocalhostChain[] =
"brave.wallet.support_eip1559_on_localhost_chain";
@@ -28,6 +28,9 @@ extern const char kBraveWalletUserAssets[];
extern const char kBraveWalletUserAssetEthContractAddressMigrated[];
// Added 06/2022 to add native assets of preloading networks to user assets.
extern const char kBraveWalletUserAssetsAddPreloadingNetworksMigrated[];
// Added 10/2022 to replace ETH selected network with mainnet if selected
// network is one of the Ethereum testnets deprecated on 10/5/2022.
extern const char kBraveWalletDeprecateEthereumTestNetworksMigrated[];
extern const char kBraveWalletAutoLockMinutes[];
extern const char kSupportEip1559OnLocalhostChain[];
// Added 02/2022 to migrate ethereum transactions to be under ethereum coin
@@ -54,7 +54,7 @@ bool IsMainnetEVMNetworkSupported(const std::string& chain_id) {
}
bool IsEVMNetworkSupported(const std::string& chain_id) {
return (chain_id == brave_wallet::mojom::kRopstenChainId ||
return (chain_id == brave_wallet::mojom::kGoerliChainId ||
IsMainnetEVMNetworkSupported(chain_id));
}
@@ -168,8 +168,8 @@ std::string SwapService::GetFee(const std::string& chain_id) {
std::string SwapService::GetBaseSwapURL(const std::string& chain_id) {
std::string url;
if (chain_id == brave_wallet::mojom::kRopstenChainId) {
url = brave_wallet::kRopstenSwapBaseAPIURL;
if (chain_id == brave_wallet::mojom::kGoerliChainId) {
url = brave_wallet::kGoerliSwapBaseAPIURL;
} else if (chain_id == brave_wallet::mojom::kMainnetChainId) {
url = brave_wallet::kSwapBaseAPIURL;
} else if (chain_id == brave_wallet::mojom::kPolygonMainnetChainId) {
@@ -200,8 +200,8 @@ std::string SwapService::GetFeeRecipient(const std::string& chain_id) {
// For easy testability on test networks, we use an address different from
// the production multisig address.
if (chain_id == brave_wallet::mojom::kRopstenChainId) {
feeRecipient = brave_wallet::kRopstenFeeRecipient;
if (chain_id == brave_wallet::mojom::kGoerliChainId) {
feeRecipient = brave_wallet::kGoerliFeeRecipient;
} else if (IsMainnetEVMNetworkSupported(chain_id)) {
feeRecipient = brave_wallet::kFeeRecipient;
} else if (IsSolanaNetworkSupported(chain_id)) {
@@ -383,18 +383,17 @@ TEST_F(SwapServiceUnitTest, GetTransactionPayloadUnexpectedReturn) {
EXPECT_TRUE(callback_run);
}
TEST_F(SwapServiceUnitTest, GetSwapConfigurationRopsten) {
std::string swap_api_url = "https://ropsten.api.0x.org/";
TEST_F(SwapServiceUnitTest, GetSwapConfigurationGoerli) {
std::string swap_api_url = "https://goerli.api.0x.org/";
std::string buy_token_percantage_fee = "0.00875";
std::string fee_recipient = "0xa92D461a9a988A7f11ec285d39783A637Fdd6ba4";
std::string affiliate_address;
EXPECT_EQ(swap_api_url, SwapService::GetBaseSwapURL(mojom::kRopstenChainId));
EXPECT_EQ(swap_api_url, SwapService::GetBaseSwapURL(mojom::kGoerliChainId));
EXPECT_EQ(buy_token_percantage_fee,
SwapService::GetFee(mojom::kRopstenChainId));
EXPECT_EQ(fee_recipient,
SwapService::GetFeeRecipient(mojom::kRopstenChainId));
SwapService::GetFee(mojom::kGoerliChainId));
EXPECT_EQ(fee_recipient, SwapService::GetFeeRecipient(mojom::kGoerliChainId));
EXPECT_EQ(affiliate_address,
SwapService::GetAffiliateAddress(mojom::kRopstenChainId));
SwapService::GetAffiliateAddress(mojom::kGoerliChainId));
}
TEST_F(SwapServiceUnitTest, GetSwapConfigurationMainnet) {
@@ -420,19 +419,20 @@ TEST_F(SwapServiceUnitTest, GetSwapConfigurationOtherNet) {
std::string buy_token_percantage_fee;
std::string fee_recipient;
std::string affiliate_address;
EXPECT_EQ(swap_api_url, SwapService::GetBaseSwapURL(mojom::kRinkebyChainId));
EXPECT_EQ(buy_token_percantage_fee,
SwapService::GetFee(mojom::kRinkebyChainId));
EXPECT_EQ(fee_recipient,
SwapService::GetFeeRecipient(mojom::kRinkebyChainId));
EXPECT_EQ(affiliate_address,
SwapService::GetAffiliateAddress(mojom::kRinkebyChainId));
EXPECT_EQ(swap_api_url, SwapService::GetBaseSwapURL("0x3"));
EXPECT_EQ(buy_token_percantage_fee, SwapService::GetFee("0x3"));
EXPECT_EQ(fee_recipient, SwapService::GetFeeRecipient("0x3"));
EXPECT_EQ(affiliate_address, SwapService::GetAffiliateAddress("0x3"));
EXPECT_EQ(swap_api_url, SwapService::GetBaseSwapURL("0x4"));
EXPECT_EQ(buy_token_percantage_fee, SwapService::GetFee("0x4"));
EXPECT_EQ(fee_recipient, SwapService::GetFeeRecipient("0x4"));
EXPECT_EQ(affiliate_address, SwapService::GetAffiliateAddress("0x4"));
}
TEST_F(SwapServiceUnitTest, IsSwapSupported) {
const std::vector<std::string> supported_chain_ids({
mojom::kMainnetChainId,
mojom::kRopstenChainId,
mojom::kGoerliChainId,
mojom::kPolygonMainnetChainId,
mojom::kPolygonMainnetChainId,
mojom::kBinanceSmartChainMainnetChainId,
@@ -447,7 +447,8 @@ TEST_F(SwapServiceUnitTest, IsSwapSupported) {
EXPECT_TRUE(IsSwapSupported(chain_id));
}
EXPECT_FALSE(IsSwapSupported(mojom::kRinkebyChainId));
EXPECT_FALSE(IsSwapSupported("0x4"));
EXPECT_FALSE(IsSwapSupported("0x3"));
EXPECT_FALSE(IsSwapSupported(""));
EXPECT_FALSE(IsSwapSupported("invalid chain_id"));
}
@@ -284,7 +284,7 @@ TEST_F(TxStateManagerUnitTest, SwitchNetwork) {
meta.set_id("001");
tx_state_manager_->AddOrUpdateTx(meta);
SetNetwork("0x3", mojom::CoinType::ETH);
SetNetwork("0x5", mojom::CoinType::ETH);
// Wait for network info
base::RunLoop().RunUntilIdle();
EXPECT_EQ(tx_state_manager_->GetTx("001"), nullptr);
@@ -305,10 +305,10 @@ TEST_F(TxStateManagerUnitTest, SwitchNetwork) {
ASSERT_TRUE(mainnet_dict);
EXPECT_EQ(mainnet_dict->size(), 1u);
EXPECT_TRUE(mainnet_dict->FindDict("001"));
const auto* ropsten_dict = ethereum_dict->FindDict("ropsten");
ASSERT_TRUE(ropsten_dict);
EXPECT_EQ(ropsten_dict->size(), 1u);
EXPECT_TRUE(ropsten_dict->FindDict("001"));
const auto* goerli_dict = ethereum_dict->FindDict("goerli");
ASSERT_TRUE(goerli_dict);
EXPECT_EQ(goerli_dict->size(), 1u);
EXPECT_TRUE(goerli_dict->FindDict("001"));
auto localhost_url_spec =
brave_wallet::GetNetworkURL(&prefs_, mojom::kLocalhostChainId,
mojom::CoinType::ETH)
@@ -758,10 +758,8 @@ struct TxData1559 {
};
const string kMainnetChainId = "0x1";
const string kRinkebyChainId = "0x4";
const string kRopstenChainId = "0x3";
const string kGoerliChainId = "0x5";
const string kKovanChainId = "0x2a";
const string kSepoliaChainId = "0xaa36a7";
const string kLocalhostChainId = "0x539";
const string kPolygonMainnetChainId = "0x89";
const string kBinanceSmartChainMainnetChainId = "0x38";
@@ -455,7 +455,7 @@ describe('useSwap hook', () => {
...mockAccount,
nativeBalanceRegistry: {
[BraveWallet.MAINNET_CHAIN_ID]: '1000000000000000000', // 1 ETH
[BraveWallet.ROPSTEN_CHAIN_ID]: '1000000000000000000' // 1 ETH
[BraveWallet.GOERLI_CHAIN_ID]: '1000000000000000000' // 1 ETH
},
tokenBalanceRegistry: {
[USDC.contractAddress.toLowerCase()]: '20000000000000000000' // 20 BAT
@@ -570,10 +570,7 @@ export type AllowSpendReturnPayload = {
export const BuySupportedChains = [
BraveWallet.MAINNET_CHAIN_ID,
BraveWallet.RINKEBY_CHAIN_ID,
BraveWallet.ROPSTEN_CHAIN_ID,
BraveWallet.GOERLI_CHAIN_ID,
BraveWallet.KOVAN_CHAIN_ID,
BraveWallet.LOCALHOST_CHAIN_ID,
BraveWallet.POLYGON_MAINNET_CHAIN_ID,
BraveWallet.BINANCE_SMART_CHAIN_MAINNET_CHAIN_ID,
@@ -740,10 +737,8 @@ export const SupportedOnRampNetworks = [
]
export const SupportedTestNetworks = [
BraveWallet.RINKEBY_CHAIN_ID,
BraveWallet.ROPSTEN_CHAIN_ID,
BraveWallet.GOERLI_CHAIN_ID,
BraveWallet.KOVAN_CHAIN_ID,
BraveWallet.SEPOLIA_CHAIN_ID,
BraveWallet.LOCALHOST_CHAIN_ID,
BraveWallet.SOLANA_DEVNET,
BraveWallet.SOLANA_TESTNET,
@@ -362,9 +362,6 @@ provideStrings({
braveWalletNetworkETH: 'Ethereum',
braveWalletNetworkMain: 'Mainnet',
braveWalletNetworkTest: 'Test Network',
braveWalletNetworkRopsten: 'Roptsten',
braveWalletNetworkKovan: 'Kovan',
braveWalletNetworkRinkeby: 'Rinkeby',
braveWalletNetworkGoerli: 'Goerli',
braveWalletNetworkBinance: 'Binance Smart Chain',
braveWalletNetworkBinanceAbbr: 'BSC',
@@ -138,7 +138,7 @@ export const mockNewAssetOptions: BraveWallet.BlockchainToken[] = [
tokenId: '',
coingeckoId: '',
coin: BraveWallet.CoinType.ETH,
chainId: '0x3'
chainId: '0x5'
},
{
contractAddress: '4',
@@ -17,13 +17,13 @@ export const mockNetworks: BraveWallet.NetworkInfo[] = [
isEip1559: true
},
{
chainId: '0x3',
chainName: 'Ethereum Testnet Ropsten',
chainId: '0x5',
chainName: 'Ethereum Testnet Goerli',
activeRpcEndpointIndex: 0,
rpcEndpoints: [{ url: 'https://ropsten.infura.io/v3/' }, { url: 'wss://ropsten.infura.io/ws/v3/' }],
blockExplorerUrls: ['https://ropsten.etherscan.io'],
symbol: 'ROP',
symbolName: 'Ropsten Ether',
rpcEndpoints: [{ url: 'https://goerli.infura.io/v3/' }, { url: 'wss://goerli.infura.io/ws/v3/' }],
blockExplorerUrls: ['https://goerli.etherscan.io'],
symbol: 'GOE',
symbolName: 'Goerli Ether',
decimals: 18,
iconUrls: [ETHIconUrl],
coin: BraveWallet.CoinType.ETH,
@@ -28,7 +28,7 @@ const mockAccount: WalletAccountType = {
},
nativeBalanceRegistry: {
[BraveWallet.MAINNET_CHAIN_ID]: '496917339073158043',
[BraveWallet.ROPSTEN_CHAIN_ID]: '496917339073158043'
[BraveWallet.GOERLI_CHAIN_ID]: '496917339073158043'
},
keyringId: undefined
}
@@ -43,41 +43,7 @@ const mockNetworkList: BraveWallet.NetworkInfo[] = [
'iconUrls': [],
'activeRpcEndpointIndex': 0,
'rpcEndpoints': [
{ url: 'https://mainnet-infura.brave.com/f7106c838853428280fa0c585acc9485' }
],
'symbol': 'ETH',
'symbolName': 'Ethereum',
'decimals': 18,
'coin': 60,
'isEip1559': true
},
{
'chainId': '0x4',
'chainName': 'Rinkeby Test Network',
'blockExplorerUrls': [
'https://rinkeby.etherscan.io'
],
'iconUrls': [],
'activeRpcEndpointIndex': 0,
'rpcEndpoints': [
{ url: 'https://rinkeby-infura.brave.com/f7106c838853428280fa0c585acc9485' }
],
'symbol': 'ETH',
'symbolName': 'Ethereum',
'decimals': 18,
'coin': 60,
'isEip1559': true
},
{
'chainId': '0x3',
'chainName': 'Ropsten Test Network',
'blockExplorerUrls': [
'https://ropsten.etherscan.io'
],
'iconUrls': [],
'activeRpcEndpointIndex': 0,
'rpcEndpoints': [
{ url: 'https://ropsten-infura.brave.com/f7106c838853428280fa0c585acc9485' }
{ url: 'https://mainnet-infura.brave.com' }
],
'symbol': 'ETH',
'symbolName': 'Ethereum',
@@ -94,7 +60,7 @@ const mockNetworkList: BraveWallet.NetworkInfo[] = [
'iconUrls': [],
'activeRpcEndpointIndex': 0,
'rpcEndpoints': [
{ url: 'https://goerli-infura.brave.com/f7106c838853428280fa0c585acc9485' }
{ url: 'https://goerli-infura.brave.com' }
],
'symbol': 'ETH',
'symbolName': 'Ethereum',
@@ -103,15 +69,15 @@ const mockNetworkList: BraveWallet.NetworkInfo[] = [
'isEip1559': true
},
{
'chainId': '0x2a',
'chainName': 'Kovan Test Network',
'chainId': '0xaa36a7',
'chainName': 'Sepolia Test Network',
'blockExplorerUrls': [
'https://kovan.etherscan.io'
'https://sepolia.etherscan.io'
],
'iconUrls': [],
'activeRpcEndpointIndex': 0,
'rpcEndpoints': [
{ url: 'https://kovan-infura.brave.com/f7106c838853428280fa0c585acc9485' }
{ url: 'https://sepolia-infura.brave.com' }
],
'symbol': 'ETH',
'symbolName': 'Ethereum',
@@ -345,7 +311,7 @@ export const mockWalletState: WalletState = {
tokenId: '',
visible: true,
coin: BraveWallet.CoinType.ETH,
chainId: BraveWallet.ROPSTEN_CHAIN_ID
chainId: BraveWallet.GOERLI_CHAIN_ID
},
{
coingeckoId: 'usd-coin',
@@ -359,7 +325,7 @@ export const mockWalletState: WalletState = {
tokenId: '',
visible: true,
coin: BraveWallet.CoinType.ETH,
chainId: BraveWallet.ROPSTEN_CHAIN_ID
chainId: BraveWallet.GOERLI_CHAIN_ID
}
],
transactionProviderErrorRegistry: {},
@@ -59,7 +59,7 @@ describe('getTokensNetwork', () => {
it('Ethereum with chainId 0x1, should return ETH Mainnet info', () => {
expect(getTokensNetwork(mockNetworks, ethToken)).toEqual(ethMainNetwork)
})
it('Binance Coin with chainId 0x3, should return ETH Ropsten Testnetwork info', () => {
it('Binance Coin with chainId 0x5, should return ETH Goerli Testnetwork info', () => {
expect(getTokensNetwork(mockNetworks, bnbToken)).toEqual(mockNetworks[1])
})
})
@@ -122,6 +122,6 @@ describe('getFilecoinKeyringIdFromNetwork', () => {
expect(getFilecoinKeyringIdFromNetwork({ chainId: BraveWallet.FILECOIN_MAINNET, coin: BraveWallet.CoinType.FIL } as BraveWallet.NetworkInfo)).toEqual(BraveWallet.FILECOIN_KEYRING_ID)
})
it('Non filecoin', () => {
expect(getFilecoinKeyringIdFromNetwork({ chainId: BraveWallet.ROPSTEN_CHAIN_ID, coin: BraveWallet.CoinType.ETH } as BraveWallet.NetworkInfo)).toEqual(undefined)
expect(getFilecoinKeyringIdFromNetwork({ chainId: BraveWallet.GOERLI_CHAIN_ID, coin: BraveWallet.CoinType.ETH } as BraveWallet.NetworkInfo)).toEqual(undefined)
})
})
+2 -4
View File
@@ -242,10 +242,8 @@
<message name="IDS_BRAVE_WALLET_NETWORK_E_T_H" desc="Network Ethereum title">Ethereum</message>
<message name="IDS_BRAVE_WALLET_NETWORK_MAIN" desc="Network Main title">Mainnet</message>
<message name="IDS_BRAVE_WALLET_NETWORK_TEST" desc="Network Test Network title">Test Network</message>
<message name="IDS_BRAVE_WALLET_NETWORK_ROPSTEN" desc="Network Ropsten title">Ropsten</message>
<message name="IDS_BRAVE_WALLET_NETWORK_KOVAN" desc="Network Kovan title">Kovan</message>
<message name="IDS_BRAVE_WALLET_NETWORK_RINKEBY" desc="Network Rinkeby title">Rinkeby</message>
<message name="IDS_BRAVE_WALLET_NETWORK_GOERLI" desc="Network Goerli title">Goerli</message>
<message name="IDS_BRAVE_WALLET_NETWORK_SEPOLIA" desc="Network Sepolia title">Sepolia</message>
<message name="IDS_BRAVE_WALLET_NETWORK_BINANCE" desc="Network Binance Smart Chain title">Binance Smart Chain</message>
<message name="IDS_BRAVE_WALLET_NETWORK_BINANCE_ABBR" desc="Network BSC abbreviation title">BSC</message>
<message name="IDS_BRAVE_WALLET_NETWORK_LOCALHOST" desc="Network Localhost title">Localhost</message>
@@ -261,7 +259,7 @@
<message name="IDS_BRAVE_WALLET_SWAP_LIMIT" desc="Swap tab limit button">Limit</message>
<message name="IDS_BRAVE_WALLET_SWAP_PRICE_IN" desc="Swap tab price label">Price in</message>
<message name="IDS_BRAVE_WALLET_BUY_TITLE" desc="Buy tab faucet button">Test faucet</message>
<message name="IDS_BRAVE_WALLET_BUY_DESCRIPTION" desc="Buy tab faucet description to get test crypto">Get Ether from a faucet for <ph name="SELECTED_NETWORK"><ex>Ropsten Network</ex>$1</ph></message>
<message name="IDS_BRAVE_WALLET_BUY_DESCRIPTION" desc="Buy tab faucet description to get test crypto">Get Ether from a faucet for <ph name="SELECTED_NETWORK"><ex>Goerli Network</ex>$1</ph></message>
<message name="IDS_BRAVE_WALLET_BUY_CONTINUE_BUTTON" desc="Buy tab continue button">Select purchase method</message>
<message name="IDS_BRAVE_WALLET_SIGN_TRANSACTION_TITLE" desc="Sign panel title">Your signature is being requested</message>
<message name="IDS_BRAVE_WALLET_SIGN_WARNING" desc="Sign panel warning message">Note that Brave cant verify what will happen if you sign. A signature could authorize nearly any operation in your account or on your behalf, including (but not limited to) giving total control of your account and crypto assets to the site making the request. Only sign if youre sure you want to take this action, and trust the requesting site.</message>
@@ -244,12 +244,12 @@ IN_PROC_BROWSER_TEST_F(JSEthereumProviderBrowserTest, OnlyWriteOwnProperty) {
ASSERT_EQ(content::EvalJs(primary_main_frame(), get_chain_id).ExtractString(),
"0x1");
GetJsonRpcService()->SetNetwork("0x3", brave_wallet::mojom::CoinType::ETH,
GetJsonRpcService()->SetNetwork("0x5", brave_wallet::mojom::CoinType::ETH,
false);
// Needed so ChainChangedEvent observers run
base::RunLoop().RunUntilIdle();
EXPECT_EQ(content::EvalJs(primary_main_frame(), get_chain_id).ExtractString(),
"0x3");
"0x5");
brave_wallet::SetDefaultEthereumWallet(
browser()->profile()->GetPrefs(),