-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use constructor to construct action
instead of assigning members after the fact.
#951
base: main
Are you sure you want to change the base?
Conversation
test.account = "wasmtest"_n; | ||
test.name = account_name((uint64_t)index); | ||
test.authorization = {{"wasmtest"_n, config::active_name}}; | ||
action test({{"wasmtest"_n, config::active_name}}, "wasmtest"_n, account_name((uint64_t)index), {}); |
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 we found no way to regenerate these files properly? I think if anything should update the generator,
spring/unittests/wasm-spec-tests/generator/eosio_wasm_spec_test_generator.cpp
Lines 39 to 43 in f45de1f
func << " action test;\n"; | |
func << " test.account = \"wasmtest\"_n;\n"; | |
func << " test.name = account_name((uint64_t)index);\n"; | |
func << " test.authorization = {{\"wasmtest\"_n, config::active_name}};\n\n"; | |
func << " push_action(tester, std::move(test), \"wasmtest\"_n.to_uint64_t());\n"; |
btw it sure looks like AntelopeIO/wasm-spec-tests@026fb4b found a way to regenerate.
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.
Updated the generator b158e5b.
act.authorization = vector<permission_level>{{signer, config::active_name}}; | ||
act.data = abi_ser.variant_to_binary(action_type_name, data, abi_serializer::create_yield_function( T::abi_serializer_max_time )); | ||
action act(vector<permission_level>{{signer, config::active_name}}, "eosio.token"_n, name, | ||
abi_ser.variant_to_binary(action_type_name, data, abi_serializer::create_yield_function( T::abi_serializer_max_time ))); | ||
|
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 feel the original way of initializing individual fields explicitly clearer and more readable. action
is a data class and used most locally. It is probably appropriate to be a struct
without const.
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 very much disagree. Because action
has constructors, it implies that the object should be constructed using the provided constructors.
The direct member initialization forgoes any hope to ensure that objects are always constructed in a consistent fashion, and that some internal members (possibly dependent on the constructors parameters) are always initialized correctly. This is not the case for action
, but I feel it is a better pattern to follow.
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.
@arhag do you have an opinion on whether it is worthwhile to merge this PR?
Note:start |
This is an experiment attempting to make two members of
action_base
const.We likely do not want to merge the
const
change as it may cause other repo tests to fail (change in second commit 986562e). However this commit was removed in the current version of the PR.I propose that we merge the PR as it currently is. It does not change
action_base
, but updates our code to constructaction
using the constructor, instead of declaring a default constructed object and assigning the members after the fact.There should be no functional difference, besides constructing
action
with the constructor instead of individual member assignments.