Skip to content

Commit

Permalink
Add filecoin testnet support
Browse files Browse the repository at this point in the history
Resolves brave/brave-browser#23368
Resolves brave/brave-browser#23241
Add separate keyring id for filecoin.
Add ui tweaks to support new keyring.
  • Loading branch information
cypt4 committed Jun 30, 2022
1 parent d77ac11 commit a7260aa
Show file tree
Hide file tree
Showing 28 changed files with 814 additions and 241 deletions.
2 changes: 1 addition & 1 deletion browser/brave_wallet/ethereum_provider_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class EthereumProviderImplUnitTest : public testing::Test {
std::vector<mojom::HardwareWalletAccountPtr> hw_accounts;
hw_accounts.push_back(mojom::HardwareWalletAccount::New(
address, "m/44'/60'/1'/0/0", "name 1", "Ledger", "device1",
mojom::CoinType::ETH));
mojom::CoinType::ETH, absl::nullopt));

keyring_service_->AddHardwareAccounts(std::move(hw_accounts));
}
Expand Down
37 changes: 15 additions & 22 deletions browser/brave_wallet/filecoin_keyring_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ TEST(FilecoinKeyring, ImportFilecoinSECP) {
ASSERT_FALSE(input_key.empty());
std::vector<uint8_t> private_key(input_key.begin(), input_key.end());

FilecoinKeyring keyring;
auto address =
keyring.ImportFilecoinAccount(private_key, mojom::kFilecoinTestnet,
mojom::FilecoinAddressProtocol::SECP256K1);
FilecoinKeyring keyring(brave_wallet::mojom::kFilecoinTestnet);
auto address = keyring.ImportFilecoinAccount(
private_key, mojom::FilecoinAddressProtocol::SECP256K1);
EXPECT_EQ(address, "t1lqarsh4nkg545ilaoqdsbtj4uofplt6sto26ziy");
EXPECT_EQ(keyring.GetImportedAccountsNumber(), size_t(1));
}
Expand All @@ -116,40 +115,35 @@ TEST(FilecoinKeyring, ImportFilecoinBLS) {
ASSERT_TRUE(FilecoinKeyring::DecodeImportPayload(private_key_hex,
&private_key, &protocol));
EXPECT_EQ(protocol, mojom::FilecoinAddressProtocol::BLS);
FilecoinKeyring keyring;
std::string address = keyring.ImportFilecoinAccount(
private_key, mojom::kFilecoinTestnet, protocol);
FilecoinKeyring keyring(brave_wallet::mojom::kFilecoinTestnet);
std::string address = keyring.ImportFilecoinAccount(private_key, protocol);
EXPECT_EQ(address,
"t3wwtato54ee5aod7j5uv2n75jpyn4hpwx3f2kx5cijtoxgytiul2dczrak3ghlbt5"
"zjnj574y3snhcb5bthva");
EXPECT_EQ(keyring.GetImportedAccountsNumber(), size_t(1));

// empty private key
ASSERT_TRUE(keyring
.ImportFilecoinAccount({}, mojom::kFilecoinTestnet,
mojom::FilecoinAddressProtocol::BLS)
.empty());
ASSERT_TRUE(
keyring.ImportFilecoinAccount({}, mojom::FilecoinAddressProtocol::BLS)
.empty());

// broken private key
private_key_hex = "6a4b3d3f3ccb3676e34e16bc07a937";
std::vector<uint8_t> broken_private_key;
ASSERT_TRUE(base::HexStringToBytes(private_key_hex, &broken_private_key));
ASSERT_TRUE(keyring
.ImportFilecoinAccount(broken_private_key,
mojom::kFilecoinTestnet,
mojom::FilecoinAddressProtocol::BLS)
.empty());

std::vector<uint8_t> zero_private_key(32, 0);
EXPECT_EQ(
keyring.ImportFilecoinAccount(zero_private_key, mojom::kFilecoinTestnet,
mojom::FilecoinAddressProtocol::BLS),
"t3yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaby2smx7a");
EXPECT_EQ(keyring.ImportFilecoinAccount(zero_private_key,
mojom::FilecoinAddressProtocol::BLS),
"t3yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaby2smx7a");
std::vector<uint8_t> ff_private_key(32, 255);
ASSERT_TRUE(keyring
.ImportFilecoinAccount(ff_private_key,
mojom::kFilecoinTestnet,
mojom::FilecoinAddressProtocol::BLS)
.empty());
}
Expand All @@ -168,7 +162,7 @@ TEST(FilecoinKeyring, fil_private_key_public_key) {
}

TEST(FilecoinKeyring, SignTransaction) {
FilecoinKeyring keyring;
FilecoinKeyring keyring(brave_wallet::mojom::kFilecoinTestnet);
EXPECT_FALSE(keyring.SignTransaction(nullptr));

auto transaction = FilTransaction::FromTxData(mojom::FilTxData::New(
Expand All @@ -183,9 +177,8 @@ TEST(FilecoinKeyring, SignTransaction) {
ASSERT_FALSE(input_key.empty());
std::vector<uint8_t> private_key(input_key.begin(), input_key.end());

auto address =
keyring.ImportFilecoinAccount(private_key, mojom::kFilecoinTestnet,
mojom::FilecoinAddressProtocol::SECP256K1);
auto address = keyring.ImportFilecoinAccount(
private_key, mojom::FilecoinAddressProtocol::SECP256K1);
EXPECT_EQ(address, "t1lqarsh4nkg545ilaoqdsbtj4uofplt6sto26ziy");
EXPECT_TRUE(keyring.SignTransaction(&transaction.value()));
}
Expand Down
Loading

0 comments on commit a7260aa

Please sign in to comment.