From 69c38ac49001a2734ab849f1e5a2e56b82bec9ae Mon Sep 17 00:00:00 2001 From: Liam Lai Date: Wed, 2 Aug 2023 09:27:46 +1000 Subject: [PATCH] fix broken the tests and one bug --- cmd/XDC/chaincmd.go | 4 +--- consensus/XDPoS/engines/engine_v2/epochSwitch.go | 2 +- consensus/tests/engine_v2_tests/adaptor_test.go | 3 +++ consensus/tests/engine_v2_tests/authorised_masternode_test.go | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/XDC/chaincmd.go b/cmd/XDC/chaincmd.go index 3abbf64940..2f18dae196 100644 --- a/cmd/XDC/chaincmd.go +++ b/cmd/XDC/chaincmd.go @@ -25,9 +25,6 @@ import ( "sync/atomic" "time" - "github.com/XinFinOrg/XDPoSChain/core/rawdb" - "github.com/XinFinOrg/XDPoSChain/metrics" - "github.com/XinFinOrg/XDPoSChain/cmd/utils" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/console" @@ -38,6 +35,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/eth/downloader" "github.com/XinFinOrg/XDPoSChain/event" "github.com/XinFinOrg/XDPoSChain/log" + "github.com/XinFinOrg/XDPoSChain/metrics" "gopkg.in/urfave/cli.v1" ) diff --git a/consensus/XDPoS/engines/engine_v2/epochSwitch.go b/consensus/XDPoS/engines/engine_v2/epochSwitch.go index 7b6e50b94b..2f699b1229 100644 --- a/consensus/XDPoS/engines/engine_v2/epochSwitch.go +++ b/consensus/XDPoS/engines/engine_v2/epochSwitch.go @@ -57,7 +57,7 @@ func (x *XDPoS_v2) getEpochSwitchInfo(chain consensus.ChainReader, header *types return nil, err } - snap, err := x.getSnapshot(chain, header.Number.Uint64(), false) + snap, err := x.getSnapshot(chain, h.Number.Uint64(), false) if err != nil { log.Error("[getEpochSwitchInfo] Adaptor v2 getSnapshot has error", "err", err) return nil, err diff --git a/consensus/tests/engine_v2_tests/adaptor_test.go b/consensus/tests/engine_v2_tests/adaptor_test.go index 564a16f585..46f56485e3 100644 --- a/consensus/tests/engine_v2_tests/adaptor_test.go +++ b/consensus/tests/engine_v2_tests/adaptor_test.go @@ -184,6 +184,7 @@ func TestAdaptorGetMasternodesV2(t *testing.T) { // block 901 is the first v2 block, and is treated as epoch switch block err := blockchain.InsertBlock(currentBlock) + adaptor.Initial(blockchain, currentBlock.Header()) assert.Nil(t, err) masternodes1 := adaptor.GetMasternodes(blockchain, currentBlock.Header()) assert.Equal(t, 5, len(masternodes1)) @@ -216,6 +217,8 @@ func TestGetCurrentEpochSwitchBlock(t *testing.T) { currentBlock = CreateBlock(blockchain, params.TestXDPoSMockChainConfig, currentBlock, blockNum, 1, blockCoinBase, signer, signFn, nil, nil, "") err = blockchain.InsertBlock(currentBlock) assert.Nil(t, err) + adaptor.Initial(blockchain, currentBlock.Header()) + currentCheckpointNumber, epochNum, err = adaptor.GetCurrentEpochSwitchBlock(blockchain, currentBlock.Number()) assert.Nil(t, err) assert.Equal(t, uint64(901), currentCheckpointNumber) diff --git a/consensus/tests/engine_v2_tests/authorised_masternode_test.go b/consensus/tests/engine_v2_tests/authorised_masternode_test.go index adf0e38b97..1fd672bcc7 100644 --- a/consensus/tests/engine_v2_tests/authorised_masternode_test.go +++ b/consensus/tests/engine_v2_tests/authorised_masternode_test.go @@ -43,6 +43,8 @@ func TestIsYourTurnConsensusV2(t *testing.T) { currentBlockHeader.Time = big.NewInt(time.Now().Unix()) err := blockchain.InsertBlock(currentBlock) assert.Nil(t, err) + adaptor.Initial(blockchain, currentBlockHeader) + // Less then Mine Period isYourTurn, err := adaptor.YourTurn(blockchain, currentBlockHeader, common.HexToAddress("xdc0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e")) assert.Nil(t, err)