From 29afe082ebbe2b02cea8cb1b1a55ac7a5e887361 Mon Sep 17 00:00:00 2001 From: Ribao Wei Date: Tue, 10 Dec 2019 13:22:15 -0800 Subject: [PATCH] Fix unit tests. --- consensus/engine_test.go | 3 +-- crypto/bn256/google/main_test.go | 2 +- netsync/sync_test.go | 13 +++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/consensus/engine_test.go b/consensus/engine_test.go index 7e8961f4..c5a9f812 100644 --- a/consensus/engine_test.go +++ b/consensus/engine_test.go @@ -213,7 +213,6 @@ func TestSingleBlockValidation(t *testing.T) { require.Equal("Invalid proposer", res.Message) } -/* func TestValidParent(t *testing.T) { require := require.New(t) @@ -265,6 +264,7 @@ func TestValidParent(t *testing.T) { eb2, err := chain.AddBlock(b2) require.Nil(err) + eb1 = chain.MarkBlockInvalid(eb1.Hash()) res := ce.validateBlock(b2, eb1) require.True(res.IsError(), "Parent block is invalid") require.Equal("Parent block is invalid", res.Message) @@ -296,7 +296,6 @@ func TestValidParent(t *testing.T) { res = ce.validateBlock(b3, eb2) require.True(res.IsOK(), "HCC is valid") } -*/ func TestChildBlockOfValidatorChange(t *testing.T) { require := require.New(t) diff --git a/crypto/bn256/google/main_test.go b/crypto/bn256/google/main_test.go index 0230f1b1..c0c85457 100644 --- a/crypto/bn256/google/main_test.go +++ b/crypto/bn256/google/main_test.go @@ -13,7 +13,7 @@ func TestRandomG2Marshal(t *testing.T) { t.Error(err) continue } - t.Logf("%d: %x\n", n, g2.Marshal()) + t.Logf("%v: %x\n", n, g2.Marshal()) } } diff --git a/netsync/sync_test.go b/netsync/sync_test.go index f966ad98..16cb5f9a 100644 --- a/netsync/sync_test.go +++ b/netsync/sync_test.go @@ -3,6 +3,12 @@ package netsync import ( "context" "testing" + "time" + + "github.com/thetatoken/theta/consensus" + "github.com/thetatoken/theta/rlp" + "github.com/thetatoken/theta/store/database/backend" + "github.com/thetatoken/theta/store/kvstore" "github.com/thetatoken/theta/core" "github.com/thetatoken/theta/crypto" @@ -52,7 +58,6 @@ func (m *MockMsgHandler) HandleMessage(message types.Message) error { return nil } -/* func TestSyncManager(t *testing.T) { assert := assert.New(t) core.ResetTestBlocks() @@ -104,6 +109,11 @@ func TestSyncManager(t *testing.T) { assert.Equal(common.ChannelIDBlock, msg1.ChannelID) assert.Equal(core.GetTestBlock("A4").Hash().Hex(), msg1.Entries[0]) + res = <-mockMsgHandler.C + msg11, ok := res.(dispatcher.DataResponse) + assert.True(ok) + assert.Equal(common.ChannelIDHeader, msg11.ChannelID) + res = <-mockMsgHandler.C msg2, ok := res.(dispatcher.InventoryRequest) assert.True(ok) @@ -160,7 +170,6 @@ func TestSyncManager(t *testing.T) { assert.Equal(core.GetTestBlock(expected[i]).Hash(), msg.(*core.Block).Hash()) } } -*/ type MockConsensus struct { chain *blockchain.Chain