mobilecoinfoundation / mobilecoin

Private payments for mobile devices.
Other
1.16k stars 148 forks source link

De-duplicate test-utils #1467

Open cbeck88 opened 2 years ago

cbeck88 commented 2 years ago

Numerous core crates come also with a "test-utils" crate (although sometimes the test-utils come in a submodule).

mc-transaction-core-test-utils mc-ledger-db::test_utils mobilecoind-test-utils

Some of these test-utils crates have a lot of very similar (possibly the same?) functionality:

In mc-transaction-core-test-utils:

In mc-transaction-std, we have separate, slightly different versions of create_transaction in the tests module.

In mc-ledger-db-test-utils, get_test_ledger_blocks is almost the same transaction-core-test-utils::get_blocks.

In ledger/sync/src/test_app/main.rs we have functions like _make_ledger_long which takes a ledger and adds a bunch of blocks to it. This is almost exactly the same as mc_transaction_core_test_utils::initialize_ledger.

In mobilecoind::test_utils, add_block_to_ledger_db is almost the same as mc-transaction-core-test-utils::initialize_ledger and the _make_ledger_long.

We could likely have 2 or 3 functions instead of 10. This would make it much easier to read and maintain this test code, if we just had one flexible "add blocks to ledger" function instead of 3 or 4 variations on a theme that no one can remember the differences between. It would also make it much easier in the future when we have to make changes to TxOut or TransactionBuilder, which will happen whenever we want to ship new features into the blockchain.

remoun commented 2 years ago

I did some of this in #2052, which I hope to merge next week.