From c8ee8e193681fd78de4284a45e9753d3b6a3bf28 Mon Sep 17 00:00:00 2001 From: Jianrong Date: Sat, 16 Oct 2021 13:22:48 +1100 Subject: [PATCH] add a simple test to verify DB is the same across different engine versions --- consensus/XDPoS/XDPoS.go | 2 ++ consensus/XDPoS/XDPoS_test.go | 15 +++++++++++++-- consensus/consensus.go | 3 ++- go.sum | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/consensus/XDPoS/XDPoS.go b/consensus/XDPoS/XDPoS.go index 676af62913..0f0437db97 100644 --- a/consensus/XDPoS/XDPoS.go +++ b/consensus/XDPoS/XDPoS.go @@ -72,6 +72,7 @@ func New(config *params.XDPoSConfig, db ethdb.Database) *XDPoS { return &XDPoS{ config: &conf, + db: db, signingTxsCache: signingTxsCache, EngineV1: *engine_v1.New(&conf, db), @@ -89,6 +90,7 @@ func NewFaker(db ethdb.Database) *XDPoS { fakeEngine = &XDPoS{ config: conf, + db: db, signingTxsCache: signingTxsCache, EngineV1: *engine_v1.NewFaker(db), diff --git a/consensus/XDPoS/XDPoS_test.go b/consensus/XDPoS/XDPoS_test.go index 8ceb83eb29..0d36c8a05b 100644 --- a/consensus/XDPoS/XDPoS_test.go +++ b/consensus/XDPoS/XDPoS_test.go @@ -1,7 +1,18 @@ package XDPoS -import "testing" +import ( + "testing" -func TestNewAdaptorShallContainMultipleConsensusEngine(t *testing.T) { + "github.com/XinFinOrg/XDPoSChain/core/rawdb" + "github.com/XinFinOrg/XDPoSChain/params" + "github.com/stretchr/testify/assert" +) +func TestAdaptorShouldShareDbWithV1Engine(t *testing.T) { + database := rawdb.NewMemoryDatabase() + config := params.TestXDPoSMockChainConfig.XDPoS + engine := New(config, database) + + assert := assert.New(t) + assert.Equal(engine.EngineV1.GetDb(), engine.GetDb()) } diff --git a/consensus/consensus.go b/consensus/consensus.go index 7ce64f0973..080b22406f 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -18,12 +18,13 @@ package consensus import ( + "math/big" + "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/types" "github.com/XinFinOrg/XDPoSChain/params" "github.com/XinFinOrg/XDPoSChain/rpc" - "math/big" ) // ChainReader defines a small collection of methods needed to access the local diff --git a/go.sum b/go.sum index 783745877f..31f624f0e8 100644 --- a/go.sum +++ b/go.sum @@ -255,6 +255,7 @@ github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8 github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 h1:njlZPzLwU639dk2kqnCPPv+wNjq7Xb6EfUxe/oX0/NM= github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=