Skip to content

Commit

Permalink
Removed underscore in test
Browse files Browse the repository at this point in the history
  • Loading branch information
EduMenges committed May 6, 2024
1 parent c3aa901 commit f869552
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 272 deletions.
10 changes: 5 additions & 5 deletions src/primitives/block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace sgns::primitives
*/
struct BlockHeader
{
BlockHash parent_hash{}; ///< 32-byte Blake2s hash of parent header
BlockNumber number = 0u; ///< index of current block in the chain
base::Hash256 state_root{}; ///< root of the Merkle tree
base::Hash256 extrinsics_root{}; ///< field for validation integrity
Digest digest{}; ///< chain-specific auxiliary data
BlockHash parent_hash; ///< 32-byte Blake2s hash of parent header
BlockNumber number = 0U; ///< index of current block in the chain
base::Hash256 state_root; ///< root of the Merkle tree
base::Hash256 extrinsics_root; ///< field for validation integrity
Digest digest; ///< chain-specific auxiliary data

bool operator==( const BlockHeader &rhs ) const
{
Expand Down
72 changes: 36 additions & 36 deletions test/src/blockchain/block_header_repository_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ using sgns::primitives::BlockHeader;
using sgns::primitives::BlockId;
using sgns::primitives::BlockNumber;

class BlockHeaderRepository_Test : public test::BaseCRDT_Test
class BlockHeaderRepositoryFixture : public test::CRDTFixture
{
public:
BlockHeaderRepository_Test() : BaseCRDT_Test( fs::path( "blockheaderrepotest.lvldb" ) )
BlockHeaderRepositoryFixture() : CRDTFixture( fs::path( "blockheaderrepotest.lvldb" ) )
{
}

Expand All @@ -43,11 +43,11 @@ class BlockHeaderRepository_Test : public test::BaseCRDT_Test
header_repo_ = std::make_shared<KeyValueBlockHeaderRepository>( db_, hasher, db_path_ );
}

outcome::result<Hash256> storeHeader( BlockNumber num, BlockHeader h )
outcome::result<Hash256> storeHeader( BlockNumber num, BlockHeader &&header )
{
BlockHeader header = std::move( h );
header.number = num;
header.number = num;
OUTCOME_TRY( ( auto &&, enc_header ), sgns::scale::encode( header ) );

auto hash = hasher->blake2b_256( enc_header );
BOOST_OUTCOME_TRYV2( auto &&,
putWithPrefix( *db_, Prefix::HEADER, header.number, hash, Buffer{ enc_header } ) );
Expand All @@ -56,20 +56,18 @@ class BlockHeaderRepository_Test : public test::BaseCRDT_Test

static BlockHeader getDefaultHeader()
{
BlockHeader h{};
h.number = 42;
h.extrinsics_root = "DEADBEEF"_hash256;
h.parent_hash = "ABCDEF"_hash256;
h.state_root = "010203"_hash256;
return h;
return { .parent_hash = "ABCDEF"_hash256,
.number = 42,
.state_root = "010203"_hash256,
.extrinsics_root = "DEADBEEF"_hash256 };
}

std::shared_ptr<sgns::crypto::Hasher> hasher;
std::shared_ptr<BlockHeaderRepository> header_repo_;
};

class BlockHeaderRepository_NumberParametrized_Test : public BlockHeaderRepository_Test,
public testing::WithParamInterface<BlockNumber>
class BlockHeaderRepositoryNumberParametrizedFixture : public BlockHeaderRepositoryFixture,
public testing::WithParamInterface<BlockNumber>
{
};

Expand All @@ -80,26 +78,28 @@ const std::vector<BlockNumber> ParamValues = { 1, 42, 12345, 0, 0xFFFFFFFF };
* @when accessing a header that wasn't put into storage
* @then result is error
*/
TEST_F( BlockHeaderRepository_Test, UnexistingHeader )
TEST_F( BlockHeaderRepositoryFixture, UnexistingHeader )
{
//auto chosen_number = ParamValues[0];
//for(auto& c: ParamValues) {
// if(c != chosen_number) {
// EXPECT_OUTCOME_TRUE_1(storeHeader(c, getDefaultHeader()));
// }
//}
//BlockHeader not_in_storage = getDefaultHeader();
//not_in_storage.number = chosen_number;
//EXPECT_OUTCOME_TRUE(enc_header, sgns::scale::encode(not_in_storage));
//auto hash = hasher->blake2b_256(enc_header);
//EXPECT_OUTCOME_FALSE_1(header_repo_->getBlockHeader(chosen_number));
//EXPECT_OUTCOME_FALSE_1(header_repo_->getBlockHeader(hash));
//EXPECT_OUTCOME_FALSE_1(header_repo_->getHashById(chosen_number));
//EXPECT_OUTCOME_FALSE_1(header_repo_->getNumberById(hash));
//
//// doesn't require access to storage, as it basically returns its argument
//EXPECT_OUTCOME_TRUE_1(header_repo_->getHashById(hash));
//EXPECT_OUTCOME_TRUE_1(header_repo_->getNumberById(chosen_number));
auto chosen_number = ParamValues[0];
for ( auto c : ParamValues )
{
if ( c != chosen_number )
{
EXPECT_OUTCOME_TRUE_1( storeHeader( c, getDefaultHeader() ) );
}
}
BlockHeader not_in_storage = getDefaultHeader();
not_in_storage.number = chosen_number;
EXPECT_OUTCOME_TRUE( enc_header, sgns::scale::encode( not_in_storage ) );
auto hash = hasher->blake2b_256( enc_header );
EXPECT_OUTCOME_FALSE_1( header_repo_->getBlockHeader( chosen_number ) );
EXPECT_OUTCOME_FALSE_1( header_repo_->getBlockHeader( hash ) );
EXPECT_OUTCOME_FALSE_1( header_repo_->getHashById( chosen_number ) );
EXPECT_OUTCOME_FALSE_1( header_repo_->getNumberById( hash ) );

// doesn't require access to storage, as it basically returns its argument
EXPECT_OUTCOME_TRUE_1( header_repo_->getHashById( hash ) );
EXPECT_OUTCOME_TRUE_1( header_repo_->getNumberById( chosen_number ) );
}

/**
Expand All @@ -108,7 +108,7 @@ TEST_F( BlockHeaderRepository_Test, UnexistingHeader )
* @then resulting hash is equal to the original hash of the block for both
* retrieval through getHashByNumber and getHashById
*/
TEST_P( BlockHeaderRepository_NumberParametrized_Test, GetHashByNumber )
TEST_P( BlockHeaderRepositoryNumberParametrizedFixture, GetHashByNumber )
{
//EXPECT_OUTCOME_TRUE(hash, storeHeader(GetParam(), getDefaultHeader()));
//EXPECT_OUTCOME_TRUE(maybe_hash, header_repo_->getHashByNumber(GetParam()));
Expand All @@ -124,7 +124,7 @@ TEST_P( BlockHeaderRepository_NumberParametrized_Test, GetHashByNumber )
* @then resulting number is equal to the original block number for both
* retrieval through getNumberByHash and getNumberById
*/
TEST_P( BlockHeaderRepository_NumberParametrized_Test, GetNumberByHash )
TEST_P( BlockHeaderRepositoryNumberParametrizedFixture, GetNumberByHash )
{
//EXPECT_OUTCOME_TRUE(hash, storeHeader(GetParam(), getDefaultHeader()));
//EXPECT_OUTCOME_TRUE(maybe_number, header_repo_->getNumberByHash(hash));
Expand All @@ -140,7 +140,7 @@ TEST_P( BlockHeaderRepository_NumberParametrized_Test, GetNumberByHash )
* @then the same header that was put into the storage is returned, regardless
* of whether the id contained a number or a hash
*/
TEST_P( BlockHeaderRepository_NumberParametrized_Test, GetHeader )
TEST_P( BlockHeaderRepositoryNumberParametrizedFixture, GetHeader )
{
//EXPECT_OUTCOME_TRUE(hash, storeHeader(GetParam(), getDefaultHeader()));
//EXPECT_OUTCOME_TRUE(header_by_num, header_repo_->getBlockHeader(GetParam()));
Expand All @@ -151,4 +151,4 @@ TEST_P( BlockHeaderRepository_NumberParametrized_Test, GetHeader )
//ASSERT_EQ(header_by_num, header_should_be);
}

INSTANTIATE_TEST_SUITE_P( Numbers, BlockHeaderRepository_NumberParametrized_Test, testing::ValuesIn( ParamValues ) );
INSTANTIATE_TEST_SUITE_P( Numbers, BlockHeaderRepositoryNumberParametrizedFixture, testing::ValuesIn( ParamValues ) );
4 changes: 2 additions & 2 deletions test/src/blockchain/block_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ using sgns::storage::face::GenericStorageMock;
using testing::_;
using testing::Return;

class BlockStorageTest : public test::BaseCRDT_Test
class BlockStorageTest : public test::CRDTFixture
{
public:
BlockStorageTest() : BaseCRDT_Test( fs::path( "blockstoragetest.lvldb" ) )
BlockStorageTest() : CRDTFixture( fs::path( "blockstoragetest.lvldb" ) )
{
}

Expand Down
135 changes: 63 additions & 72 deletions test/src/crypto/crypto_store/crypto_store_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,78 +41,69 @@ using namespace sgns::crypto::key_types;
static CryptoStoreImpl::Path crypto_store_test_directory =
boost::filesystem::temp_directory_path() / "crypto_store_test";

struct CryptoStoreTest : public test::BaseFS_Test {
CryptoStoreTest() : BaseFS_Test(crypto_store_test_directory) {}

void SetUp() override {
auto ed25519_provider = std::make_shared<ED25519ProviderImpl>();
auto csprng = std::make_shared<BoostRandomGenerator>();
auto sr25519_provider = std::make_shared<SR25519ProviderImpl>(csprng);
auto secp256k1_provider = std::make_shared<Secp256k1ProviderImpl>();

auto pbkdf2_provider = std::make_shared<Pbkdf2ProviderImpl>();
bip39_provider =
std::make_shared<Bip39ProviderImpl>(std::move(pbkdf2_provider));
crypto_store =
std::make_shared<CryptoStoreImpl>(std::move(ed25519_provider),
std::move(sr25519_provider),
std::move(secp256k1_provider),
bip39_provider,
std::move(csprng));

mnemonic =
"ozone drill grab fiber curtain grace pudding thank cruise elder eight "
"picnic";
EXPECT_OUTCOME_TRUE(e, Buffer::fromHex("9e885d952ad362caeb4efe34a8e91bd2"));
entropy = std::move(e);
EXPECT_OUTCOME_TRUE(s,
Blob<32>::fromHex("a4681403ba5b6a3f3bd0b0604ce439a78244"
"c7d43b127ec35cd8325602dd47fd"));
seed = s;
key_type = kProd;

EXPECT_OUTCOME_TRUE(
ed_publ,
// ED25519PublicKey::fromHex("3e765f2bde3daadd443097b3145abf1f71f99f0aa946"
// "960990fe02aa26b7fc72"));
ED25519PublicKey::fromHex("3086e3f8cdc1e69f855a1b1907331b7594500c0fc40e"
"91e25e734513df85289f"));
EXPECT_OUTCOME_TRUE(
ed_priv,
ED25519PrivateKey::fromHex("a4681403ba5b6a3f3bd0b0604ce439a78244c7d43b1"
"27ec35cd8325602dd47fd"));
ed_pair = {ed_priv, ed_publ};

EXPECT_OUTCOME_TRUE(
sr_publ,
SR25519PublicKey::fromHex("7e68abebffcfe3409af87fbb0b5254b7add6ec3efc1f5b882f3621df45afec15"));
EXPECT_OUTCOME_TRUE(
sr_secr,
SR25519SecretKey::fromHex(
"d0c92c34038c17ea76208b04623203cbd9ce0901e82486da0053c0c2c4488b69"
"19f52f334750e98500ba84fd528a6ff810b91b43d11e3d3eb1c2176c9dda0b57"));
sr_pair = {sr_secr, sr_publ};

EXPECT_OUTCOME_TRUE_MSG_1(
crypto_store->initialize(crypto_store_test_directory),
"initialization failed");
}

bool isStoredOnDisk(KeyTypeId kt, const Blob<32> &public_key) {
auto file_name = sgns::crypto::decodeKeyTypeId(kt) + public_key.toHex();
auto file_path = crypto_store_test_directory / file_name;
return boost::filesystem::exists(file_path);
}

std::shared_ptr<Bip39Provider> bip39_provider;
std::shared_ptr<CryptoStoreImpl> crypto_store;
std::string mnemonic;
Buffer entropy;
Blob<32> seed;
KeyTypeId key_type;

ED25519Keypair ed_pair;
SR25519Keypair sr_pair;
struct CryptoStoreTest : public test::FSFixture
{
CryptoStoreTest() : FSFixture( crypto_store_test_directory )
{
}

void SetUp() override
{
auto ed25519_provider = std::make_shared<ED25519ProviderImpl>();
auto csprng = std::make_shared<BoostRandomGenerator>();
auto sr25519_provider = std::make_shared<SR25519ProviderImpl>( csprng );
auto secp256k1_provider = std::make_shared<Secp256k1ProviderImpl>();

auto pbkdf2_provider = std::make_shared<Pbkdf2ProviderImpl>();
bip39_provider = std::make_shared<Bip39ProviderImpl>( std::move( pbkdf2_provider ) );
crypto_store =
std::make_shared<CryptoStoreImpl>( std::move( ed25519_provider ), std::move( sr25519_provider ),
std::move( secp256k1_provider ), bip39_provider, std::move( csprng ) );

mnemonic = "ozone drill grab fiber curtain grace pudding thank cruise elder eight "
"picnic";
EXPECT_OUTCOME_TRUE( e, Buffer::fromHex( "9e885d952ad362caeb4efe34a8e91bd2" ) );
entropy = std::move( e );
EXPECT_OUTCOME_TRUE( s, Blob<32>::fromHex( "a4681403ba5b6a3f3bd0b0604ce439a78244"
"c7d43b127ec35cd8325602dd47fd" ) );
seed = s;
key_type = kProd;

EXPECT_OUTCOME_TRUE( ed_publ,
// ED25519PublicKey::fromHex("3e765f2bde3daadd443097b3145abf1f71f99f0aa946"
// "960990fe02aa26b7fc72"));
ED25519PublicKey::fromHex( "3086e3f8cdc1e69f855a1b1907331b7594500c0fc40e"
"91e25e734513df85289f" ) );
EXPECT_OUTCOME_TRUE( ed_priv, ED25519PrivateKey::fromHex( "a4681403ba5b6a3f3bd0b0604ce439a78244c7d43b1"
"27ec35cd8325602dd47fd" ) );
ed_pair = { ed_priv, ed_publ };

EXPECT_OUTCOME_TRUE(
sr_publ, SR25519PublicKey::fromHex( "7e68abebffcfe3409af87fbb0b5254b7add6ec3efc1f5b882f3621df45afec15" ) );
EXPECT_OUTCOME_TRUE(
sr_secr, SR25519SecretKey::fromHex( "d0c92c34038c17ea76208b04623203cbd9ce0901e82486da0053c0c2c4488b69"
"19f52f334750e98500ba84fd528a6ff810b91b43d11e3d3eb1c2176c9dda0b57" ) );
sr_pair = { sr_secr, sr_publ };

EXPECT_OUTCOME_TRUE_MSG_1( crypto_store->initialize( crypto_store_test_directory ), "initialization failed" );
}

bool isStoredOnDisk( KeyTypeId kt, const Blob<32> &public_key )
{
auto file_name = sgns::crypto::decodeKeyTypeId( kt ) + public_key.toHex();
auto file_path = crypto_store_test_directory / file_name;
return boost::filesystem::exists( file_path );
}

std::shared_ptr<Bip39Provider> bip39_provider;
std::shared_ptr<CryptoStoreImpl> crypto_store;
std::string mnemonic;
Buffer entropy;
Blob<32> seed;
KeyTypeId key_type;

ED25519Keypair ed_pair;
SR25519Keypair sr_pair;
};

/**
Expand Down
9 changes: 6 additions & 3 deletions test/src/storage/rocksdb/rocksdb_fs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ namespace fs = boost::filesystem;

namespace sgns::storage
{
struct rocksdb_Open : public test::BaseFS_Test {
rocksdb_Open() : test::BaseFS_Test("supergenius_rocksdb_open") {}
};
struct rocksdb_Open : public test::FSFixture
{
rocksdb_Open() : test::FSFixture( "supergenius_rocksdb_open" )
{
}
};

/**
* @given options with disabled option `create_if_missing`
Expand Down
Loading

0 comments on commit f869552

Please sign in to comment.