-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test on LiquidityRatioFromPriceDepth & resolve message codec…
… registration issue
- Loading branch information
Showing
4 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
x/amm/keeper/msg_server_feed_multiple_external_liquidity_test.go
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 |
---|---|---|
@@ -1 +1,27 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/elys-network/elys/x/amm/keeper" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestLiquidityRatioFromPriceDepth() { | ||
depth := sdk.NewDecWithPrec(1, 2) // 1% | ||
suite.Require().Equal("0.005012562893380046", keeper.LiquidityRatioFromPriceDepth(depth).String()) | ||
depth = sdk.NewDecWithPrec(2, 2) // 2% | ||
suite.Require().Equal("0.010050506338833466", keeper.LiquidityRatioFromPriceDepth(depth).String()) | ||
depth = sdk.NewDecWithPrec(5, 2) // 5% | ||
suite.Require().Equal("0.025320565519103610", keeper.LiquidityRatioFromPriceDepth(depth).String()) | ||
depth = sdk.NewDecWithPrec(10, 2) // 10% | ||
suite.Require().Equal("0.051316701949486201", keeper.LiquidityRatioFromPriceDepth(depth).String()) | ||
depth = sdk.NewDecWithPrec(30, 2) // 30% | ||
suite.Require().Equal("0.163339973465924452", keeper.LiquidityRatioFromPriceDepth(depth).String()) | ||
depth = sdk.NewDecWithPrec(50, 2) // 50% | ||
suite.Require().Equal("0.292893218813452476", keeper.LiquidityRatioFromPriceDepth(depth).String()) | ||
depth = sdk.NewDecWithPrec(70, 2) // 70% | ||
suite.Require().Equal("0.452277442494833887", keeper.LiquidityRatioFromPriceDepth(depth).String()) | ||
depth = sdk.NewDecWithPrec(90, 2) // 90% | ||
suite.Require().Equal("0.683772233983162067", keeper.LiquidityRatioFromPriceDepth(depth).String()) | ||
depth = sdk.NewDecWithPrec(100, 2) // 100% | ||
suite.Require().Equal("1.000000000000000000", keeper.LiquidityRatioFromPriceDepth(depth).String()) | ||
} |
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,45 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const TypeMsgFeedMultipleExternalLiquidity = "feed_multiple_external_liquidity" | ||
|
||
var _ sdk.Msg = &MsgFeedMultipleExternalLiquidity{} | ||
|
||
func NewMsgFeedMultipleExternalLiquidity(sender string) *MsgFeedMultipleExternalLiquidity { | ||
return &MsgFeedMultipleExternalLiquidity{ | ||
Sender: sender, | ||
} | ||
} | ||
|
||
func (msg *MsgFeedMultipleExternalLiquidity) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgFeedMultipleExternalLiquidity) Type() string { | ||
return TypeMsgSwapExactAmountOut | ||
} | ||
|
||
func (msg *MsgFeedMultipleExternalLiquidity) GetSigners() []sdk.AccAddress { | ||
sender, err := sdk.AccAddressFromBech32(msg.Sender) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{sender} | ||
} | ||
|
||
func (msg *MsgFeedMultipleExternalLiquidity) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgFeedMultipleExternalLiquidity) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Sender) | ||
if err != nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) | ||
} | ||
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