forked from lavanet/lava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
663 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdkerrors "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/lavanet/lava/x/protocol/types" | ||
) | ||
|
||
func (k msgServer) SetVersion(goCtx context.Context, msg *types.MsgSetVersion) (*types.MsgSetVersionResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
if msg.Authority != k.authority { | ||
sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority) | ||
} | ||
|
||
params := k.GetParams(ctx) | ||
params.Version = *msg.Version | ||
if err := params.Validate(); err != nil { | ||
return &types.MsgSetVersionResponse{}, err | ||
} | ||
|
||
k.SetParams(ctx, params) | ||
|
||
return &types.MsgSetVersionResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package types | ||
|
||
import ( | ||
sdkerrors "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
const TypeMsgSetVersion = "set_version" | ||
|
||
var _ sdk.Msg = &MsgSetVersion{} | ||
|
||
func NewMsgSetVersion(authority string, version Version) *MsgSetVersion { | ||
return &MsgSetVersion{ | ||
Authority: authority, | ||
Version: &version, | ||
} | ||
} | ||
|
||
func (msg *MsgSetVersion) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgSetVersion) Type() string { | ||
return TypeMsgSetVersion | ||
} | ||
|
||
func (msg *MsgSetVersion) GetSigners() []sdk.AccAddress { | ||
authority, _ := sdk.AccAddressFromBech32(msg.Authority) | ||
return []sdk.AccAddress{authority} | ||
} | ||
|
||
func (msg *MsgSetVersion) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgSetVersion) ValidateBasic() error { | ||
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { | ||
return sdkerrors.Wrap(err, "invalid authority address") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/lavanet/lava/testutil/sample" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSetIprpcData_ValidateBasic(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
msg MsgSetVersion | ||
valid bool | ||
}{ | ||
{ | ||
name: "invalid authority address", | ||
msg: MsgSetVersion{ | ||
Authority: "invalid_address", | ||
}, | ||
valid: false, | ||
}, | ||
{ | ||
name: "invalid subscription address", | ||
msg: MsgSetVersion{ | ||
Authority: sample.AccAddress(), | ||
}, | ||
valid: false, | ||
}, | ||
{ | ||
name: "valid message", | ||
msg: MsgSetVersion{ | ||
Authority: sample.AccAddress(), | ||
}, | ||
valid: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := tt.msg.ValidateBasic() | ||
if tt.valid { | ||
require.NoError(t, err) | ||
return | ||
} | ||
require.Error(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.