Skip to content

Commit 0e156f1

Browse files
webmaster128DimitrisJimcolin-axner
authored
chore: Add tests for acknowledgement.Acknowledgement() (#3433)
Co-authored-by: Jim Fasarakis-Hilliard <d.f.hilliard@gmail.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
1 parent 1ebf293 commit 0e156f1

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

modules/core/04-channel/types/acknowledgement_test.go

+22-15
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,50 @@ const (
1818
gasWanted = uint64(100)
1919
)
2020

21-
// tests acknowledgement.ValidateBasic and acknowledgement.GetBytes
21+
// tests acknowledgement.ValidateBasic and acknowledgement.Acknowledgement
2222
func (suite TypesTestSuite) TestAcknowledgement() { //nolint:govet // this is a test, we are okay with copying locks
2323
testCases := []struct {
24-
name string
25-
ack types.Acknowledgement
26-
expSuccess bool // indicate if this is a success or failed ack
27-
expPass bool
24+
name string
25+
ack types.Acknowledgement
26+
expValidates bool
27+
expBytes []byte
28+
expSuccess bool // indicate if this is a success or failed ack
2829
}{
2930
{
3031
"valid successful ack",
3132
types.NewResultAcknowledgement([]byte("success")),
3233
true,
34+
[]byte(`{"result":"c3VjY2Vzcw=="}`),
3335
true,
3436
},
3537
{
3638
"valid failed ack",
3739
types.NewErrorAcknowledgement(fmt.Errorf("error")),
38-
false,
3940
true,
41+
[]byte(`{"error":"ABCI code: 1: error handling packet: see events for details"}`),
42+
false,
4043
},
4144
{
4245
"empty successful ack",
4346
types.NewResultAcknowledgement([]byte{}),
44-
true,
4547
false,
48+
nil,
49+
true,
4650
},
4751
{
4852
"empty failed ack",
4953
types.NewErrorAcknowledgement(fmt.Errorf(" ")),
50-
false,
5154
true,
55+
[]byte(`{"error":"ABCI code: 1: error handling packet: see events for details"}`),
56+
false,
5257
},
5358
{
5459
"nil response",
5560
types.Acknowledgement{
5661
Response: nil,
5762
},
5863
false,
64+
nil,
5965
false,
6066
},
6167
}
@@ -68,18 +74,19 @@ func (suite TypesTestSuite) TestAcknowledgement() { //nolint:govet // this is a
6874

6975
err := tc.ack.ValidateBasic()
7076

71-
if tc.expPass {
77+
if tc.expValidates {
7278
suite.Require().NoError(err)
79+
80+
// expect all valid acks to be able to be marshaled
81+
suite.NotPanics(func() {
82+
bz := tc.ack.Acknowledgement()
83+
suite.Require().NotNil(bz)
84+
suite.Require().Equal(tc.expBytes, bz)
85+
})
7386
} else {
7487
suite.Require().Error(err)
7588
}
7689

77-
// expect all acks to be able to be marshaled
78-
suite.NotPanics(func() {
79-
bz := tc.ack.Acknowledgement()
80-
suite.Require().NotNil(bz)
81-
})
82-
8390
suite.Require().Equal(tc.expSuccess, tc.ack.Success())
8491
})
8592
}

0 commit comments

Comments
 (0)