Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
59 lines
2.6 KiB
Go
59 lines
2.6 KiB
Go
package testing
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/v10/types"
|
|
clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
|
|
commitmenttypes "github.com/cosmos/ibc-go/v10/modules/core/23-commitment/types"
|
|
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
|
|
ibctesting "github.com/cosmos/ibc-go/v10/testing"
|
|
)
|
|
|
|
var (
|
|
// Represents the code of the wasm contract used in the tests with a mock vm.
|
|
WasmMagicNumber = []byte("\x00\x61\x73\x6D")
|
|
Code = append(WasmMagicNumber, []byte("0123456780123456780123456780")...)
|
|
MockClientStateBz = []byte("client-state-data")
|
|
MockConsensusStateBz = []byte("consensus-state-data")
|
|
MockTendermitClientState = CreateMockTendermintClientState(clienttypes.NewHeight(1, 10))
|
|
MockTendermintClientHeader = &ibctm.Header{}
|
|
MockTendermintClientMisbehaviour = ibctm.NewMisbehaviour("client-id", MockTendermintClientHeader, MockTendermintClientHeader)
|
|
MockTendermintClientConsensusState = ibctm.NewConsensusState(time.Now(), commitmenttypes.NewMerkleRoot([]byte("hash")), []byte("nextValsHash"))
|
|
MockValidProofBz = []byte("valid proof")
|
|
MockInvalidProofBz = []byte("invalid proof")
|
|
MockUpgradedClientStateProofBz = []byte("upgraded client state proof")
|
|
MockUpgradedConsensusStateProofBz = []byte("upgraded consensus state proof")
|
|
|
|
ErrMockContract = errors.New("mock contract error")
|
|
ErrMockVM = errors.New("mock vm error")
|
|
)
|
|
|
|
// CreateMockTendermintClientState returns a valid Tendermint client state for use in tests.
|
|
func CreateMockTendermintClientState(height clienttypes.Height) *ibctm.ClientState {
|
|
return ibctm.NewClientState(
|
|
"chain-id",
|
|
ibctm.DefaultTrustLevel,
|
|
ibctesting.TrustingPeriod,
|
|
ibctesting.UnbondingPeriod,
|
|
ibctesting.MaxClockDrift,
|
|
height,
|
|
commitmenttypes.GetSDKSpecs(),
|
|
ibctesting.UpgradePath,
|
|
)
|
|
}
|
|
|
|
// CreateMockClientStateBz returns valid client state bytes for use in tests.
|
|
func CreateMockClientStateBz(cdc codec.BinaryCodec, checksum types.Checksum) []byte {
|
|
wrappedClientStateBz := clienttypes.MustMarshalClientState(cdc, MockTendermitClientState)
|
|
mockClientSate := types.NewClientState(wrappedClientStateBz, checksum, MockTendermitClientState.LatestHeight)
|
|
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...)
|
|
}
|