MCPcopy Create free account
hub / github.com/Sifchain/sifnode / TestKeeper_OpenClose

Function TestKeeper_OpenClose

x/margin/keeper/msg_server_test.go:820–1054  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

818}
819
820func TestKeeper_OpenClose(t *testing.T) {
821 table := []struct {
822 name string
823 externalAsset string
824 err error
825 errString error
826 }{
827 {
828 name: "one round open/close long position",
829 externalAsset: "xxx",
830 // errString: errors.New("pool health too low to open new positions: margin not enabled for pool"),
831 // errString: errors.New("rowan: using rowan as collateral asset is not allowed"),
832 },
833 }
834
835 for _, tt := range table {
836 tt := tt
837 t.Run(tt.name, func(t *testing.T) {
838 ctx, app := test.CreateTestAppMargin(false)
839 marginKeeper := app.MarginKeeper
840
841 app.ClpKeeper.SetSwapFeeParams(ctx, clptypes.GetDefaultSwapFeeParams())
842
843 app.TokenRegistryKeeper.SetToken(ctx, &tokenregistrytypes.RegistryEntry{
844 Denom: tt.externalAsset,
845 Decimals: 18,
846 Permissions: []tokenregistrytypes.Permission{tokenregistrytypes.Permission_CLP},
847 })
848
849 params := types.Params{
850 LeverageMax: sdk.NewDec(2),
851 InterestRateMax: sdk.NewDec(1),
852 InterestRateMin: sdk.NewDecWithPrec(1, 1),
853 InterestRateIncrease: sdk.NewDecWithPrec(1, 1),
854 InterestRateDecrease: sdk.NewDecWithPrec(1, 1),
855 HealthGainFactor: sdk.NewDecWithPrec(1, 2),
856 EpochLength: 0,
857 RemovalQueueThreshold: sdk.ZeroDec(),
858 ForceCloseFundPercentage: sdk.NewDecWithPrec(1, 1),
859 ForceCloseFundAddress: "sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd",
860 IncrementalInterestPaymentFundPercentage: sdk.NewDecWithPrec(1, 1),
861 IncrementalInterestPaymentFundAddress: "sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd",
862 IncrementalInterestPaymentEnabled: false,
863 PoolOpenThreshold: sdk.NewDecWithPrec(1, 1),
864 MaxOpenPositions: 10000,
865 SqModifier: sdk.MustNewDecFromStr("10000000000000000000000000"),
866 SafetyFactor: sdk.MustNewDecFromStr("1.05"),
867 Pools: []string{tt.externalAsset},
868 RowanCollateralEnabled: true,
869 }
870 expectedGenesis := types.GenesisState{Params: &params}
871 marginKeeper.InitGenesis(ctx, expectedGenesis)
872 genesis := marginKeeper.ExportGenesis(ctx)
873 require.Equal(t, expectedGenesis, *genesis)
874
875 msgServer := keeper.NewMsgServerImpl(marginKeeper)
876
877 nativeAsset := clptypes.NativeSymbol

Callers

nothing calls this directly

Calls 15

CreateTestAppMarginFunction · 0.92
NewMsgServerImplFunction · 0.92
SetSwapFeeParamsMethod · 0.80
SetTokenMethod · 0.65
InitGenesisMethod · 0.65
ExportGenesisMethod · 0.65
SetEnabledPoolsMethod · 0.65
SetPoolMethod · 0.65
ClpKeeperMethod · 0.65
MintCoinsMethod · 0.65
GetModuleAccountMethod · 0.65
HasBalanceMethod · 0.65

Tested by

no test coverage detected