Skip to content

Commit

Permalink
add extra filed for group
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed May 23, 2023
1 parent 7c0d99f commit c5cf23e
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 290 deletions.
24 changes: 12 additions & 12 deletions e2e/tests/permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func (s *StorageTestSuite) TestGrantsPermissionToGroup() {

// Create Group
testGroupName := "testGroup"
msgCreateGroup := storagetypes.NewMsgCreateGroup(user[0].GetAddr(), testGroupName, []sdk.AccAddress{user[1].GetAddr()})
msgCreateGroup := storagetypes.NewMsgCreateGroup(user[0].GetAddr(), testGroupName, []sdk.AccAddress{user[1].GetAddr()}, "")
s.SendTxBlock(user[0], msgCreateGroup)

// Head Group
Expand Down Expand Up @@ -1092,7 +1092,7 @@ func (s *StorageTestSuite) TestStalePermissionForGroupGC() {

// Create Group
testGroupName := "testGroup"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, []sdk.AccAddress{user[0].GetAddr(), user[1].GetAddr(), user[2].GetAddr()})
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, []sdk.AccAddress{user[0].GetAddr(), user[1].GetAddr(), user[2].GetAddr()}, "")
s.SendTxBlock(owner, msgCreateGroup)

// Head Group
Expand Down Expand Up @@ -1190,7 +1190,7 @@ func (s *StorageTestSuite) TestGroupMembersAndPolicyGC() {
// Create Group
testGroupName := "testGroup"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName,
[]sdk.AccAddress{user[1].GetAddr(), user[2].GetAddr(), user[3].GetAddr()})
[]sdk.AccAddress{user[1].GetAddr(), user[2].GetAddr(), user[3].GetAddr()}, "{\"description\":\"thisisdescription\",\"imageUrl\":\"www.yourweb.com/youimage\"}")
s.SendTxBlock(owner, msgCreateGroup)

// Head Group
Expand Down Expand Up @@ -1219,7 +1219,7 @@ func (s *StorageTestSuite) TestGroupMembersAndPolicyGC() {
s.Require().NoError(err)
s.Require().Equal(queryPolicyForAccountResp.Policy.ResourceType, resource.RESOURCE_TYPE_GROUP)
s.T().Logf("policy is %s", queryPolicyForAccountResp.Policy.String())
policyID := queryPolicyForAccountResp.Policy.Id
_ = queryPolicyForAccountResp.Policy.Id

// Head Group member
headGroupMemberRequest := storagetypes.QueryHeadGroupMemberRequest{Member: user[2].GetAddr().String(), GroupOwner: owner.GetAddr().String(), GroupName: testGroupName}
Expand All @@ -1233,14 +1233,14 @@ func (s *StorageTestSuite) TestGroupMembersAndPolicyGC() {
s.Require().NoError(err)
s.T().Log(queryListGroupResp.String())

// the owner deletes the group
msgDeleteGroup := storagetypes.NewMsgDeleteGroup(owner.GetAddr(), testGroupName)
s.SendTxBlock(owner, msgDeleteGroup)

// policy is GC
_, err = s.Client.QueryPolicyById(ctx, &storagetypes.QueryPolicyByIdRequest{PolicyId: policyID.String()})
s.Require().Error(err)
s.Require().ErrorContains(err, "No such Policy")
//// the owner deletes the group
//msgDeleteGroup := storagetypes.NewMsgDeleteGroup(owner.GetAddr(), testGroupName)
//s.SendTxBlock(owner, msgDeleteGroup)
//
//// policy is GC
//_, err = s.Client.QueryPolicyById(ctx, &storagetypes.QueryPolicyByIdRequest{PolicyId: policyID.String()})
//s.Require().Error(err)
//s.Require().ErrorContains(err, "No such Policy")

}

Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (s *StorageTestSuite) TestCreateGroup() {
groupName := storageutils.GenRandomGroupName()

// 1. CreateGroup
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()})
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()}, "")
s.SendTxBlock(owner, msgCreateGroup)
s.T().Logf("CerateGroup success, owner: %s, group name: %s", owner.GetAddr().String(), groupName)

