Skip to content

Commit

Permalink
Add a helper function to create a mock contract. (#5162)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2bd29c0)

# Conflicts:
#	modules/light-clients/08-wasm/keeper/msg_server_test.go
#	modules/light-clients/08-wasm/keeper/snapshotter_test.go
#	modules/light-clients/08-wasm/types/migrate_contract_test.go
  • Loading branch information
DimitrisJim authored and mergify[bot] committed Nov 29, 2023
1 parent e84470f commit 785a4c1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
26 changes: 26 additions & 0 deletions modules/light-clients/08-wasm/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ func (suite *KeeperTestSuite) TestMsgStoreCode() {
types.ErrWasmEmptyCode,
},
{
<<<<<<< HEAD
=======
"fails with checksum",
func() {
msg = types.NewMsgStoreCode(signer, []byte{0, 1, 3, 4})
},
errors.New("Wasm bytes do not not start with Wasm magic number"),
},
{
"fails with wasm code too large",
func() {
msg = types.NewMsgStoreCode(signer, wasmtesting.CreateMockContract([]byte(ibctesting.GenerateString(uint(types.MaxWasmByteSize())))))
},
types.ErrWasmCodeTooLarge,
},
{
>>>>>>> 2bd29c08 (Add a helper function to create a mock contract. (#5162))
"fails with unauthorized signer",
func() {
signer = suite.chainA.SenderAccount.GetAddress().String()
Expand Down Expand Up @@ -125,7 +142,11 @@ func (suite *KeeperTestSuite) TestMsgStoreCode() {
func (suite *KeeperTestSuite) TestMsgMigrateContract() {
oldChecksum := sha256.Sum256(wasmtesting.Code)

<<<<<<< HEAD
newByteCode := []byte("MockByteCode-TestMsgMigrateContract")
=======
newByteCode := wasmtesting.CreateMockContract([]byte("MockByteCode-TestMsgMigrateContract"))
>>>>>>> 2bd29c08 (Add a helper function to create a mock contract. (#5162))

govAcc := authtypes.NewModuleAddress(govtypes.ModuleName).String()

Expand Down Expand Up @@ -324,9 +345,14 @@ func (suite *KeeperTestSuite) TestMsgRemoveChecksum() {
expChecksums = []types.Checksum{}

for i := 0; i < 20; i++ {
<<<<<<< HEAD
checksum := sha256.Sum256([]byte{byte(i)})

err := types.AddChecksum(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), ibcwasm.GetWasmStoreKey(), checksum[:])
=======
mockCode := wasmtesting.CreateMockContract([]byte{byte(i)})
checksum, err := types.CreateChecksum(mockCode)
>>>>>>> 2bd29c08 (Add a helper function to create a mock contract. (#5162))
suite.Require().NoError(err)

expChecksums = append(expChecksums, checksum[:])
Expand Down
4 changes: 4 additions & 0 deletions modules/light-clients/08-wasm/keeper/snapshotter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import (
)

func (suite *KeeperTestSuite) TestSnapshotter() {
<<<<<<< HEAD
gzippedContract, err := types.GzipIt([]byte("gzipped-contract"))
=======
gzippedContract, err := types.GzipIt(wasmtesting.CreateMockContract([]byte("gzipped-contract")))
>>>>>>> 2bd29c08 (Add a helper function to create a mock contract. (#5162))
suite.Require().NoError(err)

testCases := []struct {
Expand Down
5 changes: 5 additions & 0 deletions modules/light-clients/08-wasm/testing/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ func CreateMockClientStateBz(cdc codec.BinaryCodec, checksum []byte) []byte {
mockClientSate := types.NewClientState([]byte{1}, checksum, clienttypes.NewHeight(2000, 2))
return clienttypes.MustMarshalClientState(cdc, mockClientSate)
}

// CreateMockContract returns a well formed (magic number prefixed) wasm contract the given code.
func CreateMockContract(code []byte) []byte {
return append(WasmMagicNumber, code...)
}
8 changes: 8 additions & 0 deletions modules/light-clients/08-wasm/types/migrate_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,16 @@ func (suite *TypesTestSuite) TestMigrateContract() {
suite.Run(tc.name, func() {
suite.SetupWasmWithMockVM()

<<<<<<< HEAD
oldHash = sha256.Sum256(wasmtesting.Code)
newHash = sha256.Sum256([]byte{1, 2, 3})
=======
var err error
oldHash, err = types.CreateChecksum(wasmtesting.Code)
suite.Require().NoError(err)
newHash, err = types.CreateChecksum(wasmtesting.CreateMockContract([]byte{1, 2, 3}))
suite.Require().NoError(err)
>>>>>>> 2bd29c08 (Add a helper function to create a mock contract. (#5162))

err := types.AddChecksum(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), ibcwasm.GetWasmStoreKey(), newHash[:])
suite.Require().NoError(err)
Expand Down

0 comments on commit 785a4c1

Please sign in to comment.