-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement fswap module's genesis and params (#1339)
* feat: implement genesis related functions Signed-off-by: 170210 <[email protected]> * chore: use mockgen Signed-off-by: 170210 <[email protected]> * chore: add tests Signed-off-by: 170210 <[email protected]> * fix: add subspace in paramsKeeper Signed-off-by: 170210 <[email protected]> * fix: fix lint Signed-off-by: 170210 <[email protected]> * fix: fix for test errors Signed-off-by: 170210 <[email protected]> * fix: fix lint Signed-off-by: 170210 <[email protected]> * fix: fix appmodulebasic Signed-off-by: 170210 <[email protected]> * chore: update CHANGLOG.md Signed-off-by: 170210 <[email protected]> * fix: use configuration instead of params Signed-off-by: 170210 <[email protected]> * chore: refactor new&default fswapped Signed-off-by: 170210 <[email protected]> * fix: add total_supply into genesisStatus & remove calculate logic Signed-off-by: 170210 <[email protected]> * fix: fix lint Signed-off-by: 170210 <[email protected]> * fix: fix module_simulation Signed-off-by: 170210 <[email protected]> * fix: set swappableNewCoinDenom as params Signed-off-by: 170210 <[email protected]> * fix: change total_supply name to swappableNewCoinAmount Signed-off-by: 170210 <[email protected]> * fix: fix lint Signed-off-by: 170210 <[email protected]> * fix: use io/collection to generate key Signed-off-by: 170210 <[email protected]> * Revert "fix: use io/collection to generate key" This reverts commit e42e064. * fix: change sdk.Coin to sdk.Int Signed-off-by: 170210 <[email protected]> * fix: fix lint Signed-off-by: 170210 <[email protected]> * fix: remote unnecessary codes Signed-off-by: 170210 <[email protected]> * fix: add validate for swappable new coin Signed-off-by: 170210 <[email protected]> * fix: add randomizedGenState Signed-off-by: 170210 <[email protected]> * fix: fix error doc Signed-off-by: 170210 <[email protected]> * fix: fix lint Signed-off-by: 170210 <[email protected]> * fix: change proto message fields' name Signed-off-by: 170210 <[email protected]> --------- Signed-off-by: 170210 <[email protected]>
- Loading branch information
Showing
38 changed files
with
863 additions
and
269 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
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,30 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/Finschia/finschia-sdk/types" | ||
"github.com/Finschia/finschia-sdk/x/fswap/types" | ||
) | ||
|
||
// GetSwapped get all parameters as types.Swapped | ||
func (k Keeper) GetSwapped(ctx sdk.Context) types.Swapped { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get([]byte{types.SwappedKey}) | ||
var swapped types.Swapped | ||
|
||
if bz == nil { | ||
panic(types.ErrSwappedNotFound) | ||
} | ||
k.cdc.MustUnmarshal(bz, &swapped) | ||
return swapped | ||
} | ||
|
||
// SetSwapped set the types.Swapped | ||
func (k Keeper) SetSwapped(ctx sdk.Context, swapped types.Swapped) error { | ||
store := ctx.KVStore(k.storeKey) | ||
bz, err := k.cdc.Marshal(&swapped) | ||
if err != nil { | ||
return err | ||
} | ||
store.Set([]byte{types.SwappedKey}, bz) | ||
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,25 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/Finschia/finschia-sdk/types" | ||
"github.com/Finschia/finschia-sdk/x/fswap/types" | ||
) | ||
|
||
// InitGenesis initializes the module's state from a provided genesis | ||
// state. | ||
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { | ||
if err := k.SetParams(ctx, genState.Params); err != nil { | ||
panic(err) | ||
} | ||
if err := k.SetSwapped(ctx, genState.Swapped); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// ExportGenesis returns the capability module's exported genesis. | ||
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
return &types.GenesisState{ | ||
Params: k.GetParams(ctx), | ||
Swapped: k.GetSwapped(ctx), | ||
} | ||
} |
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_test | ||
|
||
import ( | ||
"github.com/Finschia/finschia-sdk/x/fswap/types" | ||
) | ||
|
||
func (s *KeeperTestSuite) TestInitAndExportGenesis() { | ||
s.keeper.InitGenesis(s.sdkCtx, *types.DefaultGenesis()) | ||
got := s.keeper.ExportGenesis(s.sdkCtx) | ||
s.Require().NotNil(got) | ||
s.Require().Equal(types.DefaultParams(), got.Params) | ||
s.Require().Equal(types.DefaultSwapped(), got.Swapped) | ||
} |
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 keeper_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/suite" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
||
"github.com/Finschia/finschia-sdk/simapp" | ||
sdk "github.com/Finschia/finschia-sdk/types" | ||
"github.com/Finschia/finschia-sdk/x/fswap/keeper" | ||
"github.com/Finschia/finschia-sdk/x/fswap/testutil" | ||
"github.com/Finschia/finschia-sdk/x/fswap/types" | ||
) | ||
|
||
type KeeperTestSuite struct { | ||
suite.Suite | ||
sdkCtx sdk.Context | ||
goCtx context.Context | ||
keeper keeper.Keeper | ||
bankKeeper types.BankKeeper | ||
|
||
msgServer types.MsgServer | ||
} | ||
|
||
func TestKeeperTestSuite(t *testing.T) { | ||
suite.Run(t, new(KeeperTestSuite)) | ||
} | ||
|
||
func (s *KeeperTestSuite) SetupTest() { | ||
ctrl := gomock.NewController(s.T()) | ||
bankKeeper := testutil.NewMockBankKeeper(ctrl) | ||
s.bankKeeper = bankKeeper | ||
checkTx := false | ||
app := simapp.Setup(checkTx) | ||
s.sdkCtx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) | ||
s.goCtx = sdk.WrapSDKContext(s.sdkCtx) | ||
s.keeper = app.FswapKeeper | ||
|
||
s.msgServer = keeper.NewMsgServerImpl(s.keeper) | ||
} |
Oops, something went wrong.