From 14a862f5fcba92ea385ff4da134723d56cdb2a34 Mon Sep 17 00:00:00 2001 From: Torekhan Abayev Date: Thu, 2 May 2024 20:26:22 +0200 Subject: [PATCH] Fix go problems in test files --- go.mod | 2 +- .../gridnode/gridnode/v1/module/module.pb.go | 320 ------------------ testutil/keeper/gridnode.go | 10 + testutil/keeper/mockAccountKeeper.go | 87 +++++ 4 files changed, 98 insertions(+), 321 deletions(-) delete mode 100644 proto/gridnode/gridnode/v1/module/module.pb.go create mode 100644 testutil/keeper/mockAccountKeeper.go diff --git a/go.mod b/go.mod index a00f3ac..93c797c 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-beta.5 github.com/cosmos/cosmos-sdk v0.50.6 github.com/cosmos/gogoproto v1.4.12 + github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -104,7 +105,6 @@ require ( github.com/gogo/googleapis v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v1.2.0 // indirect - github.com/golang/mock v1.6.0 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/cel-go v0.18.2 // indirect diff --git a/proto/gridnode/gridnode/v1/module/module.pb.go b/proto/gridnode/gridnode/v1/module/module.pb.go deleted file mode 100644 index 0055c5a..0000000 --- a/proto/gridnode/gridnode/v1/module/module.pb.go +++ /dev/null @@ -1,320 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: gridnode/gridnode/v1/module/module.proto - -package gridnode_gridnode_v1_module - -import ( - _ "cosmos/app/v1alpha1" - fmt "fmt" - proto "github.com/cosmos/gogoproto/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 - -// Module is the config object for the module. -type Module struct { - // authority defines the custom module authority. If not set, defaults to the governance module. - Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` -} - -func (m *Module) Reset() { *m = Module{} } -func (m *Module) String() string { return proto.CompactTextString(m) } -func (*Module) ProtoMessage() {} -func (*Module) Descriptor() ([]byte, []int) { - return fileDescriptor_70132d11547b1efc, []int{0} -} -func (m *Module) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Module) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Module.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 *Module) XXX_Merge(src proto.Message) { - xxx_messageInfo_Module.Merge(m, src) -} -func (m *Module) XXX_Size() int { - return m.Size() -} -func (m *Module) XXX_DiscardUnknown() { - xxx_messageInfo_Module.DiscardUnknown(m) -} - -var xxx_messageInfo_Module proto.InternalMessageInfo - -func (m *Module) GetAuthority() string { - if m != nil { - return m.Authority - } - return "" -} - -func init() { - proto.RegisterType((*Module)(nil), "gridnode.gridnode.v1.module.Module") -} - -func init() { - proto.RegisterFile("gridnode/gridnode/v1/module/module.proto", fileDescriptor_70132d11547b1efc) -} - -var fileDescriptor_70132d11547b1efc = []byte{ - // 166 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x48, 0x2f, 0xca, 0x4c, - 0xc9, 0xcb, 0x4f, 0x49, 0xd5, 0x87, 0x33, 0xca, 0x0c, 0xf5, 0x73, 0xf3, 0x53, 0x4a, 0x73, 0x52, - 0xa1, 0x94, 0x5e, 0x41, 0x51, 0x7e, 0x49, 0xbe, 0x90, 0x34, 0x4c, 0x81, 0x1e, 0x9c, 0x51, 0x66, - 0xa8, 0x07, 0x51, 0x22, 0xa5, 0x90, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0xac, 0x9f, 0x58, 0x50, 0xa0, - 0x5f, 0x66, 0x98, 0x98, 0x53, 0x90, 0x91, 0x68, 0x88, 0xa2, 0x5d, 0xc9, 0x99, 0x8b, 0xcd, 0x17, - 0xcc, 0x17, 0x92, 0xe1, 0xe2, 0x4c, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0x94, 0x60, - 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x08, 0x58, 0x49, 0xef, 0x3a, 0x30, 0xed, 0x16, 0xa3, 0x28, - 0x97, 0x30, 0xdc, 0x3d, 0x15, 0x70, 0xa7, 0x39, 0x49, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, - 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, - 0xb1, 0x1c, 0x43, 0x12, 0x1b, 0xd8, 0x16, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7a, 0x1c, - 0x58, 0xa1, 0xd0, 0x00, 0x00, 0x00, -} - -func (m *Module) 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 *Module) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Module) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Authority) > 0 { - i -= len(m.Authority) - copy(dAtA[i:], m.Authority) - i = encodeVarintModule(dAtA, i, uint64(len(m.Authority))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintModule(dAtA []byte, offset int, v uint64) int { - offset -= sovModule(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Module) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Authority) - if l > 0 { - n += 1 + l + sovModule(uint64(l)) - } - return n -} - -func sovModule(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozModule(x uint64) (n int) { - return sovModule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Module) 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 ErrIntOverflowModule - } - 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: Module: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowModule - } - 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 ErrInvalidLengthModule - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthModule - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Authority = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipModule(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthModule - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipModule(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, ErrIntOverflowModule - } - 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, ErrIntOverflowModule - } - 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, ErrIntOverflowModule - } - 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, ErrInvalidLengthModule - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupModule - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthModule - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthModule = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowModule = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupModule = fmt.Errorf("proto: unexpected end of group") -) diff --git a/testutil/keeper/gridnode.go b/testutil/keeper/gridnode.go index b9b6526..4b733a2 100644 --- a/testutil/keeper/gridnode.go +++ b/testutil/keeper/gridnode.go @@ -43,6 +43,7 @@ func GridnodeKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { // Create a mock BankKeeper for testing purposes bankKeeper := mockBankKeeper() + accountKeeper := mockAccountKeeper() k := keeper.NewKeeper( cdc, @@ -50,6 +51,7 @@ func GridnodeKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { bankKeeper, // Pass the bankKeeper as an argument authority.String(), runtime.NewKVStoreService(storeKey), + accountKeeper, ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) @@ -67,3 +69,11 @@ func mockBankKeeper() types.BankKeeper { // with the necessary methods for your tests return &MockBankKeeper{} } + +// Create a mock BankKeeper for testing purposes +func mockAccountKeeper() types.AccountKeeper { + // Implement your mock BankKeeper here + // This can be a simple struct that fulfills the types.BankKeeper interface + // with the necessary methods for your tests + return &MockAccountKeeper{} +} diff --git a/testutil/keeper/mockAccountKeeper.go b/testutil/keeper/mockAccountKeeper.go new file mode 100644 index 0000000..873ca8c --- /dev/null +++ b/testutil/keeper/mockAccountKeeper.go @@ -0,0 +1,87 @@ +package keeper + +import ( + context "context" + reflect "reflect" + + address "cosmossdk.io/core/address" + types "github.com/cosmos/cosmos-sdk/types" + gomock "github.com/golang/mock/gomock" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// AddressCodec mocks base method. +func (m *MockAccountKeeper) AddressCodec() address.Codec { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddressCodec") + ret0, _ := ret[0].(address.Codec) + return ret0 +} + +// AddressCodec indicates an expected call of AddressCodec. +func (mr *MockAccountKeeperMockRecorder) AddressCodec() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddressCodec", reflect.TypeOf((*MockAccountKeeper)(nil).AddressCodec)) +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types.AccAddress) types.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// NewAccountWithAddress mocks base method. +func (m *MockAccountKeeper) NewAccountWithAddress(ctx context.Context, addr types.AccAddress) types.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewAccountWithAddress", ctx, addr) + ret0, _ := ret[0].(types.AccountI) + return ret0 +} + +// NewAccountWithAddress indicates an expected call of NewAccountWithAddress. +func (mr *MockAccountKeeperMockRecorder) NewAccountWithAddress(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAccountWithAddress", reflect.TypeOf((*MockAccountKeeper)(nil).NewAccountWithAddress), ctx, addr) +} + +// SetAccount mocks base method. +func (m *MockAccountKeeper) SetAccount(ctx context.Context, acc types.AccountI) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetAccount", ctx, acc) +} + +// SetAccount indicates an expected call of SetAccount. +func (mr *MockAccountKeeperMockRecorder) SetAccount(ctx, acc interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetAccount), ctx, acc) +}