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

chore: Add tests for acknowledgement.Acknowledgement() #3433

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved the check up to the ValidateBasic success case because I don't want to make any assumptions how invalid instances are marchalled. Probybly they should never be marshalled.


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