-
Notifications
You must be signed in to change notification settings - Fork 296
Conversation
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
This allows addition of validator in the future Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
This allows addition of validator in the future Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
namespace shared_model { | ||
namespace interface { | ||
/** | ||
* CommonObjectsFactory provides methods to construct simple objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "simple object"? Can you, please, define it in more specific way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess "common_objects" is a better name here since they are in the folder with this name
/** | ||
* Create amount instance from string | ||
* | ||
* @param value integer will be divided by 10 * precision, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't this implementation issues, which should not be located in interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the description of the contract which factory provides.
It basically says that if you pass this precision, this is the final result you should get.
* For example: "1.23", "10" etc. | ||
*/ | ||
virtual FactoryResult<std::unique_ptr<Amount>> createAmount( | ||
std::string amount) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not const reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we modify this parameter in the code below. This logic was not written by me, and will be thrown out in the future, so it is simpler to just pass by value for now.
} // namespace interface | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_COMMONOBJECTSFACTORY_HPP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No empty line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is present
target_link_libraries(proto_common_objects_factory_test | ||
shared_model_cryptography | ||
shared_model_stateless_validation | ||
schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bracket on a new line?
} | ||
|
||
Validator validator_; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an empty space between curly braces in the beginning of the file, but not here
validator_.validatePeer(reasons, peer); | ||
}); | ||
|
||
if (answer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look very readable. Maybe, you should rename the variable to errors
? It represents something wrong happened only, so I think it's a reasonable name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you choose to follow the advice, change names of all variables in below functions as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answer can be empty, which indicates lack of errors. But i agree that errors is a better name here
// create uint256 value from obtained string | ||
boost::multiprecision::uint256_t value = 0; | ||
if (begin <= amount.size()) { | ||
value = boost::multiprecision::uint256_t(amount.substr(begin)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't overflow possible anywhere? Of course, I don't think someone's going to provide more than uint256, but still, for safety reasons, is it possible to handle such kind of error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is taken from lib/amount. It has worked so far, and I do not want to touch it :). It will be changed in the future, then we can replace it here
@@ -0,0 +1,259 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole file is implantation inside an .hpp, won't is cause troubles with recompiling etc? Isn't it better to split it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will only be used in setup of storage, so its fine.
TEST_F(PeerTest, InvalidPeerInitialization) { | ||
auto peer = factory.createPeer(invalid_address, valid_pubkey); | ||
|
||
peer.match( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't it be substituted with just ASSERT_TRUE(err(peer));
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, if you decide to follow, change it everywhere downwards as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue with err() is that it copies return result, but we have unique_ptr here.
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
e21faae
to
e40cb10
Compare
|
||
auto errors = validate(*proto_amount, [](const auto &, auto &) { | ||
// no validation needed, | ||
// since any amount is valid in general context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still validateAmount
function, so please use it
*/ | ||
|
||
#include <gtest/gtest.h> | ||
#include <ed25519/ed25519.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that the header should be here
#include <gtest/gtest.h> | ||
#include <ed25519/ed25519.h> | ||
|
||
#include "backend/protobuf/common_objects/amount.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That header should probably be in common_objects/common_objects_factory.hpp instead
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/benchmark/CMakeLists.txt # test/benchmark/bm_proto_creation.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
…ects_factory Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/module/shared_model/backend_proto/CMakeLists.txt
Signed-off-by: Nikita Alekseev <[email protected]> # Conflicts: # test/module/shared_model/backend_proto/CMakeLists.txt
55742bb
to
653b982
Compare
Allows to polymorphically create common objects Signed-off-by: Nikita Alekseev <[email protected]>
Allows to polymorphically create common objects Signed-off-by: Nikita Alekseev <[email protected]>
Allows to polymorphically create common objects Signed-off-by: Nikita Alekseev <[email protected]>
Allows to polymorphically create common objects Signed-off-by: Nikita Alekseev <[email protected]>
Allows to polymorphically create common objects Signed-off-by: Nikita Alekseev <[email protected]>
Allows to polymorphically create common objects Signed-off-by: Nikita Alekseev <[email protected]>
Allows to polymorphically create common objects Signed-off-by: Nikita Alekseev <[email protected]>
Description of the Change
This Pull Requests implements abstract factory for common objects in shared model.
There is an abstract factory as well as implementation in protobuf
Benefits
Can remove builders for common objects in the future
Possible Drawbacks
None
Alternate Designs [optional]
Builders are not needed since no fields are optional