Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowman committed Feb 13, 2024
1 parent 29e5fe4 commit ed81656
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
74 changes: 74 additions & 0 deletions x/interchainstaking/keeper/callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/quicksilver-zone/quicksilver/app"
"github.com/quicksilver-zone/quicksilver/utils/addressutils"
"github.com/quicksilver-zone/quicksilver/utils/ica"
icqtypes "github.com/quicksilver-zone/quicksilver/x/interchainquery/types"
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper"
icstypes "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types"
Expand Down Expand Up @@ -2574,6 +2575,33 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalancesCallback() {
}
}

func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallbackDenomMismatch() {
suite.Run("delegation account balance", func() {
suite.SetupTest()
suite.setupTestZones()

app := suite.GetQuicksilverApp(suite.chainA)
app.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks()
ctx := suite.chainA.GetContext()

zone, _ := app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
zone.SetWithdrawalWaitgroup(app.Logger(), 2, "init")
zone.DelegationAddress.Balance = sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(500_000_000)))
app.InterchainstakingKeeper.SetZone(ctx, &zone)

response := sdk.NewCoin("uatom", sdk.NewInt(500_000_000))
respbz, err := app.AppCodec().Marshal(&response)
suite.Require().NoError(err)

accAddr, err := sdk.AccAddressFromBech32(zone.DelegationAddress.Address)
suite.Require().NoError(err)
data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte("uqck")...)

err = keeper.DelegationAccountBalanceCallback(app.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data})
suite.Require().Error(err)
})
}

func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallback() {
suite.Run("delegation account balance", func() {
suite.SetupTest()
Expand Down Expand Up @@ -2642,6 +2670,52 @@ func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallbackLSM() {
})
}

func (suite *KeeperTestSuite) TestDelegationAccountBalanceCallbackLSMBadZone() {
suite.Run("delegation account balance", func() {
suite.SetupTest()
suite.setupTestZones()

txk := ica.TxKeeper{}
app := suite.GetQuicksilverApp(suite.chainA)
app.InterchainstakingKeeper.OverrideTxSubmit(ica.GetTestSubmitTxFn(&txk))

app.InterchainstakingKeeper.CallbackHandler().RegisterCallbacks()
ctx := suite.chainA.GetContext()

zone, _ := app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)

valOper := addressutils.GenerateAddressForTestWithPrefix("quickvaloper")
denom := valOper + "/1"
zone.SetWithdrawalWaitgroup(app.Logger(), 2, "init")
zone.DelegationAddress.Balance = sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(500)))
app.InterchainstakingKeeper.SetZone(ctx, &zone)

response := sdk.NewCoin(denom, sdk.NewInt(10))
respbz, err := app.AppCodec().Marshal(&response)
suite.Require().NoError(err)

accAddr, err := sdk.AccAddressFromBech32(zone.DelegationAddress.Address)
suite.Require().NoError(err)
data := append(banktypes.CreateAccountBalancesPrefix(accAddr), []byte(denom)...)

err = keeper.DelegationAccountBalanceCallback(app.InterchainstakingKeeper, ctx, respbz, icqtypes.Query{ChainId: suite.chainB.ChainID, Request: data})
suite.Require().NoError(err)

ctx = suite.chainA.GetContext()
zone, _ = app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
suite.Equal(uint32(1), zone.GetWithdrawalWaitgroup()) // initial 2 is reduced to 1, and not incremented (no wg increment for sendToWithdrawal)
suite.Equal(sdk.NewInt(500), zone.DelegationAddress.Balance.AmountOf("uatom"))
suite.Equal(sdk.NewInt(10), zone.DelegationAddress.Balance.AmountOf(denom))
suite.Equal(1, len(txk.Txs))

sendMsg, ok := txk.Txs[0].Msgs[0].(*banktypes.MsgSend)
suite.True(ok)
suite.Equal(zone.WithdrawalAddress.Address, sendMsg.ToAddress)
suite.Equal(zone.DelegationAddress.Address, sendMsg.FromAddress)
suite.Equal(sdk.NewCoins(response), sendMsg.Amount)
})
}

