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

Function TestKeeper_AddUpExistingMTP

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

Source from the content-addressed store, hash-verified

2007}
2008
2009func TestKeeper_AddUpExistingMTP(t *testing.T) {
2010 nativeAsset := clptypes.NativeSymbol
2011 externalAsset := clptypes.Asset{Symbol: "xxx"}
2012
2013 ctx, app := test.CreateTestAppMargin(false)
2014 marginKeeper := app.MarginKeeper
2015
2016 app.TokenRegistryKeeper.SetToken(ctx, &tokenregistrytypes.RegistryEntry{
2017 Denom: externalAsset.Symbol,
2018 Decimals: 18,
2019 Permissions: []tokenregistrytypes.Permission{tokenregistrytypes.Permission_CLP},
2020 })
2021
2022 msgServer := keeper.NewMsgServerImpl(marginKeeper)
2023
2024 SwapPriceNative := sdk.ZeroDec()
2025 SwapPriceExternal := sdk.ZeroDec()
2026
2027 pool := clptypes.Pool{
2028 ExternalAsset: &externalAsset,
2029 NativeAssetBalance: sdk.NewUintFromString("10000000000000000000000000"),
2030 ExternalAssetBalance: sdk.NewUintFromString("10000000000000000000000000"),
2031 NativeCustody: sdk.ZeroUint(),
2032 ExternalCustody: sdk.ZeroUint(),
2033 NativeLiabilities: sdk.ZeroUint(),
2034 ExternalLiabilities: sdk.ZeroUint(),
2035 PoolUnits: sdk.ZeroUint(),
2036 Health: sdk.OneDec(),
2037 InterestRate: sdk.NewDecWithPrec(1, 1),
2038 SwapPriceNative: &SwapPriceNative,
2039 SwapPriceExternal: &SwapPriceExternal,
2040 RewardPeriodNativeDistributed: sdk.ZeroUint(),
2041 }
2042
2043 marginKeeper.SetEnabledPools(ctx, []string{externalAsset.Symbol})
2044 // nolint:errcheck
2045 marginKeeper.ClpKeeper().SetPool(ctx, &pool)
2046
2047 nativeCoin := sdk.NewCoin(nativeAsset, sdk.Int(pool.NativeAssetBalance))
2048 externalCoin := sdk.NewCoin(externalAsset.Symbol, sdk.Int(pool.ExternalAssetBalance))
2049 err := app.BankKeeper.MintCoins(ctx, clptypes.ModuleName, sdk.NewCoins(nativeCoin, externalCoin))
2050 require.Nil(t, err)
2051
2052 signer := clptest.GenerateAddress(clptest.AddressKey1)
2053 nativeCoin = sdk.NewCoin(nativeAsset, sdk.Int(sdk.NewUintFromString("100000000000000000000000")))
2054 externalCoin = sdk.NewCoin(externalAsset.Symbol, sdk.Int(sdk.NewUintFromString("100000000000000000000000")))
2055 err = sifapp.AddCoinsToAccount(types.ModuleName, app.BankKeeper, ctx, signer, sdk.NewCoins(nativeCoin, externalCoin))
2056 require.Nil(t, err)
2057
2058 msg1 := types.MsgOpen{
2059 Signer: signer.String(),
2060 CollateralAsset: externalAsset.Symbol,
2061 CollateralAmount: sdk.NewUintFromString("1000000000000000000000"),
2062 BorrowAsset: nativeAsset,
2063 Position: types.Position_LONG,
2064 Leverage: sdk.NewDec(2),
2065 }
2066

Callers

nothing calls this directly

Calls 12

CreateTestAppMarginFunction · 0.92
NewMsgServerImplFunction · 0.92
SetTokenMethod · 0.65
SetEnabledPoolsMethod · 0.65
SetPoolMethod · 0.65
ClpKeeperMethod · 0.65
MintCoinsMethod · 0.65
WhitelistAddressMethod · 0.65
OpenMethod · 0.65
GetMTPMethod · 0.65
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected