Skip to content

Commit

Permalink
feat: improve ICS misbehaviour E2E testing coverage (#1225)
Browse files Browse the repository at this point in the history
* update e2e tests

* update the chain halt assertion
  • Loading branch information
sainoe authored Aug 23, 2023
1 parent a77eea1 commit 21e3d83
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
24 changes: 22 additions & 2 deletions tests/e2e/actions_consumer_misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (tr TestRun) forkConsumerChain(action forkConsumerChainAction, verbose bool
)

if verbose {
fmt.Println("forkConsumerChain - reconfigure node cmd:", configureNodeCmd.String())
log.Println("forkConsumerChain - reconfigure node cmd:", configureNodeCmd.String())
}

cmdReader, err := configureNodeCmd.StdoutPipe()
Expand All @@ -47,7 +47,7 @@ func (tr TestRun) forkConsumerChain(action forkConsumerChainAction, verbose bool
for scanner.Scan() {
out := scanner.Text()
if verbose {
fmt.Println("fork consumer validator : " + out)
log.Println("fork consumer validator : " + out)
}
if out == done {
break
Expand Down Expand Up @@ -90,3 +90,23 @@ func (tr TestRun) updateLightClient(

tr.waitBlocks(action.hostChain, 5, 30*time.Second)
}

type assertChainIsHaltedAction struct {
chain chainID
}

// assertChainIsHalted verifies that the chain isn't producing blocks
// by checking that the block height is still the same after 20 seconds
func (tr TestRun) assertChainIsHalted(
action assertChainIsHaltedAction,
verbose bool,
) {
blockHeight := tr.getBlockHeight(action.chain)
time.Sleep(20 * time.Second)
if blockHeight != tr.getBlockHeight(action.chain) {
panic(fmt.Sprintf("chain %v isn't expected to produce blocks", action.chain))
}
if verbose {
log.Printf("assertChainIsHalted - chain %v was successfully halted\n", action.chain)
}
}
2 changes: 2 additions & 0 deletions tests/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ func (tr *TestRun) runStep(step Step, verbose bool) {
tr.forkConsumerChain(action, verbose)
case updateLightClientAction:
tr.updateLightClient(action, verbose)
case assertChainIsHaltedAction:
tr.assertChainIsHalted(action, verbose)
default:
log.Fatalf("unknown action in testRun %s: %#v", tr.name, action)
}
Expand Down
14 changes: 8 additions & 6 deletions tests/e2e/steps_consumer_misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,15 @@ func stepsCauseConsumerMisbehaviour(consumerName string) []Step {
},
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 20,
},
},
},
},
// we expect the consumer chain to be halted since the last VSC packet should
// have updated the alice validator power to 0.
{
action: assertChainIsHaltedAction{
chain: chainID("consu"),
},
state: State{},
},
}
}

0 comments on commit 21e3d83

Please sign in to comment.