const (
txFixtureLsm = "GsEDCiCFDDobCzFK2Vf0BXcgdEycLSdJL8IP7PEVWKelDQeJ3xL2AgrXAQrUAQocL2Nvc21vcy5iYW5rLnYxYmV0YTEuTXNnU2VuZBKzAQotY29zbW9zMWEyemh0OHgyajBkcXZ1ZWpyOHB4cHU3ZHVlM3FtazQwbGdkeTNoEkFjb3Ntb3MxYXZ2ZWhmM25wdm42d2V5eHR2eXU3bWh3d3Zqcnl6dzY5ZzQzdHEwbmw4MHdxamdscjZoc2U1bWN6NBo/Cjdjb3Ntb3N2YWxvcGVyMWdnN3c4dzJ5OWpmdjc2YTJ5eWFoZTQyeTA5ZzlyeTJyYWE1cnFmLzE0EgQ1MDAwElgKUApGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQLaGco86x6BgxaGOBf/rgbHMEyZzECi+5in9DJ31ln/0BIECgIIARgoEgQQwJoMGkAtbKm5mTCs2SJzFZL5UKaFbKascEfSLtLFX4w9H/iLKXVqia/1REtynG8yLW374PPGFRplDo62C3SrhSBSLETgGiQIARoghQw6GwsxStlX9AV3IHRMnC0nSS/CD+zxFVinpQ0Hid8i2wYK0AQKkgMKAggLEgpnYWlhdGVzdC0xGJjdDiIMCPHf2agGEODypL8CKkgKIFvrRJTTqdEJ0eh/bm+bNFIMSX7ad1Uz9FX2u8acwNOAEiQIARIgqdknqwXY2NKl/r0A/JEd6hFCVr+E+xoDP5xqjTdMzkkyIFTqmUpOcyiALxE9GyyJ8B0qHyYAXdEyebrP+zlYCVe/OiCFDDobCzFK2Vf0BXcgdEycLSdJL8IP7PEVWKelDQeJ30IgLdUPCAh3Ii0/aGdGLRM24PsOqJJsvS6jPy3hstJUQ0RKIC3VDwgIdyItP2h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5wNj2ddC7mj52Ls03KuAsxvWItEYeJLvQGEn4KPQoUeQRs3t3nFppZq/OiJ+/f0AsW+twSIgogx4ew5LC25gOeUAdpun5LhBSfIBHUbK7Zjyzn8VRr1ZwYqyESPQoUeQRs3t3nFppZq/OiJ+/f0AsW+twSIgogx4ew5LC25gOeUAdpun5LhBSfIBHUbK7Zjyzn8VRr1ZwYqyEaBggBEMnnECJ+Cj0KFHkEbN7d5xaaWavzoifv39ALFvrcEiIKIMeHsOSwtuYDnlAHabp+S4QUnyAR1Gyu2Y8s5/FUa9WcGKshEj0KFHkEbN7d5xaaWavzoifv39ALFvrcEiIKIMeHsOSwtuYDnlAHabp+S4QUnyAR1Gyu2Y8s5/FUa9WcGKsh"
Expand Down
24 changes: 24 additions & 0 deletions x/interchainstaking/keeper/ibc_packet_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4494,6 +4494,30 @@ func (suite *KeeperTestSuite) TestHandleFailedDelegate_Batch_OK() {
suite.Equal(uint32(99), zone.GetWithdrawalWaitgroup())
}

func (suite *KeeperTestSuite) TestHandleFailedDelegate_Batch_BadWg() {
suite.SetupTest()
suite.setupTestZones()

app := suite.GetQuicksilverApp(suite.chainA)
ctx := suite.chainA.GetContext()

zone, found := app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
suite.True(found)

zone.SetWithdrawalWaitgroup(app.Logger(), 0, "init")
app.InterchainstakingKeeper.SetZone(ctx, &zone)

vals := app.InterchainstakingKeeper.GetValidatorAddresses(ctx, suite.chainB.ChainID)
msg := stakingtypes.MsgDelegate{DelegatorAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0], Amount: sdk.NewCoin("uatom", sdk.NewInt(100))}
var msgMsg sdk.Msg = &msg
err := app.InterchainstakingKeeper.HandleFailedDelegate(ctx, msgMsg, "batch/12345678")
suite.Error(err)

zone, found = app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
suite.True(found)
suite.Equal(uint32(0), zone.GetWithdrawalWaitgroup())
}

func (suite *KeeperTestSuite) TestHandleFailedDelegate_PerfAddress_OK() {
suite.SetupTest()
suite.setupTestZones()
Expand Down

0 comments on commit ed81656

Please sign in to comment.