diff --git a/CHANGELOG.md b/CHANGELOG.md index 8656e892956..1bcdbc707c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +49,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* (testutil) [#12278](https:12278//github.com/cosmos/cosmos-sdk/pull/12278) Move all function from `simapp/helpers` to `testutil/sims` +* (simapp) [#12312](https:12278//github.com/cosmos/cosmos-sdk/pull/12312) Move `simapp.EmptyAppOptions` to `simtestutil.EmptyAppOptions` (`testutil/sims`) +* (simapp) [#12312](https:12278//github.com/cosmos/cosmos-sdk/pull/12312) Remove `skipUpgradeHeights map[int64]bool` and `homePath string` from `NewSimApp` constructor as per migration of `x/upgrade` to app-wiring. +* (testutil) [#12278](https:12278//github.com/cosmos/cosmos-sdk/pull/12278) Move all functions from `simapp/helpers` to `testutil/sims` * (testutil) [#12233](https://github.com/cosmos/cosmos-sdk/pull/12233) Move `simapp.TestAddr` to `simtestutil.TestAddr` (`testutil/sims`) * (x/staking) [#12102](https://github.com/cosmos/cosmos-sdk/pull/12102) Staking keeper now is passed by reference instead of copy. Keeper's SetHooks no longer returns keeper. It updates the keeper in place instead. * (linting) [#12141](https://github.com/cosmos/cosmos-sdk/pull/12141) Fix usability related linting for database. This means removing the infix Prefix from `prefix.NewPrefixWriter` and such so that it is `prefix.NewWriter` and making `db.DBConnection` and such into `db.Connection` diff --git a/api/cosmos/bank/module/v1/module.pulsar.go b/api/cosmos/bank/module/v1/module.pulsar.go index f18cd522dcb..1b3b958e857 100644 --- a/api/cosmos/bank/module/v1/module.pulsar.go +++ b/api/cosmos/bank/module/v1/module.pulsar.go @@ -506,7 +506,7 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// Module is the config object of the params module. +// Module is the config object of the bank module. type Module struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/api/cosmos/upgrade/module/v1/module.pulsar.go b/api/cosmos/upgrade/module/v1/module.pulsar.go new file mode 100644 index 00000000000..3b715768374 --- /dev/null +++ b/api/cosmos/upgrade/module/v1/module.pulsar.go @@ -0,0 +1,503 @@ +// 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_cosmos_upgrade_module_v1_module_proto_init() + md_Module = File_cosmos_upgrade_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_cosmos_upgrade_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: cosmos.upgrade.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.upgrade.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: cosmos.upgrade.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.upgrade.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: cosmos.upgrade.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.upgrade.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: cosmos.upgrade.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.upgrade.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: cosmos.upgrade.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.upgrade.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: cosmos.upgrade.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.upgrade.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 cosmos.upgrade.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: cosmos/upgrade/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 upgrade module. +type Module struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Module) Reset() { + *x = Module{} + if protoimpl.UnsafeEnabled { + mi := &file_cosmos_upgrade_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_cosmos_upgrade_module_v1_module_proto_rawDescGZIP(), []int{0} +} + +var File_cosmos_upgrade_module_v1_module_proto protoreflect.FileDescriptor + +var file_cosmos_upgrade_module_v1_module_proto_rawDesc = []byte{ + 0x0a, 0x25, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, + 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 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, 0x38, 0x0a, 0x06, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x2e, 0xba, + 0xc0, 0x96, 0xda, 0x01, 0x28, 0x0a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, + 0x73, 0x64, 0x6b, 0x2f, 0x78, 0x2f, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x42, 0xe2, 0x01, + 0x0a, 0x1c, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x75, 0x70, 0x67, + 0x72, 0x61, 0x64, 0x65, 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, 0x32, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x2f, 0x6d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, + 0x31, 0xa2, 0x02, 0x03, 0x43, 0x55, 0x4d, 0xaa, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2e, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, + 0x56, 0x31, 0xca, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x55, 0x70, 0x67, 0x72, + 0x61, 0x64, 0x65, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x24, + 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x5c, 0x4d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, + 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x55, + 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, + 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_cosmos_upgrade_module_v1_module_proto_rawDescOnce sync.Once + file_cosmos_upgrade_module_v1_module_proto_rawDescData = file_cosmos_upgrade_module_v1_module_proto_rawDesc +) + +func file_cosmos_upgrade_module_v1_module_proto_rawDescGZIP() []byte { + file_cosmos_upgrade_module_v1_module_proto_rawDescOnce.Do(func() { + file_cosmos_upgrade_module_v1_module_proto_rawDescData = protoimpl.X.CompressGZIP(file_cosmos_upgrade_module_v1_module_proto_rawDescData) + }) + return file_cosmos_upgrade_module_v1_module_proto_rawDescData +} + +var file_cosmos_upgrade_module_v1_module_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_cosmos_upgrade_module_v1_module_proto_goTypes = []interface{}{ + (*Module)(nil), // 0: cosmos.upgrade.module.v1.Module +} +var file_cosmos_upgrade_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_cosmos_upgrade_module_v1_module_proto_init() } +func file_cosmos_upgrade_module_v1_module_proto_init() { + if File_cosmos_upgrade_module_v1_module_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_cosmos_upgrade_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_cosmos_upgrade_module_v1_module_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_cosmos_upgrade_module_v1_module_proto_goTypes, + DependencyIndexes: file_cosmos_upgrade_module_v1_module_proto_depIdxs, + MessageInfos: file_cosmos_upgrade_module_v1_module_proto_msgTypes, + }.Build() + File_cosmos_upgrade_module_v1_module_proto = out.File + file_cosmos_upgrade_module_v1_module_proto_rawDesc = nil + file_cosmos_upgrade_module_v1_module_proto_goTypes = nil + file_cosmos_upgrade_module_v1_module_proto_depIdxs = nil +} diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 173ba79b0e8..9fd64fe46dd 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -64,7 +64,7 @@ func TestBaseApp_BlockGas(t *testing.T) { } encCfg := simapp.MakeTestEncodingConfig() - app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, "", 0, encCfg, simapp.EmptyAppOptions{}, routerOpt) + app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, 0, encCfg, simtestutil.EmptyAppOptions{}, routerOpt) app.InterfaceRegistry().RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}, ) diff --git a/depinject/README.md b/depinject/README.md index c234bead99d..f4dab01bbcb 100644 --- a/depinject/README.md +++ b/depinject/README.md @@ -52,8 +52,6 @@ func NewSimApp( db dbm.DB, traceStore io.Writer, loadLatest bool, - skipUpgradeHeights map[int64]bool, - homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, appOpts servertypes.AppOptions, @@ -106,8 +104,9 @@ Here is an example Graphviz rendering of a dependency graph build which failed: ![Graphviz Error Example](./testdata/example_error.svg) Graphviz DOT files can be converted into SVG's for viewing in a web browser using the `dot` command-line tool, ex: -``` + +```txt > dot -Tsvg debug_container.dot > debug_container.svg ``` -Many other tools including some IDEs support working with DOT files. \ No newline at end of file +Many other tools including some IDEs support working with DOT files. diff --git a/docs/architecture/adr-038-state-listening.md b/docs/architecture/adr-038-state-listening.md index b9c209b4aa3..db3c2b8ea74 100644 --- a/docs/architecture/adr-038-state-listening.md +++ b/docs/architecture/adr-038-state-listening.md @@ -435,9 +435,8 @@ e.g. in `NewSimApp`: ```go func NewSimApp( - logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool, - homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, - appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), + logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, invCheckPeriod uint, + encodingConfig simappparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { ... diff --git a/proto/cosmos/bank/module/v1/module.proto b/proto/cosmos/bank/module/v1/module.proto index a967334015b..96ddcc834e1 100644 --- a/proto/cosmos/bank/module/v1/module.proto +++ b/proto/cosmos/bank/module/v1/module.proto @@ -4,7 +4,7 @@ package cosmos.bank.module.v1; import "cosmos/app/v1alpha1/module.proto"; -// Module is the config object of the params module. +// Module is the config object of the bank module. message Module { option (cosmos.app.v1alpha1.module) = { go_import: "github.com/cosmos/cosmos-sdk/x/bank" diff --git a/proto/cosmos/upgrade/module/v1/module.proto b/proto/cosmos/upgrade/module/v1/module.proto new file mode 100644 index 00000000000..da848b73648 --- /dev/null +++ b/proto/cosmos/upgrade/module/v1/module.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package cosmos.upgrade.module.v1; + +import "cosmos/app/v1alpha1/module.proto"; + +// Module is the config object of the upgrade module. +message Module { + option (cosmos.app.v1alpha1.module) = { + go_import: "github.com/cosmos/cosmos-sdk/x/upgrade" + }; +} \ No newline at end of file diff --git a/server/README.md b/server/README.md index 0d7d30ac0f7..cc4b910631a 100644 --- a/server/README.md +++ b/server/README.md @@ -81,19 +81,13 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts server.A cache = store.NewCommitKVStoreCacheManager() } - skipUpgradeHeights := make(map[int64]bool) - for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { - skipUpgradeHeights[int64(h)] = true - } - pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts) if err != nil { panic(err) } return simapp.NewSimApp( - logger, db, traceStore, true, skipUpgradeHeights, - cast.ToString(appOpts.Get(flags.FlagHome)), + logger, db, traceStore, true, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), baseapp.SetPruning(pruningOpts), baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), diff --git a/server/export_test.go b/server/export_test.go index 7ce2f40b051..7f8a5f5e582 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -129,7 +129,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t logger, _ := log.NewDefaultLogger("plain", "info", false) db := dbm.NewMemDB() encCfg := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(logger, db, nil, true, 0, encCfg, simtestutil.NewAppOptionsWithFlagHome(tempDir)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") @@ -155,18 +155,18 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t app.Commit() cmd := server.ExportCmd( - func(_ log.Logger, _ dbm.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOptons types.AppOptions) (types.ExportedApp, error) { + func(_ log.Logger, _ dbm.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOptions types.AppOptions) (types.ExportedApp, error) { encCfg := simapp.MakeTestEncodingConfig() var simApp *simapp.SimApp if height != -1 { - simApp = simapp.NewSimApp(logger, db, nil, false, map[int64]bool{}, "", 0, encCfg, appOptons) + simApp = simapp.NewSimApp(logger, db, nil, false, 0, encCfg, appOptions) if err := simApp.LoadHeight(height); err != nil { return types.ExportedApp{}, err } } else { - simApp = simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, "", 0, encCfg, appOptons) + simApp = simapp.NewSimApp(logger, db, nil, true, 0, encCfg, appOptions) } return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) diff --git a/simapp/app.go b/simapp/app.go index 802b99f6ada..8beea90b13e 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -99,8 +99,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) -const appName = "SimApp" - var ( // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -200,17 +198,18 @@ var AppConfig = appconfig.LoadYAML(appConfigYaml) // NewSimApp returns a reference to an initialized SimApp. func NewSimApp( - logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool, - homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, + logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { - app := &SimApp{ - invCheckPeriod: invCheckPeriod, - } - var appBuilder *runtime.AppBuilder + var ( + appBuilder *runtime.AppBuilder + app = &SimApp{invCheckPeriod: invCheckPeriod} + // merge the app.yaml and the appOpts in one config + appConfig = depinject.Configs(AppConfig, depinject.Supply(appOpts)) + ) - if err := depinject.Inject(AppConfig, + if err := depinject.Inject(appConfig, &appBuilder, &app.ParamsKeeper, &app.CapabilityKeeper, @@ -228,16 +227,14 @@ func NewSimApp( &app.MintKeeper, &app.EvidenceKeeper, &app.DistrKeeper, + &app.UpgradeKeeper, ); err != nil { panic(err) } app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) - app.keys = sdk.NewKVStoreKeys( - govtypes.StoreKey, - upgradetypes.StoreKey, - ) + app.keys = sdk.NewKVStoreKeys(govtypes.StoreKey) // configure state listening capabilities using AppOptions // we are doing nothing with the returned streamingServices and waitGroup in this case @@ -276,11 +273,12 @@ func NewSimApp( // register the governance hooks ), ) - // set the governance module account as the authority for conducting upgrades - app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, app.keys[upgradetypes.StoreKey], app.appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) /**** Module Options ****/ + // Sets the version setter for the upgrade module + app.UpgradeKeeper.SetVersionSetter(app.BaseApp) + // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment // we prefer to be more strict in what arguments the modules expect. skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) @@ -290,7 +288,6 @@ func NewSimApp( if err := app.RegisterModules( crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - upgrade.NewAppModule(app.UpgradeKeeper), ); err != nil { panic(err) } diff --git a/simapp/app.yaml b/simapp/app.yaml index 56b4a75a486..277b236d006 100644 --- a/simapp/app.yaml +++ b/simapp/app.yaml @@ -137,3 +137,7 @@ modules: - name: vesting config: "@type": cosmos.vesting.module.v1.Module + + - name: upgrade + config: + "@type": cosmos.upgrade.module.v1.Module diff --git a/simapp/app_test.go b/simapp/app_test.go index e8e27f1e2bf..b3e3874a2df 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/tests/mocks" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" @@ -40,13 +41,11 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { db := dbm.NewMemDB() logger, _ := log.NewDefaultLogger("plain", "info", false) app := NewSimappWithCustomOptions(t, false, SetupOptions{ - Logger: logger, - DB: db, - InvCheckPeriod: 0, - EncConfig: encCfg, - HomePath: DefaultNodeHome, - SkipUpgradeHeights: map[int64]bool{}, - AppOpts: EmptyAppOptions{}, + Logger: logger, + DB: db, + InvCheckPeriod: 0, + EncConfig: encCfg, + AppOpts: simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), }) for acc := range maccPerms { @@ -61,7 +60,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { logger2, _ := log.NewDefaultLogger("plain", "info", false) // Making a new app object with the db, so that initchain hasn't been called - app2 := NewSimApp(logger2, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}) + app2 := NewSimApp(logger2, db, nil, true, 0, encCfg, simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome)) _, err := app2.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } @@ -75,10 +74,10 @@ func TestRunMigrations(t *testing.T) { db := dbm.NewMemDB() encCfg := MakeTestEncodingConfig() logger, _ := log.NewDefaultLogger("plain", "info", false) - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}) + app := NewSimApp(logger, db, nil, true, 0, encCfg, simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome)) // Create a new baseapp and configurator for the purpose of this test. - bApp := baseapp.NewBaseApp(appName, logger, db, encCfg.TxConfig.TxDecoder()) + bApp := baseapp.NewBaseApp(app.Name(), logger, db, encCfg.TxConfig.TxDecoder()) bApp.SetCommitMultiStoreTracer(nil) bApp.SetInterfaceRegistry(encCfg.InterfaceRegistry) app.BaseApp = bApp @@ -208,7 +207,7 @@ func TestInitGenesisOnMigration(t *testing.T) { db := dbm.NewMemDB() encCfg := MakeTestEncodingConfig() logger, _ := log.NewDefaultLogger("plain", "info", false) - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}) + app := NewSimApp(logger, db, nil, true, 0, encCfg, simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome)) ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) // Create a mock module. This module will serve as the new module we're @@ -253,13 +252,11 @@ func TestUpgradeStateOnGenesis(t *testing.T) { db := dbm.NewMemDB() logger, _ := log.NewDefaultLogger("plain", "info", false) app := NewSimappWithCustomOptions(t, false, SetupOptions{ - Logger: logger, - DB: db, - InvCheckPeriod: 0, - EncConfig: encCfg, - HomePath: DefaultNodeHome, - SkipUpgradeHeights: map[int64]bool{}, - AppOpts: EmptyAppOptions{}, + Logger: logger, + DB: db, + InvCheckPeriod: 0, + EncConfig: encCfg, + AppOpts: simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), }) // make sure the upgrade keeper has version map in state @@ -268,4 +265,6 @@ func TestUpgradeStateOnGenesis(t *testing.T) { for v, i := range app.ModuleManager.Modules { require.Equal(t, vm[v], i.ConsensusVersion()) } + + require.NotNil(t, app.UpgradeKeeper.GetVersionSetter()) } diff --git a/simapp/sim_bench_test.go b/simapp/sim_bench_test.go index ae96661a9a1..9536a9699d1 100644 --- a/simapp/sim_bench_test.go +++ b/simapp/sim_bench_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" ) @@ -30,7 +31,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { require.NoError(b, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( @@ -77,7 +78,7 @@ func BenchmarkInvariants(b *testing.B) { require.NoError(b, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 189f2d119fe..d50a6b0df4d 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -71,7 +71,7 @@ func TestFullAppSimulation(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) // run randomized simulation @@ -109,7 +109,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) // Run randomized simulation @@ -149,7 +149,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), fauxMerkleModeOpt) require.Equal(t, "SimApp", newApp.Name()) var genesisState GenesisState @@ -218,7 +218,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) // Run randomized simulation @@ -263,7 +263,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), fauxMerkleModeOpt) require.Equal(t, "SimApp", newApp.Name()) newApp.InitChain(abci.RequestInitChain{ @@ -314,7 +314,7 @@ func TestAppStateDeterminism(t *testing.T) { } db := dbm.NewMemDB() - app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), interBlockCacheOpt()) fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index cb0d3f6e0c3..af91a043777 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -277,8 +277,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a ) return simapp.NewSimApp( - logger, db, traceStore, true, skipUpgradeHeights, - cast.ToString(appOpts.Get(flags.FlagHome)), + logger, db, traceStore, true, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encCfg, appOpts, @@ -300,19 +299,22 @@ func (a appCreator) appExport( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOpts servertypes.AppOptions, ) (servertypes.ExportedApp, error) { var simApp *simapp.SimApp + + // this check is necessary as we use the flag in x/upgrade. + // we can exit more gracefully by checking the flag here. homePath, ok := appOpts.Get(flags.FlagHome).(string) if !ok || homePath == "" { return servertypes.ExportedApp{}, errors.New("application home not set") } if height != -1 { - simApp = simapp.NewSimApp(logger, db, traceStore, false, map[int64]bool{}, homePath, uint(1), a.encCfg, appOpts) + simApp = simapp.NewSimApp(logger, db, traceStore, false, uint(1), a.encCfg, appOpts) if err := simApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - simApp = simapp.NewSimApp(logger, db, traceStore, true, map[int64]bool{}, homePath, uint(1), a.encCfg, appOpts) + simApp = simapp.NewSimApp(logger, db, traceStore, true, uint(1), a.encCfg, appOpts) } return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index aff0a84e3cb..92849b80a88 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -37,19 +37,17 @@ import ( // SetupOptions defines arguments that are passed into `Simapp` constructor. type SetupOptions struct { - Logger log.Logger - DB *dbm.MemDB - InvCheckPeriod uint - HomePath string - SkipUpgradeHeights map[int64]bool - EncConfig params.EncodingConfig - AppOpts types.AppOptions + Logger log.Logger + DB *dbm.MemDB + InvCheckPeriod uint + EncConfig params.EncodingConfig + AppOpts types.AppOptions } func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { db := dbm.NewMemDB() encCdc := MakeTestEncodingConfig() - app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{}) + app := NewSimApp(log.NewNopLogger(), db, nil, true, invCheckPeriod, encCdc, simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome)) if withGenesis { return app, NewDefaultGenesisState(encCdc.Codec) } @@ -75,7 +73,7 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), } - app := NewSimApp(options.Logger, options.DB, nil, true, options.SkipUpgradeHeights, options.HomePath, options.InvCheckPeriod, options.EncConfig, options.AppOpts) + app := NewSimApp(options.Logger, options.DB, nil, true, options.InvCheckPeriod, options.EncConfig, options.AppOpts) genesisState := NewDefaultGenesisState(app.appCodec) genesisState, err = simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance) require.NoError(t, err) @@ -378,14 +376,6 @@ func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) { return &ed25519.PubKey{Key: pkBytes} } -// EmptyAppOptions is a stub implementing AppOptions -type EmptyAppOptions struct{} - -// Get implements AppOptions -func (ao EmptyAppOptions) Get(o string) interface{} { - return nil -} - // ModuleAccountAddrs provides a list of blocked module accounts from configuration in app.yaml // // Ported from SimApp diff --git a/store/streaming/constructor_test.go b/store/streaming/constructor_test.go index 1b0479cc7d5..5edaeccd4ea 100644 --- a/store/streaming/constructor_test.go +++ b/store/streaming/constructor_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/streaming" "github.com/cosmos/cosmos-sdk/store/streaming/file" "github.com/cosmos/cosmos-sdk/store/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -59,7 +60,7 @@ func TestLoadStreamingServices(t *testing.T) { activeStreamersLen int }{ "empty app options": { - appOpts: simapp.EmptyAppOptions{}, + appOpts: simtestutil.EmptyAppOptions{}, }, "all StoreKeys exposed": { appOpts: streamingAppOptions{keys: []string{"*"}}, diff --git a/testutil/network/network.go b/testutil/network/network.go index c335a78d3b6..bc39a4118b8 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -44,6 +44,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/testutil" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -62,9 +63,9 @@ type AppConstructor = func(val Validator) servertypes.Application func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor { return func(val Validator) servertypes.Application { return simapp.NewSimApp( - val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0, + val.Ctx.Logger, dbm.NewMemDB(), nil, true, 0, encodingCfg, - simapp.EmptyAppOptions{}, + simtestutil.NewAppOptionsWithFlagHome(val.Ctx.Config.RootDir), baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), ) diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index 26ac443c648..61a5d521192 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -13,12 +13,14 @@ import ( tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/depinject" "github.com/cosmos/cosmos-sdk/runtime" + servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/testutil/mock" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -220,3 +222,24 @@ func GenesisStateWithValSet(codec codec.Codec, genesisState map[string]json.RawM return genesisState, nil } + +// EmptyAppOptions is a stub implementing AppOptions +type EmptyAppOptions struct{} + +// Get implements AppOptions +func (ao EmptyAppOptions) Get(o string) interface{} { + return nil +} + +// AppOptionsMap is a stub implementing AppOptions which can get data from a map +type AppOptionsMap map[string]interface{} + +func (m AppOptionsMap) Get(key string) interface{} { + return m[key] +} + +func NewAppOptionsWithFlagHome(homePath string) servertypes.AppOptions { + return AppOptionsMap{ + flags.FlagHome: homePath, + } +} diff --git a/x/auth/module_test.go b/x/auth/module_test.go index 6f527c587e4..84d16cd5476 100644 --- a/x/auth/module_test.go +++ b/x/auth/module_test.go @@ -11,13 +11,14 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/simapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/x/auth/types" ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.Marshal(genesisState) diff --git a/x/distribution/module_test.go b/x/distribution/module_test.go index 70e2e50ea8b..3297ff84dc3 100644 --- a/x/distribution/module_test.go +++ b/x/distribution/module_test.go @@ -11,6 +11,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/simapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/distribution/types" ) @@ -18,7 +19,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.Marshal(genesisState) diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index dad646eedbe..82f8e9c4aac 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -74,7 +74,7 @@ func TestImportExportQueues(t *testing.T) { } db := dbm.NewMemDB() - app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{}) + app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 0, simapp.MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome)) app2.InitChain( abci.RequestInitChain{ diff --git a/x/gov/module_test.go b/x/gov/module_test.go index c43f570dbac..761cd712878 100644 --- a/x/gov/module_test.go +++ b/x/gov/module_test.go @@ -11,6 +11,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/simapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -18,7 +19,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.Marshal(genesisState) diff --git a/x/staking/module_test.go b/x/staking/module_test.go index 3f1e5d91688..5fe1d917f4f 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -11,6 +11,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/simapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -18,7 +19,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.Marshal(genesisState) diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 8f3b8f52dbf..878f1f0ab0d 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -9,17 +9,21 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - dbm "github.com/tendermint/tm-db" + "golang.org/x/exp/maps" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/depinject" + "github.com/cosmos/cosmos-sdk/server" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/upgrade" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/testutil" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -34,22 +38,23 @@ type TestSuite struct { var s TestSuite func setupTest(t *testing.T, height int64, skip map[int64]bool) TestSuite { - db := dbm.NewMemDB() - app := simapp.NewSimappWithCustomOptions(t, false, simapp.SetupOptions{ - Logger: log.NewNopLogger(), - SkipUpgradeHeights: skip, - DB: db, - InvCheckPeriod: 0, - HomePath: simapp.DefaultNodeHome, - EncConfig: simapp.MakeTestEncodingConfig(), - AppOpts: simapp.EmptyAppOptions{}, - }) + var ( + legacyAmino *codec.LegacyAmino + appOptions = make(simtestutil.AppOptionsMap, 0) + ) + + appOptions[server.FlagUnsafeSkipUpgrades] = maps.Keys(skip) + appOptions[flags.FlagHome] = t.TempDir() + + appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(appOptions)) + app, err := simtestutil.Setup(appConfig, &s.keeper, &legacyAmino) + s.keeper.SetVersionSetter(app.BaseApp) + require.NoError(t, err) - s.keeper = app.UpgradeKeeper s.ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: height, Time: time.Now()}) s.module = upgrade.NewAppModule(s.keeper) - s.querier = s.module.LegacyQuerierHandler(app.LegacyAmino()) + s.querier = s.module.LegacyQuerierHandler(legacyAmino) s.handler = upgrade.NewSoftwareUpgradeProposalHandler(s.keeper) return s } diff --git a/x/upgrade/client/testutil/cli_test.go b/x/upgrade/client/testutil/cli_test.go index 5b3ef61c5a4..7f92bbeeff5 100644 --- a/x/upgrade/client/testutil/cli_test.go +++ b/x/upgrade/client/testutil/cli_test.go @@ -1,6 +1,3 @@ -//go:build norace -// +build norace - package testutil import ( diff --git a/x/upgrade/client/testutil/suite.go b/x/upgrade/client/testutil/suite.go index d5e21ce47ae..9e5eca3b234 100644 --- a/x/upgrade/client/testutil/suite.go +++ b/x/upgrade/client/testutil/suite.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/upgrade/client/cli" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -21,25 +22,25 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { type IntegrationTestSuite struct { suite.Suite - app *simapp.SimApp - cfg network.Config - network *network.Network - ctx sdk.Context + upgradeKeeper keeper.Keeper + cfg network.Config + network *network.Network + ctx sdk.Context } func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") + app := simapp.Setup(s.T(), false) - s.app = app - s.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) + s.upgradeKeeper = app.UpgradeKeeper - cfg := network.DefaultConfig() - cfg.NumValidators = 1 + s.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) - s.cfg = cfg + s.upgradeKeeper.SetVersionSetter(app.BaseApp) + s.upgradeKeeper.SetModuleVersionMap(s.ctx, app.ModuleManager.GetVersionMap()) var err error - s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) } @@ -80,8 +81,8 @@ func (s *IntegrationTestSuite) TestModuleVersionsCLI() { // avoid printing as yaml from CLI command clientCtx.OutputFormat = "JSON" - vm := s.app.UpgradeKeeper.GetModuleVersionMap(s.ctx) - mv := s.app.UpgradeKeeper.GetModuleVersions(s.ctx) + vm := s.upgradeKeeper.GetModuleVersionMap(s.ctx) + mv := s.upgradeKeeper.GetModuleVersions(s.ctx) s.Require().NotEmpty(vm) for _, tc := range testCases { diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index da54ae7fe4b..39600ba96fc 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - gocontext "context" + "context" "fmt" "testing" @@ -9,28 +9,37 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/simapp" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/testutil" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) type UpgradeTestSuite struct { suite.Suite - app *simapp.SimApp - ctx sdk.Context - queryClient types.QueryClient + upgradeKeeper keeper.Keeper + ctx sdk.Context + queryClient types.QueryClient } func (suite *UpgradeTestSuite) SetupTest() { - suite.app = simapp.Setup(suite.T(), false) - suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{}) + var interfaceRegistry codectypes.InterfaceRegistry - queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) - types.RegisterQueryServer(queryHelper, suite.app.UpgradeKeeper) + app, err := simtestutil.Setup(testutil.AppConfig, &interfaceRegistry, &suite.upgradeKeeper) + suite.NoError(err) + suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) + + suite.upgradeKeeper.SetVersionSetter(app.BaseApp) + suite.upgradeKeeper.SetModuleVersionMap(suite.ctx, app.ModuleManager.GetVersionMap()) + + queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, interfaceRegistry) + types.RegisterQueryServer(queryHelper, suite.upgradeKeeper) suite.queryClient = types.NewQueryClient(queryHelper) } @@ -57,7 +66,7 @@ func (suite *UpgradeTestSuite) TestQueryCurrentPlan() { "with current upgrade plan", func() { plan := types.Plan{Name: "test-plan", Height: 5} - suite.app.UpgradeKeeper.ScheduleUpgrade(suite.ctx, plan) + suite.upgradeKeeper.ScheduleUpgrade(suite.ctx, plan) req = &types.QueryCurrentPlanRequest{} expResponse = types.QueryCurrentPlanResponse{Plan: &plan} @@ -72,7 +81,7 @@ func (suite *UpgradeTestSuite) TestQueryCurrentPlan() { tc.malleate() - res, err := suite.queryClient.CurrentPlan(gocontext.Background(), req) + res, err := suite.queryClient.CurrentPlan(context.Background(), req) if tc.expPass { suite.Require().NoError(err) @@ -110,13 +119,13 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() { planName := "test-plan" plan := types.Plan{Name: planName, Height: expHeight} - suite.app.UpgradeKeeper.ScheduleUpgrade(suite.ctx, plan) + suite.upgradeKeeper.ScheduleUpgrade(suite.ctx, plan) suite.ctx = suite.ctx.WithBlockHeight(expHeight) - suite.app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + suite.upgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) - suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, plan) + suite.upgradeKeeper.ApplyUpgrade(suite.ctx, plan) req = &types.QueryAppliedPlanRequest{Name: planName} }, @@ -130,7 +139,7 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() { tc.malleate() - res, err := suite.queryClient.AppliedPlan(gocontext.Background(), req) + res, err := suite.queryClient.AppliedPlan(context.Background(), req) if tc.expPass { suite.Require().NoError(err) @@ -170,14 +179,14 @@ func (suite *UpgradeTestSuite) TestModuleVersions() { }, } - vm := suite.app.UpgradeKeeper.GetModuleVersionMap(suite.ctx) - mv := suite.app.UpgradeKeeper.GetModuleVersions(suite.ctx) + vm := suite.upgradeKeeper.GetModuleVersionMap(suite.ctx) + mv := suite.upgradeKeeper.GetModuleVersions(suite.ctx) for _, tc := range testCases { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset - res, err := suite.queryClient.ModuleVersions(gocontext.Background(), &tc.req) + res, err := suite.queryClient.ModuleVersions(context.Background(), &tc.req) if tc.expPass { suite.Require().NoError(err) @@ -206,7 +215,7 @@ func (suite *UpgradeTestSuite) TestModuleVersions() { } func (suite *UpgradeTestSuite) TestAuthority() { - res, err := suite.queryClient.Authority(gocontext.Background(), &types.QueryAuthorityRequest{}) + res, err := suite.queryClient.Authority(context.Background(), &types.QueryAuthorityRequest{}) suite.Require().NoError(err) suite.Require().Equal(authtypes.NewModuleAddress(govtypes.ModuleName).String(), res.Address) } diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index c8edaceeb6b..21e3ee70fb4 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -56,6 +56,15 @@ func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey storetypes.StoreKey, } } +// SetVersionSetter sets the interface implemented by baseapp which allows setting baseapp's protocol version field +func (k *Keeper) SetVersionSetter(vs xp.ProtocolVersionSetter) { + k.versionSetter = vs +} + +func (k *Keeper) GetVersionSetter() xp.ProtocolVersionSetter { + return k.versionSetter +} + // SetUpgradeHandler sets an UpgradeHandler for the upgrade specified by name. This handler will be called when the upgrade // with this name is applied. In order for an upgrade with the given name to proceed, a handler for this upgrade // must be set even if it is a no-op function. diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 19fee1054ec..c9e2b053602 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -8,46 +8,55 @@ import ( "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/depinject" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/testutil" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) type KeeperTestSuite struct { suite.Suite - homeDir string - app *simapp.SimApp - ctx sdk.Context - msgSrvr types.MsgServer - addrs []sdk.AccAddress + baseApp *baseapp.BaseApp + upgradeKeeper keeper.Keeper + homeDir string + ctx sdk.Context + msgSrvr types.MsgServer + addrs []sdk.AccAddress } func (s *KeeperTestSuite) SetupTest() { - app := simapp.Setup(s.T(), false) - homeDir := filepath.Join(s.T().TempDir(), "x_upgrade_keeper_test") - app.UpgradeKeeper = keeper.NewKeeper( // recreate keeper in order to use a custom home path - make(map[int64]bool), app.GetKey(types.StoreKey), app.AppCodec(), homeDir, app.BaseApp, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + var ( + bankKeeper bankkeeper.Keeper + stakingKeeper *stakingkeeper.Keeper ) + + homeDir := filepath.Join(s.T().TempDir(), "x_upgrade_keeper_test") + appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.NewAppOptionsWithFlagHome(homeDir))) + app, err := simtestutil.Setup(appConfig, &s.upgradeKeeper, &bankKeeper, &stakingKeeper) + s.NoError(err) + s.upgradeKeeper.SetVersionSetter(app.BaseApp) + s.T().Log("home dir:", homeDir) s.homeDir = homeDir - s.app = app s.ctx = app.BaseApp.NewContext(false, tmproto.Header{ Time: time.Now(), Height: 10, }) - s.msgSrvr = keeper.NewMsgServerImpl(s.app.UpgradeKeeper) - s.addrs = simapp.AddTestAddrsIncremental(app, s.ctx, 1, sdk.NewInt(30000000)) + s.msgSrvr = keeper.NewMsgServerImpl(s.upgradeKeeper) + s.addrs = simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, s.ctx, 1, sdk.NewInt(30000000)) + s.baseApp = app.BaseApp } func (s *KeeperTestSuite) TestReadUpgradeInfoFromDisk() { // require no error when the upgrade info file does not exist - _, err := s.app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + _, err := s.upgradeKeeper.ReadUpgradeInfoFromDisk() s.Require().NoError(err) expected := types.Plan{ @@ -56,9 +65,9 @@ func (s *KeeperTestSuite) TestReadUpgradeInfoFromDisk() { } // create an upgrade info file - s.Require().NoError(s.app.UpgradeKeeper.DumpUpgradeInfoToDisk(101, expected)) + s.Require().NoError(s.upgradeKeeper.DumpUpgradeInfoToDisk(101, expected)) - ui, err := s.app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + ui, err := s.upgradeKeeper.ReadUpgradeInfoFromDisk() s.Require().NoError(err) expected.Height = 101 s.Require().Equal(expected, ui) @@ -89,7 +98,7 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { Height: 123450000, }, setup: func() { - s.app.UpgradeKeeper.ScheduleUpgrade(s.ctx, types.Plan{ + s.upgradeKeeper.ScheduleUpgrade(s.ctx, types.Plan{ Name: "alt-good", Info: "new text here", Height: 543210000, @@ -123,10 +132,10 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { Height: 123450000, }, setup: func() { - s.app.UpgradeKeeper.SetUpgradeHandler("all-good", func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.upgradeKeeper.SetUpgradeHandler("all-good", func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) - s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, types.Plan{ + s.upgradeKeeper.ApplyUpgrade(s.ctx, types.Plan{ Name: "all-good", Info: "some text here", Height: 123450000, @@ -146,7 +155,7 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { // setup test case tc.setup() - err := s.app.UpgradeKeeper.ScheduleUpgrade(s.ctx, tc.plan) + err := s.upgradeKeeper.ScheduleUpgrade(s.ctx, tc.plan) if tc.expPass { s.Require().NoError(err, "valid test case failed") @@ -176,7 +185,7 @@ func (s *KeeperTestSuite) TestSetUpgradedClient() { name: "success", height: 10, setup: func() { - s.app.UpgradeKeeper.SetUpgradedClient(s.ctx, 10, cs) + s.upgradeKeeper.SetUpgradedClient(s.ctx, 10, cs) }, exists: true, }, @@ -189,7 +198,7 @@ func (s *KeeperTestSuite) TestSetUpgradedClient() { // setup test case tc.setup() - gotCs, exists := s.app.UpgradeKeeper.GetUpgradedClient(s.ctx, tc.height) + gotCs, exists := s.upgradeKeeper.GetUpgradedClient(s.ctx, tc.height) if tc.exists { s.Require().Equal(cs, gotCs, "valid case: %s did not retrieve correct client state", tc.name) s.Require().True(exists, "valid case: %s did not retrieve client state", tc.name) @@ -203,15 +212,15 @@ func (s *KeeperTestSuite) TestSetUpgradedClient() { // Test that the protocol version successfully increments after an // upgrade and is successfully set on BaseApp's appVersion. func (s *KeeperTestSuite) TestIncrementProtocolVersion() { - oldProtocolVersion := s.app.BaseApp.AppVersion() - s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) + oldProtocolVersion := s.baseApp.AppVersion() + s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) dummyPlan := types.Plan{ Name: "dummy", Info: "some text here", Height: 100, } - s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) - upgradedProtocolVersion := s.app.BaseApp.AppVersion() + s.upgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) + upgradedProtocolVersion := s.baseApp.AppVersion() s.Require().Equal(oldProtocolVersion+1, upgradedProtocolVersion) } @@ -220,9 +229,9 @@ func (s *KeeperTestSuite) TestIncrementProtocolVersion() { // an upgrade. func (s *KeeperTestSuite) TestMigrations() { initialVM := module.VersionMap{"bank": uint64(1)} - s.app.UpgradeKeeper.SetModuleVersionMap(s.ctx, initialVM) - vmBefore := s.app.UpgradeKeeper.GetModuleVersionMap(s.ctx) - s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.upgradeKeeper.SetModuleVersionMap(s.ctx, initialVM) + vmBefore := s.upgradeKeeper.GetModuleVersionMap(s.ctx) + s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { // simulate upgrading the bank module vm["bank"] = vm["bank"] + 1 return vm, nil @@ -233,13 +242,13 @@ func (s *KeeperTestSuite) TestMigrations() { Height: 123450000, } - s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) - vm := s.app.UpgradeKeeper.GetModuleVersionMap(s.ctx) + s.upgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) + vm := s.upgradeKeeper.GetModuleVersionMap(s.ctx) s.Require().Equal(vmBefore["bank"]+1, vm["bank"]) } func (s *KeeperTestSuite) TestLastCompletedUpgrade() { - keeper := s.app.UpgradeKeeper + keeper := s.upgradeKeeper require := s.Require() s.T().Log("verify empty name if applied upgrades are empty") @@ -280,7 +289,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgrade() { // This test ensures that `GetLastDoneUpgrade` always returns the last upgrade according to the block height // it was executed at, rather than using an ordering based on upgrade names. func (s *KeeperTestSuite) TestLastCompletedUpgradeOrdering() { - keeper := s.app.UpgradeKeeper + keeper := s.upgradeKeeper require := s.Require() // apply first upgrade diff --git a/x/upgrade/keeper/msg_server_test.go b/x/upgrade/keeper/msg_server_test.go index a83cdc09b7a..738f021eb49 100644 --- a/x/upgrade/keeper/msg_server_test.go +++ b/x/upgrade/keeper/msg_server_test.go @@ -5,7 +5,8 @@ import ( ) func (s *KeeperTestSuite) TestSoftwareUpgrade() { - govAccAddr := s.app.GovKeeper.GetGovernanceAccount(s.ctx).GetAddress().String() + govAccAddr := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" // TODO + // govAccAddr := s.govKeeper.GetGovernanceAccount(s.ctx).GetAddress().String() testCases := []struct { name string @@ -59,7 +60,7 @@ func (s *KeeperTestSuite) TestSoftwareUpgrade() { s.Require().Contains(err.Error(), tc.errMsg) } else { s.Require().NoError(err) - plan, found := s.app.UpgradeKeeper.GetUpgradePlan(s.ctx) + plan, found := s.upgradeKeeper.GetUpgradePlan(s.ctx) s.Require().Equal(true, found) s.Require().Equal(tc.req.Plan, plan) } @@ -68,8 +69,9 @@ func (s *KeeperTestSuite) TestSoftwareUpgrade() { } func (s *KeeperTestSuite) TestCancelUpgrade() { - govAccAddr := s.app.GovKeeper.GetGovernanceAccount(s.ctx).GetAddress().String() - err := s.app.UpgradeKeeper.ScheduleUpgrade(s.ctx, types.Plan{ + govAccAddr := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" // TODO + // govAccAddr := s.govKeeper.GetGovernanceAccount(s.ctx).GetAddress().String() + err := s.upgradeKeeper.ScheduleUpgrade(s.ctx, types.Plan{ Name: "some name", Info: "some info", Height: 123450000, @@ -107,7 +109,7 @@ func (s *KeeperTestSuite) TestCancelUpgrade() { s.Require().Contains(err.Error(), tc.errMsg) } else { s.Require().NoError(err) - _, found := s.app.UpgradeKeeper.GetUpgradePlan(s.ctx) + _, found := s.upgradeKeeper.GetUpgradePlan(s.ctx) s.Require().Equal(false, found) } }) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 2bece77259a..471c50dc740 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -4,15 +4,27 @@ import ( "context" "encoding/json" - "github.com/grpc-ecosystem/grpc-gateway/runtime" + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cast" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/depinject" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/server" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + modulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" "github.com/cosmos/cosmos-sdk/x/upgrade/client/cli" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -45,7 +57,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the upgrade module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { panic(err) } @@ -141,3 +153,55 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } + +// +// New App Wiring Setup +// + +func init() { + appmodule.Register(&modulev1.Module{}, + appmodule.Provide(provideModuleBasic, provideModule), + ) +} + +func provideModuleBasic() runtime.AppModuleBasicWrapper { + return runtime.WrapAppModuleBasic(AppModuleBasic{}) +} + +type upgradeInputs struct { + depinject.In + + Config *modulev1.Module + Key *store.KVStoreKey + Cdc codec.Codec + + AppOpts servertypes.AppOptions `optional:"true"` +} + +type upgradeOutputs struct { + depinject.Out + + UpgradeKeeper keeper.Keeper + Module runtime.AppModuleWrapper +} + +func provideModule(in upgradeInputs) upgradeOutputs { + var ( + homePath string + skipUpgradeHeights = make(map[int64]bool) + ) + + if in.AppOpts != nil { + for _, h := range cast.ToIntSlice(in.AppOpts.Get(server.FlagUnsafeSkipUpgrades)) { + skipUpgradeHeights[int64(h)] = true + } + + homePath = cast.ToString(in.AppOpts.Get(flags.FlagHome)) + } + + // set the governance module account as the authority for conducting upgrades + k := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, homePath, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + m := NewAppModule(k) + + return upgradeOutputs{UpgradeKeeper: k, Module: runtime.WrapAppModule(m)} +} diff --git a/x/upgrade/spec/05_app_wiring.md b/x/upgrade/spec/05_app_wiring.md new file mode 100644 index 00000000000..c06b45afe7c --- /dev/null +++ b/x/upgrade/spec/05_app_wiring.md @@ -0,0 +1,5 @@ +# App Wiring + +The minimal app-wiring configuration for `x/upgrade` is as follows: + ++++ https://github.com/cosmos/cosmos-sdk/blob/main/x/upgrade/testutil/app.yaml diff --git a/x/upgrade/spec/README.md b/x/upgrade/spec/README.md index 73ea2268ac7..2522ef0e058 100644 --- a/x/upgrade/spec/README.md +++ b/x/upgrade/spec/README.md @@ -29,3 +29,4 @@ recover from. * [CLI](04_client.md#cli) * [REST](04_client.md#rest) * [gRPC](04_client.md#grpc) +5. **[App Wiring](05_app_wiring.md) diff --git a/x/upgrade/testutil/app.yaml b/x/upgrade/testutil/app.yaml new file mode 100644 index 00000000000..5bc0bd1dacb --- /dev/null +++ b/x/upgrade/testutil/app.yaml @@ -0,0 +1,51 @@ +modules: + - name: runtime + config: + "@type": cosmos.app.runtime.v1alpha1.Module + + app_name: UpgradeApp + + begin_blockers: [upgrade, mint, staking, auth, bank, genutil, params] + end_blockers: [staking, auth, bank, mint, genutil, params, upgrade] + init_genesis: [auth, bank, staking, mint, genutil, params, upgrade] + + - name: auth + config: + "@type": cosmos.auth.module.v1.Module + bech32_prefix: cosmos + module_account_permissions: + - account: fee_collector + - account: mint + permissions: [minter] + - account: bonded_tokens_pool + permissions: [burner, staking] + - account: not_bonded_tokens_pool + permissions: [burner, staking] + + - name: bank + config: + "@type": cosmos.bank.module.v1.Module + + - name: params + config: + "@type": cosmos.params.module.v1.Module + + - name: tx + config: + "@type": cosmos.tx.module.v1.Module + + - name: staking + config: + "@type": cosmos.staking.module.v1.Module + + - name: genutil + config: + "@type": cosmos.genutil.module.v1.Module + + - name: mint + config: + "@type": cosmos.mint.module.v1.Module + + - name: upgrade + config: + "@type": cosmos.upgrade.module.v1.Module diff --git a/x/upgrade/testutil/app_config.go b/x/upgrade/testutil/app_config.go new file mode 100644 index 00000000000..fb0517a4f7f --- /dev/null +++ b/x/upgrade/testutil/app_config.go @@ -0,0 +1,20 @@ +package testutil + +import ( + _ "embed" + + "cosmossdk.io/core/appconfig" + _ "github.com/cosmos/cosmos-sdk/x/auth" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" + _ "github.com/cosmos/cosmos-sdk/x/bank" + _ "github.com/cosmos/cosmos-sdk/x/genutil" + _ "github.com/cosmos/cosmos-sdk/x/mint" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" + _ "github.com/cosmos/cosmos-sdk/x/upgrade" +) + +//go:embed app.yaml +var appConfig []byte + +var AppConfig = appconfig.LoadYAML(appConfig)