-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: LegacyMsg support * ugov module implementation * lint
- Loading branch information
1 parent
50f2ded
commit 6a6cb90
Showing
13 changed files
with
324 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ugov | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
cdctypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/msgservice" | ||
"github.com/gogo/protobuf/proto" | ||
) | ||
|
||
// Amino codecs | ||
// Note, the ModuleCdc should ONLY be used in certain instances of tests and for JSON | ||
// encoding as Amino is still used for that purpose. | ||
var ( | ||
amino = codec.NewLegacyAmino() | ||
ModuleCdc = codec.NewAminoCodec(amino) | ||
) | ||
|
||
func init() { | ||
cryptocodec.RegisterCrypto(amino) | ||
sdk.RegisterLegacyAminoCodec(amino) | ||
RegisterLegacyAminoCodec(amino) | ||
|
||
amino.Seal() | ||
} | ||
|
||
// RegisterLegacyAminoCodec registers the necessary x/uibc interfaces and | ||
// concrete types on the provided LegacyAmino codec. These types are used for | ||
// Amino JSON serialization. | ||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { | ||
cdc.RegisterConcrete(&MsgGovUpdateMinGasPrice{}, proto.MessageName(&MsgGovUpdateMinGasPrice{}), nil) | ||
} | ||
|
||
func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { | ||
registry.RegisterImplementations( | ||
(*sdk.Msg)(nil), | ||
&MsgGovUpdateMinGasPrice{}, | ||
) | ||
|
||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) | ||
} |
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,16 @@ | ||
package ugov | ||
|
||
import ( | ||
"github.com/umee-network/umee/v4/util/coin" | ||
) | ||
|
||
// DefaultGenesis creates a default genesis state | ||
func DefaultGenesis() *GenesisState { | ||
return &GenesisState{ | ||
MinGasPrice: coin.UmeeDec("0.1"), | ||
} | ||
} | ||
|
||
func (gs *GenesisState) Validate() error { | ||
return gs.MinGasPrice.Validate() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
package ugov | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/umee-network/umee/v4/util/coin" | ||
) | ||
|
||
func TestGenesis(t *testing.T) { | ||
require := require.New(t) | ||
gs := DefaultGenesis() | ||
|
||
require.NoError(gs.Validate(), "default genesis must be correct") | ||
|
||
gs.MinGasPrice = coin.UtokenDec(coin.Dollar, "0.1") | ||
require.NoError(gs.Validate(), "min_gas_price = 0.1dollar is correct") | ||
|
||
gs.MinGasPrice.Amount = sdk.MustNewDecFromStr("-1") | ||
require.Error(gs.Validate(), "negative min_gas_price is NOT correct") | ||
} |
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,13 @@ | ||
package keeper | ||
|
||
import "github.com/umee-network/umee/v4/x/ugov" | ||
|
||
func (k Keeper) ExportGenesis() *ugov.GenesisState { | ||
return &ugov.GenesisState{ | ||
MinGasPrice: k.MinGasPrice(), | ||
} | ||
} | ||
|
||
func (k Keeper) InitGenesis(gs *ugov.GenesisState) error { | ||
return k.SetMinGasPrice(gs.MinGasPrice) | ||
} |
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,22 @@ | ||
package keeper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/umee-network/umee/v4/x/ugov" | ||
) | ||
|
||
func TestGenesis(t *testing.T) { | ||
t.Parallel() | ||
require := require.New(t) | ||
k := initKeeper(t) | ||
|
||
gs := ugov.DefaultGenesis() | ||
err := k.InitGenesis(gs) | ||
require.NoError(err) | ||
|
||
gsOut := k.ExportGenesis() | ||
require.Equal(gs, gsOut) | ||
} |
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
Oops, something went wrong.