8000 [test] Small unit test improvements, including helper to make mempool transaction by amitiuttarwar · Pull Request #21121 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[test] Small unit test improvements, including helper to make mempool transaction #21121

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

Merged
merged 5 commits into from
Feb 17, 2021

Conversation

amitiuttarwar
Copy link
Contributor
@amitiuttarwar amitiuttarwar commented Feb 8, 2021

Some miscellaneous improvements that came up when working on #21061

  • The first commit is a helper to make valid mempool transactions & submit via ATMP. Introducing in this PR, using in [p2p] Introduce node rebroadcast module  #21061.
  • The second commit is a small improvement in miner_tests.cpp that uses BOOST_REQUIRE_EQUAL to properly terminate the program instead of segfaulting in the failure scenario where the blocks do not include the expected number of transactions.
  • The third commit changes the function signature of GetMockTime() to return a chrono type.
  • The fourth & fifth commit overload SetMockTime to also accept chrono type, and adds documentation to indicate that the int64_t function signature is deprecated.

@amitiuttarwar
Copy link
Contributor Author

the failing test seems unrelated. The failure is in feature_assumevalid.py, which seems hard to impact from changes that exclusively touch the unit tests, unit test framework, and some comments :)

@DrahtBot
Copy link
Contributor
DrahtBot commented Feb 9, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

