Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
supermassive committed Nov 8, 2022
1 parent 37e9fe9 commit 1e34bd9
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 94 deletions.
9 changes: 0 additions & 9 deletions components/brave_wallet/browser/json_rpc_response_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,6 @@ ConverterForGetAccountInfo() {
"/result/value/rentEpoch"}));
}

base::OnceCallback<absl::optional<std::string>(const std::string& raw_response)>
ConverterForGetProrgamAccounts() {
return base::BindOnce(
&ConvertMultiUint64ToString,
std::vector<std::string>(
// Expecting 0 or 1 accounts here, so converting only at index 0.
{"/result/0/account/lamports", "/result/0/account/rentEpoch"}));
}

} // namespace solana

} // namespace brave_wallet
2 changes: 0 additions & 2 deletions components/brave_wallet/browser/json_rpc_response_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ namespace solana {

base::OnceCallback<absl::optional<std::string>(const std::string& raw_response)>
ConverterForGetAccountInfo();
base::OnceCallback<absl::optional<std::string>(const std::string& raw_response)>
ConverterForGetProrgamAccounts();

} // namespace solana

Expand Down
12 changes: 6 additions & 6 deletions components/brave_wallet/browser/json_rpc_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1360,14 +1360,14 @@ void JsonRpcService::SnsGetSolAddr(const std::string& domain,
SnsGetSolAddrCallback callback) {
if (!base::FeatureList::IsEnabled(features::kBraveWalletSnsFeature)) {
std::move(callback).Run(
"", mojom::ProviderError::kInvalidParams,
"", mojom::SolanaProviderError::kInvalidParams,
l10n_util::GetStringUTF8(IDS_WALLET_INVALID_PARAMETERS));
return;
}

if (!IsValidDomain(domain)) {
std::move(callback).Run(
"", mojom::ProviderError::kInvalidParams,
"", mojom::SolanaProviderError::kInvalidParams,
l10n_util::GetStringUTF8(IDS_WALLET_INVALID_PARAMETERS));
return;
}
Expand All @@ -1381,7 +1381,7 @@ void JsonRpcService::SnsGetSolAddr(const std::string& domain,
mojom::CoinType::SOL);
if (!network_url.is_valid()) {
std::move(callback).Run(
"", mojom::ProviderError::kInvalidParams,
"", mojom::SolanaProviderError::kInvalidParams,
l10n_util::GetStringUTF8(IDS_WALLET_INVALID_PARAMETERS));
return;
}
Expand All @@ -1407,15 +1407,15 @@ void JsonRpcService::OnSnsGetSolAddrTaskDone(
}

std::string address;
mojom::ProviderError error =
task_error ? task_error->error : mojom::ProviderError::kSuccess;
mojom::SolanaProviderError error =
task_error ? task_error->error : mojom::SolanaProviderError::kSuccess;
std::string error_message = task_error ? task_error->error_message : "";

if (task_result) {
if (task_result->resolved_address.IsValid()) {
address = task_result->resolved_address.ToBase58();
} else {
error = mojom::ProviderError::kInvalidParams;
error = mojom::SolanaProviderError::kInvalidParams;
error_message = l10n_util::GetStringUTF8(IDS_WALLET_INVALID_PARAMETERS);
}
}
Expand Down
25 changes: 13 additions & 12 deletions components/brave_wallet/browser/json_rpc_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "brave/components/ipfs/ipfs_service.h"
#include "brave/components/ipfs/ipfs_utils.h"
#include "brave/components/ipfs/pref_names.h"
#include "components/grit/brave_components_strings.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/storage_partition.h"
Expand Down Expand Up @@ -5788,15 +5789,15 @@ TEST_F(SnsJsonRpcServiceUnitTest, GetWalletAddr_NftOwner) {
// Has nft for domain. Return nft owner.
base::MockCallback<JsonRpcService::SnsGetSolAddrCallback> callback;
EXPECT_CALL(callback, Run(NftOwnerAddress().ToBase58(),
mojom::ProviderError::kSuccess, ""));
mojom::SolanaProviderError::kSuccess, ""));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&callback);

