From a2978b4b10dc480ebccdbe1ee954e8ec5df5993f Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 30 Sep 2022 12:30:51 +0200 Subject: [PATCH] fix up e2e tests --- consensus/replay.go | 2 +- state/execution.go | 14 +++++++------- state/execution_test.go | 10 +++++----- test/e2e/tests/app_test.go | 21 ++++++++++++++------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/consensus/replay.go b/consensus/replay.go index 0368084cd..3dd198cee 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -469,7 +469,7 @@ func (h *Handshaker) replayBlocks( assertAppHashEqualsOneFromBlock(appHash, block) } - err = sm.ExecCommitBlock(proxyApp.Consensus(), block, h.logger, h.stateStore, h.genDoc.InitialHeight) + appHash, err = sm.ExecCommitBlock(proxyApp.Consensus(), block, h.logger, h.stateStore, h.genDoc.InitialHeight) if err != nil { return nil, err } diff --git a/state/execution.go b/state/execution.go index 20706f981..7db82dc31 100644 --- a/state/execution.go +++ b/state/execution.go @@ -570,19 +570,19 @@ func ExecCommitBlock( logger log.Logger, store Store, initialHeight int64, -) error { - _, err := execBlockOnProxyApp(logger, appConnConsensus, block, store, initialHeight) +) ([]byte, error) { + resp, err := execBlockOnProxyApp(logger, appConnConsensus, block, store, initialHeight) if err != nil { logger.Error("failed executing block on proxy app", "height", block.Height, "err", err) - return err + return nil, err } // Commit block, get hash back - res, err := appConnConsensus.Commit(context.TODO()) + _, err = appConnConsensus.Commit(context.TODO()) if err != nil { - logger.Error("client error during proxyAppConn.CommitSync", "err", res) - return err + logger.Error("client error during proxyAppConn.CommitSync", "err", err) + return nil, err } - return nil + return resp.AgreedAppData, nil } diff --git a/state/execution_test.go b/state/execution_test.go index fa5c56908..949d98601 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -74,8 +74,8 @@ func TestApplyBlock(t *testing.T) { assert.EqualValues(t, 1, state.Version.Consensus.App, "App version wasn't updated") } -// TestBeginBlockValidators ensures we send absent validators list. -func TestBeginBlockValidators(t *testing.T) { +// TestFinalizeBlockValidators ensures we send absent validators list. +func TestFinalizeBlockValidators(t *testing.T) { app := &testApp{} cc := proxy.NewLocalClientCreator(app) proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) @@ -121,7 +121,7 @@ func TestBeginBlockValidators(t *testing.T) { // block for height 2 block := makeBlock(state, 2, lastCommit) - err = sm.ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), stateStore, 1) + _, err = sm.ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), stateStore, 1) require.Nil(t, err, tc.desc) // -> app receives a list of validators with a bool indicating if they signed @@ -139,8 +139,8 @@ func TestBeginBlockValidators(t *testing.T) { } } -// TestBeginBlockByzantineValidators ensures we send byzantine validators list. -func TestBeginBlockByzantineValidators(t *testing.T) { +// TestFinalizeBlockByzantineValidators ensures we send byzantine validators list. +func TestFinalizeBlockByzantineValidators(t *testing.T) { app := &testApp{} cc := proxy.NewLocalClientCreator(app) proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) diff --git a/test/e2e/tests/app_test.go b/test/e2e/tests/app_test.go index 8b8d23960..801b5a5c7 100644 --- a/test/e2e/tests/app_test.go +++ b/test/e2e/tests/app_test.go @@ -42,15 +42,22 @@ func TestApp_Hash(t *testing.T) { require.NoError(t, err) require.NotEmpty(t, info.Response.LastBlockAppHash, "expected app to return app hash") - block, err := client.Block(ctx, nil) - require.NoError(t, err) - require.EqualValues(t, info.Response.LastBlockAppHash, block.Block.AppHash, - "app hash does not match last block's app hash") + // In next-block execution, the app hash is stored in the next block + requestedHeight := info.Response.LastBlockHeight + 1 - status, err := client.Status(ctx) + require.Eventually(t, func() bool { + status, err := client.Status(ctx) + require.NoError(t, err) + require.NotZero(t, status.SyncInfo.LatestBlockHeight) + return status.SyncInfo.LatestBlockHeight >= requestedHeight + }, 5*time.Second, 500*time.Millisecond) + + block, err := client.Block(ctx, &requestedHeight) require.NoError(t, err) - require.EqualValues(t, info.Response.LastBlockAppHash, status.SyncInfo.LatestAppHash, - "app hash does not match node status") + require.Equal(t, + fmt.Sprintf("%x", info.Response.LastBlockAppHash), + fmt.Sprintf("%x", block.Block.AppHash.Bytes()), + "app hash does not match last block's app hash") }) }