From 07ccf2cf78a042c37f206267ffd264dadd8a00c3 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Thu, 13 Apr 2023 05:43:46 +0700 Subject: [PATCH] Lint v4 (#51) * Add v2 migrations * lint v4 * add golangci config * golangci in github actions * apptypes -> transfertypes * apptypes -> transfertypes * linting complete * sdk 4513, ibc 430, tendermint 0.34.25 * apptypes to transfertypes * lint --------- Co-authored-by: Andrew Gouin --- .github/workflows/golangci.yaml | 27 ++ .golangci.yml | 66 ++++ router/keeper/genesis.go | 2 + router/keeper/keeper.go | 2 +- router/migrations/v1/genesis.pb.go | 495 +++++++++++++++++++++++++ router/migrations/v2/gen_state.go | 16 + router/migrations/v2/gen_state_test.go | 35 ++ router/module.go | 5 +- router/module_test.go | 14 +- router/types/genesis.go | 12 +- router/types/keys.go | 8 +- router/types/params.go | 1 - test/setup.go | 7 +- 13 files changed, 672 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/golangci.yaml create mode 100644 .golangci.yml create mode 100644 router/migrations/v1/genesis.pb.go create mode 100644 router/migrations/v2/gen_state.go create mode 100644 router/migrations/v2/gen_state_test.go diff --git a/.github/workflows/golangci.yaml b/.github/workflows/golangci.yaml new file mode 100644 index 0000000..28daa82 --- /dev/null +++ b/.github/workflows/golangci.yaml @@ -0,0 +1,27 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - master + - main + pull_request: +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..e5b8c80 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,66 @@ +run: + tests: true + timeout: 10m + sort-results: true + allow-parallel-runners: true + exclude-dir: testutil/testdata_pulsar + concurrency: 4 + +linters: + disable-all: true + enable: + - depguard + - dogsled + - exportloopref + - goconst + - gocritic + - gofumpt + - gosec + - gosimple + - govet + - ineffassign + - misspell + - nakedret + - nolintlint + - staticcheck + - revive + - stylecheck + - typecheck + - unconvert + - unused + +issues: + exclude-rules: + - text: "Use of weak random number generator" + linters: + - gosec + - text: "ST1003:" + linters: + - stylecheck + # FIXME: Disabled until golangci-lint updates stylecheck with this fix: + # https://github.com/dominikh/go-tools/issues/389 + - text: "ST1016:" + linters: + - stylecheck + - path: "migrations" + text: "SA1019:" + linters: + - staticcheck + - text: "leading space" + linters: + - nolintlint + + max-issues-per-linter: 10000 + max-same-issues: 10000 + +linters-settings: + dogsled: + max-blank-identifiers: 3 + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true + nolintlint: + allow-unused: false + allow-leading-space: true + require-explanation: false + require-specific: false diff --git a/router/keeper/genesis.go b/router/keeper/genesis.go index 5187464..38dfe01 100644 --- a/router/keeper/genesis.go +++ b/router/keeper/genesis.go @@ -12,6 +12,8 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { // Initialize store refund path for forwarded packets in genesis state that have not yet been acked. store := ctx.KVStore(k.storeKey) for key, value := range state.InFlightPackets { + key := key + value := value bz := k.cdc.MustMarshal(&value) store.Set([]byte(key), bz) } diff --git a/router/keeper/keeper.go b/router/keeper/keeper.go index d90c0a2..6ad28a9 100644 --- a/router/keeper/keeper.go +++ b/router/keeper/keeper.go @@ -381,7 +381,7 @@ func (k *Keeper) RetryTimeout( denom := transfertypes.ParseDenomTrace(data.Denom).IBCDenom() - var token = sdk.NewCoin(denom, amount) + token := sdk.NewCoin(denom, amount) // srcPacket and srcPacketSender are empty because inFlightPacket is non-nil. return k.ForwardTransferPacket( diff --git a/router/migrations/v1/genesis.pb.go b/router/migrations/v1/genesis.pb.go new file mode 100644 index 0000000..5a3757f --- /dev/null +++ b/router/migrations/v1/genesis.pb.go @@ -0,0 +1,495 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: router/v1/genesis.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = 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 the router 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_4940b763c55c4e0b, []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 (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// Params defines the set of IBC router parameters. +type Params struct { + FeePercentage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=fee_percentage,json=feePercentage,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"fee_percentage" yaml:"fee_percentage"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_4940b763c55c4e0b, []int{1} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*GenesisState)(nil), "router.v1.GenesisState") + proto.RegisterType((*Params)(nil), "router.v1.Params") +} + +func init() { proto.RegisterFile("router/v1/genesis.proto", fileDescriptor_4940b763c55c4e0b) } + +var fileDescriptor_4940b763c55c4e0b = []byte{ + // 291 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x50, 0x4d, 0x4b, 0xc3, 0x40, + 0x10, 0x4d, 0x40, 0x02, 0x8d, 0x1f, 0x60, 0x50, 0x14, 0x0f, 0x1b, 0xc9, 0x41, 0xbc, 0x64, 0x97, + 0xd6, 0x9b, 0x17, 0x21, 0x08, 0xc5, 0x5b, 0xa9, 0x37, 0x2f, 0xb2, 0xdd, 0x4c, 0xd6, 0xd0, 0x24, + 0x1b, 0x76, 0x37, 0xa9, 0xfd, 0x17, 0xfe, 0xac, 0x1e, 0x7b, 0x14, 0x0f, 0x41, 0x92, 0x7f, 0xe0, + 0x2f, 0x90, 0x6e, 0x42, 0xd1, 0xd3, 0xcc, 0xbc, 0xf7, 0xe6, 0xcd, 0xf0, 0xdc, 0x0b, 0x29, 0x2a, + 0x0d, 0x92, 0xd4, 0x63, 0xc2, 0xa1, 0x00, 0x95, 0x2a, 0x5c, 0x4a, 0xa1, 0x85, 0x37, 0xea, 0x09, + 0x5c, 0x8f, 0xaf, 0xce, 0xb8, 0xe0, 0xc2, 0xa0, 0x64, 0xd7, 0xf5, 0x82, 0xe0, 0xc1, 0x3d, 0x9a, + 0xf6, 0x1b, 0xcf, 0x9a, 0x6a, 0xf0, 0x88, 0xeb, 0x94, 0x54, 0xd2, 0x5c, 0x5d, 0xda, 0xd7, 0xf6, + 0xed, 0xe1, 0xe4, 0x14, 0xef, 0x1d, 0xf0, 0xcc, 0x10, 0xd1, 0xc1, 0xa6, 0xf1, 0xad, 0xf9, 0x20, + 0x0b, 0xde, 0x5d, 0xa7, 0xc7, 0xbd, 0xc2, 0x3d, 0x49, 0x00, 0x5e, 0x4b, 0x90, 0x0c, 0x0a, 0x4d, + 0x39, 0x18, 0x8b, 0x51, 0x34, 0xdd, 0xe9, 0xbf, 0x1a, 0xff, 0x86, 0xa7, 0xfa, 0xad, 0x5a, 0x60, + 0x26, 0x72, 0xc2, 0x84, 0xca, 0x85, 0x1a, 0x4a, 0xa8, 0xe2, 0x25, 0xd1, 0xeb, 0x12, 0x14, 0x7e, + 0x04, 0xf6, 0xd3, 0xf8, 0xe7, 0x6b, 0x9a, 0x67, 0xf7, 0xc1, 0x7f, 0xb7, 0x60, 0x7e, 0x9c, 0x00, + 0xcc, 0xf6, 0x73, 0xc4, 0x36, 0x2d, 0xb2, 0xb7, 0x2d, 0xb2, 0xbf, 0x5b, 0x64, 0x7f, 0x74, 0xc8, + 0xda, 0x76, 0xc8, 0xfa, 0xec, 0x90, 0xf5, 0xf2, 0xf4, 0xe7, 0x92, 0xd2, 0x92, 0x16, 0x1c, 0x32, + 0x51, 0x43, 0x58, 0x43, 0xa1, 0x2b, 0x09, 0x8a, 0x94, 0x94, 0x2d, 0x41, 0x87, 0x89, 0x90, 0x2b, + 0x2a, 0xe3, 0x30, 0x4f, 0xe3, 0x38, 0x83, 0x15, 0x95, 0x40, 0xea, 0x09, 0x19, 0xb2, 0x34, 0x0f, + 0x2d, 0x1c, 0x13, 0xd3, 0xdd, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0c, 0x58, 0x6d, 0x0c, 0x62, + 0x01, 0x00, 0x00, +} + +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 (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.FeePercentage.Size() + i -= size + if _, err := m.FeePercentage.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + 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 (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.FeePercentage.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 (m *Params) 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeePercentage", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.FeePercentage.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") +) \ No newline at end of file diff --git a/router/migrations/v2/gen_state.go b/router/migrations/v2/gen_state.go new file mode 100644 index 0000000..e88c77a --- /dev/null +++ b/router/migrations/v2/gen_state.go @@ -0,0 +1,16 @@ +package v2 + +import ( + v1 "github.com/strangelove-ventures/packet-forward-middleware/v4/router/migrations/v1" + routertypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" +) + +// MigrateGenState accepts exported v1 packetforwardmiddleware genesis state and migrates it to +// v2 packetforwardmiddleware genesis state. The migration includes: +// Introduce inFlightPackets map for keeping track of forwarded packet state. +func MigrateGenState(oldState *v1.GenesisState) *routertypes.GenesisState { + return &routertypes.GenesisState{ + Params: routertypes.Params(oldState.Params), + InFlightPackets: make(map[string]routertypes.InFlightPacket), + } +} diff --git a/router/migrations/v2/gen_state_test.go b/router/migrations/v2/gen_state_test.go new file mode 100644 index 0000000..08b5cb9 --- /dev/null +++ b/router/migrations/v2/gen_state_test.go @@ -0,0 +1,35 @@ +package v2_test + +import ( + "testing" + + v1 "github.com/strangelove-ventures/packet-forward-middleware/v4/router/migrations/v1" + v2 "github.com/strangelove-ventures/packet-forward-middleware/v4/router/migrations/v2" + routertypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" + "github.com/stretchr/testify/require" +) + +func TestMigrateGenState(t *testing.T) { + tests := []struct { + name string + oldState *v1.GenesisState + newState *routertypes.GenesisState + }{ + { + name: "successful migration introducing inFlightPackets", + oldState: &v1.GenesisState{Params: v1.Params{FeePercentage: routertypes.DefaultFeePercentage}}, + newState: &routertypes.GenesisState{ + Params: routertypes.Params{FeePercentage: routertypes.DefaultFeePercentage}, + InFlightPackets: make(map[string]routertypes.InFlightPacket), + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + actualState := v2.MigrateGenState(tc.oldState) + require.Equal(t, tc.newState, actualState) + require.NoError(t, actualState.Validate()) + }) + } +} diff --git a/router/module.go b/router/module.go index 6151c86..b535ef1 100644 --- a/router/module.go +++ b/router/module.go @@ -21,6 +21,9 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) +// ConsensusVersion defines the current packetforwardmiddleware module consensus version. +const ConsensusVersion = 2 + var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} @@ -128,7 +131,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 1 } +func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // BeginBlock implements the AppModule interface func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {} diff --git a/router/module_test.go b/router/module_test.go index 1882378..6945a14 100644 --- a/router/module_test.go +++ b/router/module_test.go @@ -6,7 +6,6 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - apptypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" transfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" "github.com/golang/mock/gomock" @@ -182,6 +181,7 @@ func TestOnRecvPacket_ForwardNoFee(t *testing.T) { port = "transfer" channel = "channel-0" ) + denom := makeIBCDenom(testDestinationPort, testDestinationChannel, testDenom) senderAccAddr := test.AccAddress() testCoin := sdk.NewCoin(denom, sdk.NewInt(100)) @@ -213,7 +213,7 @@ func TestOnRecvPacket_ForwardNoFee(t *testing.T) { keeper.DefaultTransferPacketTimeoutHeight, uint64(ctx.BlockTime().UnixNano())+uint64(keeper.DefaultForwardTransferPacketTimeoutTimestamp.Nanoseconds()), ), - ).Return(&apptypes.MsgTransferResponse{Sequence: 0}, nil), + ).Return(&transfertypes.MsgTransferResponse{Sequence: 0}, nil), setup.Mocks.IBCModuleMock.EXPECT().OnAcknowledgementPacket(ctx, packetFwd, successAck, senderAccAddr). Return(nil), @@ -285,7 +285,7 @@ func TestOnRecvPacket_ForwardWithFee(t *testing.T) { keeper.DefaultTransferPacketTimeoutHeight, uint64(ctx.BlockTime().UnixNano())+uint64(keeper.DefaultForwardTransferPacketTimeoutTimestamp.Nanoseconds()), ), - ).Return(&apptypes.MsgTransferResponse{Sequence: 0}, nil), + ).Return(&transfertypes.MsgTransferResponse{Sequence: 0}, nil), setup.Mocks.IBCModuleMock.EXPECT().OnAcknowledgementPacket(ctx, packetFwd, successAck, senderAccAddr). Return(nil), @@ -380,7 +380,7 @@ func TestOnRecvPacket_ForwardMultihopStringNext(t *testing.T) { setup.Mocks.TransferKeeperMock.EXPECT().Transfer( sdk.WrapSDKContext(ctx), msgTransfer1, - ).Return(&apptypes.MsgTransferResponse{Sequence: 0}, nil), + ).Return(&transfertypes.MsgTransferResponse{Sequence: 0}, nil), setup.Mocks.IBCModuleMock.EXPECT().OnRecvPacket(ctx, packet2, senderAccAddr2). Return(acknowledgement), @@ -388,7 +388,7 @@ func TestOnRecvPacket_ForwardMultihopStringNext(t *testing.T) { setup.Mocks.TransferKeeperMock.EXPECT().Transfer( sdk.WrapSDKContext(ctx), msgTransfer2, - ).Return(&apptypes.MsgTransferResponse{Sequence: 0}, nil), + ).Return(&transfertypes.MsgTransferResponse{Sequence: 0}, nil), setup.Mocks.IBCModuleMock.EXPECT().OnAcknowledgementPacket(ctx, packetFwd, successAck, senderAccAddr2). Return(nil), @@ -497,7 +497,7 @@ func TestOnRecvPacket_ForwardMultihopJSONNext(t *testing.T) { setup.Mocks.TransferKeeperMock.EXPECT().Transfer( sdk.WrapSDKContext(ctx), msgTransfer1, - ).Return(&apptypes.MsgTransferResponse{Sequence: 0}, nil), + ).Return(&transfertypes.MsgTransferResponse{Sequence: 0}, nil), setup.Mocks.IBCModuleMock.EXPECT().OnRecvPacket(ctx, packet2, senderAccAddr2). Return(acknowledgement), @@ -505,7 +505,7 @@ func TestOnRecvPacket_ForwardMultihopJSONNext(t *testing.T) { setup.Mocks.TransferKeeperMock.EXPECT().Transfer( sdk.WrapSDKContext(ctx), msgTransfer2, - ).Return(&apptypes.MsgTransferResponse{Sequence: 0}, nil), + ).Return(&transfertypes.MsgTransferResponse{Sequence: 0}, nil), setup.Mocks.IBCModuleMock.EXPECT().OnAcknowledgementPacket(ctx, packetFwd, successAck, senderAccAddr2). Return(nil), diff --git a/router/types/genesis.go b/router/types/genesis.go index 10efe10..0c9a079 100644 --- a/router/types/genesis.go +++ b/router/types/genesis.go @@ -1,5 +1,7 @@ package types +import "fmt" + // NewGenesisState creates a 29-fee GenesisState instance. func NewGenesisState(params Params, inFlightPackets map[string]InFlightPacket) *GenesisState { return &GenesisState{ @@ -19,5 +21,13 @@ func DefaultGenesisState() *GenesisState { // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - return gs.Params.Validate() + if err := gs.Params.Validate(); err != nil { + return fmt.Errorf("failed to validate genesis params: %w", err) + } + + if gs.InFlightPackets == nil { + return fmt.Errorf("in flight packets not initialized in genesis") + } + + return nil } diff --git a/router/types/keys.go b/router/types/keys.go index 7c8c1c4..3634eb6 100644 --- a/router/types/keys.go +++ b/router/types/keys.go @@ -16,9 +16,11 @@ const ( QuerierRoute = ModuleName ) -type NonrefundableKey struct{} -type DisableDenomCompositionKey struct{} -type ProcessedKey struct{} +type ( + NonrefundableKey struct{} + DisableDenomCompositionKey struct{} + ProcessedKey struct{} +) func RefundPacketKey(channelID, portID string, sequence uint64) []byte { return []byte(fmt.Sprintf("%s/%s/%d", channelID, portID, sequence)) diff --git a/router/types/params.go b/router/types/params.go index 894f77e..8884cfe 100644 --- a/router/types/params.go +++ b/router/types/params.go @@ -49,7 +49,6 @@ func validateFeePercentage(i interface{}) error { } if v.IsNegative() { return fmt.Errorf("invalid fee percentage. expected not negative, got %d", v.RoundInt64()) - } if !(v.LTE(sdk.OneDec())) { return fmt.Errorf("invalid fee percentage. expected less than one 1 got %d", v.RoundInt64()) diff --git a/test/setup.go b/test/setup.go index 7fc2612..7103f51 100644 --- a/test/setup.go +++ b/test/setup.go @@ -23,7 +23,7 @@ import ( tmdb "github.com/tendermint/tm-db" ) -func NewTestSetup(t *testing.T, ctl *gomock.Controller) *TestSetup { +func NewTestSetup(t *testing.T, ctl *gomock.Controller) *Setup { initializer := newInitializer() transferKeeperMock := mock.NewMockTransferKeeper(ctl) @@ -35,13 +35,12 @@ func NewTestSetup(t *testing.T, ctl *gomock.Controller) *TestSetup { paramsKeeper := initializer.paramsKeeper() routerKeeper := initializer.routerKeeper(paramsKeeper, transferKeeperMock, channelKeeperMock, distributionKeeperMock, bankKeeperMock, ics4WrapperMock) - //routerModule := initializer.routerModule(routerKeeper) require.NoError(t, initializer.StateStore.LoadLatestVersion()) routerKeeper.SetParams(initializer.Ctx, types.DefaultParams()) - return &TestSetup{ + return &Setup{ Initializer: initializer, Keepers: &testKeepers{ @@ -61,7 +60,7 @@ func NewTestSetup(t *testing.T, ctl *gomock.Controller) *TestSetup { } } -type TestSetup struct { +type Setup struct { Initializer initializer Keepers *testKeepers