From cf81c897dfa3dec88f72f0c040eb8189b37ddc52 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 14 Jul 2021 17:41:24 -0700 Subject: [PATCH] test: handle null blocks in TestForkRefuseCall Otherwise, this fails on rare occasions. --- chain/stmgr/forks_test.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index dd2e47a57ab..6d22a294d71 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -297,22 +297,26 @@ func TestForkRefuseCall(t *testing.T) { t.Fatal(err) } + pts, err := cg.ChainStore().LoadTipSet(ts.TipSet.TipSet().Parents()) + require.NoError(t, err) + parentHeight := pts.Height() + currentHeight := ts.TipSet.TipSet().Height() + + // CallWithGas calls _at_ the current tipset. ret, err := sm.CallWithGas(ctx, m, nil, ts.TipSet.TipSet()) - switch ts.TipSet.TipSet().Height() { - case testForkHeight, testForkHeight + 1: + if parentHeight <= testForkHeight && currentHeight >= testForkHeight { // If I had a fork, or I _will_ have a fork, it should fail. require.Equal(t, ErrExpensiveFork, err) - default: + } else { require.NoError(t, err) require.True(t, ret.MsgRct.ExitCode.IsSuccess()) } - // Call just runs on the parent state for a tipset, so we only - // expect an error at the fork height. + + // Call always applies the message to the "next block" after the tipset's parent state. ret, err = sm.Call(ctx, m, ts.TipSet.TipSet()) - switch ts.TipSet.TipSet().Height() { - case testForkHeight + 1: + if parentHeight == testForkHeight { require.Equal(t, ErrExpensiveFork, err) - default: + } else { require.NoError(t, err) require.True(t, ret.MsgRct.ExitCode.IsSuccess()) }