From 7954ec15524be37f155e36b2084e62e2fc611143 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Tue, 22 Aug 2023 15:45:10 +0530 Subject: [PATCH 01/11] add params setting via genesis --- demo/app/app.go | 9 +- docs/proto/proto-docs.md | 34 ++ .../meshsecurity/v1beta1/genesis.proto | 18 + x/meshsecurity/keeper/genesis.go | 18 + x/meshsecurity/module.go | 26 +- x/meshsecurity/types/genesis.go | 15 + x/meshsecurity/types/genesis.pb.go | 357 ++++++++++++++++++ 7 files changed, 467 insertions(+), 10 deletions(-) create mode 100644 proto/osmosis/meshsecurity/v1beta1/genesis.proto create mode 100644 x/meshsecurity/keeper/genesis.go create mode 100644 x/meshsecurity/types/genesis.go create mode 100644 x/meshsecurity/types/genesis.pb.go diff --git a/demo/app/app.go b/demo/app/app.go index fb17fcf0..40e3e1a5 100644 --- a/demo/app/app.go +++ b/demo/app/app.go @@ -112,7 +112,7 @@ import ( ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" - transfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer" + "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v7/modules/core" @@ -871,12 +871,6 @@ func NewMeshApp( if err := app.WasmKeeper.InitializePinnedCodes(ctx); err != nil { tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err)) } - - // todo: remove set-params and initialize via genesis - if err := app.MeshSecKeeper.SetParams(ctx, meshsectypes.DefaultParams(sdk.DefaultBondDenom)); err != nil { - tmos.Exit(fmt.Sprintf("failed to set mesh params: %s", err)) - } - } return app @@ -1094,6 +1088,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(icahosttypes.SubModuleName) paramsKeeper.Subspace(icacontrollertypes.SubModuleName) paramsKeeper.Subspace(wasm.ModuleName) + paramsKeeper.Subspace(meshsectypes.ModuleName) return paramsKeeper } diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index c43a980e..1841ad19 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -8,6 +8,9 @@ - [Params](#osmosis.meshsecurity.v1beta1.Params) - [VirtualStakingMaxCapInfo](#osmosis.meshsecurity.v1beta1.VirtualStakingMaxCapInfo) +- [osmosis/meshsecurity/v1beta1/genesis.proto](#osmosis/meshsecurity/v1beta1/genesis.proto) + - [GenesisState](#osmosis.meshsecurity.v1beta1.GenesisState) + - [osmosis/meshsecurity/v1beta1/query.proto](#osmosis/meshsecurity/v1beta1/query.proto) - [QueryParamsRequest](#osmosis.meshsecurity.v1beta1.QueryParamsRequest) - [QueryParamsResponse](#osmosis.meshsecurity.v1beta1.QueryParamsResponse) @@ -69,6 +72,37 @@ virtual staking max cap + + + + + + + + + + + +

Top

