Skip to content

Commit

Permalink
Remove txNumber (hyperledger-iroha#1074)
Browse files Browse the repository at this point in the history
Signed-off-by: Dumitru <[email protected]>
  • Loading branch information
x3medima17 committed Mar 30, 2018
1 parent 1856941 commit 5a60e08
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ namespace shared_model {

enum RequiredFields {
Transactions,
TxNumber,
Height,
PrevHash,
CreatedTime,
Expand Down Expand Up @@ -97,12 +96,6 @@ namespace shared_model {
});
}

auto txNumber(interface::Block::TransactionsNumberType tx_number) const {
return transform<TxNumber>([&](auto &block) {
block.mutable_payload()->set_tx_number(tx_number);
});
}

auto height(interface::types::HeightType height) const {
return transform<Height>(
[&](auto &block) { block.mutable_payload()->set_height(height); });
Expand All @@ -123,8 +116,13 @@ namespace shared_model {

BT build() {
static_assert(S == (1 << TOTAL) - 1, "Required fields are not set");

auto tx_number = block_.payload().transactions().size();
block_.mutable_payload()->set_tx_number(tx_number);

auto result = Block(iroha::protocol::Block(block_));
auto answer = stateless_validator_.validate(result);

if (answer.hasErrors()) {
throw std::invalid_argument(answer.reason());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ DROP TABLE IF EXISTS index_by_id_height_asset;
shared_model::proto::BlockBuilder()
.transactions(
std::vector<shared_model::proto::Transaction>{genesis_tx})
.txNumber(1)
.height(1)
.prevHash(Sha3_256::makeHash(Blob("")))
.createdTime(iroha::time::now())
Expand Down
15 changes: 0 additions & 15 deletions test/module/irohad/ametsuchi/ametsuchi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ TEST_F(AmetsuchiTest, SampleTest) {
.build()}))
.height(1)
.prevHash(fake_hash)
.txNumber(1)
.build();

apply(storage, block1);
Expand All @@ -225,7 +224,6 @@ TEST_F(AmetsuchiTest, SampleTest) {
.build()}))
.height(2)
.prevHash(block1.hash())
.txNumber(1)
.build();

apply(storage, block2);
Expand Down Expand Up @@ -262,7 +260,6 @@ TEST_F(AmetsuchiTest, PeerTest) {

auto block =
TestBlockBuilder()
.txNumber(1)
.transactions(std::vector<shared_model::proto::Transaction>{txn})
.prevHash(fake_hash)
.build();
Expand Down Expand Up @@ -314,7 +311,6 @@ TEST_F(AmetsuchiTest, queryGetAccountAssetTransactionsTest) {
.height(1)
.transactions(std::vector<shared_model::proto::Transaction>({txn1}))
.prevHash(fake_hash)
.txNumber(1)
.build();

apply(storage, block1);
Expand All @@ -341,7 +337,6 @@ TEST_F(AmetsuchiTest, queryGetAccountAssetTransactionsTest) {
.transactions(std::vector<shared_model::proto::Transaction>({txn2}))
.height(2)
.prevHash(block1.hash())
.txNumber(1)
.build();

apply(storage, block2);
Expand All @@ -367,7 +362,6 @@ TEST_F(AmetsuchiTest, queryGetAccountAssetTransactionsTest) {
.transactions(std::vector<shared_model::proto::Transaction>({txn3}))
.height(3)
.prevHash(block2.hash())
.txNumber(1)
.build();

apply(storage, block3);
Expand Down Expand Up @@ -429,7 +423,6 @@ TEST_F(AmetsuchiTest, AddSignatoryTest) {
.transactions(std::vector<shared_model::proto::Transaction>({txn1}))
.height(1)
.prevHash(fake_hash)
.txNumber(1)
.build();

apply(storage, block1);
Expand Down Expand Up @@ -458,7 +451,6 @@ TEST_F(AmetsuchiTest, AddSignatoryTest) {
.transactions(std::vector<shared_model::proto::Transaction>({txn2}))
.height(2)
.prevHash(block1.hash())
.txNumber(1)
.build();

apply(storage, block2);
Expand All @@ -485,7 +477,6 @@ TEST_F(AmetsuchiTest, AddSignatoryTest) {
.transactions(std::vector<shared_model::proto::Transaction>({txn3}))
.height(3)
.prevHash(block2.hash())
.txNumber(1)
.build();

apply(storage, block3);
Expand Down Expand Up @@ -520,7 +511,6 @@ TEST_F(AmetsuchiTest, AddSignatoryTest) {
.transactions(std::vector<shared_model::proto::Transaction>({txn4}))
.height(4)
.prevHash(block3.hash())
.txNumber(1)
.build();

apply(storage, block4);
Expand Down Expand Up @@ -554,7 +544,6 @@ TEST_F(AmetsuchiTest, AddSignatoryTest) {
.transactions(std::vector<shared_model::proto::Transaction>({txn5}))
.height(5)
.prevHash(block4.hash())
.txNumber(1)
.build();

apply(storage, block5);
Expand Down Expand Up @@ -585,7 +574,6 @@ TEST_F(AmetsuchiTest, AddSignatoryTest) {
.transactions(std::vector<shared_model::proto::Transaction>({txn6}))
.height(6)
.prevHash(block5.hash())
.txNumber(1)
.build();

apply(storage, block6);
Expand All @@ -610,7 +598,6 @@ shared_model::proto::Block getBlock() {
.transactions(std::vector<shared_model::proto::Transaction>({txn}))
.height(1)
.prevHash(fake_hash)
.txNumber(1)
.build();
return block;
}
Expand Down Expand Up @@ -730,7 +717,6 @@ TEST_F(AmetsuchiTest, FindTxByHashTest) {
{txn1, txn2}))
.height(1)
.prevHash(fake_hash)
.txNumber(2)
.build();

apply(storage, block);
Expand Down Expand Up @@ -893,7 +879,6 @@ TEST_F(AmetsuchiTest, TestRestoreWSV) {
TestBlockBuilder()
.transactions(
std::vector<shared_model::proto::Transaction>{genesis_tx})
.txNumber(1)
.height(1)
.prevHash(shared_model::crypto::Sha3_256::makeHash(
shared_model::crypto::Blob("")))
Expand Down
2 changes: 0 additions & 2 deletions test/module/irohad/ametsuchi/block_query_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class BlockQueryTest : public AmetsuchiTest {
.transactions(
std::vector<shared_model::proto::Transaction>({txn1_1, txn1_2}))
.prevHash(shared_model::crypto::Hash(zero_string))
.txNumber(2)
.build();

// First tx in block 1
Expand All @@ -83,7 +82,6 @@ class BlockQueryTest : public AmetsuchiTest {
.transactions(
std::vector<shared_model::proto::Transaction>({txn2_1, txn2_2}))
.prevHash(block1.hash())
.txNumber(2)
.build();

for (const auto &b : {block1, block2}) {
Expand Down
2 changes: 0 additions & 2 deletions test/module/irohad/ametsuchi/block_query_transfer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ namespace iroha {
.build()}))
.height(1)
.prevHash(fake_hash)
.txNumber(1)
.build();
}

Expand All @@ -128,7 +127,6 @@ namespace iroha {
.build()}))
.height(height)
.prevHash(hash)
.txNumber(1)
.build();
}

Expand Down
3 changes: 1 addition & 2 deletions test/module/irohad/network/block_loader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ class BlockLoaderTest : public testing::Test {
}

auto getBaseBlockBuilder() const {
constexpr auto kTotal = (1 << 5) - 1;
constexpr auto kTotal = (1 << 4) - 1;
return shared_model::proto::TemplateBlockBuilder<
kTotal,
shared_model::validation::DefaultBlockValidator,
shared_model::proto::Block>()
.txNumber(0)
.height(1)
.prevHash(Hash(std::string(32, '0')))
.createdTime(iroha::time::now());
Expand Down
1 change: 0 additions & 1 deletion test/module/irohad/simulator/simulator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class SimulatorTest : public ::testing::Test {

shared_model::proto::Block makeBlock(int height) {
return TestBlockBuilder()
.txNumber(0)
.transactions(std::vector<shared_model::proto::Transaction>())
.height(height)
.prevHash(shared_model::crypto::Hash(std::string("0", 32)))
Expand Down
2 changes: 0 additions & 2 deletions test/module/irohad/torii/torii_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ TEST_F(ToriiServiceTest, StatusWhenBlocking) {
TestBlockBuilder()
.transactions(txs)
.height(1)
.txNumber(txs.size())
.createdTime(0)
.prevHash(shared_model::crypto::Hash(std::string(32, '0')))
.build());
Expand Down Expand Up @@ -394,7 +393,6 @@ TEST_F(ToriiServiceTest, StreamingFullPipelineTest) {
.height(1)
.createdTime(iroha::time::now())
.transactions(txs)
.txNumber(1)
.prevHash(crypto::Hash(std::string(32, '0')))
.build()
.signAndAddSignature(keypair));
Expand Down
1 change: 0 additions & 1 deletion test/module/irohad/validation/chain_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class ChainValidationTest : public ::testing::Test {
auto getBlockBuilder() const {
return TestBlockBuilder()
.transactions(std::vector<shared_model::proto::Transaction>{})
.txNumber(0)
.height(1)
.prevHash(hash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class TransportBuilderTest : public ::testing::Test {
auto createBlock() {
return TestBlockBuilder()
.transactions(std::vector<Transaction>({createTransaction()}))
.txNumber(1)
.height(1)
.prevHash(crypto::Hash("asd"))
.createdTime(created_time)
Expand All @@ -94,7 +93,6 @@ class TransportBuilderTest : public ::testing::Test {
auto createInvalidBlock() {
return TestBlockBuilder()
.transactions(std::vector<Transaction>({createTransaction()}))
.txNumber(1)
.height(1)
.prevHash(crypto::Hash("asd"))
.createdTime(123) // invalid time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ TEST(JsonProtoConverterTest, JsonToProtoBlockTest) {
auto orig_block =
block_builder.transactions(std::vector<Transaction>({tx_builder.build()}))
.createdTime(123)
.txNumber(1)
.build();

auto json = modelToJson(orig_block);
Expand Down

0 comments on commit 5a60e08

Please sign in to comment.