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

Updated CLI integration test to check for specific size instead of multiple of the share size #429

Closed
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
25 changes: 23 additions & 2 deletions x/payment/client/testutil/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testutil

import (
"encoding/hex"
"fmt"
"strconv"
"testing"
Expand Down Expand Up @@ -140,9 +141,13 @@ func (s *IntegrationTestSuite) TestSubmitWirePayForData() {
signer := e.GetAttributes()[0].GetValue()
_, err = sdk.AccAddressFromBech32(signer)
require.NoError(err)
msgSize, err := strconv.ParseUint(e.GetAttributes()[1].GetValue(), 10, 64)
msgSize, err := strconv.ParseInt(e.GetAttributes()[1].GetValue(), 10, 64)
require.NoError(err)
s.Equal(uint64(0), msgSize%consts.ShareSize, "Message length should be multiples of const.ShareSize=%v", consts.ShareSize)
msg, err := hex.DecodeString(tc.args[1])
require.NoError(err)
msg = s.padMessage(msg)
require.NoError(err)
require.Equal(len(msg), int(msgSize))
}
}

Expand All @@ -159,6 +164,22 @@ func (s *IntegrationTestSuite) TestSubmitWirePayForData() {
}
})
}

}

// padMessage adds padding to the msg if the length of the msg is not divisible
// by the share size specified in celestia-core
func (s *IntegrationTestSuite) padMessage(msg []byte) []byte {
// check if the message needs padding
if len(msg)%consts.ShareSize == 0 {
return msg
}

shareCount := (len(msg) / consts.ShareSize) + 1

padded := make([]byte, shareCount*consts.ShareSize)
copy(padded, msg)
return padded
}

func TestIntegrationTestSuite(t *testing.T) {
Expand Down