Skip to content

Commit

Permalink
Remove grandpa unit test contract, rm test_data (backport #5150) (#5259)
Browse files Browse the repository at this point in the history
* Remove grandpa unit test contract, rm test_data (backport #5150)

* add GenerateString function

---------

Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
  • Loading branch information
Carlos Rodriguez and DimitrisJim authored Nov 30, 2023
1 parent 87ee6db commit 9527f78
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (suite *TypesTestSuite) TestValidateAccountAddress() {
},
{
"address is too long",
ibctesting.LongString,
ibctesting.GenerateString(uint(types.DefaultMaxAddrLength) + 1),
false,
},
}
Expand Down
14 changes: 5 additions & 9 deletions modules/light-clients/08-wasm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package keeper_test

import (
"encoding/hex"
"os"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

wasmtesting "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing"
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
)

Expand All @@ -22,9 +22,7 @@ func (suite *KeeperTestSuite) TestQueryCode() {
"success",
func() {
signer := authtypes.NewModuleAddress(govtypes.ModuleName).String()
code, err := os.ReadFile("../test_data/ics10_grandpa_cw.wasm.gz")
suite.Require().NoError(err)
msg := types.NewMsgStoreCode(signer, code)
msg := types.NewMsgStoreCode(signer, wasmtesting.Code)

res, err := GetSimApp(suite.chainA).WasmClientKeeper.StoreCode(suite.chainA.GetContext(), msg)
suite.Require().NoError(err)
Expand All @@ -51,7 +49,7 @@ func (suite *KeeperTestSuite) TestQueryCode() {

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest()
suite.SetupWasmWithMockVM()

tc.malleate()

Expand Down Expand Up @@ -87,9 +85,7 @@ func (suite *KeeperTestSuite) TestQueryChecksums() {
"success with one checksum",
func() {
signer := authtypes.NewModuleAddress(govtypes.ModuleName).String()
code, err := os.ReadFile("../test_data/ics10_grandpa_cw.wasm.gz")
suite.Require().NoError(err)
msg := types.NewMsgStoreCode(signer, code)
msg := types.NewMsgStoreCode(signer, wasmtesting.Code)

res, err := GetSimApp(suite.chainA).WasmClientKeeper.StoreCode(suite.chainA.GetContext(), msg)
suite.Require().NoError(err)
Expand All @@ -102,7 +98,7 @@ func (suite *KeeperTestSuite) TestQueryChecksums() {

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest()
suite.SetupWasmWithMockVM()

tc.malleate()

Expand Down
12 changes: 2 additions & 10 deletions modules/light-clients/08-wasm/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"os"
"strings"

wasmvm "github.com/CosmWasm/wasmvm"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
Expand Down Expand Up @@ -71,13 +69,7 @@ func (suite *KeeperTestSuite) TestMsgStoreCode() {
{
"fails with wasm code too large",
func() {
var sb strings.Builder
for i := 0; i < int(types.MaxWasmByteSize()); i++ {
err := sb.WriteByte(byte(i))
suite.Require().NoError(err)
}

msg = types.NewMsgStoreCode(signer, append(wasmtesting.WasmMagicNumber, []byte(sb.String())...))
msg = types.NewMsgStoreCode(signer, wasmtesting.CreateMockContract([]byte(ibctesting.GenerateString(uint(types.MaxWasmByteSize())))))
},
types.ErrWasmCodeTooLarge,
},
Expand Down Expand Up @@ -107,7 +99,7 @@ func (suite *KeeperTestSuite) TestMsgStoreCode() {
suite.SetupWasmWithMockVM()

signer = authtypes.NewModuleAddress(govtypes.ModuleName).String()
data, _ = os.ReadFile("../test_data/ics10_grandpa_cw.wasm.gz")
data = wasmtesting.Code

tc.malleate()

Expand Down
Binary file not shown.
3 changes: 1 addition & 2 deletions modules/light-clients/08-wasm/types/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types_test

import (
"crypto/rand"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -28,7 +27,7 @@ func TestValidateWasmCode(t *testing.T) {
{
"success",
func() {
code, _ = os.ReadFile("../test_data/ics10_grandpa_cw.wasm.gz")
code = wasmtesting.Code
},
nil,
},
Expand Down
10 changes: 10 additions & 0 deletions testing/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ibctesting

import (
"math/rand"
"testing"

abci "github.com/cometbft/cometbft/abci/types"
Expand All @@ -21,3 +22,12 @@ func ApplyValSetChanges(t *testing.T, valSet *tmtypes.ValidatorSet, valUpdates [

return newVals
}

// GenerateString generates a random string of the given length in bytes
func GenerateString(length uint) string {
bytes := make([]byte, length)
for i := range bytes {
bytes[i] = charset[rand.Intn(len(charset))]
}
return string(bytes)
}
3 changes: 2 additions & 1 deletion testing/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const (
Title = "title"
Description = "description"

LongString = "LoremipsumdolorsitameconsecteturadipiscingeliseddoeiusmodtemporincididuntutlaboreetdoloremagnaaliquUtenimadminimveniamquisnostrudexercitationullamcolaborisnisiutaliquipexeacommodoconsequDuisauteiruredolorinreprehenderitinvoluptateelitsseillumoloreufugiatnullaariaturEcepteurintoccaectupidatatonroidentuntnulpauifficiaeseruntmollitanimidestlaborum"
// character set used for generating a random string in GenerateString
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)

var (
Expand Down

0 comments on commit 9527f78

Please sign in to comment.