mirror of
https://github.com/monero-project/monero.git
synced 2026-01-18 07:36:32 -08:00
wallet: improve lookahead logic & make rpc persistent
This commit is contained in:
@@ -103,12 +103,36 @@ TEST_F(WalletSubaddress, OutOfBoundsIndexes)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(WalletSubaddress, ExpandPubkeyTable)
|
||||
// Helper function to check max subaddrs allocated
|
||||
static void check_expected_max(const tools::wallet2 &w1, const cryptonote::subaddress_index exp_max)
|
||||
{
|
||||
// these test assume we are starting with the default setup state
|
||||
for (uint32_t i = 0; i <= exp_max.minor; ++i)
|
||||
{
|
||||
auto subaddr = w1.get_subaddress({exp_max.major, i});
|
||||
EXPECT_NE(boost::none, w1.get_subaddress_index(subaddr));
|
||||
}
|
||||
auto subaddr = w1.get_subaddress({exp_max.major, exp_max.minor + 1});
|
||||
EXPECT_EQ(boost::none, w1.get_subaddress_index(subaddr));
|
||||
};
|
||||
|
||||
static void expect_default_wallet_state(const tools::wallet2 &w1)
|
||||
{
|
||||
// these tests assume we are starting with the default setup state
|
||||
EXPECT_EQ(2, w1.get_num_subaddress_accounts());
|
||||
EXPECT_EQ(50, w1.get_subaddress_lookahead().first);
|
||||
EXPECT_EQ(200, w1.get_subaddress_lookahead().second);
|
||||
|
||||
// We assume we start with subaddrs for minor indexes 0 to 199
|
||||
check_expected_max(w1, {0,199});
|
||||
check_expected_max(w1, {1,199});
|
||||
check_expected_max(w1, {49,199});
|
||||
check_expected_max(w1, {50,199}); // 50 because the test starts with accounts 0 and 1 already allocated
|
||||
EXPECT_EQ(boost::none, w1.get_subaddress_index(w1.get_subaddress({51,0})));
|
||||
}
|
||||
|
||||
TEST_F(WalletSubaddress, SetLookahead)
|
||||
{
|
||||
expect_default_wallet_state(w1);
|
||||
// get_subaddress_index looks up keys in the private m_subaddresses dictionary so we will use it to test if a key is properly being scanned for
|
||||
cryptonote::subaddress_index test_idx = {50, 199};
|
||||
auto subaddr = w1.get_subaddress(test_idx);
|
||||
@@ -117,14 +141,75 @@ TEST_F(WalletSubaddress, ExpandPubkeyTable)
|
||||
w1.set_subaddress_lookahead(100, 200);
|
||||
EXPECT_EQ(100, w1.get_subaddress_lookahead().first);
|
||||
EXPECT_EQ(200, w1.get_subaddress_lookahead().second);
|
||||
test_idx = {100, 199};
|
||||
subaddr = w1.get_subaddress(test_idx);
|
||||
EXPECT_NE(boost::none, w1.get_subaddress_index(subaddr));
|
||||
check_expected_max(w1, {100, 199});
|
||||
// next test expanding the minor lookahead
|
||||
w1.set_subaddress_lookahead(100, 300);
|
||||
EXPECT_EQ(100, w1.get_subaddress_lookahead().first);
|
||||
EXPECT_EQ(300, w1.get_subaddress_lookahead().second);
|
||||
test_idx = {100, 299};
|
||||
subaddr = w1.get_subaddress(test_idx);
|
||||
EXPECT_NE(boost::none, w1.get_subaddress_index(subaddr));
|
||||
check_expected_max(w1, {100, 299});
|
||||
}
|
||||
|
||||
TEST_F(WalletSubaddress, ExpandThenSetMinorIncreaseOnly)
|
||||
{
|
||||
expect_default_wallet_state(w1);
|
||||
|
||||
// Mock receive to {0,150}, so expand from there
|
||||
w1.expand_subaddresses({0,150});
|
||||
// We should now have subaddresses for minor indexes 0 to 349
|
||||
check_expected_max(w1, {0,349});
|
||||
check_expected_max(w1, {1,199});
|
||||
check_expected_max(w1, {49,199});
|
||||
check_expected_max(w1, {50,199});
|
||||
EXPECT_EQ(boost::none, w1.get_subaddress_index(w1.get_subaddress({51,0})));
|
||||
|
||||
// Now set the minor lookahead 100 higher
|
||||
w1.set_subaddress_lookahead(50, 200+100);
|
||||
// We should have subaddresses for minor indexes 0 to 449
|
||||
check_expected_max(w1, {0,449});
|
||||
check_expected_max(w1, {1,299});
|
||||
check_expected_max(w1, {49,299});
|
||||
check_expected_max(w1, {50,299});
|
||||
EXPECT_EQ(boost::none, w1.get_subaddress_index(w1.get_subaddress({51,0})));
|
||||
}
|
||||
|
||||
TEST_F(WalletSubaddress, ExpandThenSetMajorIncreaseOnly)
|
||||
{
|
||||
expect_default_wallet_state(w1);
|
||||
|
||||
// Mock receive to {40,0}, so expand from there
|
||||
w1.expand_subaddresses({40,0});
|
||||
check_expected_max(w1, {0,199});
|
||||
check_expected_max(w1, {1,199});
|
||||
check_expected_max(w1, {40,199});
|
||||
check_expected_max(w1, {89,199});
|
||||
EXPECT_EQ(boost::none, w1.get_subaddress_index(w1.get_subaddress({90,0})));
|
||||
|
||||
// Now set the major lookahead 10 higher
|
||||
w1.set_subaddress_lookahead(50+10, 200);
|
||||
check_expected_max(w1, {0,199});
|
||||
check_expected_max(w1, {1,199});
|
||||
check_expected_max(w1, {40,199});
|
||||
check_expected_max(w1, {99,199});
|
||||
EXPECT_EQ(boost::none, w1.get_subaddress_index(w1.get_subaddress({100,0})));
|
||||
}
|
||||
|
||||
TEST_F(WalletSubaddress, ExpandThenSetIncreaseBoth)
|
||||
{
|
||||
expect_default_wallet_state(w1);
|
||||
|
||||
// Mock receive to {40,150}, so expand from there
|
||||
w1.expand_subaddresses({40,150});
|
||||
check_expected_max(w1, {0,199});
|
||||
check_expected_max(w1, {1,199});
|
||||
check_expected_max(w1, {40,349});
|
||||
check_expected_max(w1, {89,199});
|
||||
EXPECT_EQ(boost::none, w1.get_subaddress_index(w1.get_subaddress({90,0})));
|
||||
|
||||
// Now set the major lookahead 10 higher and minor 100 higher
|
||||
w1.set_subaddress_lookahead(50+10, 200+100);
|
||||
check_expected_max(w1, {0,299});
|
||||
check_expected_max(w1, {1,299});
|
||||
check_expected_max(w1, {40,449});
|
||||
check_expected_max(w1, {99,299});
|
||||
EXPECT_EQ(boost::none, w1.get_subaddress_index(w1.get_subaddress({100,0})));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user