Skip to content

Commit

Permalink
chore: Add tests for acknowledgement.Acknowledgement() (#3433)
Browse files Browse the repository at this point in the history
Co-authored-by: Jim Fasarakis-Hilliard <[email protected]>
Co-authored-by: colin axnér <[email protected]>
  • Loading branch information
3 people authored Apr 13, 2023
1 parent 1ebf293 commit 0e156f1
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions modules/core/04-channel/types/acknowledgement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,50 @@ const (
gasWanted = uint64(100)
)

// tests acknowledgement.ValidateBasic and acknowledgement.GetBytes
// tests acknowledgement.ValidateBasic and acknowledgement.Acknowledgement
func (suite TypesTestSuite) TestAcknowledgement() { //nolint:govet // this is a test, we are okay with copying locks
testCases := []struct {
name string
ack types.Acknowledgement
expSuccess bool // indicate if this is a success or failed ack
expPass bool
name string
ack types.Acknowledgement
expValidates bool
expBytes []byte
expSuccess bool // indicate if this is a success or failed ack
}{
{
"valid successful ack",
types.NewResultAcknowledgement([]byte("success")),
true,
[]byte(`{"result":"c3VjY2Vzcw=="}`),
true,
},
{
"valid failed ack",
types.NewErrorAcknowledgement(fmt.Errorf("error")),
false,
true,
[]byte(`{"error":"ABCI code: 1: error handling packet: see events for details"}`),
false,
},
{
"empty successful ack",
types.NewResultAcknowledgement([]byte{}),
true,
false,
nil,
true,
},
{
"empty failed ack",
types.NewErrorAcknowledgement(fmt.Errorf(" ")),
false,
true,
[]byte(`{"error":"ABCI code: 1: error handling packet: see events for details"}`),
false,
},
{
"nil response",
types.Acknowledgement{
Response: nil,
},
false,
nil,
false,
},
}
Expand All @@ -68,18 +74,19 @@ func (suite TypesTestSuite) TestAcknowledgement() { //nolint:govet // this is a

err := tc.ack.ValidateBasic()

if tc.expPass {
if tc.expValidates {
suite.Require().NoError(err)

// expect all valid acks to be able to be marshaled
suite.NotPanics(func() {
bz := tc.ack.Acknowledgement()
suite.Require().NotNil(bz)
suite.Require().Equal(tc.expBytes, bz)
})
} else {
suite.Require().Error(err)
}

// expect all acks to be able to be marshaled
suite.NotPanics(func() {
bz := tc.ack.Acknowledgement()
suite.Require().NotNil(bz)
})

suite.Require().Equal(tc.expSuccess, tc.ack.Success())
})
}
Expand Down

0 comments on commit 0e156f1

Please sign in to comment.