-
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: wip, done(keeper, query, msg_server)
- Loading branch information
1 parent
fd4945a
commit f74fa62
Showing
31 changed files
with
875 additions
and
316 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package config | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/Finschia/finschia-sdk/types" | ||
) | ||
|
||
type FswapConfig interface { | ||
OldDenom() string | ||
NewDenom() string | ||
SwapCap() types.Int | ||
SwapMultiple() types.Int | ||
} | ||
|
||
func DefaultConfig() *Config { | ||
oldDenom := "cony" | ||
newDenom := "peb" | ||
defaultCap, _ := big.NewInt(0).SetString("1151185567094084523856000000", 10) | ||
swapCap := types.NewIntFromBigInt(defaultCap) | ||
num, _ := big.NewInt(0).SetString("148079656000000", 10) | ||
swapMultiple := types.NewIntFromBigInt(num) | ||
|
||
return &Config{ | ||
oldDenom, | ||
newDenom, | ||
swapCap, | ||
swapMultiple, | ||
} | ||
} | ||
|
||
type Config struct { | ||
oldDenom string | ||
newDenom string | ||
swapCap types.Int | ||
swapMultiple types.Int | ||
} | ||
|
||
func (c Config) OldDenom() string { | ||
return c.oldDenom | ||
} | ||
|
||
func (c Config) NewDenom() string { | ||
return c.newDenom | ||
} | ||
|
||
func (c Config) SwapCap() types.Int { | ||
return c.swapCap | ||
} | ||
|
||
func (c Config) SwapMultiple() types.Int { | ||
return c.swapMultiple | ||
} |
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,33 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/Finschia/finschia-sdk/types" | ||
"github.com/Finschia/finschia-sdk/x/fswap/types" | ||
) | ||
|
||
// InitGenesis initializes the module's state accWithOldCoin 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 { | ||
params, err := k.GetParams(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
swapped, err := k.GetSwapped(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return &types.GenesisState{ | ||
Params: params, | ||
Swapped: 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
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.ctx, *types.DefaultGenesis()) | ||
got := s.keeper.ExportGenesis(s.ctx) | ||
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 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,53 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/Finschia/finschia-sdk/types" | ||
"github.com/Finschia/finschia-sdk/x/fswap/types" | ||
) | ||
|
||
func (s *KeeperTestSuite) TestQuerySwap() { | ||
testCases := map[string]struct { | ||
swapReq *types.MsgSwapRequest | ||
expectedBalanceWithoutMultiply sdk.Int | ||
}{ | ||
"valid request": { | ||
&types.MsgSwapRequest{ | ||
s.accWithOldCoin.String(), | ||
sdk.NewCoin(s.keeper.OldDenom(), sdk.NewInt(100)), | ||
}, | ||
sdk.NewInt(100), | ||
}, | ||
} | ||
for name, tc := range testCases { | ||
s.Run(name, func() { | ||
s.Require().NoError(tc.swapReq.ValidateBasic()) | ||
ctx, _ := s.ctx.CacheContext() | ||
res, err := s.msgServer.Swap(sdk.WrapSDKContext(ctx), tc.swapReq) | ||
s.Require().NoError(err) | ||
s.Require().NotNil(res) | ||
swapped, err := s.queryServer.Swapped(sdk.WrapSDKContext(ctx), &types.QuerySwappedRequest{}) | ||
s.Require().NoError(err) | ||
|
||
expectedOldAmount := tc.expectedBalanceWithoutMultiply | ||
expectedNewAmount := tc.expectedBalanceWithoutMultiply.Mul(s.keeper.SwapMultiple()) | ||
actualOldCoinAmount := swapped.GetSwapped().OldCoinAmount | ||
actualNewCoinAmount := swapped.GetSwapped().NewCoinAmount | ||
s.Require().Equal(expectedOldAmount, actualOldCoinAmount) | ||
s.Require().Equal(expectedNewAmount, actualNewCoinAmount) | ||
}) | ||
} | ||
} | ||
|
||
func (s *KeeperTestSuite) TestQueryTotalNewCurrencySwapLimit() { | ||
// TODO: Need to confirm, it may not necessary | ||
// Can be calculated by query Params.SwappableNewCoinAmount and query Swapped.NewCoinAmount | ||
|
||
// SwappableNewCoinAmount << as param and after first set it'll become constant value | ||
// Why user want to know constant?? use may want to remaining swappable balance. | ||
|
||
//ctx, _ := s.ctx.CacheContext() | ||
//res, err := s.queryServer.TotalNewCurrencySwapLimit(sdk.WrapSDKContext(ctx), &types.QueryTotalSwappableAmountRequest{}) | ||
//s.Require().NoError(err) | ||
//expectedLimit := sdk.NewCoin(s.keeper.NewDenom(), s.keeper.SwapCap()) | ||
//s.Require().Equal(expectedLimit, res.SwappableNewCoinAmount) | ||
} |
Oops, something went wrong.