Skip to content

Commit

Permalink
Update set_finalizers_tests
Browse files Browse the repository at this point in the history
* Fixed breaking strict-aliasing rules
* Added public key check
  • Loading branch information
linh2931 committed Dec 7, 2023
1 parent 5e504d3 commit cb73eae
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions tests/integration/set_finalizers_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,12 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try {

produce_block();

const std::vector<uint8_t> G1 = {0x22, 0x0e, 0xf5, 0xc4, 0x9c, 0x18, 0x68, 0xe8,
0x5b, 0x82, 0x65, 0x8d, 0xf9, 0x76, 0x6f, 0xc2,
0xce, 0xe4, 0xbd, 0x0b, 0x5d, 0x98, 0x80, 0xd4,
0xcd, 0xee, 0x91, 0x39, 0xed, 0xd3, 0xc4, 0xeb,
0xda, 0xe4, 0x07, 0x4f, 0x1d, 0x3d, 0xb3, 0xf3,
0xc9, 0x21, 0x39, 0x62, 0x94, 0x2e, 0xef, 0x09,
0x1b, 0x00, 0xd9, 0xf2, 0xa9, 0xb8, 0x37, 0x01,
0x5c, 0x8d, 0xbe, 0x50, 0x7f, 0x24, 0x2a, 0xee,
0x45, 0x92, 0x72, 0x58, 0x9b, 0x6b, 0x29, 0x73,
0xbc, 0xf3, 0x3e, 0xb4, 0x60, 0x87, 0x22, 0xc7,
0x0c, 0x1a, 0xc3, 0xd1, 0xad, 0xe4, 0x0c, 0x84,
0x5b, 0x9e, 0x15, 0xea, 0x63, 0x80, 0x08, 0x0a}; // 12x8 = 96 bytes

push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo()
("fin_set", mvo()("fthreshold", 1)
("finalizers", std::vector<mvo>{mvo()
("description", "test_desc")
("fweight", 1)
("public_key_g1_affine_le", *reinterpret_cast<const std::vector<char>*>(&G1))})));
("public_key_g1_affine_le", "220ef5c49c1868e85b82658df9766fc2cee4bd0b5d9880d4cdee9139edd3c4ebdae4074f1d3db3f3c9213962942eef091b00d9f2a9b837015c8dbe507f242aee459272589b6b2973bcf33eb4608722c70c1ac3d1ade40c845b9e15ea6380080a")})));

This comment has been minimized.

Copy link
@greg7mdp

greg7mdp Dec 7, 2023

That's not equivalent. 0x22 != "22".

This comment has been minimized.

Copy link
@linh2931

linh2931 Dec 7, 2023

Author Member

Thank you so much! I did it without thinking... LOL

This comment has been minimized.

Copy link
@greg7mdp

greg7mdp Dec 7, 2023

You could do: "\x22\x0e\xf5..."

This comment has been minimized.

Copy link
@linh2931

linh2931 Dec 8, 2023

Author Member

Actually the 220ef5... is correct. The FC variant conversion treats them as hex digits and automatically converts them into binary. No change is needed.

This comment has been minimized.

Copy link
@greg7mdp

greg7mdp Dec 8, 2023

amazing!

signed_block_ptr cur_block = produce_block();
fc::variant pretty_output;
abi_serializer::to_variant( *cur_block, pretty_output, get_resolver(), fc::microseconds::maximum() );
Expand All @@ -51,7 +38,7 @@ BOOST_FIXTURE_TEST_CASE(set_finalizers_test, tester) try {
BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"].size(), 1u);
BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"][size_t(0)]["description"], "test_desc");
BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"][size_t(0)]["fweight"], 1);
//TODO: add key check here after base64 support will be added
BOOST_REQUIRE_EQUAL(pretty_output["proposed_finalizer_policy"]["finalizers"][size_t(0)]["public_key"], "PUB_BLS_Ig71xJwYaOhbgmWN+XZvws7kvQtdmIDUze6ROe3TxOva5AdPHT2z88khOWKULu8JGwDZ8qm4NwFcjb5QfyQq7kWSclibaylzvPM+tGCHIscMGsPRreQMhFueFepjgAgKXjOb8g==");

// testing wrong public key size
BOOST_CHECK_THROW(push_action(config::system_account_name, "setfinal"_n, "test"_n, mvo()
Expand Down

0 comments on commit cb73eae

Please # to comment.