Skip to content
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

Add support to run unit tests in both Legacy and Savanna (Part 1) #145

Merged
merged 3 commits into from
May 16, 2024

Conversation

linh2931
Copy link
Member

@linh2931 linh2931 commented May 15, 2024

This PR (and subsequent ones) addresses those requirements:

  • for any unit test which can be run in both Legacy and Savanna (majority of our unit tests are), we would like CICD to run it in both modes,
  • for any tests which can be only run in Legacy or Savanna, place in a separate file,
  • we want to easily turn off and remove Legacy testing some time in the future

This is the first PR which demonstrates how running both modes can be achieved. After it is approved, it will be applied to other tests.

Both BOOST_AUTO_TEST_CASE_TEMPLATE and BOOST_FIXTURE_TEST_CASE_TEMPLATE work. Either involves about the same amount of coding. If an original test already use tester chain; declaration, BOOST_AUTO_TEST_CASE_TEMPLATE requires fewer changes; if it uses a fixture, BOOST_FIXTURE_TEST_CASE_TEMPLATE can be used, but it requires adding this or T in front of methods.

BOOST_AUTO_TEST_CASE_TEMPLATE( missing_sigs, T, validating_testers ) { try {
   T chain;
   chain.create_accounts( {"alice"_n} );

BOOST_FIXTURE_TEST_CASE_TEMPLATE( missing_sigs, T, validating_testers, T ) { try {
   this->create_accounts( {"alice"_n} );
   or
   T::create_accounts( {"alice"_n} );

Partially resolves #11

@linh2931 linh2931 requested a review from heifner May 15, 2024 19:45
//todoBOOST_REQUIRE_EQUAL(true, chain_has_transaction(trace->id));

} FC_LOG_AND_RETHROW() }


BOOST_AUTO_TEST_CASE(update_auths) {
try {
validating_tester chain;
savanna_validating_tester chain;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chain.find on line 120 below causes compilation failure when BOOST_AUTO_TEST_CASE_TEMPLATE is used. We test Savanna for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just need chain.template find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("owner")));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank! It worked.

@arhag arhag linked an issue May 15, 2024 that may be closed by this pull request
@arhag arhag requested review from arhag and spoonincode May 15, 2024 20:02
create_accounts( {"alice"_n} );
produce_block();
BOOST_AUTO_TEST_CASE_TEMPLATE( missing_sigs, TESTER, validating_testers ) { try {
TESTER chain;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if there was a way to combine BOOST_AUTO_TEST_CASE_TEMPLATE and BOOST_FIXTURE_TEST_CASE so that TESTER chain; was not needed. I don't see a way to do that, but maybe @spoonincode might know a way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can use the (sparsely documented?1) BOOST_FIXTURE_TEST_CASE_TEMPLATE for example

BOOST_AUTO_TEST_CASE_TEMPLATE( missing_sigs, T, validating_testers, T ) { try {

but there is a problem with dependent lookup so you're going to get stuck with doing either

BOOST_AUTO_TEST_CASE_TEMPLATE( missing_sigs, T, validating_testers, T ) { try {
   this->create_accounts( {"alice"_n} );
   T::produce_block();

so it's not immediately clear to me if it's any better or not.

Footnotes

  1. I only found it documented at the very bottom of this page https://www.boost.org/doc/libs/1_85_0/libs/test/doc/html/boost_test/tests_organization/decorators/explicit_decorator_declaration.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this. Either way is fine. But I think chain.create_accounts is more readable. We can just keep it as is.

@linh2931 linh2931 merged commit 1874c5f into main May 16, 2024
36 checks passed
@linh2931 linh2931 deleted the unittest_svnn_and_legacy branch May 16, 2024 13:16
@ericpassmore
Copy link
Contributor

Note:start
group: IF
category: TEST
summary: Run unit tests in both Legacy DPOS and Savanna Consensus Modes, part 1.
Note:end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create IF versions of applicable unittests
4 participants