From 67f3e124dd4e187893813985bb0a27a0a9ef77b3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 20 Jun 2022 18:08:44 +0200 Subject: [PATCH 01/12] feat: migrate `x/upgrade` to use app wiring --- api/cosmos/bank/module/v1/module.pulsar.go | 2 +- api/cosmos/upgrade/module/v1/module.pulsar.go | 503 ++++++++++++++++++ proto/cosmos/bank/module/v1/module.proto | 2 +- proto/cosmos/upgrade/module/v1/module.proto | 12 + simapp/app.go | 9 +- x/upgrade/module.go | 52 +- 6 files changed, 569 insertions(+), 11 deletions(-) create mode 100644 api/cosmos/upgrade/module/v1/module.pulsar.go create mode 100644 proto/cosmos/upgrade/module/v1/module.proto 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/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/simapp/app.go b/simapp/app.go index 400a8a40430..b051e997965 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -227,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 @@ -275,8 +273,6 @@ 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 ****/ @@ -289,7 +285,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/x/upgrade/module.go b/x/upgrade/module.go index 2bece77259a..5cd7dc1b57a 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -4,15 +4,24 @@ import ( "context" "encoding/json" - "github.com/grpc-ecosystem/grpc-gateway/runtime" + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "cosmossdk.io/core/appmodule" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "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" + 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 +54,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 +150,42 @@ 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 + + BaseApp *baseapp.BaseApp +} + +type upgradeOutputs struct { + depinject.Out + + UpgradeKeeper keeper.Keeper + Module runtime.AppModuleWrapper +} + +func provideModule(in upgradeInputs) upgradeOutputs { + // set the governance module account as the authority for conducting upgrades + k := keeper.NewKeeper(nil, in.Key, in.Cdc, "", in.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + m := NewAppModule(k) + + return upgradeOutputs{UpgradeKeeper: k, Module: runtime.WrapAppModule(m)} +} From 79a9cfb08af82b2564ad447f2184c3325c1b4b8d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 20 Jun 2022 22:32:51 +0200 Subject: [PATCH 02/12] updates --- CHANGELOG.md | 2 ++ baseapp/block_gas_test.go | 2 +- server/export_test.go | 4 ++-- simapp/app.go | 17 ++++++++--------- simapp/app_test.go | 32 ++++++++++++++------------------ simapp/sim_bench_test.go | 4 ++-- simapp/sim_test.go | 12 ++++++------ simapp/simd/cmd/root.go | 10 ++++++---- simapp/test_helpers.go | 16 +++++++--------- testutil/network/network.go | 2 +- x/auth/module_test.go | 2 +- x/distribution/module_test.go | 2 +- x/gov/genesis_test.go | 2 +- x/gov/module_test.go | 2 +- x/staking/module_test.go | 2 +- x/upgrade/abci_test.go | 12 +++++------- x/upgrade/module.go | 12 +++++++++++- 17 files changed, 70 insertions(+), 65 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3f0df662ca..3577d47fada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes + +* (simapp) [#XXXXX](https:12278//github.com/cosmos/cosmos-sdk/pull/XXXXX) 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 function 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. diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 173ba79b0e8..784e83f0aa1 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, simapp.EmptyAppOptions{}, routerOpt) app.InterfaceRegistry().RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}, ) diff --git a/server/export_test.go b/server/export_test.go index 7ce2f40b051..d36339108af 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -160,13 +160,13 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t 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, appOptons) 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, appOptons) } return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) diff --git a/simapp/app.go b/simapp/app.go index b051e997965..fce43fb6dc8 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -98,8 +98,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) -const appName = "SimApp" - var ( // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -199,17 +197,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, diff --git a/simapp/app_test.go b/simapp/app_test.go index e8e27f1e2bf..0feff7d6ec1 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -40,13 +40,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: EmptyAppOptions{}, }) for acc := range maccPerms { @@ -61,7 +59,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, EmptyAppOptions{}) _, err := app2.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } @@ -75,10 +73,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, EmptyAppOptions{}) // 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 +206,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, EmptyAppOptions{}) 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 +251,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: EmptyAppOptions{}, }) // make sure the upgrade keeper has version map in state diff --git a/simapp/sim_bench_test.go b/simapp/sim_bench_test.go index ae96661a9a1..df154455997 100644 --- a/simapp/sim_bench_test.go +++ b/simapp/sim_bench_test.go @@ -30,7 +30,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(), EmptyAppOptions{}, interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( @@ -77,7 +77,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(), EmptyAppOptions{}, interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 189f2d119fe..7d763291518 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(), EmptyAppOptions{}, 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(), EmptyAppOptions{}, 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(), EmptyAppOptions{}, 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(), EmptyAppOptions{}, 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(), EmptyAppOptions{}, 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(), EmptyAppOptions{}, 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..934a02c7500 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, EmptyAppOptions{}) 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) diff --git a/testutil/network/network.go b/testutil/network/network.go index c335a78d3b6..33537d3844a 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -62,7 +62,7 @@ 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, val.Ctx.Config.RootDir, 0, encodingCfg, simapp.EmptyAppOptions{}, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), diff --git a/x/auth/module_test.go b/x/auth/module_test.go index 6f527c587e4..a613b8e9745 100644 --- a/x/auth/module_test.go +++ b/x/auth/module_test.go @@ -17,7 +17,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, simapp.EmptyAppOptions{}) 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..ad7708fbf21 100644 --- a/x/distribution/module_test.go +++ b/x/distribution/module_test.go @@ -18,7 +18,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, simapp.EmptyAppOptions{}) 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..ed10a84b82b 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(), simapp.EmptyAppOptions{}) app2.InitChain( abci.RequestInitChain{ diff --git a/x/gov/module_test.go b/x/gov/module_test.go index c43f570dbac..7136279c01b 100644 --- a/x/gov/module_test.go +++ b/x/gov/module_test.go @@ -18,7 +18,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, simapp.EmptyAppOptions{}) 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..39e688475ac 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -18,7 +18,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, simapp.EmptyAppOptions{}) 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..1cd4adb8735 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -36,13 +36,11 @@ 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{}, + Logger: log.NewNopLogger(), + DB: db, + InvCheckPeriod: 0, + EncConfig: simapp.MakeTestEncodingConfig(), + AppOpts: simapp.EmptyAppOptions{}, }) s.keeper = app.UpgradeKeeper diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 5cd7dc1b57a..1c9aafa4607 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -5,16 +5,20 @@ import ( "encoding/json" 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/baseapp" "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" @@ -172,6 +176,7 @@ type upgradeInputs struct { Key *store.KVStoreKey Cdc codec.Codec + AppOpts servertypes.AppOptions BaseApp *baseapp.BaseApp } @@ -183,8 +188,13 @@ type upgradeOutputs struct { } func provideModule(in upgradeInputs) upgradeOutputs { + skipUpgradeHeights := make(map[int64]bool) + for _, h := range cast.ToIntSlice(in.AppOpts.Get(server.FlagUnsafeSkipUpgrades)) { + skipUpgradeHeights[int64(h)] = true + } + // set the governance module account as the authority for conducting upgrades - k := keeper.NewKeeper(nil, in.Key, in.Cdc, "", in.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + k := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, cast.ToString(in.AppOpts.Get(flags.FlagHome)), in.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) m := NewAppModule(k) return upgradeOutputs{UpgradeKeeper: k, Module: runtime.WrapAppModule(m)} From 27141345b58b2df462ca653067e5c3fe1fa4f4d8 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 20 Jun 2022 22:34:38 +0200 Subject: [PATCH 03/12] updates --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3577d47fada..45b3dd3cddf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,7 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* (simapp) [#XXXXX](https:12278//github.com/cosmos/cosmos-sdk/pull/XXXXX) Remove `skipUpgradeHeights map[int64]bool` and `homePath string` from `NewSimApp` constructor as per migration of `x/upgrade` to app-wiring. +* (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 function 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. From bcde7aa92acb217111e503b64604c90b9e1de218 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Jun 2022 12:28:45 +0200 Subject: [PATCH 04/12] updates --- depinject/README.md | 7 +++---- docs/architecture/adr-038-state-listening.md | 5 ++--- server/README.md | 8 +------- server/export_test.go | 2 +- simapp/test_helpers.go | 17 +++++++++++++++++ testutil/network/network.go | 4 ++-- x/upgrade/abci_test.go | 3 ++- 7 files changed, 28 insertions(+), 18 deletions(-) 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/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 d36339108af..ab2c2d6b059 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, simapp.NewCustomAppOptions(nil, tempDir)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 934a02c7500..7844f5decfa 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -19,11 +19,14 @@ import ( "cosmossdk.io/math" bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/depinject" + "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" + servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/testutil/mock" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -384,6 +387,20 @@ func (ao EmptyAppOptions) Get(o string) interface{} { return nil } +// AppOptionsMap is a stub implementing AppOptions which can get +type AppOptionsMap map[string]interface{} + +func (m AppOptionsMap) Get(key string) interface{} { + return m[key] +} + +func NewCustomAppOptions(skipUpgradeHeights []int64, homePath string) servertypes.AppOptions { + return AppOptionsMap{ + server.FlagUnsafeSkipUpgrades: skipUpgradeHeights, + flags.FlagHome: homePath, + } +} + // ModuleAccountAddrs provides a list of blocked module accounts from configuration in app.yaml // // Ported from SimApp diff --git a/testutil/network/network.go b/testutil/network/network.go index 33537d3844a..306f958e772 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -62,9 +62,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, val.Ctx.Config.RootDir, 0, + val.Ctx.Logger, dbm.NewMemDB(), nil, true, 0, encodingCfg, - simapp.EmptyAppOptions{}, + simapp.NewCustomAppOptions(nil, val.Ctx.Config.RootDir), baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), ) diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 1cd4adb8735..322d9bf93e6 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -12,6 +12,7 @@ import ( "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" sdk "github.com/cosmos/cosmos-sdk/types" @@ -40,7 +41,7 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) TestSuite { DB: db, InvCheckPeriod: 0, EncConfig: simapp.MakeTestEncodingConfig(), - AppOpts: simapp.EmptyAppOptions{}, + AppOpts: simapp.NewCustomAppOptions(maps.Keys(skip), ""), }) s.keeper = app.UpgradeKeeper From 1205a17061ac52bea3e83dffadfe2f49078c938b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Jun 2022 12:42:53 +0200 Subject: [PATCH 05/12] updates --- server/export_test.go | 6 +++--- simapp/app_test.go | 10 +++++----- simapp/sim_bench_test.go | 4 ++-- simapp/sim_test.go | 12 ++++++------ simapp/test_helpers.go | 2 +- x/auth/module_test.go | 2 +- x/distribution/module_test.go | 2 +- x/gov/genesis_test.go | 2 +- x/gov/module_test.go | 2 +- x/staking/module_test.go | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/server/export_test.go b/server/export_test.go index ab2c2d6b059..3836498dbf7 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -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, 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, 0, encCfg, appOptons) + simApp = simapp.NewSimApp(logger, db, nil, true, 0, encCfg, appOptions) } return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) diff --git a/simapp/app_test.go b/simapp/app_test.go index 0feff7d6ec1..5b554fe4b82 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -44,7 +44,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { DB: db, InvCheckPeriod: 0, EncConfig: encCfg, - AppOpts: EmptyAppOptions{}, + AppOpts: NewCustomAppOptions(nil, DefaultNodeHome), }) for acc := range maccPerms { @@ -59,7 +59,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, 0, encCfg, EmptyAppOptions{}) + app2 := NewSimApp(logger2, db, nil, true, 0, encCfg, NewCustomAppOptions(nil, DefaultNodeHome)) _, err := app2.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } @@ -73,7 +73,7 @@ func TestRunMigrations(t *testing.T) { db := dbm.NewMemDB() encCfg := MakeTestEncodingConfig() logger, _ := log.NewDefaultLogger("plain", "info", false) - app := NewSimApp(logger, db, nil, true, 0, encCfg, EmptyAppOptions{}) + app := NewSimApp(logger, db, nil, true, 0, encCfg, NewCustomAppOptions(nil, DefaultNodeHome)) // Create a new baseapp and configurator for the purpose of this test. bApp := baseapp.NewBaseApp(app.Name(), logger, db, encCfg.TxConfig.TxDecoder()) @@ -206,7 +206,7 @@ func TestInitGenesisOnMigration(t *testing.T) { db := dbm.NewMemDB() encCfg := MakeTestEncodingConfig() logger, _ := log.NewDefaultLogger("plain", "info", false) - app := NewSimApp(logger, db, nil, true, 0, encCfg, EmptyAppOptions{}) + app := NewSimApp(logger, db, nil, true, 0, encCfg, NewCustomAppOptions(nil, DefaultNodeHome)) ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) // Create a mock module. This module will serve as the new module we're @@ -255,7 +255,7 @@ func TestUpgradeStateOnGenesis(t *testing.T) { DB: db, InvCheckPeriod: 0, EncConfig: encCfg, - AppOpts: EmptyAppOptions{}, + AppOpts: NewCustomAppOptions(nil, DefaultNodeHome), }) // make sure the upgrade keeper has version map in state diff --git a/simapp/sim_bench_test.go b/simapp/sim_bench_test.go index df154455997..e2ca62e3685 100644 --- a/simapp/sim_bench_test.go +++ b/simapp/sim_bench_test.go @@ -30,7 +30,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { require.NoError(b, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( @@ -77,7 +77,7 @@ func BenchmarkInvariants(b *testing.B) { require.NoError(b, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 7d763291518..37ddee33027 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, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), interBlockCacheOpt()) fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 7844f5decfa..bf133399b70 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -50,7 +50,7 @@ type SetupOptions struct { func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { db := dbm.NewMemDB() encCdc := MakeTestEncodingConfig() - app := NewSimApp(log.NewNopLogger(), db, nil, true, invCheckPeriod, encCdc, EmptyAppOptions{}) + app := NewSimApp(log.NewNopLogger(), db, nil, true, invCheckPeriod, encCdc, NewCustomAppOptions(nil, DefaultNodeHome)) if withGenesis { return app, NewDefaultGenesisState(encCdc.Codec) } diff --git a/x/auth/module_test.go b/x/auth/module_test.go index a613b8e9745..aca880a4d8c 100644 --- a/x/auth/module_test.go +++ b/x/auth/module_test.go @@ -17,7 +17,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simapp.NewCustomAppOptions(nil, 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 ad7708fbf21..b7cb68d42ca 100644 --- a/x/distribution/module_test.go +++ b/x/distribution/module_test.go @@ -18,7 +18,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simapp.NewCustomAppOptions(nil, 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 ed10a84b82b..9a41067f575 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, 0, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{}) + app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 0, simapp.MakeTestEncodingConfig(), simapp.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) app2.InitChain( abci.RequestInitChain{ diff --git a/x/gov/module_test.go b/x/gov/module_test.go index 7136279c01b..7ce8ed03f80 100644 --- a/x/gov/module_test.go +++ b/x/gov/module_test.go @@ -18,7 +18,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simapp.NewCustomAppOptions(nil, 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 39e688475ac..e33382905c1 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -18,7 +18,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simapp.EmptyAppOptions{}) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simapp.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.Marshal(genesisState) From 614be15e1a556cea24d027a8342f2220925dfcf6 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Jun 2022 15:44:44 +0200 Subject: [PATCH 06/12] updates --- CHANGELOG.md | 6 +- baseapp/block_gas_test.go | 2 +- server/export_test.go | 2 +- simapp/app.yaml | 4 ++ simapp/app_test.go | 11 ++-- simapp/sim_bench_test.go | 5 +- simapp/sim_test.go | 12 ++-- simapp/test_helpers.go | 27 +-------- store/streaming/constructor_test.go | 3 +- testutil/network/network.go | 3 +- testutil/sims/app_helpers.go | 25 +++++++++ x/auth/module_test.go | 3 +- x/distribution/module_test.go | 3 +- x/gov/genesis_test.go | 2 +- x/gov/module_test.go | 3 +- x/staking/module_test.go | 3 +- x/upgrade/abci_test.go | 23 ++++---- x/upgrade/client/testutil/cli_test.go | 9 ++- x/upgrade/client/testutil/suite.go | 30 ++++++---- x/upgrade/keeper/grpc_query_test.go | 37 ++++++++----- x/upgrade/keeper/keeper_test.go | 80 +++++++++++++++------------ x/upgrade/keeper/msg_server_test.go | 12 ++-- x/upgrade/module.go | 5 +- x/upgrade/spec/05_app_wiring.md | 5 ++ x/upgrade/spec/README.md | 1 + x/upgrade/testutil/app.yaml | 51 +++++++++++++++++ x/upgrade/testutil/app_config.go | 20 +++++++ 27 files changed, 252 insertions(+), 135 deletions(-) create mode 100644 x/upgrade/spec/05_app_wiring.md create mode 100644 x/upgrade/testutil/app.yaml create mode 100644 x/upgrade/testutil/app_config.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 45b3dd3cddf..b92f4619279 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,9 +49,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes - -* (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 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/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 784e83f0aa1..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, 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/server/export_test.go b/server/export_test.go index 3836498dbf7..d0146b04614 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, 0, encCfg, simapp.NewCustomAppOptions(nil, tempDir)) + app := simapp.NewSimApp(logger, db, nil, true, 0, encCfg, simtestutil.NewCustomAppOptions(nil, tempDir)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") 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 5b554fe4b82..f36e68c4b1e 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" @@ -44,7 +45,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { DB: db, InvCheckPeriod: 0, EncConfig: encCfg, - AppOpts: NewCustomAppOptions(nil, DefaultNodeHome), + AppOpts: simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), }) for acc := range maccPerms { @@ -59,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, 0, encCfg, NewCustomAppOptions(nil, DefaultNodeHome)) + app2 := NewSimApp(logger2, db, nil, true, 0, encCfg, simtestutil.NewCustomAppOptions(nil, DefaultNodeHome)) _, err := app2.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } @@ -73,7 +74,7 @@ func TestRunMigrations(t *testing.T) { db := dbm.NewMemDB() encCfg := MakeTestEncodingConfig() logger, _ := log.NewDefaultLogger("plain", "info", false) - app := NewSimApp(logger, db, nil, true, 0, encCfg, NewCustomAppOptions(nil, DefaultNodeHome)) + app := NewSimApp(logger, db, nil, true, 0, encCfg, simtestutil.NewCustomAppOptions(nil, DefaultNodeHome)) // Create a new baseapp and configurator for the purpose of this test. bApp := baseapp.NewBaseApp(app.Name(), logger, db, encCfg.TxConfig.TxDecoder()) @@ -206,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, 0, encCfg, NewCustomAppOptions(nil, DefaultNodeHome)) + app := NewSimApp(logger, db, nil, true, 0, encCfg, simtestutil.NewCustomAppOptions(nil, DefaultNodeHome)) ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) // Create a mock module. This module will serve as the new module we're @@ -255,7 +256,7 @@ func TestUpgradeStateOnGenesis(t *testing.T) { DB: db, InvCheckPeriod: 0, EncConfig: encCfg, - AppOpts: NewCustomAppOptions(nil, DefaultNodeHome), + AppOpts: simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), }) // make sure the upgrade keeper has version map in state diff --git a/simapp/sim_bench_test.go b/simapp/sim_bench_test.go index e2ca62e3685..b52671e0ee1 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, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 37ddee33027..fbc2dd561ec 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, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, 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, FlagPeriodValue, MakeTestEncodingConfig(), NewCustomAppOptions(nil, DefaultNodeHome), interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), interBlockCacheOpt()) fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index bf133399b70..85f0408de5a 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -19,14 +19,11 @@ import ( "cosmossdk.io/math" bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/depinject" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" - servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/testutil/mock" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -50,7 +47,7 @@ type SetupOptions struct { func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { db := dbm.NewMemDB() encCdc := MakeTestEncodingConfig() - app := NewSimApp(log.NewNopLogger(), db, nil, true, invCheckPeriod, encCdc, NewCustomAppOptions(nil, DefaultNodeHome)) + app := NewSimApp(log.NewNopLogger(), db, nil, true, invCheckPeriod, encCdc, simtestutil.NewCustomAppOptions(nil, DefaultNodeHome)) if withGenesis { return app, NewDefaultGenesisState(encCdc.Codec) } @@ -379,28 +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 -} - -// AppOptionsMap is a stub implementing AppOptions which can get -type AppOptionsMap map[string]interface{} - -func (m AppOptionsMap) Get(key string) interface{} { - return m[key] -} - -func NewCustomAppOptions(skipUpgradeHeights []int64, homePath string) servertypes.AppOptions { - return AppOptionsMap{ - server.FlagUnsafeSkipUpgrades: skipUpgradeHeights, - flags.FlagHome: homePath, - } -} - // 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 306f958e772..007e15cfc16 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" @@ -64,7 +65,7 @@ func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor { return simapp.NewSimApp( val.Ctx.Logger, dbm.NewMemDB(), nil, true, 0, encodingCfg, - simapp.NewCustomAppOptions(nil, val.Ctx.Config.RootDir), + simtestutil.NewCustomAppOptions(nil, 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..49d41fb8ad5 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -13,12 +13,15 @@ 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" + "github.com/cosmos/cosmos-sdk/server" + 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 +223,25 @@ 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 NewCustomAppOptions(skipUpgradeHeights []int64, homePath string) servertypes.AppOptions { + return AppOptionsMap{ + server.FlagUnsafeSkipUpgrades: skipUpgradeHeights, + flags.FlagHome: homePath, + } +} diff --git a/x/auth/module_test.go b/x/auth/module_test.go index aca880a4d8c..a661bbf3f06 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, 5, encCdc, simapp.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewCustomAppOptions(nil, 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 b7cb68d42ca..815b75c2e56 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, 5, encCdc, simapp.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewCustomAppOptions(nil, 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 9a41067f575..355985d8f0e 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, 0, simapp.MakeTestEncodingConfig(), simapp.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 0, simapp.MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) app2.InitChain( abci.RequestInitChain{ diff --git a/x/gov/module_test.go b/x/gov/module_test.go index 7ce8ed03f80..70bfb4361c5 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, 5, encCdc, simapp.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewCustomAppOptions(nil, 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 e33382905c1..1088e0e5679 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, 5, encCdc, simapp.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewCustomAppOptions(nil, 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 322d9bf93e6..19469e1724c 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -9,18 +9,19 @@ 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/codec" + "github.com/cosmos/cosmos-sdk/depinject" + 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" ) @@ -35,20 +36,16 @@ 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(), - DB: db, - InvCheckPeriod: 0, - EncConfig: simapp.MakeTestEncodingConfig(), - AppOpts: simapp.NewCustomAppOptions(maps.Keys(skip), ""), - }) + var legacyAmino *codec.LegacyAmino + + appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.NewCustomAppOptions(maps.Keys(skip), ""))) + app, err := simtestutil.Setup(appConfig, &s.keeper, &legacyAmino) + 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..a3f4da486fd 100644 --- a/x/upgrade/client/testutil/cli_test.go +++ b/x/upgrade/client/testutil/cli_test.go @@ -6,13 +6,20 @@ package testutil import ( "testing" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/depinject" "github.com/cosmos/cosmos-sdk/testutil/network" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/x/upgrade/testutil" ) func TestIntegrationTestSuite(t *testing.T) { - cfg := network.DefaultConfig() + appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) + + cfg, err := network.DefaultConfigWithAppConfig(appConfig) + require.NoError(t, err) cfg.NumValidators = 1 suite.Run(t, NewIntegrationTestSuite(cfg)) } diff --git a/x/upgrade/client/testutil/suite.go b/x/upgrade/client/testutil/suite.go index d5e21ce47ae..106087753fe 100644 --- a/x/upgrade/client/testutil/suite.go +++ b/x/upgrade/client/testutil/suite.go @@ -6,11 +6,14 @@ 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/depinject" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" 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/testutil" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -21,24 +24,27 @@ 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 + + appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) + + app, err := simtestutil.Setup(appConfig, &s.upgradeKeeper) + s.Require().NoError(err) + s.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) - cfg := network.DefaultConfig() + cfg, err := network.DefaultConfigWithAppConfig(appConfig) + s.Require().NoError(err) cfg.NumValidators = 1 - s.cfg = cfg - var err error s.network, err = network.New(s.T(), s.T().TempDir(), cfg) s.Require().NoError(err) } @@ -80,8 +86,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..37d220aa55c 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -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" + "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" + "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) + appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) + app, err := simtestutil.Setup(appConfig, &interfaceRegistry, &suite.upgradeKeeper) + suite.NoError(err) + + suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) + + 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} @@ -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} }, @@ -170,8 +179,8 @@ 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() { diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 19fee1054ec..20e75664e58 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -8,46 +8,54 @@ 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.NewCustomAppOptions(nil, homeDir))) + app, err := simtestutil.Setup(appConfig, &s.upgradeKeeper, &bankKeeper, &stakingKeeper) + s.NoError(err) + 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 +64,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 +97,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 +131,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 +154,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 +184,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 +197,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 +211,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 +228,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 +241,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 +288,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 1c9aafa4607..a0f0c415363 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -10,7 +10,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "cosmossdk.io/core/appmodule" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -177,7 +176,7 @@ type upgradeInputs struct { Cdc codec.Codec AppOpts servertypes.AppOptions - BaseApp *baseapp.BaseApp + // BaseApp *baseapp.BaseApp } type upgradeOutputs struct { @@ -194,7 +193,7 @@ func provideModule(in upgradeInputs) upgradeOutputs { } // set the governance module account as the authority for conducting upgrades - k := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, cast.ToString(in.AppOpts.Get(flags.FlagHome)), in.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + k := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, cast.ToString(in.AppOpts.Get(flags.FlagHome)), 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) From 8767a96619a4d2c040b67f732c44dfabaef9dece Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Jun 2022 17:23:36 +0200 Subject: [PATCH 07/12] use interface instead --- x/upgrade/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index a0f0c415363..a08032c9582 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -176,7 +176,7 @@ type upgradeInputs struct { Cdc codec.Codec AppOpts servertypes.AppOptions - // BaseApp *baseapp.BaseApp + // ProtocolVersionSetter xp.ProtocolVersionSetter } type upgradeOutputs struct { From 1b774efd056addb8e319c88fc6d99ae21ad1afc9 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Jun 2022 19:02:29 +0200 Subject: [PATCH 08/12] add version setter --- simapp/app.go | 3 +++ x/upgrade/abci_test.go | 1 + x/upgrade/client/testutil/suite.go | 8 ++------ x/upgrade/keeper/grpc_query_test.go | 11 ++++++----- x/upgrade/keeper/keeper.go | 5 +++++ x/upgrade/keeper/keeper_test.go | 1 + x/upgrade/module.go | 1 - 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index fce43fb6dc8..b69678e4851 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -275,6 +275,9 @@ func NewSimApp( /**** 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)) diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 19469e1724c..77f936f3897 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -40,6 +40,7 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) TestSuite { appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.NewCustomAppOptions(maps.Keys(skip), ""))) app, err := simtestutil.Setup(appConfig, &s.keeper, &legacyAmino) + s.keeper.SetVersionSetter(app.BaseApp) require.NoError(t, err) s.ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: height, Time: time.Now()}) diff --git a/x/upgrade/client/testutil/suite.go b/x/upgrade/client/testutil/suite.go index 106087753fe..d5e535381c7 100644 --- a/x/upgrade/client/testutil/suite.go +++ b/x/upgrade/client/testutil/suite.go @@ -36,16 +36,12 @@ func (s *IntegrationTestSuite) SetupSuite() { appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) app, err := simtestutil.Setup(appConfig, &s.upgradeKeeper) + s.upgradeKeeper.SetVersionSetter(app.BaseApp) s.Require().NoError(err) s.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) - cfg, err := network.DefaultConfigWithAppConfig(appConfig) - s.Require().NoError(err) - cfg.NumValidators = 1 - s.cfg = cfg - - 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) } diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 37d220aa55c..22f410c263b 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" @@ -35,6 +35,7 @@ func (suite *UpgradeTestSuite) SetupTest() { appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) app, err := simtestutil.Setup(appConfig, &interfaceRegistry, &suite.upgradeKeeper) suite.NoError(err) + suite.upgradeKeeper.SetVersionSetter(app.BaseApp) suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) @@ -81,7 +82,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) @@ -139,7 +140,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) @@ -186,7 +187,7 @@ func (suite *UpgradeTestSuite) TestModuleVersions() { 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) @@ -215,7 +216,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..7881bc67dae 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -56,6 +56,11 @@ 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 +} + // 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 20e75664e58..bb72389c2f4 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -41,6 +41,7 @@ func (s *KeeperTestSuite) SetupTest() { appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.NewCustomAppOptions(nil, 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 diff --git a/x/upgrade/module.go b/x/upgrade/module.go index a08032c9582..816fec491ac 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -176,7 +176,6 @@ type upgradeInputs struct { Cdc codec.Codec AppOpts servertypes.AppOptions - // ProtocolVersionSetter xp.ProtocolVersionSetter } type upgradeOutputs struct { From 492eded13124f1f32ec2ef45a4010c5d2814a644 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 21 Jun 2022 21:58:13 +0200 Subject: [PATCH 09/12] update tests --- x/upgrade/client/testutil/suite.go | 4 +++- x/upgrade/keeper/grpc_query_test.go | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/x/upgrade/client/testutil/suite.go b/x/upgrade/client/testutil/suite.go index d5e535381c7..f4f01b95448 100644 --- a/x/upgrade/client/testutil/suite.go +++ b/x/upgrade/client/testutil/suite.go @@ -36,11 +36,13 @@ func (s *IntegrationTestSuite) SetupSuite() { appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) app, err := simtestutil.Setup(appConfig, &s.upgradeKeeper) - s.upgradeKeeper.SetVersionSetter(app.BaseApp) s.Require().NoError(err) s.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) + s.upgradeKeeper.SetVersionSetter(app.BaseApp) + s.upgradeKeeper.SetModuleVersionMap(s.ctx, app.ModuleManager.GetVersionMap()) + s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) } diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 22f410c263b..5e127bb79b9 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -35,10 +35,11 @@ func (suite *UpgradeTestSuite) SetupTest() { appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) app, err := simtestutil.Setup(appConfig, &interfaceRegistry, &suite.upgradeKeeper) suite.NoError(err) - suite.upgradeKeeper.SetVersionSetter(app.BaseApp) - 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) From 188c4b807aa0a92ceaec4e84045806d018908470 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 22 Jun 2022 08:24:09 +0200 Subject: [PATCH 10/12] clean up --- server/export_test.go | 2 +- simapp/app_test.go | 10 +++++----- simapp/sim_bench_test.go | 4 ++-- simapp/sim_test.go | 12 ++++++------ simapp/test_helpers.go | 2 +- testutil/network/network.go | 2 +- testutil/sims/app_helpers.go | 6 ++---- x/auth/module_test.go | 2 +- x/distribution/module_test.go | 2 +- x/gov/genesis_test.go | 2 +- x/gov/module_test.go | 2 +- x/staking/module_test.go | 2 +- x/upgrade/abci_test.go | 12 ++++++++++-- x/upgrade/client/testutil/cli_test.go | 6 +----- x/upgrade/client/testutil/suite.go | 5 +---- x/upgrade/keeper/grpc_query_test.go | 4 +--- x/upgrade/keeper/keeper_test.go | 2 +- x/upgrade/module.go | 18 +++++++++++++----- 18 files changed, 50 insertions(+), 45 deletions(-) diff --git a/server/export_test.go b/server/export_test.go index d0146b04614..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, 0, encCfg, simtestutil.NewCustomAppOptions(nil, tempDir)) + app := simapp.NewSimApp(logger, db, nil, true, 0, encCfg, simtestutil.NewAppOptionsWithFlagHome(tempDir)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") diff --git a/simapp/app_test.go b/simapp/app_test.go index f36e68c4b1e..ec7cad8ccf9 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -45,7 +45,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { DB: db, InvCheckPeriod: 0, EncConfig: encCfg, - AppOpts: simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), + AppOpts: simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), }) for acc := range maccPerms { @@ -60,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, 0, encCfg, simtestutil.NewCustomAppOptions(nil, DefaultNodeHome)) + 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") } @@ -74,7 +74,7 @@ func TestRunMigrations(t *testing.T) { db := dbm.NewMemDB() encCfg := MakeTestEncodingConfig() logger, _ := log.NewDefaultLogger("plain", "info", false) - app := NewSimApp(logger, db, nil, true, 0, encCfg, simtestutil.NewCustomAppOptions(nil, DefaultNodeHome)) + 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(app.Name(), logger, db, encCfg.TxConfig.TxDecoder()) @@ -207,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, 0, encCfg, simtestutil.NewCustomAppOptions(nil, DefaultNodeHome)) + 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 @@ -256,7 +256,7 @@ func TestUpgradeStateOnGenesis(t *testing.T) { DB: db, InvCheckPeriod: 0, EncConfig: encCfg, - AppOpts: simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), + AppOpts: simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), }) // make sure the upgrade keeper has version map in state diff --git a/simapp/sim_bench_test.go b/simapp/sim_bench_test.go index b52671e0ee1..9536a9699d1 100644 --- a/simapp/sim_bench_test.go +++ b/simapp/sim_bench_test.go @@ -31,7 +31,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { require.NoError(b, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome), interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( @@ -78,7 +78,7 @@ func BenchmarkInvariants(b *testing.B) { require.NoError(b, os.RemoveAll(dir)) }() - app := NewSimApp(logger, db, nil, true, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), 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 fbc2dd561ec..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, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), 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, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), 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, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), 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, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), 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, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), 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, FlagPeriodValue, MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, DefaultNodeHome), 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/test_helpers.go b/simapp/test_helpers.go index 85f0408de5a..92849b80a88 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -47,7 +47,7 @@ type SetupOptions struct { func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { db := dbm.NewMemDB() encCdc := MakeTestEncodingConfig() - app := NewSimApp(log.NewNopLogger(), db, nil, true, invCheckPeriod, encCdc, simtestutil.NewCustomAppOptions(nil, DefaultNodeHome)) + app := NewSimApp(log.NewNopLogger(), db, nil, true, invCheckPeriod, encCdc, simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome)) if withGenesis { return app, NewDefaultGenesisState(encCdc.Codec) } diff --git a/testutil/network/network.go b/testutil/network/network.go index 007e15cfc16..bc39a4118b8 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -65,7 +65,7 @@ func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor { return simapp.NewSimApp( val.Ctx.Logger, dbm.NewMemDB(), nil, true, 0, encodingCfg, - simtestutil.NewCustomAppOptions(nil, val.Ctx.Config.RootDir), + 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 49d41fb8ad5..61a5d521192 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -20,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "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" "github.com/cosmos/cosmos-sdk/testutil/mock" sdk "github.com/cosmos/cosmos-sdk/types" @@ -239,9 +238,8 @@ func (m AppOptionsMap) Get(key string) interface{} { return m[key] } -func NewCustomAppOptions(skipUpgradeHeights []int64, homePath string) servertypes.AppOptions { +func NewAppOptionsWithFlagHome(homePath string) servertypes.AppOptions { return AppOptionsMap{ - server.FlagUnsafeSkipUpgrades: skipUpgradeHeights, - flags.FlagHome: homePath, + flags.FlagHome: homePath, } } diff --git a/x/auth/module_test.go b/x/auth/module_test.go index a661bbf3f06..84d16cd5476 100644 --- a/x/auth/module_test.go +++ b/x/auth/module_test.go @@ -18,7 +18,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + 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 815b75c2e56..3297ff84dc3 100644 --- a/x/distribution/module_test.go +++ b/x/distribution/module_test.go @@ -19,7 +19,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + 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 355985d8f0e..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, 0, simapp.MakeTestEncodingConfig(), simtestutil.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + 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 70bfb4361c5..761cd712878 100644 --- a/x/gov/module_test.go +++ b/x/gov/module_test.go @@ -19,7 +19,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + 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 1088e0e5679..5fe1d917f4f 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -19,7 +19,7 @@ import ( func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { db := dbm.NewMemDB() encCdc := simapp.MakeTestEncodingConfig() - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, 5, encCdc, simtestutil.NewCustomAppOptions(nil, simapp.DefaultNodeHome)) + 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 77f936f3897..878f1f0ab0d 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -12,8 +12,10 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "golang.org/x/exp/maps" + "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" @@ -36,9 +38,15 @@ type TestSuite struct { var s TestSuite func setupTest(t *testing.T, height int64, skip map[int64]bool) TestSuite { - var legacyAmino *codec.LegacyAmino + 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(simtestutil.NewCustomAppOptions(maps.Keys(skip), ""))) + 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) diff --git a/x/upgrade/client/testutil/cli_test.go b/x/upgrade/client/testutil/cli_test.go index a3f4da486fd..6989e80d57e 100644 --- a/x/upgrade/client/testutil/cli_test.go +++ b/x/upgrade/client/testutil/cli_test.go @@ -9,16 +9,12 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/cosmos/cosmos-sdk/depinject" "github.com/cosmos/cosmos-sdk/testutil/network" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/x/upgrade/testutil" ) func TestIntegrationTestSuite(t *testing.T) { - appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) - - cfg, err := network.DefaultConfigWithAppConfig(appConfig) + cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig) require.NoError(t, err) cfg.NumValidators = 1 suite.Run(t, NewIntegrationTestSuite(cfg)) diff --git a/x/upgrade/client/testutil/suite.go b/x/upgrade/client/testutil/suite.go index f4f01b95448..8bab5bd950f 100644 --- a/x/upgrade/client/testutil/suite.go +++ b/x/upgrade/client/testutil/suite.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/depinject" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -33,9 +32,7 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) - - app, err := simtestutil.Setup(appConfig, &s.upgradeKeeper) + app, err := simtestutil.Setup(testutil.AppConfig, &s.upgradeKeeper) s.Require().NoError(err) s.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 5e127bb79b9..39600ba96fc 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "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" @@ -32,8 +31,7 @@ type UpgradeTestSuite struct { func (suite *UpgradeTestSuite) SetupTest() { var interfaceRegistry codectypes.InterfaceRegistry - appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.EmptyAppOptions{})) - app, err := simtestutil.Setup(appConfig, &interfaceRegistry, &suite.upgradeKeeper) + app, err := simtestutil.Setup(testutil.AppConfig, &interfaceRegistry, &suite.upgradeKeeper) suite.NoError(err) suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index bb72389c2f4..c9e2b053602 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -38,7 +38,7 @@ func (s *KeeperTestSuite) SetupTest() { ) homeDir := filepath.Join(s.T().TempDir(), "x_upgrade_keeper_test") - appConfig := depinject.Configs(testutil.AppConfig, depinject.Supply(simtestutil.NewCustomAppOptions(nil, homeDir))) + 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) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 816fec491ac..471c50dc740 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -175,7 +175,7 @@ type upgradeInputs struct { Key *store.KVStoreKey Cdc codec.Codec - AppOpts servertypes.AppOptions + AppOpts servertypes.AppOptions `optional:"true"` } type upgradeOutputs struct { @@ -186,13 +186,21 @@ type upgradeOutputs struct { } func provideModule(in upgradeInputs) upgradeOutputs { - skipUpgradeHeights := make(map[int64]bool) - for _, h := range cast.ToIntSlice(in.AppOpts.Get(server.FlagUnsafeSkipUpgrades)) { - skipUpgradeHeights[int64(h)] = true + 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, cast.ToString(in.AppOpts.Get(flags.FlagHome)), nil, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + 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)} From 51c0e958115e8c320df717ed3b7f66b15cd6963f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 22 Jun 2022 11:45:00 +0200 Subject: [PATCH 11/12] updates --- simapp/app_test.go | 2 ++ x/upgrade/keeper/keeper.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/simapp/app_test.go b/simapp/app_test.go index ec7cad8ccf9..b3e3874a2df 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -265,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/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 7881bc67dae..21e3ee70fb4 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -61,6 +61,10 @@ 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. From 381518ea746800b975e267d5a368aa0dda9468c8 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 22 Jun 2022 12:18:21 +0200 Subject: [PATCH 12/12] revert integration test --- x/upgrade/client/testutil/cli_test.go | 8 +------- x/upgrade/client/testutil/suite.go | 8 ++++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/x/upgrade/client/testutil/cli_test.go b/x/upgrade/client/testutil/cli_test.go index 6989e80d57e..7f92bbeeff5 100644 --- a/x/upgrade/client/testutil/cli_test.go +++ b/x/upgrade/client/testutil/cli_test.go @@ -1,21 +1,15 @@ -//go:build norace -// +build norace - package testutil import ( "testing" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/cosmos/cosmos-sdk/x/upgrade/testutil" ) func TestIntegrationTestSuite(t *testing.T) { - cfg, err := network.DefaultConfigWithAppConfig(testutil.AppConfig) - require.NoError(t, err) + cfg := network.DefaultConfig() cfg.NumValidators = 1 suite.Run(t, NewIntegrationTestSuite(cfg)) } diff --git a/x/upgrade/client/testutil/suite.go b/x/upgrade/client/testutil/suite.go index 8bab5bd950f..9e5eca3b234 100644 --- a/x/upgrade/client/testutil/suite.go +++ b/x/upgrade/client/testutil/suite.go @@ -6,13 +6,12 @@ import ( "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/simapp" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" 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/testutil" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -32,14 +31,15 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - app, err := simtestutil.Setup(testutil.AppConfig, &s.upgradeKeeper) - s.Require().NoError(err) + app := simapp.Setup(s.T(), false) + s.upgradeKeeper = app.UpgradeKeeper s.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) 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(), s.cfg) s.Require().NoError(err) }