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: implement fswap module's genesis and params #1339

Merged
merged 27 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c5d92f9
feat: implement genesis related functions
170210 Apr 18, 2024
7063c9b
chore: use mockgen
170210 Apr 19, 2024
27b9b2a
chore: add tests
170210 Apr 19, 2024
3afadd4
fix: add subspace in paramsKeeper
170210 Apr 19, 2024
31d3829
fix: fix lint
170210 Apr 19, 2024
f63ce4d
fix: fix for test errors
170210 Apr 19, 2024
6d59aa8
fix: fix lint
170210 Apr 19, 2024
96da1de
fix: fix appmodulebasic
170210 Apr 19, 2024
065f4f2
chore: update CHANGLOG.md
170210 Apr 19, 2024
0423ac7
fix: use configuration instead of params
170210 Apr 23, 2024
8fcbab8
chore: refactor new&default fswapped
170210 Apr 23, 2024
c91259f
fix: add total_supply into genesisStatus & remove calculate logic
170210 Apr 23, 2024
d6f2ce9
fix: fix lint
170210 Apr 23, 2024
d0f4841
fix: fix module_simulation
170210 Apr 23, 2024
3cd7acb
fix: set swappableNewCoinDenom as params
170210 Apr 24, 2024
c2a9b61
fix: change total_supply name to swappableNewCoinAmount
170210 Apr 24, 2024
f0be4eb
fix: fix lint
170210 Apr 24, 2024
e42e064
fix: use io/collection to generate key
170210 Apr 24, 2024
09562a4
Revert "fix: use io/collection to generate key"
170210 Apr 24, 2024
688d489
fix: change sdk.Coin to sdk.Int
170210 Apr 24, 2024
a9ca68f
fix: fix lint
170210 Apr 24, 2024
722e95b
fix: remote unnecessary codes
170210 Apr 24, 2024
160f953
fix: add validate for swappable new coin
170210 Apr 24, 2024
eff7746
fix: add randomizedGenState
170210 Apr 24, 2024
bd076f9
fix: fix error doc
170210 Apr 24, 2024
61f09fa
fix: fix lint
170210 Apr 24, 2024
9d583c3
fix: change proto message fields' name
170210 Apr 24, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features
* (consensus) [\#1178](https://github.com/Finschia/finschia-sdk/pull/1178) change the consensus from Ostracon to Tendermint v0.34.24
* (x/fswap) [\#1336](https://github.com/Finschia/finschia-sdk/pull/1336) Initialize fswap module
* (x/fswap) [\#1339](https://github.com/Finschia/finschia-sdk/pull/1339) Implement fswap module's genesis

### Improvements
* (docs) [\#1120](https://github.com/Finschia/finschia-sdk/pull/1120) Update links in x/foundation README.md
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ mocks: $(MOCKS_DIR)
mockgen -package mocks -destination tests/mocks/grpc_server.go github.com/gogo/protobuf/grpc Server
mockgen -package mocks -destination tests/mocks/tendermint_tendermint_libs_log_DB.go github.com/tendermint/tendermint/libs/log Logger
mockgen -source=x/stakingplus/expected_keepers.go -package testutil -destination x/stakingplus/testutil/expected_keepers_mocks.go
mockgen -source=x/fswap/types/expected_keepers.go -package testutil -destination x/fswap/testutil/expected_keepers_mocks.go
.PHONY: mocks

$(MOCKS_DIR):
Expand Down
36 changes: 1 addition & 35 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,6 @@
- [lbm/fswap/v1/fswap.proto](#lbm/fswap/v1/fswap.proto)
- [Swapped](#lbm.fswap.v1.Swapped)

- [lbm/fswap/v1/params.proto](#lbm/fswap/v1/params.proto)
- [Params](#lbm.fswap.v1.Params)

- [lbm/fswap/v1/genesis.proto](#lbm/fswap/v1/genesis.proto)
- [GenesisState](#lbm.fswap.v1.GenesisState)

Expand Down Expand Up @@ -12766,37 +12763,6 @@ Msg defines the foundation Msg service.



<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="lbm/fswap/v1/params.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## lbm/fswap/v1/params.proto



<a name="lbm.fswap.v1.Params"></a>

### Params
Params defines the parameters for the module.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `new_coin_denom` | [string](#string) | | new denomination for new coin after swap |





<!-- end messages -->

<!-- end enums -->
Expand All @@ -12822,8 +12788,8 @@ GenesisState defines the fswap module's genesis state.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#lbm.fswap.v1.Params) | | |
| `swapped` | [Swapped](#lbm.fswap.v1.Swapped) | | |
| `swappable_new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |



Expand Down
2 changes: 1 addition & 1 deletion proto/lbm/fswap/v1/fswap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

message Swapped{
message Swapped {
cosmos.base.v1beta1.Coin old_coin_amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
cosmos.base.v1beta1.Coin new_coin_amount = 2
Expand Down
7 changes: 4 additions & 3 deletions proto/lbm/fswap/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ package lbm.fswap.v1;
option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types";

import "gogoproto/gogo.proto";
import "lbm/fswap/v1/params.proto";
import "lbm/fswap/v1/fswap.proto";
import "cosmos/base/v1beta1/coin.proto";

// GenesisState defines the fswap module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
Swapped swapped =2 [(gogoproto.nullable) = false];
Swapped swapped = 1 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin swappable_new_coin_amount = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
13 changes: 0 additions & 13 deletions proto/lbm/fswap/v1/params.proto

This file was deleted.

14 changes: 14 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ import (
foundationclient "github.com/Finschia/finschia-sdk/x/foundation/client"
foundationkeeper "github.com/Finschia/finschia-sdk/x/foundation/keeper"
foundationmodule "github.com/Finschia/finschia-sdk/x/foundation/module"
"github.com/Finschia/finschia-sdk/x/fswap"
fswapkeeper "github.com/Finschia/finschia-sdk/x/fswap/keeper"
fswaptypes "github.com/Finschia/finschia-sdk/x/fswap/types"
"github.com/Finschia/finschia-sdk/x/genutil"
genutiltypes "github.com/Finschia/finschia-sdk/x/genutil/types"
"github.com/Finschia/finschia-sdk/x/gov"
Expand Down Expand Up @@ -138,6 +141,7 @@ var (
vesting.AppModuleBasic{},
tokenmodule.AppModuleBasic{},
collectionmodule.AppModuleBasic{},
fswap.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -197,6 +201,7 @@ type SimApp struct {
ClassKeeper classkeeper.Keeper
TokenKeeper tokenkeeper.Keeper
CollectionKeeper collectionkeeper.Keeper
FswapKeeper fswapkeeper.Keeper

// the module manager
mm *module.Manager
Expand Down Expand Up @@ -250,6 +255,7 @@ func NewSimApp(
token.StoreKey,
collection.StoreKey,
authzkeeper.StoreKey,
fswaptypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
// NOTE: The testingkey is just mounted for testing purposes. Actual applications should
Expand Down Expand Up @@ -352,6 +358,10 @@ func NewSimApp(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

/**** Phase 1 ****/
fswapConfig := fswaptypes.DefaultConfig()
app.FswapKeeper = fswapkeeper.NewKeeper(appCodec, keys[fswaptypes.StoreKey], app.AccountKeeper, app.BankKeeper, fswapConfig)

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down Expand Up @@ -383,6 +393,7 @@ func NewSimApp(
tokenmodule.NewAppModule(appCodec, app.TokenKeeper),
collectionmodule.NewAppModule(appCodec, app.CollectionKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
fswap.NewAppModule(appCodec, app.FswapKeeper, app.AccountKeeper, app.BankKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -410,6 +421,7 @@ func NewSimApp(
vestingtypes.ModuleName,
token.ModuleName,
collection.ModuleName,
fswaptypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName,
Expand All @@ -431,6 +443,7 @@ func NewSimApp(
foundation.ModuleName,
token.ModuleName,
collection.ModuleName,
fswaptypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -458,6 +471,7 @@ func NewSimApp(
vestingtypes.ModuleName,
token.ModuleName,
collection.ModuleName,
fswaptypes.ModuleName,
)

// Uncomment if you want to set a custom migration order here.
Expand Down
3 changes: 2 additions & 1 deletion x/ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@

|Error Name|Codespace|Code|Description|
|:-|:-|:-|:-|
|ErrSample|fswap|1100|sample error|
|ErrSwappedNotFound|fswap|1100|swapped does not exist|
|ErrTotalSupplyNotFound|fswap|1101|swappable new coin amount does not exist|

>You can also find detailed information in the following Errors.go files:
* [fswap/types/errors.go](fswap/types/errors.go)
Expand Down
24 changes: 0 additions & 24 deletions x/fswap/genesis.go

This file was deleted.

1 change: 0 additions & 1 deletion x/fswap/genesis_test.go

This file was deleted.

51 changes: 51 additions & 0 deletions x/fswap/keeper/fswap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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)

Check warning on line 15 in x/fswap/keeper/fswap.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/fswap.go#L15

Added line #L15 was not covered by tests
}
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

Check warning on line 26 in x/fswap/keeper/fswap.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/fswap.go#L26

Added line #L26 was not covered by tests
}
store.Set([]byte{types.SwappedKey}, bz)
return nil
}

func (k Keeper) GetTotalSupply(ctx sdk.Context) sdk.Coin {
store := ctx.KVStore(k.storeKey)
170210 marked this conversation as resolved.
Show resolved Hide resolved
bz := store.Get([]byte{types.SwappableNewCoinAmountKey})
var totalSupply sdk.Coin
if bz == nil {
panic(types.ErrTotalSupplyNotFound)

Check warning on line 37 in x/fswap/keeper/fswap.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/fswap.go#L37

Added line #L37 was not covered by tests
}
k.cdc.MustUnmarshal(bz, &totalSupply)
return totalSupply
}

func (k Keeper) SetTotalSupply(ctx sdk.Context, totalSupply sdk.Coin) error {
store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(&totalSupply)
if err != nil {
return err

Check warning on line 47 in x/fswap/keeper/fswap.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/fswap.go#L47

Added line #L47 was not covered by tests
}
store.Set([]byte{types.SwappableNewCoinAmountKey}, bz)
return nil
}
25 changes: 25 additions & 0 deletions x/fswap/keeper/genesis.go
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.SetSwapped(ctx, genState.Swapped); err != nil {
panic(err)

Check warning on line 12 in x/fswap/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/genesis.go#L12

Added line #L12 was not covered by tests
}
if err := k.SetTotalSupply(ctx, genState.SwappableNewCoinAmount); err != nil {
panic(err)

Check warning on line 15 in x/fswap/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/genesis.go#L15

Added line #L15 was not covered by tests
}
}

// ExportGenesis returns the capability module's exported genesis.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return &types.GenesisState{
Swapped: k.GetSwapped(ctx),
SwappableNewCoinAmount: k.GetTotalSupply(ctx),
}
}
13 changes: 13 additions & 0 deletions x/fswap/keeper/genesis_test.go
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.DefaultSwapped(), got.Swapped)
s.Require().Equal(types.DefaultTotalSupply, got.SwappableNewCoinAmount)
}
9 changes: 6 additions & 3 deletions x/fswap/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@ import (
type (
Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
storeKey storetypes.StoreKey
config types.Config
}
)

func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
ak types.AccountKeeper,
bk types.BankKeeper,
storeKey storetypes.StoreKey,
config types.Config,
) Keeper {
return Keeper{
cdc: cdc,
storeKey: storeKey,
accountKeeper: ak,
bankKeeper: bk,
storeKey: storeKey,
config: config,
}
}

Expand Down
43 changes: 43 additions & 0 deletions x/fswap/keeper/keeper_test.go
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)
}
Loading
Loading