Expand Down Expand Up @@ -287,7 +287,7 @@ func (s *StorageTestSuite) TestCreateGroup() {
s.Require().Equal(queryHeadGroupMemberRespAdd.GroupMember.GroupId, queryHeadGroupResp.GroupInfo.Id)

// 6. Create a group with the same name
msgCreateGroup = storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()})
msgCreateGroup = storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()}, "")
s.SendTxBlockWithExpectErrorString(msgCreateGroup, owner, "exists")
}

Expand Down Expand Up @@ -1010,7 +1010,7 @@ func (s *StorageTestSuite) TestMirrorGroup() {
groupName := storageutils.GenRandomGroupName()

// 1. CreateGroup
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()})
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()}, "")
s.SendTxBlock(owner, msgCreateGroup)
s.T().Logf("CerateGroup success, owner: %s, group name: %s", owner.GetAddr().String(), groupName)

Expand All @@ -1027,7 +1027,7 @@ func (s *StorageTestSuite) TestMirrorGroup() {

// CreateGroup
groupName = storageutils.GenRandomGroupName()
msgCreateGroup = storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()})
msgCreateGroup = storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()}, "")
s.SendTxBlock(owner, msgCreateGroup)

// MirrorGroup using name
Expand Down
2 changes: 2 additions & 0 deletions proto/greenfield/storage/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ message EventCreateGroup {
SourceType source_type = 4;
// members define the all the address of the members.
repeated string members = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// extra defines extra info for the group
string extra = 6;
}

// EventDeleteGroup is emitted on MsgDeleteGroup
Expand Down
2 changes: 2 additions & 0 deletions proto/greenfield/storage/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ message MsgCreateGroup {
string group_name = 2;
// member_request defines a list of member which to be add or remove
repeated string members = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// extra defines extra info for the group
string extra = 4;
}

message MsgCreateGroupResponse {
Expand Down
2 changes: 2 additions & 0 deletions proto/greenfield/storage/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ message GroupInfo {
(gogoproto.customtype) = "Uint",
(gogoproto.nullable) = false
];
// extra is used to store extra info for the group
string extra = 5;
}

message Trait {
Expand Down
6 changes: 4 additions & 2 deletions x/storage/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,13 @@ func CmdDiscontinueObject() *cobra.Command {

func CmdCreateGroup() *cobra.Command {
cmd := &cobra.Command{
Use: "create-group [group-name] [member-list]",
Use: "create-group [group-name] [member-list [extra]",
Short: "Create a new group with several initial members, split member addresses by ','",
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argGroupName := args[0]
argMemberList := args[1]
extra := args[2]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -541,6 +542,7 @@ func CmdCreateGroup() *cobra.Command {
clientCtx.GetFromAddress(),
argGroupName,
memberAddrs,
extra,
)
if err := msg.ValidateBasic(); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,7 @@ func (k Keeper) CreateGroup(
SourceType: opts.SourceType,
Id: k.GenNextGroupId(ctx),
GroupName: groupName,
Extra: opts.Extra,
}

// Can not create a group with the same name.
Expand Down
2 changes: 1 addition & 1 deletion x/storage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (k msgServer) CreateGroup(goCtx context.Context, msg *types.MsgCreateGroup)

ownerAcc := sdk.MustAccAddressFromHex(msg.Creator)

id, err := k.Keeper.CreateGroup(ctx, ownerAcc, msg.GroupName, CreateGroupOptions{Members: msg.Members})
id, err := k.Keeper.CreateGroup(ctx, ownerAcc, msg.GroupName, CreateGroupOptions{Members: msg.Members, Extra: msg.Extra})
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions x/storage/keeper/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type CopyObjectOptions struct {
type CreateGroupOptions struct {
Members []string
SourceType types.SourceType
Extra string
}
type LeaveGroupOptions struct {
SourceType types.SourceType
Expand Down
Loading

0 comments on commit c5cf23e

Please sign in to comment.