-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shared model: update blob on addSignature
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
- Loading branch information
Showing
7 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
test/module/shared_model/backend_proto/shared_proto_add_signature_test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
#include "backend/protobuf/block.hpp" | ||
#include "backend/protobuf/queries/proto_blocks_query.hpp" | ||
#include "backend/protobuf/queries/proto_query.hpp" | ||
#include "backend/protobuf/transaction.hpp" | ||
|
||
using namespace shared_model::crypto; | ||
using namespace shared_model::proto; | ||
|
||
template <typename T> | ||
class SharedProtoAddSignatureTest : public ::testing::Test {}; | ||
|
||
using ModelTypes = ::testing::Types<Block, BlocksQuery, Transaction, Query>; | ||
TYPED_TEST_SUITE(SharedProtoAddSignatureTest, ModelTypes, ); | ||
|
||
/// empty initializer | ||
template <typename T> | ||
auto initializeProto(T &proto) {} | ||
|
||
/// initializes query with the first specific type | ||
template <> | ||
auto initializeProto(Query::TransportType &proto) { | ||
auto payload = proto.mutable_payload(); | ||
auto refl = payload->GetReflection(); | ||
auto desc = payload->GetDescriptor()->FindOneofByName("query"); | ||
auto field = desc->field(0); | ||
refl->SetAllocatedMessage( | ||
payload, refl->GetMessage(*payload, field).New(), field); | ||
} | ||
|
||
/** | ||
* @given signable object with its shared model wrapper | ||
* @when a signature is added | ||
* @then it is reflected in wrapper blob getter result | ||
*/ | ||
TYPED_TEST(SharedProtoAddSignatureTest, AddSignature) { | ||
typename TypeParam::TransportType proto; | ||
initializeProto(proto); | ||
TypeParam model{proto}; | ||
|
||
Signed signature{"signature"}; | ||
PublicKey public_key{"public_key"}; | ||
|
||
model.addSignature(signature, public_key); | ||
|
||
typename TypeParam::TransportType new_proto; | ||
new_proto.ParseFromString(toBinaryString(model.blob())); | ||
TypeParam new_model{new_proto}; | ||
|
||
auto signatures = new_model.signatures(); | ||
ASSERT_EQ(1, boost::size(signatures)); | ||
ASSERT_EQ(signature, signatures.front().signedData()); | ||
ASSERT_EQ(public_key, signatures.front().publicKey()); | ||
} |