Skip to content

Commit

Permalink
add is frozen
Browse files Browse the repository at this point in the history
  • Loading branch information
trevormil committed Dec 26, 2023
1 parent c93fa40 commit a55ef5f
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 37 deletions.
6 changes: 4 additions & 2 deletions chain-handlers/ethereum/ethereum/eip712/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func GetSchemas() []string {
"creator": "",
"name": "",
"uri": "",
"customData": ""
"customData": "",
"isFrozen": false
}
}`)

Expand All @@ -47,7 +48,8 @@ func GetSchemas() []string {
"creator": "",
"name": "",
"uri": "",
"customData": ""
"customData": "",
"isFrozen": false
}
}`)

Expand Down
3 changes: 3 additions & 0 deletions proto/protocols/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ message Protocol {
string uri = 2;
string customData = 3;
string createdBy = 4;
bool isFrozen = 5;
}

message MsgCreateProtocol {
string creator = 1;
string name = 2;
string uri = 3;
string customData = 4;
bool isFrozen = 5;
}

message MsgCreateProtocolResponse {}
Expand All @@ -36,6 +38,7 @@ message MsgUpdateProtocol {
string name = 2;
string uri = 3;
string customData = 4;
bool isFrozen = 5;
}

message MsgUpdateProtocolResponse {}
Expand Down
35 changes: 35 additions & 0 deletions x/badges/keeper/balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,37 @@ func (suite *TestSuite) TestUpdateAndGetBalancesForIds() {
})
}

func (suite *TestSuite) TestDefaultBalances() {
err := UpdateCollection(suite, suite.ctx, &types.MsgUniversalUpdateCollection{
CollectionId: sdkmath.NewUint(0),
Creator: alice,
ManagerTimeline: []*types.ManagerTimeline{},
BalancesType: "Standard",
DefaultBalances: &types.UserBalanceStore{
Balances: []*types.Balance{
{
Amount: sdkmath.NewUint(1),
OwnershipTimes: GetFullUintRanges(),
BadgeIds: GetFullUintRanges(),
},
},
},
})
suite.Require().Nil(err, "Error updating collection: %s")

bal, err := GetUserBalance(suite, suite.ctx, sdkmath.NewUint(1), "address1")
suite.Require().Nil(err, "Error getting user balance: %s")

AssertBalancesEqual(suite, bal.Balances, []*types.Balance{
{
Amount: sdkmath.NewUint(1),
OwnershipTimes: GetFullUintRanges(),
BadgeIds: GetFullUintRanges(),
},
})
}


// Adjust these values to test more or less
const NUM_RUNS = 1
const NUM_IDS = 10
Expand Down Expand Up @@ -413,6 +444,9 @@ func (suite *TestSuite) TestBalancesFuzz() {
}
}




/* --------------------------------------START TESTING WITH TIMES-------------------------------------- */
//Previously, everything was just FullUintRanges() for times

Expand Down Expand Up @@ -546,3 +580,4 @@ func (suite *TestSuite) TestBalancesWithTimesFuzz() {
}
}
}

11 changes: 9 additions & 2 deletions x/protocols/client/cli/tx_create_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@ var _ = strconv.Itoa(0)

func CmdCreateProtocol() *cobra.Command {
cmd := &cobra.Command{
Use: "create-protocol [name] [uri] [customData]",
Use: "create-protocol [name] [uri] [customData] [isFrozen]",
Short: "Broadcast message createProtocol",
Args: cobra.ExactArgs(3),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

//parse args[3] to bool
isFrozen := false
if args[3] == "true" {
isFrozen = true
}

msg := types.NewMsgCreateProtocol(
clientCtx.GetFromAddress().String(),
args[0],
args[1],
args[2],
isFrozen,
)
if err := msg.ValidateBasic(); err != nil {
return err
Expand Down
10 changes: 8 additions & 2 deletions x/protocols/client/cli/tx_update_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@ var _ = strconv.Itoa(0)

func CmdUpdateProtocol() *cobra.Command {
cmd := &cobra.Command{
Use: "update-protocol [name] [uri] [customData]",
Use: "update-protocol [name] [uri] [customData] [isFrozen]",
Short: "Broadcast message updateProtocol",
Args: cobra.ExactArgs(3),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

isFrozen := false
if args[3] == "true" {
isFrozen = true
}

msg := types.NewMsgUpdateProtocol(
clientCtx.GetFromAddress().String(),
args[0],
args[1],
args[2],
isFrozen,
)
if err := msg.ValidateBasic(); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions x/protocols/keeper/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ var (
ErrProtocolExists = sdkerrors.Register(types.ModuleName, 1, "protocol already exists")
ErrProtocolDoesNotExist = sdkerrors.Register(types.ModuleName, 2, "protocol does not exist")
ErrNotProtocolCreator = sdkerrors.Register(types.ModuleName, 3, "not protocol creator")
ErrProtocolIsFrozen = sdkerrors.Register(types.ModuleName, 4, "protocol is frozen")
)
1 change: 1 addition & 0 deletions x/protocols/keeper/msg_server_create_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (k msgServer) CreateProtocol(goCtx context.Context, msg *types.MsgCreatePro
Uri: msg.Uri,
CustomData: msg.CustomData,
CreatedBy: msg.Creator,
IsFrozen: msg.IsFrozen,
}

//Check if protocol already exists
Expand Down
5 changes: 5 additions & 0 deletions x/protocols/keeper/msg_server_update_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ func (k msgServer) UpdateProtocol(goCtx context.Context, msg *types.MsgUpdatePro
return nil, sdkerrors.Wrap(ErrNotProtocolCreator, "Not protocol creator")
}

if currProtocol.IsFrozen {
return nil, sdkerrors.Wrap(ErrProtocolIsFrozen, "Protocol is frozen")
}

newProtocol := types.Protocol{
Name: msg.Name,
Uri: msg.Uri,
CustomData: msg.CustomData,
CreatedBy: msg.Creator,
IsFrozen: msg.IsFrozen,
}

//Update protocol in store
Expand Down
3 changes: 2 additions & 1 deletion x/protocols/types/message_create_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ const TypeMsgCreateProtocol = "create_protocol"

var _ sdk.Msg = &MsgCreateProtocol{}

func NewMsgCreateProtocol(creator string, name string, uri string, customData string) *MsgCreateProtocol {
func NewMsgCreateProtocol(creator string, name string, uri string, customData string, isFrozen bool) *MsgCreateProtocol {
return &MsgCreateProtocol{
Creator: creator,
Name: name,
Uri: uri,
CustomData: customData,
IsFrozen: isFrozen,
}
}

Expand Down
3 changes: 2 additions & 1 deletion x/protocols/types/message_update_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ const TypeMsgUpdateProtocol = "update_protocol"

var _ sdk.Msg = &MsgUpdateProtocol{}

func NewMsgUpdateProtocol(creator string, name string, uri string, customData string) *MsgUpdateProtocol {
func NewMsgUpdateProtocol(creator string, name string, uri string, customData string, isFrozen bool) *MsgUpdateProtocol {
return &MsgUpdateProtocol{
Creator: creator,
Name: name,
Uri: uri,
CustomData: customData,
IsFrozen: isFrozen,
}
}

Expand Down
Loading

0 comments on commit a55ef5f

Please sign in to comment.