From 21e3d839ce3fc7141b6c808ab40b46899d5f9123 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Wed, 23 Aug 2023 16:38:35 +0200 Subject: [PATCH] feat: improve ICS misbehaviour E2E testing coverage (#1225) * update e2e tests * update the chain halt assertion --- tests/e2e/actions_consumer_misbehaviour.go | 24 ++++++++++++++++++++-- tests/e2e/main.go | 2 ++ tests/e2e/steps_consumer_misbehaviour.go | 14 +++++++------ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/tests/e2e/actions_consumer_misbehaviour.go b/tests/e2e/actions_consumer_misbehaviour.go index 2b01c2818e..84eb93152c 100644 --- a/tests/e2e/actions_consumer_misbehaviour.go +++ b/tests/e2e/actions_consumer_misbehaviour.go @@ -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() @@ -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 @@ -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) + } +} diff --git a/tests/e2e/main.go b/tests/e2e/main.go index 4c7b6722cd..406a015e63 100644 --- a/tests/e2e/main.go +++ b/tests/e2e/main.go @@ -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) } diff --git a/tests/e2e/steps_consumer_misbehaviour.go b/tests/e2e/steps_consumer_misbehaviour.go index 7d7fda94b1..6401b5f638 100644 --- a/tests/e2e/steps_consumer_misbehaviour.go +++ b/tests/e2e/steps_consumer_misbehaviour.go @@ -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{}, + }, } }