Skip to content

Commit

Permalink
Slash undeleg test addition (#641)
Browse files Browse the repository at this point in the history
* checkDelegatorBalance refactored out

* fix comments
  • Loading branch information
shaspitz authored Jan 6, 2023
1 parent a1c78a7 commit d9f5f9f
Showing 1 changed file with 27 additions and 49 deletions.
76 changes: 27 additions & 49 deletions tests/e2e/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ func (suite *CCVTestSuite) TestSlashUndelegation() {
fmt.Printf("providerUnbondingPeriod: %s\n", providerUnbondingPeriod)

testCases := []struct {
name string
slash func(consAddr sdk.ConsAddress)
checkDelegatorBalance func(delAddr sdk.AccAddress, initBalance sdk.Int)
name string
slash func(consAddr sdk.ConsAddress)
expSlashOccurred bool
}{
// infraction - delegate - undelegate - slash - mature consumer - mature provider
// TODO: this behavior is unexpected
Expand Down Expand Up @@ -433,14 +433,7 @@ func (suite *CCVTestSuite) TestSlashUndelegation() {
3, // 2 VSCMaturedPackets and 1 SlashPacket
)
},
func(delAddr sdk.AccAddress, initBalance sdk.Int) {
// expectedBalance := initBalance
// suite.Require().Equal(
// expectedBalance,
// getBalance(suite, suite.providerCtx(), delAddr),
// "delegator shouldn't have been slashed",
// )
},
true, // TODO: this should be false!
},
// delegate - infraction - undelegate - slash - mature consumer - mature provider
// slash
Expand Down Expand Up @@ -474,15 +467,8 @@ func (suite *CCVTestSuite) TestSlashUndelegation() {
3, // 2 VSCMaturedPackets and 1 SlashPacket
)
},
func(delAddr sdk.AccAddress, initBalance sdk.Int) {
// infraction before undelegate; slash successful
expectedBalance := initBalance.Sub(halfBondAmt).Sub(slashAmount)
suite.Require().Equal(
expectedBalance,
getBalance(suite, suite.providerCtx(), delAddr),
"delegator should have been slashed",
)
},
// infraction before undelegate; slash successful
true,
},
// delegate - undelegate - infraction - slash - mature consumer - mature provider
// no slash
Expand Down Expand Up @@ -516,15 +502,8 @@ func (suite *CCVTestSuite) TestSlashUndelegation() {
3,
)
},
func(delAddr sdk.AccAddress, initBalance sdk.Int) {
// undelegation occurred before infraction, thus it is not slashed
expectedBalance := initBalance.Sub(halfBondAmt)
suite.Require().Equal(
expectedBalance,
getBalance(suite, suite.providerCtx(), delAddr),
"delegator shouldn't have been slashed",
)
},
// undelegation occurred before infraction, thus it is not slashed
false,
},
// delegate - infraction - undelegate - mature consumer - slash - mature provider
// slash
Expand Down Expand Up @@ -567,16 +546,9 @@ func (suite *CCVTestSuite) TestSlashUndelegation() {
1,
)
},
func(delAddr sdk.AccAddress, initBalance sdk.Int) {
// the undelegation was only matured on the consumer,
// thus the slash was successful
expectedBalance := initBalance.Sub(halfBondAmt).Sub(slashAmount)
suite.Require().Equal(
expectedBalance,
getBalance(suite, suite.providerCtx(), delAddr),
"delegator should have been slashed",
)
},
// the undelegation was only matured on the consumer,
// thus the slash was successful
true,
},
// delegate - infraction - undelegate - mature consumer - mature provider - slash
// no slash
Expand Down Expand Up @@ -622,15 +594,8 @@ func (suite *CCVTestSuite) TestSlashUndelegation() {
1,
)
},
func(delAddr sdk.AccAddress, initBalance sdk.Int) {
// the undelegation is already matured, thus it is not slashed
expectedBalance := initBalance.Sub(halfBondAmt)
suite.Require().Equal(
expectedBalance,
getBalance(suite, suite.providerCtx(), delAddr),
"delegator shouldn't have been slashed",
)
},
// the undelegation is already matured, thus it is not slashed
false,
},
}

Expand Down Expand Up @@ -732,7 +697,20 @@ func (suite *CCVTestSuite) TestSlashUndelegation() {
// increment time so that the unbonding period ends on the provider
incrementTime(suite, providerUnbondingPeriod)

tc.checkDelegatorBalance(delAddr, initBalance)
var expectedBalance sdk.Int
var errMsg string
if tc.expSlashOccurred {
expectedBalance = initBalance.Sub(halfBondAmt).Sub(slashAmount)
errMsg = "delegator should have been slashed"
} else {
expectedBalance = initBalance.Sub(halfBondAmt)
errMsg = "delegator should not have been slashed"
}
suite.Require().Equal(
expectedBalance,
getBalance(suite, suite.providerCtx(), delAddr),
errMsg,
)

if i+1 < len(testCases) {
// reset suite to reset provider client
Expand Down

0 comments on commit d9f5f9f

Please sign in to comment.