Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
Fix develop (#1534)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergei <[email protected]>
  • Loading branch information
Solonets authored and l4l committed Jul 25, 2018
1 parent 58da20d commit 610a970
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
53 changes: 44 additions & 9 deletions test/module/shared_model/validators/transaction_validator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class TransactionValidatorTest : public ValidatorsTest {

TestTransactionBuilder builder;
auto tx = builder.creatorAccountId(creator_account_id)
.createdTime(created_time)
.quorum(1)
.build()
.getTransport();
.createdTime(created_time)
.quorum(1)
.build()
.getTransport();
return tx;
}
shared_model::validation::DefaultTransactionValidator transaction_validator;
Expand Down Expand Up @@ -111,13 +111,22 @@ TEST_F(TransactionValidatorTest, StatelessValidTest) {

ASSERT_FALSE(answer.hasErrors()) << answer.reason();
}

/**
* @given transaction made of commands with valid fields
* @when commands validation is invoked
* @then answer has no errors
* @given Protobuf transaction object with unset command
* @when validate is called
* @then there is a error returned
*/
TEST_F(TransactionValidatorTest, BatchValidTest) {
std::string creator_account_id = "admin@test";
TEST_F(TransactionValidatorTest, UnsetCommand) {
iroha::protocol::Transaction tx = generateEmptyTransaction();
tx.mutable_payload()->mutable_reduced_payload()->set_creator_account_id(
account_id);
tx.mutable_payload()->mutable_reduced_payload()->set_created_time(
created_time);
auto answer = transaction_validator.validate(proto::Transaction(tx));
tx.mutable_payload()->mutable_reduced_payload()->add_commands();
ASSERT_TRUE(answer.hasErrors());
}

/**
* @given transaction made of commands with invalid fields
Expand Down Expand Up @@ -155,3 +164,29 @@ TEST_F(TransactionValidatorTest, StatelessInvalidTest) {
ASSERT_EQ(answer.getReasonsMap().size(),
iroha::protocol::Command::descriptor()->field_count() + 1);
}
/**
* @given transaction made of commands with valid fields
* @when commands validation is invoked
* @then answer has no errors
*/
TEST_F(TransactionValidatorTest, BatchValidTest) {
std::string creator_account_id = "admin@test";

TestTransactionBuilder builder;
auto tx = builder.creatorAccountId(creator_account_id)
.createdTime(created_time)
.quorum(1)
.batchMeta(interface::types::BatchType::ATOMIC,
std::vector<interface::types::HashType>())
.createDomain("test", "test")
.build()
.getTransport();
shared_model::validation::DefaultTransactionValidator transaction_validator;
auto result = proto::Transaction(iroha::protocol::Transaction(tx));
auto answer = transaction_validator.validate(result);

ASSERT_FALSE(answer.hasErrors()) << answer.reason();
ASSERT_EQ(tx.payload().batch().type(),
static_cast<int>(interface::types::BatchType::ATOMIC));
}

2 changes: 1 addition & 1 deletion test/module/shared_model/validators/validators_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class ValidatorsTest : public ::testing::Test {
void *ptr = new std::shared_ptr<google::protobuf::Message>(mcopy);
std::shared_ptr<google::protobuf::Message> *m =
static_cast<std::shared_ptr<google::protobuf::Message> *>(ptr);
iterateContainerRecursive(*m, field_validators, field_op, validator);
this->iterateContainerRecursive(*m, field_validators, field_op, validator);
}
});
}
Expand Down

0 comments on commit 610a970

Please sign in to comment.