From 26e4a951d6250bda3881e8b36c9e270178202341 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Mon, 21 Aug 2023 21:33:45 +0200 Subject: [PATCH 1/2] update e2e tests --- tests/e2e/actions_consumer_misbehaviour.go | 26 ++++++++++++++++++++-- tests/e2e/main.go | 2 ++ tests/e2e/steps_consumer_misbehaviour.go | 14 +++++++----- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/tests/e2e/actions_consumer_misbehaviour.go b/tests/e2e/actions_consumer_misbehaviour.go index 2b01c2818e..71a437fada 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,25 @@ func (tr TestRun) updateLightClient( tr.waitBlocks(action.hostChain, 5, 30*time.Second) } + +type assertChainIsHaltedAction struct { + chain chainID +} + +func (tr TestRun) assertChainIsHalted( + action assertChainIsHaltedAction, + verbose bool, +) { + // Recover the panic if the chain doesn't produce blocks as expected + defer func() { + if r := recover(); r != nil { + if verbose { + log.Printf("assertChainIsHalted - chain %v was successfully halted\n", action.chain) + } + } + }() + + // Panic if the chain still produces blocks + tr.waitBlocks(action.chain, 1, 20*time.Second) + panic(fmt.Sprintf("chain %v isn't expected to produce blocks", 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{}, + }, } } From 49eb6460244e5aafbd615ecfd5e2e51d4c86fc22 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Wed, 23 Aug 2023 09:15:39 +0200 Subject: [PATCH 2/2] update the chain halt assertion --- tests/e2e/actions_consumer_misbehaviour.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/e2e/actions_consumer_misbehaviour.go b/tests/e2e/actions_consumer_misbehaviour.go index 71a437fada..84eb93152c 100644 --- a/tests/e2e/actions_consumer_misbehaviour.go +++ b/tests/e2e/actions_consumer_misbehaviour.go @@ -95,20 +95,18 @@ 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, ) { - // Recover the panic if the chain doesn't produce blocks as expected - defer func() { - if r := recover(); r != nil { - if verbose { - log.Printf("assertChainIsHalted - chain %v was successfully halted\n", action.chain) - } - } - }() - - // Panic if the chain still produces blocks - tr.waitBlocks(action.chain, 1, 20*time.Second) - panic(fmt.Sprintf("chain %v isn't expected to produce blocks", action.chain)) + 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) + } }