Skip to content

Commit

Permalink
Build fix & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cypt4 committed Jan 7, 2025
1 parent efe7414 commit e377474
Show file tree
Hide file tree
Showing 18 changed files with 459 additions and 258 deletions.
36 changes: 36 additions & 0 deletions components/brave_wallet/browser/internal/hd_key_zip32_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,40 @@ TEST(HDKeyZip32Test, FullViewKey) {
}
}

// Gen script:
// https://github.com/zcash/zcash-test-vectors/blob/1ac6808080e302ba2c7b02333d6fa3713f7d1f0e/zcash_test_vectors/orchard/zip32.py#L1
// Result:
// https://github.com/zcash/zcash-test-vectors/blob/1ac6808080e302ba2c7b02333d6fa3713f7d1f0e/test-vectors/rust/orchard_zip32.rs#L1
TEST(HDKeyZip32Test, SpendingKey) {
auto hd_key = HDKeyZip32::GenerateFromSeed(std::vector<uint8_t>(
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}));

{
constexpr OrchardSpendingKey expected = {
0x98, 0xd7, 0x03, 0xfc, 0xb4, 0x05, 0x04, 0xc9, 0x5b, 0x3b, 0x6e,
0xd1, 0x0e, 0xcd, 0x50, 0x08, 0x2c, 0xff, 0x97, 0xdf, 0xd1, 0xdd,
0x9a, 0xa0, 0x91, 0x3c, 0x78, 0xf9, 0x77, 0xc9, 0x62, 0xaf};
EXPECT_EQ(expected, hd_key->DeriveHardenedChild(1)->GetSpendingKey());
}
{
constexpr OrchardSpendingKey expected = {
0x98, 0xd7, 0x03, 0xfc, 0xb4, 0x05, 0x04, 0xc9, 0x5b, 0x3b, 0x6e,
0xd1, 0x0e, 0xcd, 0x50, 0x08, 0x2c, 0xff, 0x97, 0xdf, 0xd1, 0xdd,
0x9a, 0xa0, 0x91, 0x3c, 0x78, 0xf9, 0x77, 0xc9, 0x62, 0xaf};
EXPECT_EQ(expected, hd_key->DeriveHardenedChild(1)->GetSpendingKey());
}

{
constexpr OrchardSpendingKey expected = {
0x99, 0xaf, 0xd8, 0x89, 0x4b, 0xaa, 0xd5, 0x87, 0x84, 0xd0, 0xec,
0x08, 0xf5, 0x14, 0x8e, 0xe2, 0xc2, 0xa1, 0x7b, 0x2b, 0x29, 0x4b,
0x08, 0xef, 0x9e, 0x0a, 0x0c, 0xf1, 0x4b, 0xcc, 0x09, 0x20};
EXPECT_EQ(expected, hd_key->DeriveHardenedChild(1)
->DeriveHardenedChild(2)
->GetSpendingKey());
}
}

} // namespace brave_wallet
10 changes: 0 additions & 10 deletions components/brave_wallet/browser/internal/orchard_sync_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,6 @@ OrchardSyncState::GetMaxCheckpointedHeight(
min_confirmations);
}

base::expected<OrchardStorage::Result, OrchardStorage::Error>
OrchardSyncState::UpdateSubtreeRoots(
const mojom::AccountIdPtr& account_id,
uint32_t start_index,
const std::vector<zcash::mojom::SubtreeRootPtr>& roots) {
// DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// return storage_.UpdateSubtreeRoots(account_id, start_index, roots);
return OrchardStorage::Result::kSuccess;
}

void OrchardSyncState::ResetDatabase() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
storage_.ResetDatabase();
Expand Down
5 changes: 0 additions & 5 deletions components/brave_wallet/browser/internal/orchard_sync_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ class OrchardSyncState {
uint32_t chain_tip_height,
uint32_t min_confirmations);

base::expected<OrchardStorage::Result, OrchardStorage::Error>
UpdateSubtreeRoots(const mojom::AccountIdPtr& account_id,
uint32_t start_index,
const std::vector<zcash::mojom::SubtreeRootPtr>& roots);

