aboutsummaryrefslogtreecommitdiffstats
path: root/core/test
diff options
context:
space:
mode:
Diffstat (limited to 'core/test')
-rw-r--r--core/test/app.go19
-rw-r--r--core/test/app_test.go24
-rw-r--r--core/test/governance.go5
-rw-r--r--core/test/governance_test.go8
-rw-r--r--core/test/stopper_test.go4
5 files changed, 37 insertions, 23 deletions
diff --git a/core/test/app.go b/core/test/app.go
index dbee059..515ed23 100644
--- a/core/test/app.go
+++ b/core/test/app.go
@@ -110,21 +110,28 @@ type App struct {
DeliverSequence common.Hashes
deliveredLock sync.RWMutex
state *State
+ gov *Governance
lastPendingHeightLock sync.RWMutex
LastPendingHeight uint64
+ roundToNotify uint64
}
// NewApp constructs a TestApp instance.
-func NewApp(state *State) *App {
- return &App{
+func NewApp(initRound uint64, gov *Governance) (app *App) {
+ app = &App{
Confirmed: make(map[common.Hash]*types.Block),
LastConfirmedHeights: make(map[uint32]uint64),
TotalOrdered: []*AppTotalOrderRecord{},
TotalOrderedByHash: make(map[common.Hash]*AppTotalOrderRecord),
Delivered: make(map[common.Hash]*AppDeliveredRecord),
DeliverSequence: common.Hashes{},
- state: state,
+ gov: gov,
+ roundToNotify: initRound,
}
+ if gov != nil {
+ app.state = gov.State()
+ }
+ return app
}
// PreparePayload implements Application interface.
@@ -274,6 +281,12 @@ func (app *App) BlockDelivered(
panic(err)
}
}
+ if app.roundToNotify == pos.Round {
+ if app.gov != nil {
+ app.gov.NotifyRound(app.roundToNotify)
+ app.roundToNotify++
+ }
+ }
}()
}
diff --git a/core/test/app_test.go b/core/test/app_test.go
index 21c9a81..5ed562a 100644
--- a/core/test/app_test.go
+++ b/core/test/app_test.go
@@ -91,12 +91,12 @@ func (s *AppTestSuite) deliverBlock(
func (s *AppTestSuite) TestCompare() {
req := s.Require()
- app1 := NewApp(nil)
+ app1 := NewApp(0, nil)
s.setupAppByTotalOrderDeliver(app1, s.to1)
s.setupAppByTotalOrderDeliver(app1, s.to2)
s.setupAppByTotalOrderDeliver(app1, s.to3)
// An App with different deliver sequence.
- app2 := NewApp(nil)
+ app2 := NewApp(0, nil)
s.setupAppByTotalOrderDeliver(app2, s.to1)
s.setupAppByTotalOrderDeliver(app2, s.to2)
hash := common.NewRandomHash()
@@ -105,7 +105,7 @@ func (s *AppTestSuite) TestCompare() {
s.deliverBlockWithTimeFromSequenceLength(app2, hash)
req.Equal(ErrMismatchBlockHashSequence, app1.Compare(app2))
// An App with different consensus time for the same block.
- app3 := NewApp(nil)
+ app3 := NewApp(0, nil)
s.setupAppByTotalOrderDeliver(app3, s.to1)
s.setupAppByTotalOrderDeliver(app3, s.to2)
for _, h := range s.to3.BlockHashes {
@@ -120,7 +120,7 @@ func (s *AppTestSuite) TestCompare() {
req.Equal(ErrMismatchConsensusTime, app1.Compare(app3))
req.Equal(ErrMismatchConsensusTime, app3.Compare(app1))
// An App without any delivered blocks.
- app4 := NewApp(nil)
+ app4 := NewApp(0, nil)
req.Equal(ErrEmptyDeliverSequence, app4.Compare(app1))
req.Equal(ErrEmptyDeliverSequence, app1.Compare(app4))
}
@@ -129,7 +129,7 @@ func (s *AppTestSuite) TestVerify() {
req := s.Require()
// An OK App instance.
- app1 := NewApp(nil)
+ app1 := NewApp(0, nil)
s.setupAppByTotalOrderDeliver(app1, s.to1)
s.setupAppByTotalOrderDeliver(app1, s.to2)
s.setupAppByTotalOrderDeliver(app1, s.to3)
@@ -139,7 +139,7 @@ func (s *AppTestSuite) TestVerify() {
uint64(len(app1.DeliverSequence)))
req.Equal(ErrDeliveredBlockNotConfirmed, app1.Verify())
// The consensus time is out of order.
- app2 := NewApp(nil)
+ app2 := NewApp(0, nil)
s.setupAppByTotalOrderDeliver(app2, s.to1)
for _, h := range s.to2.BlockHashes {
app2.BlockConfirmed(types.Block{Hash: h})
@@ -149,14 +149,14 @@ func (s *AppTestSuite) TestVerify() {
uint64(len(app2.DeliverSequence)+1))
req.Equal(ErrConsensusTimestampOutOfOrder, app2.Verify())
// A delivered block is not found in total ordering delivers.
- app3 := NewApp(nil)
+ app3 := NewApp(0, nil)
s.setupAppByTotalOrderDeliver(app3, s.to1)
hash := common.NewRandomHash()
app3.BlockConfirmed(types.Block{Hash: hash})
s.deliverBlockWithTimeFromSequenceLength(app3, hash)
req.Equal(ErrMismatchTotalOrderingAndDelivered, app3.Verify())
// A delivered block is not found in total ordering delivers.
- app4 := NewApp(nil)
+ app4 := NewApp(0, nil)
s.setupAppByTotalOrderDeliver(app4, s.to1)
for _, h := range s.to2.BlockHashes {
app4.BlockConfirmed(types.Block{Hash: h})
@@ -167,10 +167,10 @@ func (s *AppTestSuite) TestVerify() {
app4.TotalOrderingDelivered(common.Hashes{hash}, core.TotalOrderingModeNormal)
s.deliverBlockWithTimeFromSequenceLength(app4, hash)
// Witness ack on unknown block.
- app5 := NewApp(nil)
+ app5 := NewApp(0, nil)
s.setupAppByTotalOrderDeliver(app5, s.to1)
// The conensus height is out of order.
- app6 := NewApp(nil)
+ app6 := NewApp(0, nil)
s.setupAppByTotalOrderDeliver(app6, s.to1)
for _, h := range s.to2.BlockHashes {
app6.BlockConfirmed(types.Block{Hash: h})
@@ -181,7 +181,7 @@ func (s *AppTestSuite) TestVerify() {
uint64(len(app6.DeliverSequence)+2))
req.Equal(ErrConsensusHeightOutOfOrder, app6.Verify())
// Test the acking block doesn't delivered.
- app7 := NewApp(nil)
+ app7 := NewApp(0, nil)
// Patch a block's acks.
b7 := &types.Block{
Hash: common.NewRandomHash(),
@@ -199,7 +199,7 @@ func (s *AppTestSuite) TestVerify() {
func (s *AppTestSuite) TestWitness() {
// Deliver several blocks, there is only one chain only.
- app := NewApp(nil)
+ app := NewApp(0, nil)
deliver := func(b *types.Block) {
app.BlockConfirmed(*b)
app.BlockDelivered(b.Hash, b.Position, b.Finalization)
diff --git a/core/test/governance.go b/core/test/governance.go
index 5cf9732..81ced54 100644
--- a/core/test/governance.go
+++ b/core/test/governance.go
@@ -93,8 +93,9 @@ func (g *Governance) CRS(round uint64) common.Hash {
return g.stateModule.CRS(round)
}
-// NotifyRoundHeight notifies governace contract to snapshot config.
-func (g *Governance) NotifyRoundHeight(round, height uint64) {
+// NotifyRound notifies governace contract to snapshot config, and broadcast
+// pending state change requests for next round if any.
+func (g *Governance) NotifyRound(round uint64) {
// Snapshot configuration for the shifted round, this behavior is synced with
// full node's implementation.
shiftedRound := round + g.roundShift
diff --git a/core/test/governance_test.go b/core/test/governance_test.go
index 30f1469..cef2aea 100644
--- a/core/test/governance_test.go
+++ b/core/test/governance_test.go
@@ -87,13 +87,13 @@ func (s *GovernanceTestSuite) TestRegisterChange() {
req.NoError(g.RegisterConfigChange(7, StateChangeNumChains, uint32(40)))
// In local mode, state for round 6 would be ready after notified with
// round 2.
- g.NotifyRoundHeight(2, 0)
- g.NotifyRoundHeight(3, 0)
+ g.NotifyRound(2)
+ g.NotifyRound(3)
// In local mode, state for round 7 would be ready after notified with
// round 6.
- g.NotifyRoundHeight(4, 0)
+ g.NotifyRound(4)
// Notify governance to take a snapshot for round 7's configuration.
- g.NotifyRoundHeight(5, 0)
+ g.NotifyRound(5)
req.Equal(g.Configuration(6).NumChains, uint32(32))
req.Equal(g.Configuration(7).NumChains, uint32(40))
}
diff --git a/core/test/stopper_test.go b/core/test/stopper_test.go
index d296727..758a0e4 100644
--- a/core/test/stopper_test.go
+++ b/core/test/stopper_test.go
@@ -70,7 +70,7 @@ func (s *StopperTestSuite) TestStopByConfirmedBlocks() {
nodes = GenerateRandomNodeIDs(2)
)
for _, nID := range nodes {
- apps[nID] = NewApp(nil)
+ apps[nID] = NewApp(0, nil)
dbInst, err := db.NewMemBackedDB()
req.NoError(err)
dbInsts[nID] = dbInst
@@ -118,7 +118,7 @@ func (s *StopperTestSuite) TestStopByRound() {
nodes = GenerateRandomNodeIDs(2)
)
for _, nID := range nodes {
- apps[nID] = NewApp(nil)
+ apps[nID] = NewApp(0, nil)
dbInst, err := db.NewMemBackedDB()
req.NoError(err)
dbInsts[nID] = dbInst