diff --git a/app/app.go b/app/app.go index ed2192d8..e72c8af6 100644 --- a/app/app.go +++ b/app/app.go @@ -859,6 +859,7 @@ func NewMilkyWayApp( app.ServicesKeeper = serviceskeeper.NewKeeper( app.appCodec, keys[servicestypes.StoreKey], + app.AccountKeeper, communityPoolKeeper, authorityAddr, ) diff --git a/proto/milkyway/services/v1/models.proto b/proto/milkyway/services/v1/models.proto index 8ed640b4..b427eccf 100644 --- a/proto/milkyway/services/v1/models.proto +++ b/proto/milkyway/services/v1/models.proto @@ -47,4 +47,9 @@ message Service { // PictureURL is the URL of the picture of the service string pictureURL = 7; + + // Address is the address of the account associated with the service. + // This will be used in order to store all the tokens that are delegated to + // this service by various users. + string address = 8 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; } diff --git a/x/services/keeper/alias_functions.go b/x/services/keeper/alias_functions.go index 6fa3795a..29322a6e 100644 --- a/x/services/keeper/alias_functions.go +++ b/x/services/keeper/alias_functions.go @@ -2,11 +2,20 @@ package keeper import ( storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/milkyway-labs/milkyway/x/services/types" ) +// createAccountIfNotExists creates an account if it does not exist +func (k *Keeper) createAccountIfNotExists(ctx sdk.Context, address sdk.AccAddress) { + if !k.accountKeeper.HasAccount(ctx, address) { + defer telemetry.IncrCounter(1, "new", "account") + k.accountKeeper.SetAccount(ctx, k.accountKeeper.NewAccountWithAddress(ctx, address)) + } +} + // IterateServices iterates over the services in the store and performs a callback function func (k *Keeper) IterateServices(ctx sdk.Context, cb func(service types.Service) (stop bool)) { store := ctx.KVStore(k.storeKey) diff --git a/x/services/keeper/common_test.go b/x/services/keeper/common_test.go index 4082c450..c7d33bac 100644 --- a/x/services/keeper/common_test.go +++ b/x/services/keeper/common_test.go @@ -103,6 +103,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.k = keeper.NewKeeper( suite.cdc, suite.storeKey, + suite.ak, keepers.NewCommunityPoolKeeper(suite.bk, authtypes.FeeCollectorName), authorityAddr, ) diff --git a/x/services/keeper/keeper.go b/x/services/keeper/keeper.go index f5253d5a..0fdab01f 100644 --- a/x/services/keeper/keeper.go +++ b/x/services/keeper/keeper.go @@ -14,7 +14,8 @@ type Keeper struct { cdc codec.BinaryCodec hooks types.ServicesHooks - poolKeeper types.CommunityPoolKeeper + accountKeeper types.AccountKeeper + poolKeeper types.CommunityPoolKeeper // authority represents the address capable of executing a MsgUpdateParams message. // Typically, this should be the x/gov module account. @@ -22,12 +23,13 @@ type Keeper struct { } // NewKeeper creates a new keeper -func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, poolKeeper types.CommunityPoolKeeper, authority string) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, accountKeeper types.AccountKeeper, poolKeeper types.CommunityPoolKeeper, authority string) *Keeper { return &Keeper{ - storeKey: storeKey, - cdc: cdc, - poolKeeper: poolKeeper, - authority: authority, + storeKey: storeKey, + cdc: cdc, + accountKeeper: accountKeeper, + poolKeeper: poolKeeper, + authority: authority, } } diff --git a/x/services/keeper/msg_server_test.go b/x/services/keeper/msg_server_test.go index e7e57cb6..0fa9adc5 100644 --- a/x/services/keeper/msg_server_test.go +++ b/x/services/keeper/msg_server_test.go @@ -111,7 +111,11 @@ func (suite *KeeperTestSuite) TestMsgServer_CreateService() { "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", ), stored) - // Make sure the next service account has been incremented + // Make sure the service account has been created properly + hasAccount := suite.ak.HasAccount(ctx, types.GetServiceAddress(1)) + suite.Require().True(hasAccount) + + // Make sure the next service id has been incremented nextServiceID, err := suite.k.GetNextServiceID(ctx) suite.Require().NoError(err) suite.Require().Equal(uint32(2), nextServiceID) diff --git a/x/services/keeper/services.go b/x/services/keeper/services.go index 67a67a03..0243f4bb 100644 --- a/x/services/keeper/services.go +++ b/x/services/keeper/services.go @@ -3,6 +3,7 @@ package keeper import ( "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/milkyway-labs/milkyway/x/services/types" ) @@ -49,6 +50,13 @@ func (k *Keeper) CreateService(ctx sdk.Context, service types.Service) error { } } + // Create the service account + serviceAddress, err := sdk.AccAddressFromBech32(service.Address) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid service address: %s", service.Address) + } + k.createAccountIfNotExists(ctx, serviceAddress) + // Store the service k.SaveService(ctx, service) diff --git a/x/services/keeper/services_test.go b/x/services/keeper/services_test.go index 3f03b452..658796c4 100644 --- a/x/services/keeper/services_test.go +++ b/x/services/keeper/services_test.go @@ -161,6 +161,10 @@ func (suite *KeeperTestSuite) TestKeeper_CreateService() { poolBalance := suite.bk.GetBalance(ctx, authtypes.NewModuleAddress(authtypes.FeeCollectorName), "uatom") suite.Require().Equal(sdk.NewCoin("uatom", sdkmath.NewInt(100_000_000)), poolBalance) + // Make sure the service account has been created + hasAccount := suite.ak.HasAccount(ctx, types.GetServiceAddress(1)) + suite.Require().True(hasAccount) + // Make sure the service has been created service, found := suite.k.GetService(ctx, 1) suite.Require().True(found) diff --git a/x/services/types/expected_keepers.go b/x/services/types/expected_keepers.go index f50056e8..3f036adf 100644 --- a/x/services/types/expected_keepers.go +++ b/x/services/types/expected_keepers.go @@ -6,6 +6,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +type AccountKeeper interface { + NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI + HasAccount(ctx context.Context, addr sdk.AccAddress) bool + SetAccount(ctx context.Context, acc sdk.AccountI) +} + type CommunityPoolKeeper interface { FundCommunityPool(ctx context.Context, amount sdk.Coins, sender sdk.AccAddress) error } diff --git a/x/services/types/genesis_test.go b/x/services/types/genesis_test.go index a6b29db9..9ed81bfa 100644 --- a/x/services/types/genesis_test.go +++ b/x/services/types/genesis_test.go @@ -30,18 +30,25 @@ func TestValidateGenesis(t *testing.T) { genesis: &types.GenesisState{ NextServiceID: 1, Services: []types.Service{ - { - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, - { - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }}, + types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), + types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), + }, Params: types.DefaultParams(), }, shouldErr: true, @@ -51,18 +58,24 @@ func TestValidateGenesis(t *testing.T) { genesis: &types.GenesisState{ NextServiceID: 1, Services: []types.Service{ - { - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, - { - ID: 2, - Status: types.SERVICE_STATUS_UNSPECIFIED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "IBC Relaying", - }, + types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), + types.NewService( + 2, + types.SERVICE_STATUS_UNSPECIFIED, + "Tucana", + "", + "", + "", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), }, Params: types.DefaultParams(), }, @@ -89,18 +102,24 @@ func TestValidateGenesis(t *testing.T) { genesis: &types.GenesisState{ NextServiceID: 1, Services: []types.Service{ - { - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, - { - ID: 2, - Status: types.SERVICE_STATUS_ACTIVE, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "IBC Relaying", - }, + types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), + types.NewService( + 2, + types.SERVICE_STATUS_ACTIVE, + "Tucana", + "", + "", + "", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), }, Params: types.NewParams( sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10))), diff --git a/x/services/types/models.go b/x/services/types/models.go index 1e1d32cd..a51ff89c 100644 --- a/x/services/types/models.go +++ b/x/services/types/models.go @@ -6,8 +6,14 @@ import ( "strings" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) +// GetServiceAddress generates a service address from its id +func GetServiceAddress(serviceID uint32) sdk.AccAddress { + return authtypes.NewModuleAddress(fmt.Sprintf("service-%d", serviceID)) +} + // ParseServiceID parses a string into a uint32 func ParseServiceID(value string) (uint32, error) { id, err := strconv.ParseUint(value, 10, 32) @@ -37,6 +43,7 @@ func NewService( Website: website, PictureURL: pictureURL, Admin: admin, + Address: GetServiceAddress(id).String(), } } @@ -59,6 +66,11 @@ func (a *Service) Validate() error { return fmt.Errorf("invalid admin address") } + _, err = sdk.AccAddressFromBech32(a.Address) + if err != nil { + return fmt.Errorf("invalid service address") + } + return nil } diff --git a/x/services/types/models.pb.go b/x/services/types/models.pb.go index 50453209..72714dfe 100644 --- a/x/services/types/models.pb.go +++ b/x/services/types/models.pb.go @@ -78,6 +78,10 @@ type Service struct { Website string `protobuf:"bytes,6,opt,name=website,proto3" json:"website,omitempty"` // PictureURL is the URL of the picture of the service PictureURL string `protobuf:"bytes,7,opt,name=pictureURL,proto3" json:"pictureURL,omitempty"` + // Address is the address of the account associated with the service. + // This will be used in order to store all the tokens that are delegated to + // this service by various users. + Address string `protobuf:"bytes,8,opt,name=address,proto3" json:"address,omitempty"` } func (m *Service) Reset() { *m = Service{} } @@ -162,6 +166,13 @@ func (m *Service) GetPictureURL() string { return "" } +func (m *Service) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + func init() { proto.RegisterEnum("milkyway.services.v1.ServiceStatus", ServiceStatus_name, ServiceStatus_value) proto.RegisterType((*Service)(nil), "milkyway.services.v1.Service") @@ -170,33 +181,34 @@ func init() { func init() { proto.RegisterFile("milkyway/services/v1/models.proto", fileDescriptor_4411e719afee9a70) } var fileDescriptor_4411e719afee9a70 = []byte{ - // 414 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0x4d, 0x8b, 0xd3, 0x40, - 0x18, 0xc7, 0x33, 0xd9, 0x6e, 0x8a, 0x23, 0x2b, 0x65, 0xa8, 0xeb, 0x6c, 0x84, 0x31, 0xea, 0xa5, - 0x08, 0x9b, 0xb0, 0xeb, 0xd1, 0x53, 0x9a, 0x46, 0x08, 0x2c, 0x8b, 0x24, 0xe9, 0x1e, 0xbc, 0x94, - 0xbc, 0x0c, 0x71, 0xb0, 0xc9, 0x84, 0xcc, 0xb4, 0x6b, 0xbf, 0x81, 0xde, 0xfc, 0x0e, 0x7e, 0x05, - 0x3f, 0x84, 0xc7, 0xc5, 0x93, 0x27, 0x91, 0xf4, 0x7b, 0x88, 0x6c, 0x5e, 0xb4, 0x96, 0xbd, 0x3d, - 0xff, 0xe7, 0xf7, 0xcb, 0x93, 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, 0x55, 0xd1, 0xb9, 0x7f, - 0x81, 0x87, 0x0d, 0xdc, 0xe9, 0xbc, 0xf8, 0x04, 0xe0, 0xd1, 0x7f, 0x9b, 0x23, 0x02, 0xf5, 0xc0, - 0xf5, 0xaf, 0x3c, 0xc7, 0x5d, 0x04, 0xa1, 0x1d, 0xce, 0x83, 0xc5, 0xfc, 0x32, 0x78, 0xe3, 0x3a, - 0xde, 0x6b, 0xcf, 0x9d, 0x8d, 0x14, 0xa4, 0xc3, 0xe3, 0x3d, 0xee, 0xf8, 0xae, 0x1d, 0xba, 0xb3, - 0x11, 0x40, 0x27, 0xf0, 0xe1, 0x1e, 0xb3, 0x9d, 0xd0, 0xbb, 0x72, 0x47, 0x2a, 0x7a, 0x0c, 0x1f, - 0xed, 0x21, 0xef, 0xb2, 0x83, 0x07, 0xfa, 0xe0, 0xe3, 0x17, 0xa2, 0x4c, 0x2f, 0xbe, 0xd5, 0x04, - 0xdc, 0xd4, 0x04, 0xfc, 0xaa, 0x09, 0xf8, 0xbc, 0x25, 0xca, 0xcd, 0x96, 0x28, 0x3f, 0xb6, 0x44, - 0x79, 0x7b, 0x9e, 0x31, 0xf9, 0x6e, 0x15, 0x9b, 0x09, 0xcf, 0xad, 0xfe, 0xf0, 0x4f, 0x97, 0x51, - 0x2c, 0xfe, 0x26, 0xeb, 0xc3, 0xbf, 0xb7, 0x22, 0x37, 0x25, 0x15, 0xb1, 0xd6, 0xdc, 0xf0, 0xcb, - 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x72, 0xa4, 0xfe, 0x63, 0x4d, 0x02, 0x00, 0x00, + // 426 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x80, 0xbd, 0x6e, 0x9a, 0xc0, 0xa0, 0xa2, 0x68, 0x15, 0xca, 0xd6, 0x48, 0x4b, 0x80, 0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0xf2, 0x4f, 0x66, + 0xbd, 0xff, 0xbb, 0x5f, 0x6a, 0x93, 0x31, 0x19, 0xb4, 0xcb, 0xad, 0x78, 0xf1, 0x3b, 0x00, 0x00, + 0xff, 0xff, 0x40, 0x5a, 0x2a, 0x1e, 0x81, 0x02, 0x00, 0x00, } func (m *Service) Marshal() (dAtA []byte, err error) { @@ -219,6 +231,13 @@ func (m *Service) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintModels(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x42 + } if len(m.PictureURL) > 0 { i -= len(m.PictureURL) copy(dAtA[i:], m.PictureURL) @@ -310,6 +329,10 @@ func (m *Service) Size() (n int) { if l > 0 { n += 1 + l + sovModels(uint64(l)) } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovModels(uint64(l)) + } return n } @@ -546,6 +569,38 @@ func (m *Service) Unmarshal(dAtA []byte) error { } m.PictureURL = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthModels + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModels + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipModels(dAtA[iNdEx:]) diff --git a/x/services/types/models_test.go b/x/services/types/models_test.go index 6fc07480..462f011e 100644 --- a/x/services/types/models_test.go +++ b/x/services/types/models_test.go @@ -71,52 +71,78 @@ func TestService_Validate(t *testing.T) { }{ { name: "invalid status returns error", - service: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_UNSPECIFIED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, + service: types.NewService( + 1, + types.SERVICE_STATUS_UNSPECIFIED, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), shouldErr: true, }, { name: "invalid ID returns error", - service: types.Service{ - ID: 0, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, + service: types.NewService( + 0, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), shouldErr: true, }, { name: "invalid name returns error", - service: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "", - }, + service: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), + shouldErr: true, + }, + { + name: "invalid admin address returns error", + service: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "", + ), shouldErr: true, }, { name: "invalid address returns error", service: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "", - Name: "MilkyWay", + ID: 1, + Status: types.SERVICE_STATUS_ACTIVE, + Name: "MilkyWay", + Admin: "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + Address: "", }, shouldErr: true, }, { - name: "valid Service returns no error", - service: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, + name: "valid service returns no error", + service: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), shouldErr: false, }, } @@ -143,90 +169,111 @@ func TestService_Update(t *testing.T) { }{ { name: "update name", - service: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, + service: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), update: types.NewServiceUpdate( "MilkyWay2", types.DoNotModify, types.DoNotModify, types.DoNotModify, ), - expResult: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay2", - }, + expResult: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay2", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), }, { name: "update description", - service: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, + service: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), update: types.NewServiceUpdate( types.DoNotModify, "New description", types.DoNotModify, types.DoNotModify, ), - expResult: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - Description: "New description", - }, + expResult: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "New description", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), }, { name: "update website", - service: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, + service: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), update: types.NewServiceUpdate( types.DoNotModify, types.DoNotModify, "https://example.com", types.DoNotModify, ), - expResult: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - Website: "https://example.com", - }, + expResult: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://example.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), }, { name: "update picture URL", - service: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - }, + service: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://milkyway.com/logo.png", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), update: types.NewServiceUpdate( types.DoNotModify, types.DoNotModify, types.DoNotModify, "https://example.com/picture.jpg", ), - expResult: types.Service{ - ID: 1, - Status: types.SERVICE_STATUS_CREATED, - Admin: "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4", - Name: "MilkyWay", - PictureURL: "https://example.com/picture.jpg", - }, + expResult: types.NewService( + 1, + types.SERVICE_STATUS_ACTIVE, + "MilkyWay", + "MilkyWay is an AVS of a restaking platform", + "https://milkyway.com", + "https://example.com/picture.jpg", + "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", + ), }, }