+ +## osmosis/meshsecurity/v1beta1/genesis.proto + + + + + +### GenesisState +GenesisState defines meshsecurity module's genesis state. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `params` | [Params](#osmosis.meshsecurity.v1beta1.Params) | | | + + + + + diff --git a/proto/osmosis/meshsecurity/v1beta1/genesis.proto b/proto/osmosis/meshsecurity/v1beta1/genesis.proto new file mode 100644 index 00000000..3b70c15c --- /dev/null +++ b/proto/osmosis/meshsecurity/v1beta1/genesis.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package osmosis.meshsecurity.v1beta1; + +import "osmosis/meshsecurity/v1beta1/meshsecurity.proto"; +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; + +option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types"; +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.equal_all) = false; + +// GenesisState defines meshsecurity module's genesis state. +message GenesisState { + option (gogoproto.equal) = true; + + Params params = 1 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} diff --git a/x/meshsecurity/keeper/genesis.go b/x/meshsecurity/keeper/genesis.go new file mode 100644 index 00000000..e669d0c3 --- /dev/null +++ b/x/meshsecurity/keeper/genesis.go @@ -0,0 +1,18 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" +) + +func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { + if err := k.SetParams(ctx, data.Params); err != nil { + panic(err) + } +} + +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + params := k.GetParams(ctx) + return types.NewGenesisState(params) +} diff --git a/x/meshsecurity/module.go b/x/meshsecurity/module.go index 7732b2d8..c717c5d6 100644 --- a/x/meshsecurity/module.go +++ b/x/meshsecurity/module.go @@ -3,6 +3,7 @@ package meshsecurity import ( "context" "encoding/json" + "fmt" abci "github.com/cometbft/cometbft/abci/types" @@ -49,12 +50,17 @@ func (AppModuleBasic) Name() string { // DefaultGenesis returns default genesis state as raw bytes for the mesh-security // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return nil + return cdc.MustMarshalJSON(types.DefaultGenesisState(sdk.DefaultBondDenom)) } // ValidateGenesis performs genesis state validation for the mesh-security module. -func (b AppModuleBasic) ValidateGenesis(marshaler codec.JSONCodec, _ client.TxEncodingConfig, message json.RawMessage) error { - return nil +func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return types.ValidateGenesis(&data) } // GetTxCmd returns the root tx command for the mesh-security module. @@ -111,6 +117,20 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { } +// InitGenesis performs genesis initialization for the mesh-security module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { + var data types.GenesisState + cdc.MustUnmarshalJSON(bz, &data) + am.k.InitGenesis(ctx, data) + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the exported genesis state as raw bytes for the mesh-security +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(am.k.ExportGenesis(ctx)) +} + // QuerierRoute returns the bank module's querier route name. func (AppModule) QuerierRoute() string { return types.RouterKey diff --git a/x/meshsecurity/types/genesis.go b/x/meshsecurity/types/genesis.go new file mode 100644 index 00000000..76545112 --- /dev/null +++ b/x/meshsecurity/types/genesis.go @@ -0,0 +1,15 @@ +package types + +func NewGenesisState(params Params) *GenesisState { + return &GenesisState{ + Params: params, + } +} + +func DefaultGenesisState(denom string) *GenesisState { + return NewGenesisState(DefaultParams(denom)) +} + +func ValidateGenesis(gs *GenesisState) error { + return gs.Params.ValidateBasic() +} diff --git a/x/meshsecurity/types/genesis.pb.go b/x/meshsecurity/types/genesis.pb.go new file mode 100644 index 00000000..5575e806 --- /dev/null +++ b/x/meshsecurity/types/genesis.pb.go @@ -0,0 +1,357 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/meshsecurity/v1beta1/genesis.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = proto.Marshal + _ = fmt.Errorf + _ = math.Inf +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines meshsecurity module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_e38a457d5139d73a, []int{0} +} + +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} + +func (m *GenesisState) XXX_Size() int { + return m.Size() +} + +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func init() { + proto.RegisterType((*GenesisState)(nil), "osmosis.meshsecurity.v1beta1.GenesisState") +} + +func init() { + proto.RegisterFile("osmosis/meshsecurity/v1beta1/genesis.proto", fileDescriptor_e38a457d5139d73a) +} + +var fileDescriptor_e38a457d5139d73a = []byte{ + // 247 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xca, 0x2f, 0xce, 0xcd, + 0x2f, 0xce, 0x2c, 0xd6, 0xcf, 0x4d, 0x2d, 0xce, 0x28, 0x4e, 0x4d, 0x2e, 0x2d, 0xca, 0x2c, 0xa9, + 0xd4, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, + 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x81, 0xaa, 0xd5, 0x43, 0x56, 0xab, 0x07, 0x55, + 0x2b, 0xa5, 0x8f, 0xd7, 0x24, 0x14, 0x2d, 0x60, 0xe3, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, + 0x4c, 0x7d, 0x10, 0x0b, 0x2a, 0x2a, 0x98, 0x98, 0x9b, 0x99, 0x97, 0xaf, 0x0f, 0x26, 0x21, 0x42, + 0x4a, 0xb1, 0x5c, 0x3c, 0xee, 0x10, 0x87, 0x04, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0xb9, 0x73, 0xb1, + 0x15, 0x24, 0x16, 0x25, 0xe6, 0x16, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0xa9, 0xe8, 0xe1, + 0x73, 0x98, 0x5e, 0x00, 0x58, 0xad, 0x13, 0xe7, 0x89, 0x7b, 0xf2, 0x0c, 0x2b, 0x9e, 0x6f, 0xd0, + 0x62, 0x0c, 0x82, 0x6a, 0xb7, 0x62, 0x79, 0xb1, 0x40, 0x9e, 0xd1, 0x29, 0xe1, 0xc4, 0x43, 0x39, + 0x86, 0x15, 0x8f, 0xe4, 0x18, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, + 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, + 0x2e, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x17, 0xe6, 0x4b, 0xdd, 0x9c, 0xc4, + 0x24, 0x88, 0x57, 0x75, 0x61, 0x16, 0xea, 0x16, 0xa7, 0x64, 0xeb, 0x57, 0xa0, 0x7a, 0xbf, 0xa4, + 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x0f, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x75, + 0x0f, 0xd3, 0x37, 0x6d, 0x01, 0x00, 0x00, +} + +func (this *GenesisState) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*GenesisState) + if !ok { + that2, ok := that.(GenesisState) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Params.Equal(&that1.Params) { + return false + } + return true +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} + +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} + +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} + +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) From 0ccd348020aa354d5320069be89939a918787188 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Mon, 28 Aug 2023 21:01:12 +0530 Subject: [PATCH 02/11] add unit tests for genesis state checks, init, export and validate --- x/meshsecurity/keeper/genesis_test.go | 66 ++++++++++++++++++++ x/meshsecurity/types/genesis_test.go | 90 +++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 x/meshsecurity/keeper/genesis_test.go create mode 100644 x/meshsecurity/types/genesis_test.go diff --git a/x/meshsecurity/keeper/genesis_test.go b/x/meshsecurity/keeper/genesis_test.go new file mode 100644 index 00000000..d69ab8dd --- /dev/null +++ b/x/meshsecurity/keeper/genesis_test.go @@ -0,0 +1,66 @@ +package keeper + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + + "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" +) + +func TestInitGenesis(t *testing.T) { + specs := map[string]struct { + state types.GenesisState + expErr bool + }{ + "custom param, should pass": { + state: types.GenesisState{ + Params: types.Params{ + TotalContractsMaxCap: sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(15_000_000_000)), + EpochLength: 2_000, + MaxGasEndBlocker: 600_000, + }, + }, + expErr: false, + }, + "custom small value param, should pass": { + state: types.GenesisState{ + Params: types.Params{ + TotalContractsMaxCap: sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(1_000_000)), + EpochLength: 20, + MaxGasEndBlocker: 10_000, + }, + }, + expErr: false, + }, + } + + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + pCtx, keepers := CreateDefaultTestInput(t) + k := keepers.MeshKeeper + + k.InitGenesis(pCtx, spec.state) + + p := k.GetParams(pCtx) + assert.Equal(t, spec.state.Params.MaxGasEndBlocker, p.MaxGasEndBlocker) + assert.Equal(t, spec.state.Params.EpochLength, p.EpochLength) + assert.Equal(t, spec.state.Params.TotalContractsMaxCap, p.TotalContractsMaxCap) + }) + } +} + +func TestExportGenesis(t *testing.T) { + pCtx, keepers := CreateDefaultTestInput(t) + k := keepers.MeshKeeper + params := types.DefaultParams(sdk.DefaultBondDenom) + + err := k.SetParams(pCtx, params) + require.NoError(t, err) + + exported := k.ExportGenesis(pCtx) + assert.Equal(t, params.MaxGasEndBlocker, exported.Params.MaxGasEndBlocker) + assert.Equal(t, params.EpochLength, exported.Params.EpochLength) + assert.Equal(t, params.TotalContractsMaxCap, exported.Params.TotalContractsMaxCap)cd diff --git a/x/meshsecurity/types/genesis_test.go b/x/meshsecurity/types/genesis_test.go new file mode 100644 index 00000000..6f2c3b00 --- /dev/null +++ b/x/meshsecurity/types/genesis_test.go @@ -0,0 +1,90 @@ +package types + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestValidateGenesis(t *testing.T) { + specs := map[string]struct { + state GenesisState + expErr bool + }{ + "default params": { + state: *DefaultGenesisState(sdk.DefaultBondDenom), + expErr: false, + }, + "custom param, should pass": { + state: GenesisState{ + Params: Params{ + TotalContractsMaxCap: sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(15_000_000_000)), + EpochLength: 2_000, + MaxGasEndBlocker: 600_000, + }, + }, + expErr: false, + }, + "custom small value param, should pass": { + state: GenesisState{ + Params: Params{ + TotalContractsMaxCap: sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(1_000_000)), + EpochLength: 20, + MaxGasEndBlocker: 10_000, + }, + }, + expErr: false, + }, + "invalid epoch length, should fail": { + state: GenesisState{ + Params: Params{ + TotalContractsMaxCap: sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(15_000_000_000)), + EpochLength: 0, + MaxGasEndBlocker: 600_000, + }, + }, + expErr: true, + }, + "invalid max gas length, should fail": { + state: GenesisState{ + Params: Params{ + TotalContractsMaxCap: sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(15_000_000_000)), + EpochLength: 10, + MaxGasEndBlocker: 0, + }, + }, + expErr: true, + }, + "invalid max cap coin denom, should fail": { + state: GenesisState{ + Params: Params{ + TotalContractsMaxCap: sdk.Coin{Denom: "invalid denom test", Amount: math.Int{}}, + EpochLength: 10, + MaxGasEndBlocker: 0, + }, + }, + expErr: true, + }, + "invalid max cap coin amount, should fail": { + state: GenesisState{ + Params: Params{ + TotalContractsMaxCap: sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: math.NewInt(-100)}, + EpochLength: 10, + MaxGasEndBlocker: 0, + }, + }, + expErr: true, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + err := ValidateGenesis(&spec.state) + if spec.expErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} From ab67069096cdd61c304e359118838b890044a8fb Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Mon, 28 Aug 2023 21:14:51 +0530 Subject: [PATCH 03/11] fix typo --- x/meshsecurity/keeper/genesis_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/meshsecurity/keeper/genesis_test.go b/x/meshsecurity/keeper/genesis_test.go index d69ab8dd..1b4b5792 100644 --- a/x/meshsecurity/keeper/genesis_test.go +++ b/x/meshsecurity/keeper/genesis_test.go @@ -63,4 +63,5 @@ func TestExportGenesis(t *testing.T) { exported := k.ExportGenesis(pCtx) assert.Equal(t, params.MaxGasEndBlocker, exported.Params.MaxGasEndBlocker) assert.Equal(t, params.EpochLength, exported.Params.EpochLength) - assert.Equal(t, params.TotalContractsMaxCap, exported.Params.TotalContractsMaxCap)cd + assert.Equal(t, params.TotalContractsMaxCap, exported.Params.TotalContractsMaxCap) +} From 086be795f81b8155f3107967abf93f3db25b0cc5 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Wed, 30 Aug 2023 18:03:54 +0530 Subject: [PATCH 04/11] update starship yaml files to run with mesh-security-sdk --- tests/starship/Makefile | 13 +- tests/starship/configs/devnet.yaml | 47 ++++--- .../configs/{starship.yaml => local.yaml} | 47 ++++--- tests/starship/go.mod | 2 +- tests/starship/go.sum | 1 + tests/starship/scripts/install.sh | 119 ++++++++++++++++++ tests/starship/scripts/port-forward.sh | 13 +- 7 files changed, 199 insertions(+), 43 deletions(-) rename tests/starship/configs/{starship.yaml => local.yaml} (53%) create mode 100644 tests/starship/scripts/install.sh diff --git a/tests/starship/Makefile b/tests/starship/Makefile index 4cce7442..aba87a70 100644 --- a/tests/starship/Makefile +++ b/tests/starship/Makefile @@ -25,26 +25,21 @@ build-linux: ### Starship Helm Charts ### ############################################################################### NAME = mesh-security -FILE = configs/starship.yaml +FILE = configs/local.yaml HELM_REPO = starship HELM_CHART = devnet -HELM_VERSION = v0.1.39-rc5 +HELM_VERSION = v0.1.46-rc0 .PHONY: check setup-deps: bash $(CURDIR)/scripts/dev-setup.sh -setup-helm: - helm repo add $(HELM_REPO) https://cosmology-tech.github.io/starship/ - helm repo update - helm search repo $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION) - install: - helm install -f $(FILE) $(NAME) $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION) + bash $(CURDIR)/scripts/install.sh --config $(FILE) --version $(HELM_VERSION) --name $(NAME) debug: - helm install -f $(FILE) $(NAME) $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION) --dry-run --debug + bash $(CURDIR)/scripts/install.sh --config $(FILE) --version $(HELM_VERSION) --name $(NAME) --dry-run delete: -helm delete $(NAME) diff --git a/tests/starship/configs/devnet.yaml b/tests/starship/configs/devnet.yaml index 35749bad..0482c3a6 100644 --- a/tests/starship/configs/devnet.yaml +++ b/tests/starship/configs/devnet.yaml @@ -1,16 +1,24 @@ chains: - - name: mesh-osmosis-1 + - name: mesh-1 type: custom numValidators: 4 - image: anmol1696/meshd:osmo + image: ghcr.io/osmosis-labs/meshd:latest home: /root/.meshd binary: meshd - prefix: osmo - denom: uosmo - coins: 100000000000000uosmo + prefix: mesh + denom: stake + coins: 100000000000000stake hdPath: m/44'/118'/0'/0/0 coinType: 118 repo: https://github.com/osmosis/mesh-security-sdk + genesis: + app_state: + meshsecurity: + params: + epoch_lenght: 10 + staking: + params: + unbonding_time: 200s ports: rest: 1313 rpc: 26653 @@ -22,18 +30,26 @@ chains: resources: cpu: 0.5 memory: 1Gi - - name: mesh-juno-1 + - name: mesh-2 type: custom numValidators: 4 - image: anmol1696/meshd:juno + image: ghcr.io/osmosis-labs/meshd:latest home: /root/.meshd binary: meshd - prefix: juno - denom: ujuno - coins: 100000000000000ujuno + prefix: mesh + denom: stake + coins: 100000000000000stake hdPath: m/44'/118'/0'/0/0 coinType: 118 repo: https://github.com/osmosis/mesh-security-sdk + genesis: + app_state: + meshsecurity: + params: + epoch_lenght: 10 + staking: + params: + unbonding_time: 200s ports: rest: 1317 rpc: 26657 @@ -47,13 +63,16 @@ chains: memory: 1Gi relayers: - - name: juno-osmo + - name: mesh-1-mesh-2 type: hermes replicas: 1 - image: ghcr.io/cosmology-tech/starship/hermes:39033cdee9e7aaa2274aeca3ab152542bf93d8bd + image: ghcr.io/cosmology-tech/starship/hermes:1.6.0 chains: - - mesh-juno-1 - - mesh-osmosis-1 + - mesh-1 + - mesh-2 + config: + event_source: + mode: pull resources: cpu: 1 memory: 2Gi diff --git a/tests/starship/configs/starship.yaml b/tests/starship/configs/local.yaml similarity index 53% rename from tests/starship/configs/starship.yaml rename to tests/starship/configs/local.yaml index 4f64f91d..ac232d59 100644 --- a/tests/starship/configs/starship.yaml +++ b/tests/starship/configs/local.yaml @@ -1,16 +1,24 @@ chains: - - name: mesh-osmosis-1 + - name: mesh-1 type: custom numValidators: 2 - image: anmol1696/meshd:osmo + image: ghcr.io/osmosis-labs/meshd:latest home: /root/.meshd binary: meshd - prefix: osmo - denom: uosmo - coins: 100000000000000uosmo + prefix: mesh + denom: stake + coins: 100000000000000stake hdPath: m/44'/118'/0'/0/0 coinType: 118 repo: https://github.com/osmosis/mesh-security-sdk + genesis: + app_state: + meshsecurity: + params: + epoch_lenght: 10 + staking: + params: + unbonding_time: 200s ports: rest: 1313 rpc: 26653 @@ -22,18 +30,26 @@ chains: resources: cpu: 0.5 memory: 1Gi - - name: mesh-juno-1 + - name: mesh-2 type: custom numValidators: 2 - image: anmol1696/meshd:juno + image: ghcr.io/osmosis-labs/meshd:latest home: /root/.meshd binary: meshd - prefix: juno - denom: ujuno - coins: 100000000000000ujuno + prefix: mesh + denom: stake + coins: 100000000000000stake hdPath: m/44'/118'/0'/0/0 coinType: 118 repo: https://github.com/osmosis/mesh-security-sdk + genesis: + app_state: + meshsecurity: + params: + epoch_lenght: 10 + staking: + params: + unbonding_time: 200s ports: rest: 1317 rpc: 26657 @@ -47,13 +63,16 @@ chains: memory: 1Gi relayers: - - name: juno-osmo + - name: mesh-1-mesh-2 type: hermes replicas: 1 - image: ghcr.io/cosmology-tech/starship/hermes:39033cdee9e7aaa2274aeca3ab152542bf93d8bd + image: ghcr.io/cosmology-tech/starship/hermes:1.6.0 chains: - - mesh-juno-1 - - mesh-osmosis-1 + - mesh-1 + - mesh-2 + config: + event_source: + mode: pull resources: cpu: 1 memory: 2Gi diff --git a/tests/starship/go.mod b/tests/starship/go.mod index a5c27425..7f57b9a7 100644 --- a/tests/starship/go.mod +++ b/tests/starship/go.mod @@ -3,7 +3,7 @@ module github.com/osmosis-labs/mesh-security-sdk/tests/starship go 1.19 require ( - github.com/CosmWasm/wasmd v0.41.0-rc.3 + github.com/CosmWasm/wasmd v0.41.0 github.com/CosmWasm/wasmvm v1.3.0 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect github.com/cosmos/cosmos-sdk v0.47.4 diff --git a/tests/starship/go.sum b/tests/starship/go.sum index e105e259..7d047bba 100644 --- a/tests/starship/go.sum +++ b/tests/starship/go.sum @@ -215,6 +215,7 @@ github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQ github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= github.com/CosmWasm/wasmd v0.41.0-rc.3 h1:0NRwC4dOO56GBV42niXvYlhyeZa8d5kEVEaUp6h4axg= github.com/CosmWasm/wasmd v0.41.0-rc.3/go.mod h1:0Sds1q2IsPaTN1gHa3BNOYcUFgtGvxH7CXEXPgoihns= +github.com/CosmWasm/wasmd v0.41.0/go.mod h1:0Sds1q2IsPaTN1gHa3BNOYcUFgtGvxH7CXEXPgoihns= github.com/CosmWasm/wasmvm v1.3.0 h1:x12X4bKlUPS7TT9QQP45+fJo2sp30GEbiSSgb9jsec8= github.com/CosmWasm/wasmvm v1.3.0/go.mod h1:vW/E3h8j9xBQs9bCoijDuawKo9kCtxOaS8N8J7KFtkc= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= diff --git a/tests/starship/scripts/install.sh b/tests/starship/scripts/install.sh new file mode 100644 index 00000000..02a1febe --- /dev/null +++ b/tests/starship/scripts/install.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +## Script used to install the helm chart for the devnet from a config file +## Usage: +## ./scripts/install.sh --coinfig +## Options: +## -c|--config: config file to use (default: config.yaml) +## -v|--version: helm chart version (default: 0.1.43) + +set -euo pipefail + +# read config file from args into variable +CONFIGFILE="config.yaml" + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +echo "Script dir: ${SCRIPT_DIR}" + +# default values +DRY_RUN="" +TIMEOUT="" +NAMESPACE="" +HELM_REPO="starship" +HELM_CHART="starship/devnet" +HELM_REPO_URL="https://cosmology-tech.github.io/starship/" +HELM_CHART_VERSION="0.1.43" + +# check_helm function verifies the helm binary is installed +function check_helm() { + if ! command -v helm &> /dev/null + then + echo "helm could not be found; please install it first!!!" + exit + fi +} + +# setup_helm function adds the helm repo and updates it +function setup_helm() { + helm repo add ${HELM_REPO} ${HELM_REPO_URL} + helm repo update + helm search repo ${HELM_CHART} --version ${HELM_CHART_VERSION} +} + +function set_helm_args() { + if [[ $TIMEOUT ]]; then + args="$args --timeout $TIMEOUT --wait --debug" + fi + if [[ $NAMESPACE ]]; then + args="$args --namespace $NAMESPACE --create-namespace" + fi + if [[ $DRY_RUN ]]; then + args="$args --dry-run" + fi + num_chains=$(yq -r ".chains | length - 1" ${CONFIGFILE}) + if [[ $num_chains -lt 0 ]]; then + echo "No chains to parse: num: $num_chains" + return 0 + fi + for i in $(seq 0 $num_chains); do + chain=$(yq -r ".chains[$i].name" ${CONFIGFILE}) + scripts=$(yq -r ".chains[$i].scripts" ${CONFIGFILE}) + if [[ "$scripts" == "null" ]]; then + return 0 + fi + datadir="$(cd "$(dirname -- "${CONFIGFILE}")" >/dev/null; pwd -P)" + for script in $(yq -r ".chains[$i].scripts | keys | .[]" ${CONFIGFILE}); do + args="$args --set-file chains[$i].scripts.$script.data=$datadir/$(yq -r ".chains[$i].scripts.$script.file" ${CONFIGFILE})" + done + done +} + +function install_chart() { + args="" + set_helm_args + echo "name: ${HELM_NAME}, args: $args, chart: ${HELM_CHART}, version: ${HELM_CHART_VERSION}" + helm install ${HELM_NAME} ${HELM_CHART} --version ${HELM_CHART_VERSION} -f ${CONFIGFILE} $args +} + +while [ $# -gt 0 ]; do + case "$1" in + -c|--config) + CONFIGFILE="$2" + shift 2 # past argument=value + ;; + -v|--version) + HELM_CHART_VERSION="$2" + shift 2 # past argument + ;; + -t|--timeout) + TIMEOUT="$2" + shift 2 # past argument + ;; + -n|--name) + HELM_NAME="$2" + shift 2 # past argument + ;; + --namespace) + NAMESPACE="$2" + shift 2 # past argument + ;; + --chart) + HELM_CHART="$2" + shift 2 # past argument + ;; + --dry-run) + DRY_RUN=1 + shift 2 # past argument + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + ;; + esac +done + +check_helm +setup_helm +install_chart diff --git a/tests/starship/scripts/port-forward.sh b/tests/starship/scripts/port-forward.sh index 1dc1eafb..ab6a1144 100755 --- a/tests/starship/scripts/port-forward.sh +++ b/tests/starship/scripts/port-forward.sh @@ -21,6 +21,7 @@ function stop_port_forward() { # Default values CHAIN_RPC_PORT=26657 +CHAIN_GRPC_PORT=9090 CHAIN_LCD_PORT=1317 CHAIN_EXPOSER_PORT=8081 CHAIN_FAUCET_PORT=8000 @@ -55,15 +56,17 @@ fi for i in $(seq 0 $num_chains); do chain=$(yq -r ".chains[$i].name" ${CONFIGFILE} ) localrpc=$(yq -r ".chains[$i].ports.rpc" ${CONFIGFILE} ) + localgrpc=$(yq -r ".chains[$i].ports.grpc" ${CONFIGFILE} ) locallcd=$(yq -r ".chains[$i].ports.rest" ${CONFIGFILE} ) localexp=$(yq -r ".chains[$i].ports.exposer" ${CONFIGFILE}) localfaucet=$(yq -r ".chains[$i].ports.faucet" ${CONFIGFILE}) - [[ "$localrpc" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $localrpc:$CHAIN_RPC_PORT > /dev/null 2>&1 & - [[ "$locallcd" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $locallcd:$CHAIN_LCD_PORT > /dev/null 2>&1 & - [[ "$localexp" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $localexp:$CHAIN_EXPOSER_PORT > /dev/null 2>&1 & - [[ "$localfaucet" != "null" ]] && kubectl port-forward pods/$chain-genesis-0 $localfaucet:$CHAIN_FAUCET_PORT > /dev/null 2>&1 & + color yellow "chains: forwarded $chain" + [[ "$localrpc" != "null" ]] && color yellow " rpc to http://localhost:$localrpc" && kubectl port-forward pods/$chain-genesis-0 $localrpc:$CHAIN_RPC_PORT > /dev/null 2>&1 & + [[ "$localgrpc" != "null" ]] && color yellow " grpc to http://localhost:$localgrpc" && kubectl port-forward pods/$chain-genesis-0 $localgrpc:$CHAIN_GRPC_PORT > /dev/null 2>&1 & + [[ "$locallcd" != "null" ]] && color yellow " lcd to http://localhost:$locallcd" && kubectl port-forward pods/$chain-genesis-0 $locallcd:$CHAIN_LCD_PORT > /dev/null 2>&1 & + [[ "$localexp" != "null" ]] && color yellow " exposer to http://localhost:$localexp" && kubectl port-forward pods/$chain-genesis-0 $localexp:$CHAIN_EXPOSER_PORT > /dev/null 2>&1 & + [[ "$localfaucet" != "null" ]] && color yellow " faucet to http://localhost:$localfaucet" && kubectl port-forward pods/$chain-genesis-0 $localfaucet:$CHAIN_FAUCET_PORT > /dev/null 2>&1 & sleep 1 - color yellow "chains: forwarded $chain lcd to http://localhost:$locallcd, rpc to http://localhost:$localrpc, faucet to http://localhost:$localfaucet" done echo "Port forward services" From 8a11acbe1ce8fa188ca50bd12b997332ca02fa12 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Thu, 31 Aug 2023 18:06:13 +0530 Subject: [PATCH 05/11] working version of starship with meshd --- tests/starship/Makefile | 2 +- tests/starship/configs/local.yaml | 8 ++++---- tests/starship/scripts/install.sh | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/starship/Makefile b/tests/starship/Makefile index aba87a70..af4ce55e 100644 --- a/tests/starship/Makefile +++ b/tests/starship/Makefile @@ -29,7 +29,7 @@ FILE = configs/local.yaml HELM_REPO = starship HELM_CHART = devnet -HELM_VERSION = v0.1.46-rc0 +HELM_VERSION = v0.1.46-rc1 .PHONY: check setup-deps: diff --git a/tests/starship/configs/local.yaml b/tests/starship/configs/local.yaml index ac232d59..7d7f0035 100644 --- a/tests/starship/configs/local.yaml +++ b/tests/starship/configs/local.yaml @@ -2,7 +2,7 @@ chains: - name: mesh-1 type: custom numValidators: 2 - image: ghcr.io/osmosis-labs/meshd:latest + image: anmol1696/meshd:latest home: /root/.meshd binary: meshd prefix: mesh @@ -15,7 +15,7 @@ chains: app_state: meshsecurity: params: - epoch_lenght: 10 + epoch_length: 10 staking: params: unbonding_time: 200s @@ -33,7 +33,7 @@ chains: - name: mesh-2 type: custom numValidators: 2 - image: ghcr.io/osmosis-labs/meshd:latest + image: anmol1696/meshd:latest home: /root/.meshd binary: meshd prefix: mesh @@ -46,7 +46,7 @@ chains: app_state: meshsecurity: params: - epoch_lenght: 10 + epoch_length: 10 staking: params: unbonding_time: 200s diff --git a/tests/starship/scripts/install.sh b/tests/starship/scripts/install.sh index 02a1febe..4b08b03f 100644 --- a/tests/starship/scripts/install.sh +++ b/tests/starship/scripts/install.sh @@ -47,8 +47,9 @@ function set_helm_args() { if [[ $NAMESPACE ]]; then args="$args --namespace $NAMESPACE --create-namespace" fi - if [[ $DRY_RUN ]]; then - args="$args --dry-run" + echo $DRY_RUN + if [[ "$DRY_RUN" == 0 ]]; then + args="$args --dry-run --debug" fi num_chains=$(yq -r ".chains | length - 1" ${CONFIGFILE}) if [[ $num_chains -lt 0 ]]; then @@ -103,7 +104,7 @@ while [ $# -gt 0 ]; do ;; --dry-run) DRY_RUN=1 - shift 2 # past argument + shift # past argument ;; -*|--*) echo "Unknown option $1" From 4b38473db6dd843b6c4d9b031fe4ffa950c1f518 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Thu, 31 Aug 2023 19:31:37 +0530 Subject: [PATCH 06/11] fix main_test.go and go mod --- tests/starship/go.sum | 3 +-- tests/starship/main_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/starship/go.sum b/tests/starship/go.sum index 7d047bba..5688ab04 100644 --- a/tests/starship/go.sum +++ b/tests/starship/go.sum @@ -213,8 +213,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= -github.com/CosmWasm/wasmd v0.41.0-rc.3 h1:0NRwC4dOO56GBV42niXvYlhyeZa8d5kEVEaUp6h4axg= -github.com/CosmWasm/wasmd v0.41.0-rc.3/go.mod h1:0Sds1q2IsPaTN1gHa3BNOYcUFgtGvxH7CXEXPgoihns= +github.com/CosmWasm/wasmd v0.41.0 h1:fmwxSbwb50zZDcBaayYFRLIaSFca+EFld1WOaQi49jg= github.com/CosmWasm/wasmd v0.41.0/go.mod h1:0Sds1q2IsPaTN1gHa3BNOYcUFgtGvxH7CXEXPgoihns= github.com/CosmWasm/wasmvm v1.3.0 h1:x12X4bKlUPS7TT9QQP45+fJo2sp30GEbiSSgb9jsec8= github.com/CosmWasm/wasmvm v1.3.0/go.mod h1:vW/E3h8j9xBQs9bCoijDuawKo9kCtxOaS8N8J7KFtkc= diff --git a/tests/starship/main_test.go b/tests/starship/main_test.go index 107496ed..5d4b78d7 100644 --- a/tests/starship/main_test.go +++ b/tests/starship/main_test.go @@ -54,11 +54,11 @@ func AssertShare(t *testing.T, p *setup.ConsumerClient, val string, exp math.Leg } func TestMain(m *testing.M) { - flag.StringVar(&wasmContractPath, "contracts-path", "testdata", "Set path to dir with gzipped wasm contracts") + flag.StringVar(&wasmContractPath, "contracts-path", "../testdata", "Set path to dir with gzipped wasm contracts") flag.BoolVar(&wasmContractGZipped, "gzipped", true, "Use `.gz` file ending when set") - flag.StringVar(&configFile, "config", "configs/devnet.yaml", "starship config file for the infra") - flag.StringVar(&providerChain, "provider-chain", "mesh-osmosis-1", "provider chain name, from config file") - flag.StringVar(&consumerChain, "consumer-chain", "mesh-juno-1", "consumer chain name, from config file") + flag.StringVar(&configFile, "config", "configs/local.yaml", "starship config file for the infra") + flag.StringVar(&providerChain, "provider-chain", "mesh-1", "provider chain name, from config file") + flag.StringVar(&consumerChain, "consumer-chain", "mesh-2", "consumer chain name, from config file") flag.Parse() os.Exit(m.Run()) From 4626a37e0e6ee8c6032c57d5a16e28c15e2d585a Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Thu, 31 Aug 2023 19:35:25 +0530 Subject: [PATCH 07/11] fix ci starship config --- tests/starship/configs/ci.yaml | 49 ++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/tests/starship/configs/ci.yaml b/tests/starship/configs/ci.yaml index 10e1c4aa..03019c03 100644 --- a/tests/starship/configs/ci.yaml +++ b/tests/starship/configs/ci.yaml @@ -1,16 +1,24 @@ chains: - - name: mesh-osmosis-1 + - name: mesh-1 type: custom numValidators: 1 - image: anmol1696/meshd:osmo + image: anmol1696/meshd:latest home: /root/.meshd binary: meshd - prefix: osmo - denom: uosmo - coins: 100000000000000uosmo + prefix: mesh + denom: stake + coins: 100000000000000stake hdPath: m/44'/118'/0'/0/0 coinType: 118 repo: https://github.com/osmosis/mesh-security-sdk + genesis: + app_state: + meshsecurity: + params: + epoch_length: 10 + staking: + params: + unbonding_time: 200s ports: rest: 1313 rpc: 26653 @@ -19,21 +27,30 @@ chains: cpu: "0.2" memory: "200M" faucet: + concurreny: 2 resources: cpu: "0.1" memory: "100M" - - name: mesh-juno-1 + - name: mesh-2 type: custom numValidators: 1 - image: anmol1696/meshd:juno + image: anmol1696/meshd:latest home: /root/.meshd binary: meshd - prefix: juno - denom: ujuno - coins: 100000000000000ujuno + prefix: mesh + denom: stake + coins: 100000000000000stake hdPath: m/44'/118'/0'/0/0 coinType: 118 repo: https://github.com/osmosis/mesh-security-sdk + genesis: + app_state: + meshsecurity: + params: + epoch_length: 10 + staking: + params: + unbonding_time: 200s ports: rest: 1317 rpc: 26657 @@ -42,18 +59,22 @@ chains: cpu: "0.2" memory: "200M" faucet: + concurreny: 2 resources: cpu: "0.1" memory: "100M" relayers: - - name: juno-osmo + - name: mesh-1-mesh-2 type: hermes replicas: 1 - image: ghcr.io/cosmology-tech/starship/hermes:39033cdee9e7aaa2274aeca3ab152542bf93d8bd + image: ghcr.io/cosmology-tech/starship/hermes:1.6.0 chains: - - mesh-juno-1 - - mesh-osmosis-1 + - mesh-1 + - mesh-2 + config: + event_source: + mode: pull resources: cpu: "0.1" memory: "100M" From 3e23f9d50e07fd5d106a343479257d5a3441a029 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Thu, 31 Aug 2023 19:38:08 +0530 Subject: [PATCH 08/11] run starship ci on push to test branch --- .../workflows/{e2e-tests.yml => starship-e2e-tests.yml} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename .github/workflows/{e2e-tests.yml => starship-e2e-tests.yml} (89%) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/starship-e2e-tests.yml similarity index 89% rename from .github/workflows/e2e-tests.yml rename to .github/workflows/starship-e2e-tests.yml index 91460cec..fa02b6b7 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/starship-e2e-tests.yml @@ -1,9 +1,10 @@ -name: E2E tests +name: Starship E2E tests on: push: branches: - main + - anmol/trim-starship-integration pull_request: branches: - main @@ -31,11 +32,11 @@ jobs: # - Port forward all ports to localhost for next steps to connect - name: Setup Test infra id: starship-action - uses: cosmology-tech/starship-action@0.2.12 + uses: cosmology-tech/starship-action@0.2.15 with: values: tests/starship/configs/ci.yaml port-forward: true - version: 0.1.39-rc5 + version: 0.1.46-rc1 - name: Run Tests run: | @@ -44,7 +45,6 @@ jobs: make test # Starship resource cleanup on cluster - # todo(@anmol1696): change this to be post step of the action - name: Cleanup cluster if: always() run: | From 8eac1af816c6a571122bd81f54eeb4f73699012a Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Thu, 31 Aug 2023 20:13:57 +0530 Subject: [PATCH 09/11] fix typo errors --- tests/starship/scripts/install.sh | 1 - tests/starship/setup/contract.go | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/starship/scripts/install.sh b/tests/starship/scripts/install.sh index 4b08b03f..734d024e 100644 --- a/tests/starship/scripts/install.sh +++ b/tests/starship/scripts/install.sh @@ -47,7 +47,6 @@ function set_helm_args() { if [[ $NAMESPACE ]]; then args="$args --namespace $NAMESPACE --create-namespace" fi - echo $DRY_RUN if [[ "$DRY_RUN" == 0 ]]; then args="$args --dry-run --debug" fi diff --git a/tests/starship/setup/contract.go b/tests/starship/setup/contract.go index 0413d383..c542b972 100644 --- a/tests/starship/setup/contract.go +++ b/tests/starship/setup/contract.go @@ -98,7 +98,7 @@ func voteAndPassGovProposal(chain *Client, proposalID uint64) error { if proposal.Proposal.Status == govv1.ProposalStatus_PROPOSAL_STATUS_PASSED { return nil } - return fmt.Errorf("proposal failed: id: %s, status: %d\n", proposal.Proposal.Id, proposal.Proposal.Status) + return fmt.Errorf("proposal failed: id: %d, status: %d\n", proposal.Proposal.Id, proposal.Proposal.Status) } func InstantiateContract(chain *Client, codeID uint64, label string, initMsg []byte, funds ...sdk.Coin) (map[uint64]string, error) { @@ -115,7 +115,7 @@ func InstantiateContract(chain *Client, codeID uint64, label string, initMsg []b if err != nil { return nil, err } - fmt.Printf("response for instantiate contract: %s\n", r.Code) + fmt.Printf("response for instantiate contract: %d\n", r.Code) // map of codeid and contract address addrs := map[uint64]string{} From 24f42649c688610206045c3824f3c68226a719c5 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 1 Sep 2023 15:28:04 +0530 Subject: [PATCH 10/11] fix typos and type errors --- tests/starship/main_test.go | 4 ++-- tests/starship/mvp_test.go | 2 +- tests/starship/setup/contract.go | 3 ++- tests/starship/setup/utils.go | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/starship/main_test.go b/tests/starship/main_test.go index 5d4b78d7..d91959a4 100644 --- a/tests/starship/main_test.go +++ b/tests/starship/main_test.go @@ -28,11 +28,11 @@ func AssertTotalDelegated(t *testing.T, p *setup.ConsumerClient, expTotalDelegat Pagination: nil, }) assert.NoError(t, err) - if expTotalDelegated == sdk.ZeroInt() { + if expTotalDelegated == math.ZeroInt() { assert.Nil(t, delegations.DelegationResponses) return } - actualDelegated := sdk.NewCoin(p.Chain.Denom, sdk.ZeroInt()) + actualDelegated := sdk.NewCoin(p.Chain.Denom, math.ZeroInt()) for _, delegation := range delegations.DelegationResponses { actualDelegated = actualDelegated.Add(delegation.Balance) } diff --git a/tests/starship/mvp_test.go b/tests/starship/mvp_test.go index 706cc826..400c6845 100644 --- a/tests/starship/mvp_test.go +++ b/tests/starship/mvp_test.go @@ -409,5 +409,5 @@ func TestMVP(t *testing.T) { Denom: providerClient.Chain.Denom, }) require.NoError(t, err) - assert.Less(t, math.NewInt(100_000), balanceAfter.Balance.Sub(*balanceBefore.Balance).Amount.Sub(math.NewInt(30_000_000))) + assert.Less(t, math.NewInt(100_000), balanceAfter.Balance.Sub(*balanceBefore.Balance).Amount.Sub(sdk.NewInt(30_000_000))) } diff --git a/tests/starship/setup/contract.go b/tests/starship/setup/contract.go index c542b972..c073a30f 100644 --- a/tests/starship/setup/contract.go +++ b/tests/starship/setup/contract.go @@ -4,6 +4,7 @@ import ( "bytes" "compress/gzip" "context" + "cosmossdk.io/math" "encoding/json" "fmt" "os" @@ -28,7 +29,7 @@ func buildPathToWasm(wasmContractPath string, fileName string, wasmContractGZipp func submitGovProposal(chain *Client, msgs ...sdk.Msg) (uint64, error) { // fetch gov params from the local - initialDeposit := sdk.NewCoins(sdk.NewCoin(chain.Denom, sdk.NewInt(10000000))) + initialDeposit := sdk.NewCoins(sdk.NewCoin(chain.Denom, math.NewInt(10000000))) govMsg, err := govv1.NewMsgSubmitProposal(msgs, initialDeposit, chain.Address, "", "my title", "my summary") if err != nil { return 0, err diff --git a/tests/starship/setup/utils.go b/tests/starship/setup/utils.go index 1873a5f5..33cd9e8e 100644 --- a/tests/starship/setup/utils.go +++ b/tests/starship/setup/utils.go @@ -2,6 +2,7 @@ package setup import ( "context" + "cosmossdk.io/math" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -21,7 +22,7 @@ func IBCTransferTokens(chain1, chain2 *Client, chain2Addr string, amount int) er return err } - coin := sdk.Coin{Denom: denom, Amount: sdk.NewInt(int64(amount))} + coin := sdk.Coin{Denom: denom, Amount: math.NewInt(int64(amount))} req := &transfertypes.MsgTransfer{ SourcePort: channel.Chain_2.PortId, SourceChannel: channel.Chain_2.ChannelId, From 5d5dd72d0da7fa1eaa144f2b7b3eb71879653a75 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 1 Sep 2023 16:00:16 +0530 Subject: [PATCH 11/11] add step to perform go mod before setting up the infra --- .github/workflows/starship-e2e-tests.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/starship-e2e-tests.yml b/.github/workflows/starship-e2e-tests.yml index fa02b6b7..35dbf7ce 100644 --- a/.github/workflows/starship-e2e-tests.yml +++ b/.github/workflows/starship-e2e-tests.yml @@ -24,6 +24,11 @@ jobs: go-version: ^1.20 id: go + - name: Deps + run: | + cd tests/starship/ + go mod tidy + # Starship Infra setup # - Connects to k8s cluster with kubeconfig (digital ocean) # - Creates a new namespace based on the name (deleted in next step) @@ -41,7 +46,6 @@ jobs: - name: Run Tests run: | cd tests/starship/ - go mod tidy make test # Starship resource cleanup on cluster