diff --git a/x/spot/client/testutil/suite.go b/x/spot/client/testutil/suite.go index 6742ff7f1..0868580bf 100644 --- a/x/spot/client/testutil/suite.go +++ b/x/spot/client/testutil/suite.go @@ -10,7 +10,6 @@ import ( sdktestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli" @@ -424,7 +423,6 @@ func (s *IntegrationTestSuite) TestNewExitPoolCmd() { } func (s *IntegrationTestSuite) TestNewExitStablePoolCmd() { - s.T().Skip("this test looks like it has a bug https://github.com/NibiruChain/nibiru/issues/869") val := s.network.Validators[0] // create a new pool @@ -432,8 +430,8 @@ func (s *IntegrationTestSuite) TestNewExitStablePoolCmd() { s.T(), val.ClientCtx, /*owner-*/ val.Address, - /*tokenWeights=*/ fmt.Sprintf("1%s,1%s", "coin-3", "coin-4"), - /*tokenWeights=*/ fmt.Sprintf("100%s,100%s", "coin-3", "coin-4"), + /*tokenWeights=*/ fmt.Sprintf("1%s,1%s", "coin-3", "coin-5"), + /*tokenWeights=*/ fmt.Sprintf("100%s,100%s", "coin-3", "coin-5"), /*swapFee=*/ "0.01", /*exitFee=*/ "0.01", /*poolType=*/ "stableswap", @@ -451,54 +449,49 @@ func (s *IntegrationTestSuite) TestNewExitStablePoolCmd() { s.Require().NoError(err, out.String()) testCases := []struct { - name string - poolId uint64 - poolSharesOut string - expectErr bool - respType proto.Message - expectedCode uint32 - expectedunibi sdkmath.Int - expectedOtherToken sdkmath.Int + name string + poolId uint64 + poolSharesOut string + expectErr bool + expectedCode uint32 + expectedCoin3 sdkmath.Int + expectedCoin5 sdkmath.Int }{ { - name: "exit pool from invalid pool", - poolId: 100, - poolSharesOut: "100nibiru/pool/100", - expectErr: false, - respType: &sdk.TxResponse{}, - expectedCode: 1, // spot.types.ErrNonExistingPool - expectedunibi: sdk.NewInt(-10), - expectedOtherToken: sdk.NewInt(0), - }, - { - name: "exit pool for too many shares", - poolId: poolID, - poolSharesOut: fmt.Sprintf("1001000000000000000000nibiru/pool/%d", poolID), - expectErr: false, - respType: &sdk.TxResponse{}, - expectedCode: 1, - expectedunibi: sdk.NewInt(-10), - expectedOtherToken: sdk.NewInt(0), - }, - { - name: "exit pool for zero shares", - poolId: poolID, - poolSharesOut: fmt.Sprintf("0nibiru/pool/%d", poolID), - expectErr: false, - respType: &sdk.TxResponse{}, - expectedCode: 1, - expectedunibi: sdk.NewInt(-10), - expectedOtherToken: sdk.NewInt(0), + name: "exit pool from invalid pool", + poolId: 100, + poolSharesOut: "100nibiru/pool/100", + expectErr: false, + expectedCode: 1, // spot.types.ErrNonExistingPool + expectedCoin3: sdk.ZeroInt(), + expectedCoin5: sdk.ZeroInt(), + }, + { + name: "exit pool for too many shares", + poolId: poolID, + poolSharesOut: fmt.Sprintf("1001000000000000000000nibiru/pool/%d", poolID), + expectErr: false, + expectedCode: 1, + expectedCoin3: sdk.ZeroInt(), + expectedCoin5: sdk.ZeroInt(), + }, + { + name: "exit pool for zero shares", + poolId: poolID, + poolSharesOut: fmt.Sprintf("0nibiru/pool/%d", poolID), + expectErr: false, + expectedCode: 1, + expectedCoin3: sdk.ZeroInt(), + expectedCoin5: sdk.ZeroInt(), }, { // Looks with a bug - name: "exit pool with sufficient balance", - poolId: poolID, - poolSharesOut: fmt.Sprintf("100000000000000000000nibiru/pool/%d", poolID), - expectErr: false, - respType: &sdk.TxResponse{}, - expectedCode: 0, - expectedunibi: sdk.NewInt(100 - 10 - 1), // Received unibi minus 10unibi tx fee minus 1 exit pool fee - expectedOtherToken: sdk.NewInt(100 - 1), // Received uusdc minus 1 exit pool fee + name: "exit pool with sufficient balance", + poolId: poolID, + poolSharesOut: fmt.Sprintf("100000000000000000000nibiru/pool/%d", poolID), + expectErr: false, + expectedCode: 0, + expectedCoin3: sdk.NewInt(99), // Received coin-3 minus 1 exit pool fee + expectedCoin5: sdk.NewInt(99), // Received coin-5 minus 1 exit pool fee }, } @@ -511,7 +504,7 @@ func (s *IntegrationTestSuite) TestNewExitStablePoolCmd() { resp, err := sdktestutil.QueryBalancesExec(ctx, val.Address) s.Require().NoError(err) var originalBalance banktypes.QueryAllBalancesResponse - s.Require().NoError(ctx.Codec.UnmarshalJSON(resp.Bytes(), &originalBalance)) + ctx.Codec.MustUnmarshalJSON(resp.Bytes(), &originalBalance) out, err := ExecMsgExitPool(ctx, tc.poolId, val.Address, tc.poolSharesOut) @@ -519,24 +512,28 @@ func (s *IntegrationTestSuite) TestNewExitStablePoolCmd() { s.Require().Error(err) } else { s.Require().NoError(err, out.String()) - s.Require().NoError(ctx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String()) + s.Require().NoError(s.network.WaitForNextBlock()) + + resp := &sdk.TxResponse{} + ctx.Codec.MustUnmarshalJSON(out.Bytes(), resp) + resp, err = testutilcli.QueryTx(ctx, resp.TxHash) + s.Require().NoError(err) - txResp := tc.respType.(*sdk.TxResponse) - s.Require().Equal(tc.expectedCode, txResp.Code, out.String()) + s.Require().Equal(tc.expectedCode, resp.Code, out.String()) // Ensure balance is ok - resp, err := sdktestutil.QueryBalancesExec(ctx, val.Address) + out, err := sdktestutil.QueryBalancesExec(ctx, val.Address) s.Require().NoError(err) var finalBalance banktypes.QueryAllBalancesResponse - s.Require().NoError(ctx.Codec.UnmarshalJSON(resp.Bytes(), &finalBalance)) + ctx.Codec.MustUnmarshalJSON(out.Bytes(), &finalBalance) - s.Require().Equal( - originalBalance.Balances.AmountOf("uusdc").Add(tc.expectedOtherToken), - finalBalance.Balances.AmountOf("uusdc"), + s.Assert().Equal( + originalBalance.Balances.AmountOf("coin-3").Add(tc.expectedCoin3), + finalBalance.Balances.AmountOf("coin-3"), ) - s.Require().Equal( - originalBalance.Balances.AmountOf("unibi").Add(tc.expectedunibi), - finalBalance.Balances.AmountOf("unibi"), + s.Assert().Equal( + originalBalance.Balances.AmountOf("coin-5").Add(tc.expectedCoin5), + finalBalance.Balances.AmountOf("coin-5"), ) } })