Skip to content

Commit

Permalink
tests: Fixed CreateWithExistingGenesis
Browse files Browse the repository at this point in the history
  • Loading branch information
EduMenges committed May 10, 2024
1 parent 365fe54 commit bfa8b76
Showing 1 changed file with 15 additions and 50 deletions.
65 changes: 15 additions & 50 deletions test/src/blockchain/block_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,67 +31,35 @@ using testing::Return;
class BlockStorageTest : public test::CRDTFixture
{
public:
BlockStorageTest() : CRDTFixture( fs::path( "blockstoragetest.lvldb" ) )
BlockStorageTest() :
CRDTFixture( fs::path( "blockstoragetest.lvldb" ) ), hasher( std::make_shared<sgns::crypto::HasherImpl>() ),
header_repo_( std::make_shared<KeyValueBlockHeaderRepository>( db_, hasher, "teststorage-963/" ) )
{
root_hash.put( std::vector<uint8_t>( 32UL, 1 ) );

createWithGenesis();
}

void SetUp() override
std::shared_ptr<KeyValueBlockStorage> createWithGenesis()
{
root_hash.put( std::vector<uint8_t>( 32ul, 1 ) );
hasher = std::make_shared<sgns::crypto::HasherImpl>();
std::string db_path_ = "teststorage-963/";
header_repo_ = std::make_shared<KeyValueBlockHeaderRepository>( db_, hasher, db_path_ );
EXPECT_OUTCOME_TRUE(
new_block_storage,
KeyValueBlockStorage::createWithGenesis( root_hash, db_, hasher, header_repo_, block_handler ) );

return new_block_storage;
}

BlockHash genesis_block_hash{ { 'g', 'e', 'n', 'e', 's', 'i', 's' } };
BlockHash regular_block_hash{ { 'r', 'e', 'g', 'u', 'l', 'a', 'r' } };
Buffer root_hash;

KeyValueBlockStorage::BlockHandler block_handler = []( auto & ) {};

std::shared_ptr<KeyValueBlockStorage> createWithGenesis()
{
//EXPECT_CALL(*hasher, blake2b_256(_))
// // calculate hash of genesis block at check existance of block
// .WillOnce(Return(genesis_block_hash))
// // calculate hash of genesis block at put block header
// .WillRepeatedly(Return(genesis_block_hash));

//EXPECT_CALL(*storage, get(_))
// // trying to get last finalized block hash which not exists yet
// .WillOnce(Return(sgns::blockchain::Error::BLOCK_NOT_FOUND))
// // check of block data during block insertion
// .WillOnce(Return(sgns::storage::DatabaseError::NOT_FOUND))
// .WillOnce(Return(sgns::storage::DatabaseError::NOT_FOUND));
//
//EXPECT_CALL(*storage, put(_, _))
// // put key-value for lookup data
// .WillRepeatedly(Return(outcome::success()));
//
//EXPECT_CALL(*storage, put_rv(_, _))
// // put key-value for lookup data
// .WillRepeatedly(Return(outcome::success()));

EXPECT_OUTCOME_TRUE( new_block_storage, KeyValueBlockStorage::createWithGenesis(
root_hash, db_, hasher, header_repo_, block_handler ) );

return new_block_storage;
}
Buffer root_hash;

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

/**
* @given a hasher instance, a genesis block, and an empty map storage
* @when initialising a block storage from it
* @then initialisation will successful
*/
TEST_F( BlockStorageTest, CreateWithGenesis )
{
createWithGenesis();
}

/**
* @given a hasher instance, a genesis block, and an map storage containing the
* block
Expand All @@ -101,12 +69,9 @@ TEST_F( BlockStorageTest, CreateWithGenesis )
*/
TEST_F( BlockStorageTest, CreateWithExistingGenesis )
{
//EXPECT_CALL(*storage, get(_))
// trying to get last finalized block hash to ensure he not exists yet
// .WillOnce(Return(Buffer{genesis_block_hash}));

EXPECT_OUTCOME_ERROR(
res, KeyValueBlockStorage::createWithGenesis( root_hash, db_, hasher, header_repo_, block_handler ),
res,
KeyValueBlockStorage::createWithGenesis( root_hash, db_, hasher, header_repo_, block_handler ),
KeyValueBlockStorage::Error::GENESIS_BLOCK_ALREADY_EXISTS );
}

Expand Down

0 comments on commit bfa8b76

Please sign in to comment.