// Clears sync data related to the account except it's birthday.
base::expected<OrchardStorage::Result, OrchardStorage::Error>
ResetAccountSyncState(const mojom::AccountIdPtr& account_id);
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet/browser/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ source_set("brave_wallet_unit_tests") {
"//brave/components/brave_wallet/browser/unstoppable_domains_dns_resolve_unittest.cc",
"//brave/components/brave_wallet/browser/unstoppable_domains_multichain_calls_unittest.cc",
"//brave/components/brave_wallet/browser/wallet_data_files_installer_unittest.cc",
"//brave/components/brave_wallet/browser/zcash/zcash_create_orchard_to_orchard_transaction_task_unittest.cc",
"//brave/components/brave_wallet/browser/zcash/zcash_grpc_utils_unittest.cc",
"//brave/components/brave_wallet/browser/zcash/zcash_keyring_unittest.cc",
"//brave/components/brave_wallet/browser/zcash/zcash_serializer_unittest.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace brave_wallet {

ZCashCreateOrchardToOrchardTransactionTask::
ZCashCreateOrchardToOrchardTransactionTask(
base::PassKey<class ZCashWalletService> pass_key,
absl::variant<
base::PassKey<class ZCashCreateOrchardToOrchardTransactionTaskTest>,
base::PassKey<class ZCashWalletService>> pass_key,
ZCashWalletService& zcash_wallet_service,
ZCashActionContext context,
const OrchardAddrRawPart& receiver,
Expand Down Expand Up @@ -48,6 +50,7 @@ void ZCashCreateOrchardToOrchardTransactionTask::ScheduleWorkOnTask() {
void ZCashCreateOrchardToOrchardTransactionTask::WorkOnTask() {
if (error_) {
std::move(callback_).Run(base::unexpected(*error_));
zcash_wallet_service_->CreateTransactionTaskDone(this);
return;
}

Expand All @@ -62,6 +65,7 @@ void ZCashCreateOrchardToOrchardTransactionTask::WorkOnTask() {
}

std::move(callback_).Run(base::ok(std::move(*transaction_)));
zcash_wallet_service_->CreateTransactionTaskDone(this);
}

void ZCashCreateOrchardToOrchardTransactionTask::GetSpendableNotes() {
Expand All @@ -80,19 +84,6 @@ void ZCashCreateOrchardToOrchardTransactionTask::OnGetSpendableNotes(
return;
}

for (size_t i = 0; i < result.value().size(); i++) {
LOG(ERROR) << "Note print note N " << i;

LOG(ERROR) << "Note addr : " << ToHex(result.value()[i].addr);
LOG(ERROR) << "Note block_id : " << result.value()[i].block_id;
LOG(ERROR) << "Note nullifier : " << ToHex(result.value()[i].nullifier);
LOG(ERROR) << "Note amount : " << result.value()[i].amount;
LOG(ERROR) << "Note orchard_commitment_tree_position : "
<< result.value()[i].orchard_commitment_tree_position;
LOG(ERROR) << "Note rho : " << ToHex(result.value()[i].rho);
LOG(ERROR) << "Note rseed : " << ToHex(result.value()[i].seed);
}

spendable_notes_ = result.value();
ScheduleWorkOnTask();
}
Expand All @@ -112,7 +103,6 @@ void ZCashCreateOrchardToOrchardTransactionTask::CreateTransaction() {
orchard_input.note = note;
zcash_transaction.orchard_part().inputs.push_back(std::move(orchard_input));
}

zcash_transaction.set_fee(pick_result->fee);

// Create shielded change
Expand Down Expand Up @@ -143,6 +133,7 @@ void ZCashCreateOrchardToOrchardTransactionTask::CreateTransaction() {

auto orchard_unified_addr = GetOrchardUnifiedAddress(
receiver_, context_.chain_id == mojom::kZCashTestnet);

if (!orchard_unified_addr) {
error_ = l10n_util::GetStringUTF8(IDS_WALLET_INTERNAL_ERROR);
ScheduleWorkOnTask();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class ZCashCreateOrchardToOrchardTransactionTask {
ZCashWalletService::CreateTransactionCallback;

ZCashCreateOrchardToOrchardTransactionTask(
base::PassKey<class ZCashWalletService> pass_key,
absl::variant<
base::PassKey<class ZCashCreateOrchardToOrchardTransactionTaskTest>,
base::PassKey<class ZCashWalletService>> pass_key,
ZCashWalletService& zcash_wallet_service,
ZCashActionContext context,
const OrchardAddrRawPart& receiver,
Expand Down
Loading

0 comments on commit e377474

Please sign in to comment.