From 36e847d9a9774cf5a8183cec49c9278653c757a7 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 11 Apr 2023 11:46:18 +0200 Subject: [PATCH] Add tests for acknowledgement.Acknowledgement() --- .../04-channel/types/acknowledgement_test.go | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/modules/core/04-channel/types/acknowledgement_test.go b/modules/core/04-channel/types/acknowledgement_test.go index ce08c218de6..40480951fd2 100644 --- a/modules/core/04-channel/types/acknowledgement_test.go +++ b/modules/core/04-channel/types/acknowledgement_test.go @@ -18,37 +18,42 @@ 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", @@ -56,6 +61,7 @@ func (suite TypesTestSuite) TestAcknowledgement() { //nolint:govet // this is a Response: nil, }, false, + nil, false, }, } @@ -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()) }) }