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

test: Implement unit testing for miner sector deals extraction #994

Merged
merged 2 commits into from
Jun 23, 2022

Conversation

frrist
Copy link
Member

@frrist frrist commented Jun 18, 2022

What

This PR:

  • creates unit tests for the SectorDealsExtractor and LoadMinerStates methods.
  • makes some changes to the SectorDealsExtractor to improve its testability by moving the extraction logic to a new method - ExtractSectorDealsModel - which accepts interfaces that may be mocked to mimic a miners state.
  • defines a new method MinerLoad on the DataSource API permitting the miner extractors to load mocked miner states for easier testing.

@frrist frrist self-assigned this Jun 18, 2022
@frrist frrist marked this pull request as ready for review June 18, 2022 00:27
@@ -0,0 +1,677 @@
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
Copy link
Member Author

Choose a reason for hiding this comment

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

Code generate mocks for the miner state interface as it's quite large.

@@ -275,6 +276,10 @@ func (t *DataSource) ExecutedAndBlockMessages(ctx context.Context, ts, pts *type
return value.(*lens.TipSetMessages), nil
}

func (t *DataSource) MinerLoad(store adt.Store, act *types.Actor) (miner.State, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Move the logic responsible for loading miners from the blockstore to an interface allowing tests to use mocked miner state for validation.

@@ -14,6 +14,7 @@ import (
"github.com/filecoin-project/lily/chain/indexer/integrated/tipset"
"github.com/filecoin-project/lily/model"
visormodel "github.com/filecoin-project/lily/model/visor"
"github.com/filecoin-project/lily/testutil"
Copy link
Member Author

Choose a reason for hiding this comment

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

mechanical change: package rename

"github.com/filecoin-project/lily/tasks/actorstate"
)

type State interface {
Copy link
Member Author

Choose a reason for hiding this comment

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

The state type used by miner extractors. Presents a (mockable) interface for gathering miner data for extraction

return ExtractSectorDealsModel(ctx, ec)
}

func ExtractSectorDealsModel(ctx context.Context, ec extraction.State) (minermodel.MinerSectorDealList, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Move the model extraction logic to a testable method. extraction.State is an interface we can mock.

@frrist frrist changed the title Implement unit testing for miner sector deals extraction test: Implement unit testing for miner sector deals extraction Jun 21, 2022
Copy link
Contributor

@placer14 placer14 left a comment

Choose a reason for hiding this comment

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

Great work!

@frrist frrist merged commit b9bc25d into master Jun 23, 2022
@frrist frrist deleted the frrist/miner-sector-deals-test branch June 23, 2022 00:25
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.

2 participants