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

feat(SPV-1169) testabilities for record transaction outline #761

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

chris-4chain
Copy link
Contributor

This PR waits for #759

Pull Request Checklist

  • πŸ“– I created my PR using provided : CODE_STANDARDS
  • πŸ“– I have read the short Code of Conduct: CODE_OF_CONDUCT
  • 🏠 I tested my changes locally.
  • βœ… I have provided tests for my changes.
  • πŸ“ I have used conventional commits.
  • πŸ“— I have updated any related documentation.
  • πŸ’Ύ PR was issued based on the Github or Jira issue.

Copy link

github-actions bot commented Nov 8, 2024

Manual Tests

ℹ️ Remember to ask team members to perform manual tests and to assign tested label after testing.

@codecov-commenter
Copy link

codecov-commenter commented Nov 8, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 105 lines in your changes missing coverage. Please review.

Project coverage is 45.16%. Comparing base (5623226) to head (b4bf7a3).

Files with missing lines Patch % Lines
...tion/record/testabilities/assert_record_outline.go 0.00% 32 Missing ⚠️
...ion/record/testabilities/fixture_record_outline.go 0.00% 30 Missing ⚠️
...ransaction/record/testabilities/mock_repository.go 0.00% 27 Missing ⚠️
...ansaction/record/testabilities/mock_broadcaster.go 0.00% 13 Missing ⚠️
...ion/record/testabilities/ability_record_outline.go 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #761      +/-   ##
==========================================
- Coverage   45.46%   45.16%   -0.31%     
==========================================
  Files         339      344       +5     
  Lines       17416    17547     +131     
==========================================
+ Hits         7919     7925       +6     
- Misses       8906     9033     +127     
+ Partials      591      589       -2     
Flag Coverage Ξ”
unittests 45.16% <0.00%> (-0.31%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Ξ”
...ion/record/testabilities/ability_record_outline.go 0.00% <0.00%> (ΓΈ)
...ansaction/record/testabilities/mock_broadcaster.go 0.00% <0.00%> (ΓΈ)
...ransaction/record/testabilities/mock_repository.go 0.00% <0.00%> (ΓΈ)
...ion/record/testabilities/fixture_record_outline.go 0.00% <0.00%> (ΓΈ)
...tion/record/testabilities/assert_record_outline.go 0.00% <0.00%> (ΓΈ)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 5623226...b4bf7a3. Read the comment docs.

@chris-4chain chris-4chain added the regression-tests Runs regression tests label Nov 12, 2024
@dorzepowski dorzepowski changed the base branch from main to feat/SPV-1169-mock-beef-gen November 14, 2024 11:20
Base automatically changed from feat/SPV-1169-mock-beef-gen to main November 15, 2024 11:04
@chris-4chain chris-4chain marked this pull request as ready for review November 15, 2024 11:45
@chris-4chain chris-4chain requested a review from a team as a code owner November 15, 2024 11:45
transactions: make(map[string]database.Transaction),
outputs: make(map[string]database.Output),
data: make(map[string]database.Data),
}
}

func (m *mockRepository) SaveTX(_ context.Context, txTable *database.Transaction, outputs []*database.Output, data []*database.Data) error {
func (m *MockRepository) SaveTX(_ context.Context, txTable *database.Transaction, outputs []*database.Output, data []*database.Data) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe some testabilities like:
WillFailOnSaveTX as a valuable test case? + such example in record_outline_test.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea
I'm adding this WillFailOnSaveTX and a test case for that πŸš€

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done πŸ˜„

@@ -36,7 +35,7 @@ func (m *mockRepository) SaveTX(_ context.Context, txTable *database.Transaction
return nil
}

func (m *mockRepository) GetOutputs(_ context.Context, outpoints iter.Seq[bsv.Outpoint]) ([]*database.Output, error) {
func (m *MockRepository) GetOutputs(_ context.Context, outpoints iter.Seq[bsv.Outpoint]) ([]*database.Output, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

And the same proposition here (but maybe it's too deep) to have WillFailOnGetOutputs? πŸ€”

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem πŸ‘

})
}
}

func TestOnBroadcastErr(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about more complex test cases like multiple error handling?
Example / pseudo code:

func TestRecordOutlineMultipleFailures(t *testing.T) {
    // given:
    given, then := testabilities.New(t)
    service := given.
        WithStoredOutputs(database.Output{
            TxID:       givenTXWithOpReturn(t).InputUTXO(0).TxID,
            Vout:       givenTXWithOpReturn(t).InputUTXO(0).Vout,
            SpendingTX: nil,
        }).
        WillFailOnSaveTX(errors.New("repository save error")).
        WillFailOnBroadcast(errors.New("broadcaster error")).
        NewRecordService()

    // and:
    outline := &outlines.Transaction{
        BEEF: givenTXWithOpReturn(t).BEEF(),
        Annotations: transaction.Annotations{
            Outputs: transaction.OutputsAnnotations{
                0: &transaction.OutputAnnotation{
                    Bucket: bucket.Data,
                },
            },
        },
    }

    // when:
    err := service.RecordTransactionOutline(context.Background(), outline)

    // then:
    then.WithErrorIs(err, txerrors.ErrTxRepositorySave).NothingChanged()
    then.WithErrorIs(err, txerrors.ErrTxBroadcast).NothingChanged()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That won't work like you're showing.
The error can be either ErrTxBroadcast or ErrTxRepositorySave - but not both at the same time.
Taking this into account - I don't think, such test will be beneficial.

WithNoError(err error) SuccessfullyCreatedRecordOutlineAssertion
WithErrorIs(err, expectedError error) ErrorAssert

StoredOutputs([]database.Output) RecordOutlineAssert
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought, don't have example πŸ˜…
What do you think about checking if the final "repository" state matches exactly what we intended without any additional entries?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean something like:

    then.WithNoError(err).
        Broadcasted(givenTXWithOpReturn(t).ID()).
        StoredOutputs(expectedOutputs).
        StoredData(expectedData)
actualOutputs := given.repository.GetAllOutputs()
actualData := given.repository.GetAllData()
    require.ElementsMatch(t, expectedOutputs, actualOutputs, "Repository contains unexpected outputs")
    require.ElementsMatch(t, expectedData, actualData, "Repository contains unexpected data")

And at the top define some expectedData used here as a parameter for require πŸ˜ƒ

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed from Subset to ElementsMatch, so now the behawior is as you described.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done πŸ˜„

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

Successfully merging this pull request may close these issues.

3 participants