/**
* For testing. Set e.g. with the setmocktime rpc, or -mocktime argument
*
* @param[in] nMockTimeIn Time in seconds.
Copy link
Member

Choose a reason for hiding this comment

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

Probably more of a hassle, but another way to document would be to use std::chrono types with explicit units.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I took a quick look at changing the signature to a chrono type, but ended up taking the efficient/lazy way for now. there are a couple tweaks that would need to be made to switch it over, nothing difficult but not currently at the top of my priority list

so I thought leaving a comment was the smallest way to help :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the latest push, I updated the function signature of GetMockTime, with updated call sites. I also overloaded SetMockTime to take in chronos. This does mean I introduced another function that doesn't get used until #21061, so I can remove if you'd prefer.

@laanwj
Copy link
Member
laanwj commented Feb 10, 2021

Code review ACK e757330

The new function is added but not used (so not tested), I would prefer if it was, but I guess it can wait until #21061.

@amitiuttarwar
Copy link
Contributor Author

@vasild- thanks for the review! I've taken all your suggestions locally, but I'm currently getting a linker error when trying to #include <boost/test/unit_test.hpp> in setup_common.cpp (to use BOOST_REQUIRE). I'll dig into it more tomorrow, but just dropping a line here incase you (or anybody else) knows the cause off hand.

@vasild
Copy link
Contributor
vasild commented Feb 12, 2021

@amitiuttarwar, I see no boost code is used in setup_common.cpp. Maybe it would be easier to use assert() inside CreateValidMempoolTransaction() instead or somehow signal a failure from that method and make the callers use BOOST_REQUIRE() to ensure that it succeeded.

@maflcko
Copy link
Member
maflcko commented Feb 12, 2021

It is only allowed to use boost in the unit tests, not the fuzz tests (or other tests). setup_common is used by all test and bench libraries.

@amitiuttarwar amitiuttarwar force-pushed the 2021-01-unit-test-valid-tx branch from e757330 to 167f442 Compare February 12, 2021 18:42
@amitiuttarwar
Copy link
Contributor Author

ah interesting. used asserts instead. thanks!

took all the feedback.

  • added asserts to CreateValidMempool helper
  • changed GetMockTime to return chrono time, updated the call sites
  • introduced a SetMockTime that takes in chrono time, did not update call sites, but documented in the notes that the int64_t is deprecated and the chrono one should be used

this means that in this commit, I introduce CreateValidMempoolTransaction and SetMockTime(std::chrono::seconds), but they are currently unused. I tested them by locally applying #21061, but ofc there is no guarantee that PR will be merged. if reviewers prefer, I can remove commit 88e62f7 Introduce a SetTMockTime that takes chrono time.

@amitiuttarwar amitiuttarwar force-pushed the 2021-01-unit-test-valid-tx branch from 167f442 to 82de557 Compare February 12, 2021 19:37
@amitiuttarwar
Copy link
Contributor Author

fixed a silent merge conflict since the function signature of ATMP has changed. updated #21061 to use e020cd6 to test the helper.

@amitiuttarwar amitiuttarwar force-pushed the 2021-01-unit-test-valid-tx branch from 82de557 to 903bbf7 Compare February 15, 2021 22:16
@amitiuttarwar
Copy link
Contributor Author

updated to incorporate feedback from @vasild

@vasild
Copy link
Contributor
vasild commented Feb 16, 2021

ACK 903bbf7

@amitiuttarwar amitiuttarwar force-pushed the 2021-01-unit-test-valid-tx branch from 903bbf7 to 1363b6c Compare February 16, 2021 20:23
@amitiuttarwar
Copy link
Contributor Author

rebased

@vasild
Copy link
Contributor
vasild commented Feb 17, 2021

ACK 1363b6c

@maflcko maflcko merged commit 569b5ba into bitcoin:master Feb 17, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 17, 2021
…elper to make mempool transaction

1363b6c [doc / util] Use comments to clarify time unit for int64_t type. (Amiti Uttarwar)
47a7a16 [util] Introduce a SetMockTime that takes chrono time (Amiti Uttarwar)
df6a5fc [util] Change GetMockTime to return chrono type instead of int (Amiti Uttarwar)
a2d908e [test] Throw error instead of segfaulting in failure scenario (Amiti Uttarwar)
9a3bbe8 [test] Introduce a unit test helper to create a valid mempool transaction. (Amiti Uttarwar)

Pull request description:

  Some miscellaneous improvements that came up when working on bitcoin#21061
  - The first commit is a helper to make valid mempool transactions & submit via ATMP. Introducing in this PR, using in bitcoin#21061.
  - The second commit is a small improvement in `miner_tests.cpp` that uses `BOOST_REQUIRE_EQUAL` to properly terminate the program instead of segfaulting in the failure scenario where the blocks do not include the expected number of transactions.
  - The third commit changes the function signature of `GetMockTime()` to return a chrono type.
  - The fourth & fifth commit overload `SetMockTime` to also accept chrono type, and adds documentation to indicate that the `int64_t` function signature is deprecated.

ACKs for top commit:
  vasild:
    ACK 1363b6c

Tree-SHA512: c72574d73668ea04ee4c33858f8de68b368780f445e05afb569aaf8564093f8112259b3afe93cf6dc2ee12a1ab5af1130ac73c16416132c1ba2851c054a67d78
@amitiuttarwar amitiuttarwar deleted the 2021-01-unit-test-valid-tx branch February 17, 2021 21:48
@@ -123,6 +123,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
m_node.mempool->addUnchecked(entry.Fee(50000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));

std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 4);
Copy link
Contributor

Choose a reason for hiding this comment

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

Somehow this leads to a "comparison of integers of different signs" on bitcoinbuilds.org:
https://bitcoinbuilds.org/index.php?ansilog=982c61cf-6969-4001-bebc-dc215e5d29a4.log#l1906
Maybe only happening on older boost versions?

fanquake added a commit that referenced this pull request Feb 19, 2021
bedb8d8 Avoid comparision of integers with different signs (Jonas Schnelli)

Pull request description:

  Fixes an integer comparison of different signs (which errors out on `-Werror,-Wsign-compare`). Introduced in #21121.

  See https://bitcoinbuilds.org/index.php?ansilog=982c61cf-6969-4001-bebc-dc215e5d29a4.log

ACKs for top commit:
  MarcoFalke:
    review ACK bedb8d8
  amitiuttarwar:
    ACK bedb8d8
  vasild:
    ACK bedb8d8

Tree-SHA512: cb22a6239a1fc9d0be5573bf6ae4ec379eb7398c88edc8fa2ae4fd721f37f9ca3724896c1ac16de14a5286888a0b631813da32cb62d177ffbf9b2c31e716a7aa
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 19, 2021
…nt signs

bedb8d8 Avoid comparision of integers with different signs (Jonas Schnelli)

Pull request description:

  Fixes an integer comparison of different signs (which errors out on `-Werror,-Wsign-compare`). Introduced in bitcoin#21121.

  See https://bitcoinbuilds.org/index.php?ansilog=982c61cf-6969-4001-bebc-dc215e5d29a4.log

ACKs for top commit:
  MarcoFalke:
    review ACK bedb8d8
  amitiuttarwar:
    ACK bedb8d8
  vasild:
    ACK bedb8d8

Tree-SHA512: cb22a6239a1fc9d0be5573bf6ae4ec379eb7398c88edc8fa2ae4fd721f37f9ca3724896c1ac16de14a5286888a0b631813da32cb62d177ffbf9b2c31e716a7aa
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0