added missing test code

This commit is contained in:
Some Random Crypto Guy
2026-03-05 14:10:49 +00:00
parent 25dccd5423
commit a4e7ebc591
16 changed files with 399 additions and 201 deletions
+33 -32
View File
@@ -53,11 +53,12 @@ public:
, const cryptonote::difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
, uint64_t num_rct_outs
, oracle::asset_type_counts& cum_rct_by_asset_type
, oracle::asset_type_counts_v2& cum_rct_by_asset_type
, const crypto::hash& blk_hash
, uint64_t slippage_total
, uint64_t yield_total
, uint64_t audit_total
, uint64_t token_total
, const cryptonote::network_type nettype
, cryptonote::yield_block_info& ybi
, cryptonote::audit_block_info& abi
@@ -104,7 +105,7 @@ TEST(major, Only)
{
TestDB db;
HardFork hf(db, 1, 0, 0, 0, 1, 0); // no voting
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
@@ -117,27 +118,27 @@ TEST(major, Only)
ASSERT_FALSE(hf.add(mkblock(0, 2), 0));
ASSERT_FALSE(hf.add(mkblock(2, 2), 0));
ASSERT_TRUE(hf.add(mkblock(1, 2), 0));
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
// block height 1, only version 1 is accepted
ASSERT_FALSE(hf.add(mkblock(0, 2), 1));
ASSERT_FALSE(hf.add(mkblock(2, 2), 1));
ASSERT_TRUE(hf.add(mkblock(1, 2), 1));
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
// block height 2, only version 2 is accepted
ASSERT_FALSE(hf.add(mkblock(0, 2), 2));
ASSERT_FALSE(hf.add(mkblock(1, 2), 2));
ASSERT_FALSE(hf.add(mkblock(3, 2), 2));
ASSERT_TRUE(hf.add(mkblock(2, 2), 2));
db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
}
TEST(empty_hardforks, Success)
{
TestDB db;
HardFork hf(db);
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
@@ -147,7 +148,7 @@ TEST(empty_hardforks, Success)
ASSERT_TRUE(hf.get_state(time(NULL) + 3600*24*400) == HardFork::Ready);
for (uint64_t h = 0; h <= 10; ++h) {
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
ASSERT_EQ(hf.get(0), 1);
@@ -173,7 +174,7 @@ TEST(check_for_height, Success)
{
TestDB db;
HardFork hf(db, 1, 0, 0, 0, 1, 0); // no voting
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
@@ -184,14 +185,14 @@ TEST(check_for_height, Success)
for (uint64_t h = 0; h <= 4; ++h) {
ASSERT_TRUE(hf.check_for_height(mkblock(1, 1), h));
ASSERT_FALSE(hf.check_for_height(mkblock(2, 2), h)); // block version is too high
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 5; h <= 10; ++h) {
ASSERT_FALSE(hf.check_for_height(mkblock(1, 1), h)); // block version is too low
ASSERT_TRUE(hf.check_for_height(mkblock(2, 2), h));
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
}
@@ -200,7 +201,7 @@ TEST(get, next_version)
{
TestDB db;
HardFork hf(db);
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
@@ -211,19 +212,19 @@ TEST(get, next_version)
for (uint64_t h = 0; h <= 4; ++h) {
ASSERT_EQ(2, hf.get_next_version());
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 5; h <= 9; ++h) {
ASSERT_EQ(4, hf.get_next_version());
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 10; h <= 15; ++h) {
ASSERT_EQ(4, hf.get_next_version());
db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
}
@@ -232,7 +233,7 @@ TEST(states, Success)
{
TestDB db;
HardFork hf(db);
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
ASSERT_TRUE(hf.add_fork(1, 0, 0));
ASSERT_TRUE(hf.add_fork(2, BLOCKS_PER_YEAR, SECONDS_PER_YEAR));
@@ -256,7 +257,7 @@ TEST(steps_asap, Success)
{
TestDB db;
HardFork hf(db, 1,0,1,1,1);
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
@@ -268,7 +269,7 @@ TEST(steps_asap, Success)
hf.init();
for (uint64_t h = 0; h < 10; ++h) {
db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
@@ -288,7 +289,7 @@ TEST(steps_1, Success)
{
TestDB db;
HardFork hf(db, 1,0,1,1,1);
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
@@ -298,7 +299,7 @@ TEST(steps_1, Success)
hf.init();
for (uint64_t h = 0 ; h < 10; ++h) {
db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
@@ -312,7 +313,7 @@ TEST(reorganize, Same)
for (int history = 1; history <= 12; ++history) {
TestDB db;
HardFork hf(db, 1, 0, 1, 1, history, 100);
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
@@ -326,7 +327,7 @@ TEST(reorganize, Same)
// index 0 1 2 3 4 5 6 7 8 9
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
for (uint64_t h = 0; h < 20; ++h) {
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
@@ -344,7 +345,7 @@ TEST(reorganize, Changed)
{
TestDB db;
HardFork hf(db, 1, 0, 1, 1, 4, 100);
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
@@ -360,7 +361,7 @@ TEST(reorganize, Changed)
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9 };
for (uint64_t h = 0; h < 16; ++h) {
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE (hf.add(db.get_block_from_height(h), h));
}
@@ -380,7 +381,7 @@ TEST(reorganize, Changed)
ASSERT_EQ(db.height(), 3);
hf.reorganize_from_block_height(2);
for (uint64_t h = 3; h < 16; ++h) {
db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
bool ret = hf.add(db.get_block_from_height(h), h);
ASSERT_EQ (ret, h < 15);
}
@@ -393,7 +394,7 @@ TEST(reorganize, Changed)
TEST(voting, threshold)
{
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
for (int threshold = 87; threshold <= 88; ++threshold) {
@@ -407,7 +408,7 @@ TEST(voting, threshold)
for (uint64_t h = 0; h <= 8; ++h) {
uint8_t v = 1 + !!(h % 8);
db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
bool ret = hf.add(db.get_block_from_height(h), h);
if (h >= 8 && threshold == 87) {
// for threshold 87, we reach the treshold at height 7, so from height 8, hard fork to version 2, but 8 tries to add 1
@@ -425,7 +426,7 @@ TEST(voting, threshold)
TEST(voting, different_thresholds)
{
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
for (int threshold = 87; threshold <= 88; ++threshold) {
@@ -444,7 +445,7 @@ TEST(voting, different_thresholds)
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 };
for (uint64_t h = 0; h < sizeof(block_versions) / sizeof(block_versions[0]); ++h) {
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
bool ret = hf.add(db.get_block_from_height(h), h);
ASSERT_EQ(ret, true);
}
@@ -458,7 +459,7 @@ TEST(voting, info)
{
TestDB db;
HardFork hf(db, 1, 0, 1, 1, 4, 50); // window size 4, default threshold 50%
oracle::asset_type_counts num_rct_outs_by_asset_type;
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
cryptonote::audit_block_info abi;
cryptonote::yield_block_info ybi;
@@ -500,7 +501,7 @@ TEST(voting, info)
ASSERT_EQ(expected_thresholds[h], threshold);
ASSERT_EQ(4, voting);
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
}
@@ -563,10 +564,10 @@ TEST(reorganize, changed)
#define ADD(v, h, a) \
do { \
cryptonote::block b = mkblock(hf, h, v); \
oracle::asset_type_counts num_rct_outs_by_asset_type; \
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; \
cryptonote::audit_block_info abi; \
cryptonote::yield_block_info ybi; \
db.add_block(b, 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); \
db.add_block(b, 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); \
ASSERT_##a(hf.add(b, h)); \
} while(0)
#define ADD_TRUE(v, h) ADD(v, h, TRUE)