new subaddress unit test added

pull/3/head
moneroexamples 5 years ago
parent 7bf2dda179
commit 3482cd42ce

@ -198,6 +198,17 @@ public:
return gen_subaddress({acc_id, addr_id});
}
unique_ptr<subaddress_index>
has_subaddress(public_key const& pub_spend_key)
{
auto it = subaddresses.find(pub_spend_key);
if (it == subaddresses.end())
return nullptr;
return make_unique<subaddress_index>(it->second);
}
/**
* Unlike above, it does not produce SubaddressAcount
* It just calcualtes public spend key for a subaddress

@ -136,7 +136,32 @@ Output::identify(transaction const& tx,
// which cointains subaddress
auto derivation_to_save = derivation;
bool mine_output = (pub_spend_key == subaddress_spendkey);
bool mine_output {false};
if (!acc)
{
// if acc is not given, we check generated
// subaddress_spendkey against the spendkey
// of the address for which the Output identifier
// was instantiated
mine_output = (pub_spend_key == subaddress_spendkey);
}
else
{
// if acc is given, we are going to use its
// subaddress unordered map to check if generated
// subaddress_spendkey is one of its keys. this is
// because the map can contain spendkeys of subaddreses
// assiciated with primary address. primary address's
// spendkey will be one of the keys as a special case
assert(!acc->is_subaddress());
auto sacc = static_cast<PrimaryAccount*>(acc);
auto subaddr_idx = sacc->has_subaddress(subaddress_spendkey);
mine_output = bool {subaddr_idx};
}
auto with_additional = false;

File diff suppressed because one or more lines are too long

@ -395,4 +395,39 @@ TEST_P(ModularIdentifierTest, RealInputRingCT)
== jtx->sender.inputs);
}
TEST(Subaddresses, RegularTwoOutputTxToSubaddress)
{
// this tx has funds for one subaddress. so we try to identify the outputs
// and the subaddress using primary address of the recipient
auto jtx = construct_jsontx("024dc13cb11d411682f04d41b52931849527d530e4cb198a63526c13da31a413");
ASSERT_TRUE(jtx);
// recipeint primary address and viewkey
string const raddress {"56heRv2ANffW1Py2kBkJDy8xnWqZsSrgjLygwjua2xc8Wbksead1NK1ehaYpjQhymGK4S8NPL9eLuJ16CuEJDag8Hq3RbPV"};
string const rviewkey {"b45e6f38b2cd1c667459527decb438cdeadf9c64d93c8bccf40a9bf98943dc09"};
auto racc = account_factory(raddress, rviewkey);
// make sure we have primary address
ASSERT_FALSE(racc->is_subaddress());
auto sacc = static_cast<PrimaryAccount*>(racc.get());
sacc->populate_subaddress_indices();
auto identifier = make_identifier(jtx->tx,
make_unique<Output>(sacc));
identifier.identify();
EXPECT_EQ(identifier.get<0>()->get().size(),
jtx->recipients.at(0).outputs.size());
EXPECT_TRUE(identifier.get<0>()->get()
== jtx->recipients.at(0).outputs);
}
}

Loading…
Cancel
Save