Skip to content

Commit

Permalink
Merge pull request #587 from dimxy/bugfix-season7-tests
Browse files Browse the repository at this point in the history
Bugfix broken notary tests due to new S7 constants
  • Loading branch information
ca333 authored May 31, 2023
2 parents 4651e28 + 8d0cc33 commit 9e4d543
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/test-komodo/test_haraka_removal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace TestHarakaRemoval {
CChain chainActive;
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);

TEST(TestHarakaRemoval, test_block_ser)
TEST(TestHarakaRemoval, DISABLED_test_block_ser) // disabled due to changed protocol version. We do not want to update it each time
{
// this test should cover genesis block (de)serialization before
// and after applying haraka removal PR
Expand Down
67 changes: 61 additions & 6 deletions src/test-komodo/test_notary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool operator==(const my_key& lhs, const my_key& rhs)
TEST(TestNotary, KomodoNotaries)
{
// Test komodo_notaries(), getkmdseason()
chainName = assetchain("");
chainName = assetchain(""); // set as KMD
SelectParams(CBaseChainParams::MAIN);
komodo_notaries_uninit();
//undo_init_STAKED();
Expand Down Expand Up @@ -124,11 +124,6 @@ TEST(TestNotary, KomodoNotaries)
EXPECT_EQ( getacseason(1), 1);
EXPECT_EQ( getacseason(1525132800), 1);
EXPECT_EQ( getacseason(1525132801), 2);
EXPECT_EQ( getacseason(1751328000), 7);
EXPECT_EQ( getacseason(1751328001), 0);

// cleanup
komodo_notaries_uninit();
}

TEST(TestNotary, ElectedNotary)
Expand Down Expand Up @@ -171,4 +166,64 @@ TEST(TestNotary, ElectedNotary)
EXPECT_EQ(numnotaries, 64);
}

// season 7 tests for KMD:
TEST(TestNotary, KomodoNotaries_S7_KMD)
{
uint8_t pubkeys[64][33];

SelectParams(CBaseChainParams::MAIN);
komodo_notaries_uninit();
chainName = assetchain(""); // set as KMD

EXPECT_EQ( getkmdseason(3484958+1), 8);
EXPECT_EQ( getkmdseason(8113400), 8);
EXPECT_EQ( getkmdseason(8113400+1), 0);
int32_t result1 = komodo_notaries(pubkeys, 3484958+1, 0);
EXPECT_EQ(result1, 64);
EXPECT_EQ( my_key(pubkeys[0]), my_key("03955c7999538cee313bf196a7df59db208c651f6a5a1b0eed94732ba753b4f3f4"));
EXPECT_EQ( my_key(pubkeys[63]), my_key("02f9a7b49282885cd03969f1f5478287497bc8edfceee9eac676053c107c5fcdaf"));

// try wrong pubkey
int32_t numnotaries;
my_key wrong_pk("02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344");
uint8_t pubkey[33];
wrong_pk.fill(pubkey);
int32_t result2 = komodo_electednotary(&numnotaries, pubkey, 3484958+1, 0);
EXPECT_EQ(result2, -1);
EXPECT_EQ(numnotaries, 64);

// cleanup
komodo_notaries_uninit();
}

// season 7 tests for asset chain:
TEST(TestNotary, KomodoNotaries_S7_AS)
{
uint8_t pubkeys[64][33];

SelectParams(CBaseChainParams::MAIN);
komodo_notaries_uninit();
chainName = assetchain("MYASSET");
EXPECT_EQ( getacseason(1688132253+1), 8);
EXPECT_EQ( getacseason(1951328000), 8);
EXPECT_EQ( getacseason(1951328001), 0);

int32_t result1 = komodo_notaries(pubkeys, 0, 1688132253+1);
EXPECT_EQ(result1, 64);
EXPECT_EQ( my_key(pubkeys[0]), my_key("03955c7999538cee313bf196a7df59db208c651f6a5a1b0eed94732ba753b4f3f4"));
EXPECT_EQ( my_key(pubkeys[63]), my_key("02f9a7b49282885cd03969f1f5478287497bc8edfceee9eac676053c107c5fcdaf"));

// try wrong pubkey
int32_t numnotaries;
my_key wrong_pk("02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344");
uint8_t pubkey[33];
wrong_pk.fill(pubkey);
int32_t result2 = komodo_electednotary(&numnotaries, pubkey, 3484958+1, 1688132253+1);
EXPECT_EQ(result2, -1);
EXPECT_EQ(numnotaries, 64);

// cleanup
komodo_notaries_uninit();
}

} // namespace TestNotary

0 comments on commit 9e4d543

Please sign in to comment.