From fc30a95128001777e76ac0e5378227d391659b6d Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 29 Apr 2024 14:57:35 +0200 Subject: [PATCH] chore: add depinject to mock module --- api/mock/module/v1/module.pulsar.go | 499 ++++++++++++++++++++++++++++ go.mod | 2 +- proto/mock/module/v1/module.proto | 12 + testing/mock/ack.go | 23 -- testing/mock/depinject.go | 56 ++++ testing/mock/mock.go | 121 +------ testing/mock/module.go | 112 +++++++ 7 files changed, 695 insertions(+), 130 deletions(-) create mode 100644 api/mock/module/v1/module.pulsar.go create mode 100644 proto/mock/module/v1/module.proto delete mode 100644 testing/mock/ack.go create mode 100644 testing/mock/depinject.go create mode 100644 testing/mock/module.go diff --git a/api/mock/module/v1/module.pulsar.go b/api/mock/module/v1/module.pulsar.go new file mode 100644 index 00000000000..fa6e8e8cf10 --- /dev/null +++ b/api/mock/module/v1/module.pulsar.go @@ -0,0 +1,499 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package modulev1 + +import ( + _ "cosmossdk.io/api/cosmos/app/v1alpha1" + fmt "fmt" + runtime "github.com/cosmos/cosmos-proto/runtime" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" +) + +var ( + md_Module protoreflect.MessageDescriptor +) + +func init() { + file_mock_module_v1_module_proto_init() + md_Module = File_mock_module_v1_module_proto.Messages().ByName("Module") +} + +var _ protoreflect.Message = (*fastReflection_Module)(nil) + +type fastReflection_Module Module + +func (x *Module) ProtoReflect() protoreflect.Message { + return (*fastReflection_Module)(x) +} + +func (x *Module) slowProtoReflect() protoreflect.Message { + mi := &file_mock_module_v1_module_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_Module_messageType fastReflection_Module_messageType +var _ protoreflect.MessageType = fastReflection_Module_messageType{} + +type fastReflection_Module_messageType struct{} + +func (x fastReflection_Module_messageType) Zero() protoreflect.Message { + return (*fastReflection_Module)(nil) +} +func (x fastReflection_Module_messageType) New() protoreflect.Message { + return new(fastReflection_Module) +} +func (x fastReflection_Module_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_Module +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_Module) Descriptor() protoreflect.MessageDescriptor { + return md_Module +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_Module) Type() protoreflect.MessageType { + return _fastReflection_Module_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_Module) New() protoreflect.Message { + return new(fastReflection_Module) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_Module) Interface() protoreflect.ProtoMessage { + return (*Module)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: mock.module.v1.Module")) + } + panic(fmt.Errorf("message mock.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: mock.module.v1.Module")) + } + panic(fmt.Errorf("message mock.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: mock.module.v1.Module")) + } + panic(fmt.Errorf("message mock.module.v1.Module does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: mock.module.v1.Module")) + } + panic(fmt.Errorf("message mock.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: mock.module.v1.Module")) + } + panic(fmt.Errorf("message mock.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: mock.module.v1.Module")) + } + panic(fmt.Errorf("message mock.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_Module) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in mock.module.v1.Module", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_Module) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_Module) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, 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 protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc (unknown) +// source: mock/module/v1/module.proto + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// Module is the config object of the mock module. +type Module struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Module) Reset() { + *x = Module{} + if protoimpl.UnsafeEnabled { + mi := &file_mock_module_v1_module_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Module) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Module) ProtoMessage() {} + +// Deprecated: Use Module.ProtoReflect.Descriptor instead. +func (*Module) Descriptor() ([]byte, []int) { + return file_mock_module_v1_module_proto_rawDescGZIP(), []int{0} +} + +var File_mock_module_v1_module_proto protoreflect.FileDescriptor + +var file_mock_module_v1_module_proto_rawDesc = []byte{ + 0x0a, 0x1b, 0x6d, 0x6f, 0x63, 0x6b, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, + 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, + 0x6f, 0x63, 0x6b, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, + 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x37, 0x0a, 0x06, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x2d, 0xba, 0xc0, 0x96, 0xda, 0x01, + 0x27, 0x0a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x69, 0x62, 0x63, 0x2d, 0x67, 0x6f, 0x2f, 0x74, 0x65, 0x73, 0x74, + 0x69, 0x6e, 0x67, 0x2f, 0x6d, 0x6f, 0x63, 0x6b, 0x42, 0xb1, 0x01, 0x0a, 0x12, 0x63, 0x6f, 0x6d, + 0x2e, 0x6d, 0x6f, 0x63, 0x6b, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, + 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x34, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2f, 0x69, 0x62, 0x63, 0x2d, 0x67, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x6f, 0x63, + 0x6b, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, + 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4d, 0x4d, 0x58, 0xaa, 0x02, 0x0e, 0x4d, 0x6f, 0x63, + 0x6b, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x0e, 0x4d, 0x6f, + 0x63, 0x6b, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1a, 0x4d, + 0x6f, 0x63, 0x6b, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, + 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x10, 0x4d, 0x6f, 0x63, 0x6b, + 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_mock_module_v1_module_proto_rawDescOnce sync.Once + file_mock_module_v1_module_proto_rawDescData = file_mock_module_v1_module_proto_rawDesc +) + +func file_mock_module_v1_module_proto_rawDescGZIP() []byte { + file_mock_module_v1_module_proto_rawDescOnce.Do(func() { + file_mock_module_v1_module_proto_rawDescData = protoimpl.X.CompressGZIP(file_mock_module_v1_module_proto_rawDescData) + }) + return file_mock_module_v1_module_proto_rawDescData +} + +var file_mock_module_v1_module_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_mock_module_v1_module_proto_goTypes = []interface{}{ + (*Module)(nil), // 0: mock.module.v1.Module +} +var file_mock_module_v1_module_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_mock_module_v1_module_proto_init() } +func file_mock_module_v1_module_proto_init() { + if File_mock_module_v1_module_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_mock_module_v1_module_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Module); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_mock_module_v1_module_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_mock_module_v1_module_proto_goTypes, + DependencyIndexes: file_mock_module_v1_module_proto_depIdxs, + MessageInfos: file_mock_module_v1_module_proto_msgTypes, + }.Build() + File_mock_module_v1_module_proto = out.File + file_mock_module_v1_module_proto_rawDesc = nil + file_mock_module_v1_module_proto_goTypes = nil + file_mock_module_v1_module_proto_depIdxs = nil +} diff --git a/go.mod b/go.mod index 55c72789dc1..6b327042ccd 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ go 1.21 module github.com/cosmos/ibc-go/v8 -// Replace to local pin of capability to pick up depinject +// Replace to local pin of capability to pick up depinject replace github.com/cosmos/ibc-go/modules/capability => ./modules/capability require ( diff --git a/proto/mock/module/v1/module.proto b/proto/mock/module/v1/module.proto new file mode 100644 index 00000000000..08eefbe94b8 --- /dev/null +++ b/proto/mock/module/v1/module.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package mock.module.v1; + +import "cosmos/app/v1alpha1/module.proto"; + +// Module is the config object of the mock module. +message Module { + option (cosmos.app.v1alpha1.module) = { + go_import: "github.com/cosmos/ibc-go/testing/mock" + }; +} \ No newline at end of file diff --git a/testing/mock/ack.go b/testing/mock/ack.go deleted file mode 100644 index 619ac098d44..00000000000 --- a/testing/mock/ack.go +++ /dev/null @@ -1,23 +0,0 @@ -package mock - -// EmptyAcknowledgement implements the exported.Acknowledgement interface and always returns an empty byte string as Response -type EmptyAcknowledgement struct { - Response []byte -} - -// NewEmptyAcknowledgement returns a new instance of EmptyAcknowledgement -func NewEmptyAcknowledgement() EmptyAcknowledgement { - return EmptyAcknowledgement{ - Response: []byte{}, - } -} - -// Success implements the Acknowledgement interface -func (EmptyAcknowledgement) Success() bool { - return true -} - -// Acknowledgement implements the Acknowledgement interface -func (EmptyAcknowledgement) Acknowledgement() []byte { - return []byte{} -} diff --git a/testing/mock/depinject.go b/testing/mock/depinject.go new file mode 100644 index 00000000000..9f1e086810a --- /dev/null +++ b/testing/mock/depinject.go @@ -0,0 +1,56 @@ +package mock + +import ( + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" + storetypes "cosmossdk.io/store/types" + + capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" + + modulev1 "github.com/cosmos/ibc-go/api/mock/module/v1" + porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" +) + +func init() { + appmodule.Register( + &modulev1.Module{}, + appmodule.Provide(ProvideModule), + ) +} + +var _ depinject.OnePerModuleType = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (AppModule) IsOnePerModuleType() {} + +// ModuleInputs defines the core module inputs for depinject. +type ModuleInputs struct { + depinject.In + + Config *modulev1.Module + + // TODO: mock memKey is not directly used by the mock IBCModule but is included in app_v1 and used in some testing. + // Verify what tests are using this and if it can be removed here. It is certainly used ibccallbacks testing with mock contract keeper. + Key *storetypes.MemoryStoreKey + + CapabilityKeeper *capabilitykeeper.Keeper + PortKeeper PortKeeper +} + +// ModuleOutputs defines the core module outputs for depinject. +type ModuleOutputs struct { + depinject.Out + + Module appmodule.AppModule + IBCModule porttypes.IBCModuleRoute + ScopedKeeper capabilitykeeper.ScopedKeeper +} + +// ProvideModule defines a depinject provider function to supply the module dependencies and return its outputs. +func ProvideModule(in ModuleInputs) ModuleOutputs { + scopedKeeper := in.CapabilityKeeper.ScopeToModule(ModuleName) + m := NewAppModule(in.PortKeeper) + ibcModule := NewIBCModule(&m, NewIBCApp(ModuleName, scopedKeeper)) + + return ModuleOutputs{Module: m, IBCModule: porttypes.IBCModuleRoute{Name: ModuleName, IBCModule: ibcModule}, ScopedKeeper: scopedKeeper} +} diff --git a/testing/mock/mock.go b/testing/mock/mock.go index 3a15d776a63..897c1efd3cc 100644 --- a/testing/mock/mock.go +++ b/testing/mock/mock.go @@ -1,27 +1,13 @@ package mock import ( - "encoding/json" "fmt" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - - "cosmossdk.io/core/appmodule" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - - abci "github.com/cometbft/cometbft/abci/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" - host "github.com/cosmos/ibc-go/v8/modules/core/24-host" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) @@ -56,113 +42,36 @@ var ( TestValue = []byte("test-value") ) -var ( - _ module.AppModuleBasic = (*AppModuleBasic)(nil) - _ appmodule.AppModule = (*AppModule)(nil) - - _ porttypes.IBCModule = (*IBCModule)(nil) -) - -// Expected Interface -// PortKeeper defines the expected IBC port keeper +// PortKeeper defines the expected IBC PortKeeper interface. type PortKeeper interface { BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability IsBound(ctx sdk.Context, portID string) bool } -// AppModuleBasic is the mock AppModuleBasic. -type AppModuleBasic struct{} +var _ exported.Acknowledgement = (*EmptyAcknowledgement)(nil) -// IsOnePerModuleType implements the depinject.OnePerModuleType interface. -func (AppModuleBasic) IsOnePerModuleType() {} - -// IsAppModule implements the appmodule.AppModule interface. -func (AppModuleBasic) IsAppModule() {} - -// Name implements AppModuleBasic interface. -func (AppModuleBasic) Name() string { - return ModuleName +// EmptyAcknowledgement implements the exported.Acknowledgement interface and always returns an empty byte string as Response +type EmptyAcknowledgement struct { + Response []byte } -// IsOnePerModuleType implements the depinject.OnePerModuleType interface. -func (AppModule) IsOnePerModuleType() {} - -// IsAppModule implements the appmodule.AppModule interface. -func (AppModule) IsAppModule() {} - -// RegisterLegacyAminoCodec implements AppModuleBasic interface. -func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} - -// RegisterInterfaces implements AppModuleBasic interface. -func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {} - -// DefaultGenesis implements AppModuleBasic interface. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return nil -} - -// ValidateGenesis implements the AppModuleBasic interface. -func (AppModuleBasic) ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error { - return nil -} - -// RegisterGRPCGatewayRoutes implements AppModuleBasic interface. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {} - -// GetTxCmd implements AppModuleBasic interface. -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil -} - -// GetQueryCmd implements AppModuleBasic interface. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - -// AppModule represents the AppModule for the mock module. -type AppModule struct { - AppModuleBasic - ibcApps []*IBCApp - portKeeper PortKeeper -} - -// NewAppModule returns a mock AppModule instance. -func NewAppModule(pk PortKeeper) AppModule { - return AppModule{ - portKeeper: pk, +// NewEmptyAcknowledgement returns a new instance of EmptyAcknowledgement +func NewEmptyAcknowledgement() EmptyAcknowledgement { + return EmptyAcknowledgement{ + Response: []byte{}, } } -// RegisterInvariants implements the AppModule interface. -func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} - -// RegisterServices implements the AppModule interface. -func (AppModule) RegisterServices(module.Configurator) {} - -// InitGenesis implements the AppModule interface. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - for _, ibcApp := range am.ibcApps { - if ibcApp.PortID != "" && !am.portKeeper.IsBound(ctx, ibcApp.PortID) { - // bind mock portID - capability := am.portKeeper.BindPort(ctx, ibcApp.PortID) - err := ibcApp.ScopedKeeper.ClaimCapability(ctx, capability, host.PortPath(ibcApp.PortID)) - if err != nil { - panic(err) - } - } - } - - return []abci.ValidatorUpdate{} +// Success implements the Acknowledgement interface +func (EmptyAcknowledgement) Success() bool { + return true } -// ExportGenesis implements the AppModule interface. -func (AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - return nil +// Acknowledgement implements the Acknowledgement interface +func (EmptyAcknowledgement) Acknowledgement() []byte { + return []byte{} } -// ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 1 } - var _ exported.Path = KeyPath{} // KeyPath defines a placeholder struct which implements the exported.Path interface diff --git a/testing/mock/module.go b/testing/mock/module.go new file mode 100644 index 00000000000..a1556169817 --- /dev/null +++ b/testing/mock/module.go @@ -0,0 +1,112 @@ +package mock + +import ( + "encoding/json" + + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + "cosmossdk.io/core/appmodule" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + host "github.com/cosmos/ibc-go/v8/modules/core/24-host" +) + +var ( + _ module.AppModuleBasic = (*AppModuleBasic)(nil) + _ appmodule.AppModule = (*AppModule)(nil) +) + +// AppModuleBasic is the mock AppModuleBasic. +type AppModuleBasic struct{} + +// IsAppModule implements the appmodule.AppModule interface. +func (AppModuleBasic) IsAppModule() {} + +// Name implements AppModuleBasic interface. +func (AppModuleBasic) Name() string { + return ModuleName +} + +// IsAppModule implements the appmodule.AppModule interface. +func (AppModule) IsAppModule() {} + +// RegisterLegacyAminoCodec implements AppModuleBasic interface. +func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} + +// RegisterInterfaces implements AppModuleBasic interface. +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {} + +// DefaultGenesis implements AppModuleBasic interface. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return nil +} + +// ValidateGenesis implements the AppModuleBasic interface. +func (AppModuleBasic) ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error { + return nil +} + +// RegisterGRPCGatewayRoutes implements AppModuleBasic interface. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {} + +// GetTxCmd implements AppModuleBasic interface. +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd implements AppModuleBasic interface. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return nil +} + +// AppModule represents the AppModule for the mock module. +type AppModule struct { + AppModuleBasic + ibcApps []*IBCApp + portKeeper PortKeeper +} + +// NewAppModule returns a mock AppModule instance. +func NewAppModule(pk PortKeeper) AppModule { + return AppModule{ + portKeeper: pk, + } +} + +// RegisterInvariants implements the AppModule interface. +func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} + +// RegisterServices implements the AppModule interface. +func (AppModule) RegisterServices(module.Configurator) {} + +// InitGenesis implements the AppModule interface. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + for _, ibcApp := range am.ibcApps { + if ibcApp.PortID != "" && !am.portKeeper.IsBound(ctx, ibcApp.PortID) { + // bind mock portID + capability := am.portKeeper.BindPort(ctx, ibcApp.PortID) + err := ibcApp.ScopedKeeper.ClaimCapability(ctx, capability, host.PortPath(ibcApp.PortID)) + if err != nil { + panic(err) + } + } + } + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis implements the AppModule interface. +func (AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + return nil +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 }