From bfa8b76010bb871281a61fc7a97652b85ea7f9e9 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Fri, 10 May 2024 13:08:19 -0300 Subject: [PATCH] tests: Fixed CreateWithExistingGenesis --- test/src/blockchain/block_storage_test.cpp | 65 +++++----------------- 1 file changed, 15 insertions(+), 50 deletions(-) diff --git a/test/src/blockchain/block_storage_test.cpp b/test/src/blockchain/block_storage_test.cpp index a813be52..c1dbcb78 100644 --- a/test/src/blockchain/block_storage_test.cpp +++ b/test/src/blockchain/block_storage_test.cpp @@ -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() ), + header_repo_( std::make_shared( db_, hasher, "teststorage-963/" ) ) { + root_hash.put( std::vector( 32UL, 1 ) ); + + createWithGenesis(); } - void SetUp() override + std::shared_ptr createWithGenesis() { - root_hash.put( std::vector( 32ul, 1 ) ); - hasher = std::make_shared(); - std::string db_path_ = "teststorage-963/"; - header_repo_ = std::make_shared( 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 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 hasher; std::shared_ptr 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 @@ -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 ); }