Skip to content

Tests: Consistent resource/account struct tests#4669

Merged
michaeldiamant merged 5 commits into
algorand:masterfrom
jasonpaulos:consistent-struct-tests
Oct 20, 2022
Merged

Tests: Consistent resource/account struct tests#4669
michaeldiamant merged 5 commits into
algorand:masterfrom
jasonpaulos:consistent-struct-tests

Conversation

@jasonpaulos
Copy link
Copy Markdown
Contributor

Summary

This PR adds new unit tests that use reflection to ensure the following sets of structs have consistent fields:

  • resourcesData (from ledger/accountdb.go) has all fields from basics.AppLocalState, basics.AppParams, basics.AssetHolding, and basics.AssetParams
  • baseAccountData (from ledger/accountdb.go), ledercore.AccountData, and basics.AccountData all have consistent fields.

When introducing a new account or resource field, it's all too easy to forgot to update all of these structs. These tests will fail if that's not done properly.

Additionally, this PR also adds ledger/testing/randomAccounts_test.go, which ensures the distribution of random accounts from RandomAccounts adheres to the following property: for every field in basics.AccountData, there is high probability that at least one randomly generated account will have a nonzero value for that field, and another randomly generated account will have a zero value for that field. This property ensures that RandomAccounts is aware of all fields in basics.AccountData, and that each field may or may not be present in an account (with some exceptions).

On the implementation side, I added to the existing reflection testing infrastructure from data/basics/fields_test.go and moved it into its own package.

Test Plan

New tests added.

@jasonpaulos jasonpaulos changed the title Consistent struct tests Tests: Consistent resource/account struct tests Oct 18, 2022
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 18, 2022

Codecov Report

Merging #4669 (d6f6199) into master (3f1f3e4) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #4669      +/-   ##
==========================================
+ Coverage   54.39%   54.40%   +0.01%     
==========================================
  Files         403      407       +4     
  Lines       51921    52376     +455     
==========================================
+ Hits        28240    28495     +255     
- Misses      21300    21503     +203     
+ Partials     2381     2378       -3     
Impacted Files Coverage Δ
ledger/testing/randomAccounts.go 55.59% <100.00%> (ø)
ledger/tracker.go 74.89% <0.00%> (-2.98%) ⬇️
ledger/testing/accountsTotals.go 0.00% <0.00%> (ø)
ledger/testing/testGenesis.go 0.00% <0.00%> (ø)
ledger/testing/initState.go 12.28% <0.00%> (ø)
network/wsNetwork.go 65.80% <0.00%> (+0.46%) ⬆️
ledger/acctupdates.go 70.19% <0.00%> (+0.59%) ⬆️
catchup/service.go 68.88% <0.00%> (+0.74%) ⬆️
catchup/peerSelector.go 100.00% <0.00%> (+1.04%) ⬆️
... and 6 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jasonpaulos jasonpaulos requested a review from jannotti October 19, 2022 01:42
Comment thread ledger/accountdb_test.go Outdated
Comment thread ledger/testing/randomAccounts_test.go Outdated
Comment thread ledger/accountdb_test.go Outdated
algorandskiy
algorandskiy previously approved these changes Oct 19, 2022
Copy link
Copy Markdown
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

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

This is a great addition to the test suite

Copy link
Copy Markdown
Contributor

@michaeldiamant michaeldiamant left a comment

Choose a reason for hiding this comment

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

@jasonpaulos Great improvement in correctness confidence here - thanks for the effort to devise + implement these tests! ☕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants