Skip to content

Commit

Permalink
chore(SPV-1169): ErrorAssert
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain committed Nov 14, 2024
1 parent e4dce8c commit f34bbf7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 2 additions & 4 deletions engine/transaction/record/record_outline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ func TestRecordOutlineOpReturnErrorCases(t *testing.T) {
err := service.RecordTransactionOutline(context.Background(), test.outline)

// then:
then.WithErrorIs(err, test.expectErr)
then.NothingChanged()
then.WithErrorIs(err, test.expectErr).NothingChanged()
})
}
}
Expand Down Expand Up @@ -312,8 +311,7 @@ func TestOnBroadcastErr(t *testing.T) {
err := service.RecordTransactionOutline(context.Background(), outline)

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

func ptr[T any](value T) *T {
Expand Down
13 changes: 8 additions & 5 deletions engine/transaction/record/testabilities/assert_record_outline.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
"github.com/stretchr/testify/require"
)

type ErrorAssert interface {
NothingChanged()
}

type RecordOutlineAssert interface {
WithNoError(err error) SuccessfullyCreatedRecordOutlineAssertion
WithErrorIs(err, expectedError error)
WithErrorIs(err, expectedError error) ErrorAssert

StoredOutputs([]database.Output) RecordOutlineAssert
StoredData([]database.Data) RecordOutlineAssert
NothingChanged() RecordOutlineAssert
}

type SuccessfullyCreatedRecordOutlineAssertion interface {
Expand All @@ -40,9 +43,10 @@ func (a *assert) WithNoError(err error) SuccessfullyCreatedRecordOutlineAssertio
return a
}

func (a *assert) WithErrorIs(err, expectedError error) {
func (a *assert) WithErrorIs(err, expectedError error) ErrorAssert {
require.Error(a.t, err, "Record transaction outline has no error")
require.ErrorIs(a.t, err, expectedError, "Record transaction outline has wrong error")
return a
}

func (a *assert) Broadcasted(txID string) SuccessfullyCreatedRecordOutlineAssertion {
Expand All @@ -69,8 +73,7 @@ func (a *assert) StoredData(data []database.Data) RecordOutlineAssert {
return a
}

func (a *assert) NothingChanged() RecordOutlineAssert {
func (a *assert) NothingChanged() {
require.ElementsMatch(a.t, a.given.initialOutputs, a.given.repository.GetAllOutputs(), "Outputs are changed")
require.ElementsMatch(a.t, a.given.initialData, a.given.repository.GetAllData(), "Data are changed")
return a
}

0 comments on commit f34bbf7

Please sign in to comment.