Skip to content

Commit

Permalink
fix(ci): Fix the LSM test for v22.
Browse files Browse the repository at this point in the history
Some versions of gaia differ in how they report shares vs tokens staked, and
that can produce discrepancies in tests. This updates us for a v22 chain,
with potential ICAs in v21 chains
  • Loading branch information
fastfadingviolets committed Jan 7, 2025
1 parent 1b5664b commit 03f6f6f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/interchain/delegator/lsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *LSMSuite) TestLSMHappyPath() {
s.Require().NoError(err)
delegatorShares2, err := s.Chain.QueryJSON(s.GetContext(), "validator.delegator_shares", "staking", "validator", providerWallet.ValoperAddress)
s.Require().NoError(err)
s.checkAMinusBEqualsX(delegatorShares2.String(), delegatorShares1.String(), sdkmath.NewInt(delegation).Mul(s.ShareFactor))
s.checkAMinusBEqualsX(delegatorShares2.String(), delegatorShares1.String(), sdkmath.NewInt(delegation))

_, err = s.Chain.GetNode().ExecTx(s.GetContext(), s.LSMWallets[lsmBondingMoniker].FormattedAddress(),
"staking", "validator-bond", providerWallet.ValoperAddress)
Expand All @@ -84,7 +84,7 @@ func (s *LSMSuite) TestLSMHappyPath() {
s.Require().NoError(err)
delegatorShares2, err := s.Chain.QueryJSON(s.GetContext(), "validator.delegator_shares", "staking", "validator", providerWallet.ValoperAddress)
s.Require().NoError(err)
s.checkAMinusBEqualsX(delegatorShares2.String(), delegatorShares1.String(), sdkmath.NewInt(delegation).Mul(s.ShareFactor))
s.checkAMinusBEqualsX(delegatorShares2.String(), delegatorShares1.String(), sdkmath.NewInt(delegation))

sharesPreTokenize, err := s.Chain.QueryJSON(s.GetContext(), "validator.liquid_shares", "staking", "validator", providerWallet.ValoperAddress)
s.Require().NoError(err)
Expand Down Expand Up @@ -201,18 +201,18 @@ func (s *LSMSuite) TestLSMHappyPath() {
happyLiquid1Delegations2Result, err := s.Chain.QueryJSON(s.GetContext(), fmt.Sprintf("delegation_responses.#(delegation.validator_address==\"%s\").delegation.shares", providerWallet.ValoperAddress), "staking", "delegations", s.LSMWallets[lsmLiquid1Moniker].FormattedAddress())
s.Require().NoError(err)
happyLiquid1Delegations2 := happyLiquid1Delegations2Result.String()
s.checkAMinusBEqualsX(happyLiquid1Delegations2, happyLiquid1Delegations1, sdkmath.NewInt(liquid1Redeem).Mul(s.ShareFactor))
s.checkAMinusBEqualsX(happyLiquid1Delegations2, happyLiquid1Delegations1, sdkmath.NewInt(liquid1Redeem))

happyLiquid2DelegationsResult, err := s.Chain.QueryJSON(s.GetContext(), fmt.Sprintf("delegation_responses.#(delegation.validator_address==\"%s\").delegation.shares", providerWallet.ValoperAddress), "staking", "delegations", s.LSMWallets[lsmLiquid2Moniker].FormattedAddress())
s.Require().NoError(err)
happyLiquid2Delegations := happyLiquid2DelegationsResult.String()
// LOL there are better ways of doing this
s.checkAMinusBEqualsX(happyLiquid2Delegations, "0", sdkmath.NewInt(bankSend).Mul(s.ShareFactor))
s.checkAMinusBEqualsX(happyLiquid2Delegations, "0", sdkmath.NewInt(bankSend))

happyLiquid3DelegationsResult, err := s.Chain.QueryJSON(s.GetContext(), fmt.Sprintf("delegation_responses.#(delegation.validator_address==\"%s\").delegation.shares", providerWallet.ValoperAddress), "staking", "delegations", s.LSMWallets[lsmLiquid3Moniker].FormattedAddress())
s.Require().NoError(err)
happyLiquid3Delegations := happyLiquid3DelegationsResult.String()
s.checkAMinusBEqualsX(happyLiquid3Delegations, "0", sdkmath.NewInt(ibcTransfer).Mul(s.ShareFactor))
s.checkAMinusBEqualsX(happyLiquid3Delegations, "0", sdkmath.NewInt(ibcTransfer))

happyLiquid1DelegationBalanceResult, err := s.Chain.QueryJSON(s.GetContext(), fmt.Sprintf("delegation_responses.#(delegation.validator_address==\"%s\").balance.amount", providerWallet.ValoperAddress), "staking", "delegations", s.LSMWallets[lsmLiquid1Moniker].FormattedAddress())
s.Require().NoError(err)
Expand Down Expand Up @@ -296,7 +296,7 @@ func (s *LSMSuite) TestICADelegate() {
s.Require().NoError(err)

exchangeRate1 := shares1Int.Quo(tokens1Int)
expectedSharesIncrease := exchangeRate1.MulRaw(bondDelegation)
expectedSharesIncrease := exchangeRate1.MulRaw(bondDelegation).Mul(s.ShareFactor)
expectedShares := expectedSharesIncrease.Add(bondShares1Int)

_, err = s.Chain.GetNode().ExecTx(s.GetContext(), bondingWallet.FormattedAddress(),
Expand Down Expand Up @@ -334,7 +334,7 @@ func (s *LSMSuite) TestICADelegate() {
preDelegationSharesInt, err := chainsuite.StrToSDKInt(preDelegationShares)
s.Require().NoError(err)
exchangeRate := preDelegationSharesInt.Quo(preDelegationTokensInt)
expectedLiquidIncrease := exchangeRate.MulRaw(delegate)
expectedLiquidIncrease := exchangeRate.MulRaw(delegate).Mul(s.ShareFactor)

delegateHappy := map[string]interface{}{
"@type": "/cosmos.staking.v1beta1.MsgDelegate",
Expand Down Expand Up @@ -376,7 +376,7 @@ func (s *LSMSuite) TestICADelegate() {
preDelegationLiquidSharesInt, err := chainsuite.StrToSDKInt(preDelegationLiquidShares)
s.Require().NoError(err)
liquidSharesDelta := postDelegationLiquidShares.Sub(preDelegationLiquidSharesInt)
s.Require().Truef(liquidSharesDelta.Sub(expectedLiquidIncrease).Abs().LTE(sdkmath.NewInt(1)), "liquidSharesDelta: %s, expectedLiquidIncrease: %d", liquidSharesDelta, expectedLiquidIncrease)
s.Require().Truef(liquidSharesDelta.Sub(expectedLiquidIncrease).Abs().LTE(sdkmath.NewInt(1)), "liquidSharesDelta: %s, expectedLiquidIncrease: %s", liquidSharesDelta, expectedLiquidIncrease)
})
}

Expand Down

0 comments on commit 03f6f6f

Please sign in to comment.