// HTTP error while checking nft mint. Fail resolution.
mint_address_handler_->FailWithTimeout();
EXPECT_CALL(callback,
Run("", mojom::ProviderError::kInternalError,
Run("", mojom::SolanaProviderError::kInternalError,
l10n_util::GetStringUTF8(IDS_WALLET_INTERNAL_ERROR)));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
Expand All @@ -5806,7 +5807,7 @@ TEST_F(SnsJsonRpcServiceUnitTest, GetWalletAddr_NftOwner) {
// HTTP error while checking nft owner. Fail resolution.
get_program_accounts_handler_->FailWithTimeout();
EXPECT_CALL(callback,
Run("", mojom::ProviderError::kInternalError,
Run("", mojom::SolanaProviderError::kInternalError,
l10n_util::GetStringUTF8(IDS_WALLET_INTERNAL_ERROR)));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
Expand All @@ -5816,7 +5817,7 @@ TEST_F(SnsJsonRpcServiceUnitTest, GetWalletAddr_NftOwner) {
// Domain detokenized. Fallback to domain/SOL owner.
mint_address_handler_->data() = GetAccountInfoHandler::MakeMintData(0);
EXPECT_CALL(callback, Run(SolRecordAddress().ToBase58(),
mojom::ProviderError::kSuccess, ""));
mojom::SolanaProviderError::kSuccess, ""));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&callback);
Expand All @@ -5829,15 +5830,15 @@ TEST_F(SnsJsonRpcServiceUnitTest, GetWalletAddr_DomainOwner) {
// No nft, no SOL record. Return domain owner address.
base::MockCallback<JsonRpcService::SnsGetSolAddrCallback> callback;
EXPECT_CALL(callback, Run(DomainOwnerAddress().ToBase58(),
mojom::ProviderError::kSuccess, ""));
mojom::SolanaProviderError::kSuccess, ""));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&callback);

// HTTP error for domain key account. Fail resolution.
domain_address_handler_->FailWithTimeout();
EXPECT_CALL(callback,
Run("", mojom::ProviderError::kInternalError,
Run("", mojom::SolanaProviderError::kInternalError,
l10n_util::GetStringUTF8(IDS_WALLET_INTERNAL_ERROR)));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
Expand All @@ -5847,8 +5848,8 @@ TEST_F(SnsJsonRpcServiceUnitTest, GetWalletAddr_DomainOwner) {
// No domain key account. Fail resolution.
domain_address_handler_->Disable();
EXPECT_CALL(callback,
Run("", mojom::ProviderError::kInvalidParams,
l10n_util::GetStringUTF8(IDS_WALLET_INVALID_PARAMETERS)));
Run("", mojom::SolanaProviderError::kInternalError,
l10n_util::GetStringUTF8(IDS_WALLET_INTERNAL_ERROR)));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&callback);
Expand All @@ -5862,15 +5863,15 @@ TEST_F(SnsJsonRpcServiceUnitTest, GetWalletAddr_SolRecordOwner) {
// No nft, has sol record. Return address from SOL record.
base::MockCallback<JsonRpcService::SnsGetSolAddrCallback> callback;
EXPECT_CALL(callback, Run(SolRecordAddress().ToBase58(),
mojom::ProviderError::kSuccess, ""));
mojom::SolanaProviderError::kSuccess, ""));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&callback);

// Bad signature. Fallback to owner address.
sol_record_address_handler_->data()[170] ^= 123;
EXPECT_CALL(callback, Run(DomainOwnerAddress().ToBase58(),
mojom::ProviderError::kSuccess, ""));
mojom::SolanaProviderError::kSuccess, ""));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&callback);
Expand All @@ -5879,7 +5880,7 @@ TEST_F(SnsJsonRpcServiceUnitTest, GetWalletAddr_SolRecordOwner) {
// HTTP error for SOL record key account. Fail resolution.
sol_record_address_handler_->FailWithTimeout();
EXPECT_CALL(callback,
Run("", mojom::ProviderError::kInternalError,
Run("", mojom::SolanaProviderError::kInternalError,
l10n_util::GetStringUTF8(IDS_WALLET_INTERNAL_ERROR)));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
Expand All @@ -5889,7 +5890,7 @@ TEST_F(SnsJsonRpcServiceUnitTest, GetWalletAddr_SolRecordOwner) {
// No SOL record account. Fallback to owner address.
sol_record_address_handler_->Disable();
EXPECT_CALL(callback, Run(DomainOwnerAddress().ToBase58(),
mojom::ProviderError::kSuccess, ""));
mojom::SolanaProviderError::kSuccess, ""));
json_rpc_service_->SnsGetSolAddr(sns_host(), callback.Get());
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&callback);
Expand Down
Loading

0 comments on commit 1e34bd9

Please sign in to comment.