GolosChain / golos

Socio-economic mediablockchain
https://developers.golos.io
Other
59 stars 36 forks source link

Research and analyze fc::reflect work. Get reflection reference values. Write tests. #466

Open AKorpusenko opened 6 years ago

AKorpusenko commented 6 years ago
  1. Analyze code of fc::reflect. Figure out what exactly fc::reflect is able to handle.
  2. Write a script which analyzes the golos code base and returns all usages FC_REFLECT (and etc) macro to get the reference values. It can be presented as a simple list.
  3. Cover all cases of fc::reflect usage with tests.
AKorpusenko commented 6 years ago

This issue is pretty big, so we've decided to split the task on few basic steps.

  1. Write a test for a random structure which was reflected with FC_REFLECT. Fill the members of that structure with some values and check that fc::raw::pack work ok with it. Check that unpack is still working ok. Check that fc::variant works ok with this structure too, I also mean to_string and from_string methods.
  2. Write a code generator script which generates such checks for all reflected structures in the project (and greps them first). Write separate functions for different reflect macroses.
AKorpusenko commented 6 years ago

I've decided to write full description of script work.

AKorpusenko commented 6 years ago

Right now 128 of 275 structures have been covered with randomized tests. @kotbegemot , @marijadia

AKorpusenko commented 6 years ago

@marijadia , @kotbegemot So, task status for today:

  1. All reflected structures are covered with the tests. You can check this out in branch 466 and last commits.
  2. Test are commented (with //) only for enums and database objects (which inherit chainbase object and got no default constructor)
  3. There are some problems with compiling. Solving them.
AKorpusenko commented 6 years ago

The main trouble now is that there are tons of structures that can not be packed with fc::pack.

AKorpusenko commented 6 years ago

:hammer_and_wrench: As u can see in latest commit. I've made possible to create database objects inside of a test case. For example:

            db = & appbase::app().get_plugin<golos::plugins::chain::plugin>().db();
            const auto& v1 = db->create<golos::plugins::private_message::message_object>(
                [&]( golos::plugins::private_message::message_object& obj ) {
                set_random_value( obj.from );
                set_random_value( obj.to );
                set_random_value( obj.from_memo_key );
                set_random_value( obj.to_memo_key );
                set_random_value( obj.sent_time );
                set_random_value( obj.receive_time );
                set_random_value( obj.checksum );
                set_random_value( obj.encrypted_message );

            } );

            auto& v2 = db->create<golos::plugins::private_message::message_object>(
                [&]( golos::plugins::private_message::message_object& obj ) {
            } );

:face_with_head_bandage: The main trouble for now is unpacking database objects (using fc::raw::unpack).

AKorpusenko commented 6 years ago

First, #518 have to be done. :gear:

AKorpusenko commented 6 years ago

Issue #518 is closed as there is no need to do what's written there to move forward.

AKorpusenko commented 6 years ago

@kotbegemot , @afalaleev I've got problem with fc::raw::pack when it tries to pack any object which uses boost::interprocess::allocator. For now I comment down all such cases to make tests compile. But in some test cases such errors can not be resolved at all, because fc::raw::pack wasn't made in such way to cover this cases.

For example u can look at golos::chain::category_object and it's field shared_string name;. As you can see shared_string is a typedef: typedef boost::interprocess::basic_string<char, std::char_traits<char>, allocator<char>> shared_string;