Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add extra field to group #258

Merged
merged 4 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 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,8 @@ 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()},
"")
s.SendTxBlock(owner, msgCreateGroup)

// Head Group
Expand Down Expand Up @@ -1348,3 +1349,56 @@ func (s *StorageTestSuite) TestExceedEachBlockLimitGC() {
s.Require().ErrorContains(err, "No such Policy")
}
}

func (s *StorageTestSuite) TestUpdateGroupExtraWithPermission() {
var err error
ctx := context.Background()

user := s.GenAndChargeAccounts(4, 1000000)
owner := user[0]

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

// Head Group
headGroupRequest := storagetypes.QueryHeadGroupRequest{GroupOwner: owner.GetAddr().String(), GroupName: testGroupName}
headGroupResponse, err := s.Client.HeadGroup(ctx, &headGroupRequest)
s.Require().NoError(err)
s.Require().Equal(headGroupResponse.GroupInfo.GroupName, testGroupName)
s.Require().True(owner.GetAddr().Equals(sdk.MustAccAddressFromHex(headGroupResponse.GroupInfo.Owner)))
s.T().Logf("GroupInfo: %s", headGroupResponse.GetGroupInfo().String())

// Put policy
groupStatement := &types.Statement{
Actions: []types.ActionType{types.ACTION_UPDATE_GROUP_EXTRA},
Effect: types.EFFECT_ALLOW,
}
msgPutGroupPolicy := storagetypes.NewMsgPutPolicy(owner.GetAddr(), types2.NewGroupGRN(owner.GetAddr(), testGroupName).String(),
types.NewPrincipalWithAccount(user[1].GetAddr()), []*types.Statement{groupStatement}, nil)
s.SendTxBlock(owner, msgPutGroupPolicy)

// user1 update the extra of group is allowed
newExtra := "newExtra"
msgUpdateGroup := storagetypes.NewMsgUpdateGroupExtra(user[1].GetAddr(), owner.GetAddr(), testGroupName, newExtra)
s.SendTxBlock(user[1], msgUpdateGroup)

// Head Group
headGroupRequest = storagetypes.QueryHeadGroupRequest{GroupOwner: owner.GetAddr().String(), GroupName: testGroupName}
headGroupResponse, err = s.Client.HeadGroup(ctx, &headGroupRequest)
s.Require().NoError(err)
s.Require().Equal(headGroupResponse.GroupInfo.GroupName, testGroupName)
s.Require().True(owner.GetAddr().Equals(sdk.MustAccAddressFromHex(headGroupResponse.GroupInfo.Owner)))
s.Require().Equal(newExtra, headGroupResponse.GroupInfo.Extra)
s.T().Logf("GroupInfo: %s", headGroupResponse.GetGroupInfo().String())

// user2 update the extra of group is not allowed
newExtra = "newExtra2"
msgUpdateGroup2 := storagetypes.NewMsgUpdateGroupExtra(user[2].GetAddr(), owner.GetAddr(), testGroupName, newExtra)
_, err = s.SendTxBlockWithoutCheck(msgUpdateGroup2, user[2])
s.Require().Error(err)

}
57 changes: 53 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 Expand Up @@ -1709,3 +1709,52 @@ func (s *StorageTestSuite) TestUpdateParams() {
s.Require().NoError(err)
require.EqualValues(s.T(), queryVersionedParamsResponse.GetParams().VersionedParams.MaxSegmentSize, 2048)
}

func (s *StorageTestSuite) TestCreateAndUpdateGroupExtraField() {
var err error
ctx := context.Background()
owner := s.GenAndChargeAccounts(1, 1000000)[0]

// Create a group without members
testGroupName := "appName/bucketName"
extra := "{\"description\":\"no description\",\"imageUrl\":\"www.images.com/image1\"}"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, nil, extra)
s.SendTxBlock(owner, msgCreateGroup)

// Head Group
headGroupRequest := storagetypes.QueryHeadGroupRequest{GroupOwner: owner.GetAddr().String(), GroupName: testGroupName}
headGroupResponse, err := s.Client.HeadGroup(ctx, &headGroupRequest)
s.Require().NoError(err)
s.Require().Equal(headGroupResponse.GroupInfo.GroupName, testGroupName)
s.Require().True(owner.GetAddr().Equals(sdk.MustAccAddressFromHex(headGroupResponse.GroupInfo.Owner)))
s.Require().Equal(headGroupResponse.GroupInfo.Extra, extra)
s.T().Logf("GroupInfo: %s", headGroupResponse.GetGroupInfo().String())

// Update the extra to empty
newExtra := ""
msgUpdateGroup := storagetypes.NewMsgUpdateGroupExtra(owner.GetAddr(), owner.GetAddr(), testGroupName, newExtra)
s.SendTxBlock(owner, msgUpdateGroup)

// Head Group
headGroupRequest = storagetypes.QueryHeadGroupRequest{GroupOwner: owner.GetAddr().String(), GroupName: testGroupName}
headGroupResponse, err = s.Client.HeadGroup(ctx, &headGroupRequest)
s.Require().NoError(err)
s.Require().Equal(headGroupResponse.GroupInfo.GroupName, testGroupName)
s.Require().True(owner.GetAddr().Equals(sdk.MustAccAddressFromHex(headGroupResponse.GroupInfo.Owner)))
s.Require().Equal(newExtra, headGroupResponse.GroupInfo.Extra)
s.T().Logf("GroupInfo: %s", headGroupResponse.GetGroupInfo().String())

