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

Slash undeleg test addition #641

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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