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

test: add E2E tests for double voting evidence handling #1256

Merged
merged 24 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN go mod tidy
RUN make install

# Get Hermes build
FROM otacrew/hermes-ics:latest AS hermes-builder
FROM otacrew/hermes-ics:double-voting AS hermes-builder

# Get CometMock
FROM informalofftermatt/cometmock:latest as cometmock-builder
Expand Down
23 changes: 22 additions & 1 deletion tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ rpc_addr = "%s"
rpc_timeout = "10s"
store_prefix = "ibc"
trusting_period = "14days"
websocket_addr = "%s"
event_source = { mode = "push", url = "%s", batch_delay = "50ms" }
ccv_consumer_chain = %v

[chains.gas_price]
Expand Down Expand Up @@ -1682,6 +1682,27 @@ func (tr TestRun) invokeDoublesignSlash(
tr.waitBlocks("provi", 10, 2*time.Minute)
}

// Run an instance of the Hermes relayer in the "evidence" mode
// to detect and report the double signing evidences committed on the consumer chain
// to the provider chain
type detectDoubleSigningEvidenceAction struct {
chain chainID
}

func (tr TestRun) detectDoubleSigningEvidence(
action detectDoubleSigningEvidenceAction,
verbose bool,
) {
chainConfig := tr.chainConfigs[action.chain]
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
bz, err := exec.Command("docker", "exec", "-d", tr.containerConfig.instanceName,
"hermes", "evidence", "--chain", string(chainConfig.chainId)).CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}
tr.waitBlocks("provi", 10, 2*time.Minute)
}

type assignConsumerPubKeyAction struct {
chain chainID
validator validatorID
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func main() {
{DemocracyTestRun(false), rewardDenomConsumerSteps},
{SlashThrottleTestRun(), slashThrottleSteps},
{ConsumerMisbehaviourTestRun(), consumerMisbehaviourSteps},
{DefaultTestRun(), consumerDoubleSignSteps},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls note that the way tests are selected/organized has changed in the latest version of main branch

}

if includeMultiConsumer != nil && *includeMultiConsumer {
testRuns = append(testRuns, testRunWithSteps{MultiConsumerTestRun(), multipleConsumers})
}
Expand Down Expand Up @@ -180,6 +182,8 @@ func (tr *TestRun) runStep(step Step, verbose bool) {
tr.updateLightClient(action, verbose)
case assertChainIsHaltedAction:
tr.assertChainIsHalted(action, verbose)
case detectDoubleSigningEvidenceAction:
tr.detectDoubleSigningEvidence(action, verbose)
default:
log.Fatalf("unknown action in testRun %s: %#v", tr.name, action)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ var consumerMisbehaviourSteps = concatSteps(
// make consumer validator to misbehave and get jail
stepsCauseConsumerMisbehaviour("consu"),
)

var consumerDoubleSignSteps = concatSteps(
// start provider and consumer chain
stepsStartChains([]string{"consu"}, false),

// make consumer validator to double sign and get jail
stepsCauseDoubleSignOnConsumer("consu"),
)
94 changes: 83 additions & 11 deletions tests/e2e/steps_double_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ func stepsDoubleSignOnProviderAndConsumer(consumerName string) []Step {
// slash on provider
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500,
validatorID("carol"): 0, // from 500 to 0
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500,
validatorID("carol"): 495, // not tombstoned on consumerName yet
validatorID("carol"): 500, // not tombstoned on consumerName yet
},
},
},
Expand All @@ -38,14 +38,14 @@ func stepsDoubleSignOnProviderAndConsumer(consumerName string) []Step {
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500,
validatorID("carol"): 0,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500,
validatorID("carol"): 0, // tombstoning visible on consumerName
},
Expand All @@ -63,14 +63,14 @@ func stepsDoubleSignOnProviderAndConsumer(consumerName string) []Step {
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500,
validatorID("carol"): 0,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500,
validatorID("carol"): 0,
},
Expand All @@ -87,14 +87,14 @@ func stepsDoubleSignOnProviderAndConsumer(consumerName string) []Step {
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500, // not tombstoned
validatorID("carol"): 0,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500, // not tombstoned
validatorID("carol"): 0,
},
Expand All @@ -112,14 +112,14 @@ func stepsDoubleSignOnProviderAndConsumer(consumerName string) []Step {
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500,
validatorID("carol"): 0,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
validatorID("alice"): 510,
validatorID("bob"): 500, // not tombstoned
validatorID("carol"): 0,
},
Expand All @@ -128,3 +128,75 @@ func stepsDoubleSignOnProviderAndConsumer(consumerName string) []Step {
},
}
}

func stepsCauseDoubleSignOnConsumer(consumerName string) []Step {
p-offtermatt marked this conversation as resolved.
Show resolved Hide resolved
return []Step{
{
action: doublesignSlashAction{
chain: chainID("consu"),
p-offtermatt marked this conversation as resolved.
Show resolved Hide resolved
validator: validatorID("bob"),
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 500,
validatorID("bob"): 500,
validatorID("carol"): 500,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 500,
validatorID("bob"): 500,
validatorID("carol"): 500,
},
},
},
},
{
action: detectDoubleSigningEvidenceAction{
chain: chainID("consu"),
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 500,
validatorID("bob"): 0,
validatorID("carol"): 500,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 500,
validatorID("bob"): 500,
validatorID("carol"): 500,
},
},
},
},
{
action: relayPacketsAction{
chainA: chainID("provi"),
chainB: chainID(consumerName),
port: "provider",
channel: 0,
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 500,
validatorID("bob"): 0,
validatorID("carol"): 500,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 500,
validatorID("bob"): 0,
validatorID("carol"): 500,
},
},
},
},
}
}
2 changes: 1 addition & 1 deletion tests/e2e/testnet-scripts/fork-consumer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ rpc_addr = "http://$CONS_CHAIN_PREFIX.252:26658"
rpc_timeout = "10s"
store_prefix = "ibc"
trusting_period = "2days"
websocket_addr = "ws://$CONS_CHAIN_PREFIX.252:26658/websocket"
websocket_addr = "event_source = { mode = 'push', url = 'ws://$CONS_CHAIN_PREFIX.252:26658/websocket' , batch_delay = '50ms' }

[chains.gas_price]
denom = "stake"
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func NewSubmitConsumerDoubleVotingCmd() *cobra.Command {
return err
}

msg, err := types.NewMsgSubmitConsumerDoubleVoting(submitter, ev, nil)
msg, err := types.NewMsgSubmitConsumerDoubleVoting(submitter, ev, &header)
sainoe marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down
Loading