// Update the extra
newExtra = "something"
msgUpdateGroup = storagetypes.NewMsgUpdateGroupExtra(owner.GetAddr(), owner.GetAddr(), testGroupName, newExtra)
s.SendTxBlock(owner, msgUpdateGroup)

// Head Group
headGroupRequest = storagetypes.QueryHeadGroupRequest{GroupOwner: owner.GetAddr().String(), GroupName: testGroupName}
headGroupResponse, err = s.Client.HeadGroup(ctx, &headGroupRequest)
s.Require().NoError(err)
s.Require().Equal(headGroupResponse.GroupInfo.GroupName, testGroupName)
s.Require().True(owner.GetAddr().Equals(sdk.MustAccAddressFromHex(headGroupResponse.GroupInfo.Owner)))
s.Require().Equal(newExtra, headGroupResponse.GroupInfo.Extra)
s.T().Logf("GroupInfo: %s", headGroupResponse.GetGroupInfo().String())
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,6 @@ replace (
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.23.0
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.1
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v0.2.1-alpha.1
github.com/cosmos/cosmos-sdk => github.com/alexgao001/greenfield-cosmos-sdk v0.0.0-20230524121756-e8ca5b40a690
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/alexgao001/greenfield-cosmos-sdk v0.0.0-20230524121756-e8ca5b40a690 h1:NO1WDmmRpuxlr/CLjnmxtMBDI4FXBSbk9FEjY/KavS4=
github.com/alexgao001/greenfield-cosmos-sdk v0.0.0-20230524121756-e8ca5b40a690/go.mod h1:6pVENKv7drpk0k46nuyvAeD1SMnQUuXD9WY0tyc060A=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
Expand Down Expand Up @@ -161,8 +163,6 @@ github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edY
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/greenfield-cometbft v0.0.1 h1:pX8S9oZKjWJCrxH07l6rbU3zee9txZ11+UwO9stsNMQ=
github.com/bnb-chain/greenfield-cometbft v0.0.1/go.mod h1:9q11eHNRY9FDwFH+4pompzPNGv//Z3VcfvkELaHJPMs=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.1-alpha.1 h1:jlXZVYSPnq5pkmHAqIqekfmyksebQBK5OQJW3NeU4BE=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.1-alpha.1/go.mod h1:6pVENKv7drpk0k46nuyvAeD1SMnQUuXD9WY0tyc060A=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230425074444-eb5869b05fe9 h1:6fLpmmI0EZvDTfPvI0zy5dBaaTUboHnEkoC5/p/w8TQ=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230425074444-eb5869b05fe9/go.mod h1:rbc4o84RSEvhf09o2+4Qiazsv0snRJLiEZdk17HeIDw=
github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230425074444-eb5869b05fe9 h1:1ZdK+iR1Up02bOa2YTZCml7PBpP//kcdamOcK6aWO/s=
Expand Down
2 changes: 2 additions & 0 deletions proto/greenfield/permission/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ enum ActionType {

ACTION_UPDATE_OBJECT_INFO = 11;

ACTION_UPDATE_GROUP_EXTRA = 12;

ACTION_TYPE_ALL = 99;
}

Expand Down
20 changes: 20 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 Expand Up @@ -338,6 +340,24 @@ message EventUpdateGroupMember {
repeated string members_to_delete = 6 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// EventUpdateGroupExtra is emitted on MsgUpdateGroupExtra
message EventUpdateGroupExtra {
// operator define the account address of operator who update the group member
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// owner define the account address of group owner
string owner = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// group_name define the name of the group
string group_name = 3;
// id define an u256 id for group
string group_id = 4 [
(cosmos_proto.scalar) = "cosmos.Uint",
(gogoproto.customtype) = "Uint",
(gogoproto.nullable) = false
];
// extra defines extra info for the group to update
string extra = 5;
}

// EventMirrorBucket is emitted on MirrorBucket
message EventMirrorBucket {
// operator define the account address of operator who mirror the bucket
Expand Down
18 changes: 18 additions & 0 deletions proto/greenfield/storage/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ service Msg {
rpc CreateGroup(MsgCreateGroup) returns (MsgCreateGroupResponse);
rpc DeleteGroup(MsgDeleteGroup) returns (MsgDeleteGroupResponse);
rpc UpdateGroupMember(MsgUpdateGroupMember) returns (MsgUpdateGroupMemberResponse);
rpc UpdateGroupExtra(MsgUpdateGroupExtra) returns (MsgUpdateGroupExtraResponse);
rpc LeaveGroup(MsgLeaveGroup) returns (MsgLeaveGroupResponse);
rpc MirrorGroup(MsgMirrorGroup) returns (MsgMirrorGroupResponse);
// basic operation of policy
Expand Down Expand Up @@ -236,6 +237,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 Expand Up @@ -274,6 +277,21 @@ message MsgUpdateGroupMember {

message MsgUpdateGroupMemberResponse {}

message MsgUpdateGroupExtra {
option (cosmos.msg.v1.signer) = "operator";

// operator defines the account address of the operator who has the UpdateGroupMember permission of the group.
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// group_owner defines the account address of the group owner
string group_owner = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// group_name defines the name of the group which to be updated
string group_name = 3;
// extra defines extra info for the group to update
string Extra = 4;
}

message MsgUpdateGroupExtraResponse {}

message MsgLeaveGroup {
option (cosmos.msg.v1.signer) = "member";

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
unclezoro marked this conversation as resolved.
Show resolved Hide resolved
string extra = 5;
}

message Trait {
Expand Down
Loading