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

test(perp): liquidate and add margin + test update cli tests #555

Closed
kai0x opened this issue Jun 9, 2022 · 4 comments · Fixed by #989
Closed

test(perp): liquidate and add margin + test update cli tests #555

kai0x opened this issue Jun 9, 2022 · 4 comments · Fixed by #989
Assignees

Comments

@kai0x
Copy link
Contributor

kai0x commented Jun 9, 2022

/*
func (s *IntegrationTestSuite) TestLiquidate() {
	// Set up the user accounts
	val := s.network.Validators[0]
	pair := common.TestStablePool

	_, err := utils.FillWalletFromValidator(s.users[0],
		sdk.NewCoins(
			sdk.NewInt64Coin(s.cfg.BondDenom, 10_000),
			sdk.NewInt64Coin(common.GovDenom, 50_000_000),
			sdk.NewInt64Coin(common.CollDenom, 50_000_000),
			sdk.NewInt64Coin(common.TestTokenDenom, 50_000_000),
			sdk.NewInt64Coin(common.StableDenom, 50_000_000),
		),
		val,
		s.cfg.BondDenom,
	)
	s.Require().NoError(err)

	_, err = utils.FillWalletFromValidator(s.users[1],
		sdk.NewCoins(
			sdk.NewInt64Coin(s.cfg.BondDenom, 10_000),
			sdk.NewInt64Coin(common.GovDenom, 50_000_000),
			sdk.NewInt64Coin(common.CollDenom, 50_000_000),
			sdk.NewInt64Coin(common.TestTokenDenom, 50_000_000),
			sdk.NewInt64Coin(common.StableDenom, 50_000_000),
		),
		val,
		s.cfg.BondDenom,
	)
	s.Require().NoError(err)

	// Check status: vpool reserve assets, balances, positions
	s.checkStatus(val, pair, s.users)

	// Open a position with first user
	s.T().Log("opening a position with user 1....")
	args := []string{
		"--from",
		s.users[0].String(),
		"buy",
		pair.String(),
		"10", // Leverage
		"1",  // Quote asset amount
		"0.0000001",
	}
	commonArgs := []string{
		fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
		fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
		fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10))).String()),
	}

	_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cli.OpenPositionCmd(), append(args, commonArgs...))
	if err != nil {
		s.T().Logf("user1 open position err: %+v", err)
	}
	s.Require().NoError(err)

	// Liquidate on user 1 to trigger bad debt
	// TODO: not working on triggering bad debt
	// TODO: error doesn't bubble up here so if a liquidation fails there is no "err" or way to know
	s.T().Log("liquidating on user 1....")
	args = []string{
		"--from",
		s.users[0].String(),
		pair.String(),
		s.users[0].String(), // user to liquidate
	}
	// error shows up in out
	out, _ := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.LiquidateCmd(), append(args, commonArgs...))
	s.T().Logf("STEVENDEBUG liquidate out: %s \n", out.String())
	s.Require().Contains(out.String(), "")

	// Check status: vpool reserve assets, balances, positions
	s.checkStatus(val, pair, s.users)
}

func (s *IntegrationTestSuite) TestAddMargin() {
	// Set up the user accounts
	val := s.network.Validators[0]
	pair := common.TestStablePool

	_, err := utils.FillWalletFromValidator(s.users[0],
		sdk.NewCoins(
			sdk.NewInt64Coin(s.cfg.BondDenom, 10_000),
			sdk.NewInt64Coin(common.GovDenom, 50_000_000),
			sdk.NewInt64Coin(common.CollDenom, 50_000_000),
			sdk.NewInt64Coin(common.TestTokenDenom, 50_000_000),
			sdk.NewInt64Coin(common.StableDenom, 50_000_000),
		),
		val,
		s.cfg.BondDenom,
	)
	s.Require().NoError(err)

	_, err = utils.FillWalletFromValidator(s.users[1],
		sdk.NewCoins(
			sdk.NewInt64Coin(s.cfg.BondDenom, 10_000),
			sdk.NewInt64Coin(common.GovDenom, 50_000_000),
			sdk.NewInt64Coin(common.CollDenom, 50_000_000),
			sdk.NewInt64Coin(common.TestTokenDenom, 50_000_000),
			sdk.NewInt64Coin(common.StableDenom, 50_000_000),
		),
		val,
		s.cfg.BondDenom,
	)
	s.Require().NoError(err)

	// Check status: vpool reserve assets, balances, positions
	s.checkStatus(val, pair, s.users)

	// Open a position with first user
	s.T().Log("opening a position with user 1....")
	args := []string{
		"--from",
		s.users[0].String(),
		"buy",
		pair.String(),
		"10", // Leverage
		"1",  // Quote asset amount
		"0.0000001",
	}
	commonArgs := []string{
		fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
		fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
		fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10))).String()),
	}

	_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cli.OpenPositionCmd(), append(args, commonArgs...))
	if err != nil {
		s.T().Logf("user1 open position err: %+v", err)
	}
	s.Require().NoError(err)

	// Add margin on user 1
	s.T().Log("adding margin on user 1....")
	args = []string{
		"--from",
		s.users[1].String(),
		pair.String(),
		fmt.Sprintf("%s%s", "1", common.TestStablePool.Token1), // amount / margin
	}
	_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cli.AddMarginCmd(), append(args, commonArgs...))
	if err != nil {
		s.T().Logf("user 1 add margin err: %+v", err)
	}
	s.Require().NoError(err)

	// Check status: vpool reserve assets, balances, positions
	s.checkStatus(val, pair, s.users)
}
*/

@kai0x
Copy link
Contributor Author

kai0x commented Jun 9, 2022

just need to fix up the above a bit and add to the cli_test

@kai0x
Copy link
Contributor Author

kai0x commented Jun 10, 2022

i can pick this one up after the remove margin tests are merged in, just wanted to get those in before these are added to prevent too much merge conflicts

@kai0x kai0x changed the title [perp] cli test - liquidate and add margin [perp] cli test - liquidate and add margin + test update Jun 10, 2022
@kai0x
Copy link
Contributor Author

kai0x commented Jun 10, 2022

When you have some free time, can you move this test to x/vpool/cli?

func (s *IntegrationTestSuite) TestGetPrices() {
. Technically it only calls vpool cli commands

https://nibiruchain.slack.com/archives/D03FQ4U31V1/p1654880044192419

@NibiruHeisenberg
Copy link
Contributor

Looks like the test code is already complete. @AgentSmithMatrix can you verify it exists in the codebase?

@NibiruHeisenberg NibiruHeisenberg changed the title [perp] cli test - liquidate and add margin + test update test(perp): liquidate and add margin + test update cli tests Sep 18, 2022
@superfiredoge superfiredoge linked a pull request Oct 6, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants