diff options
Diffstat (limited to 'core/test')
-rw-r--r-- | core/test/app.go | 19 | ||||
-rw-r--r-- | core/test/app_test.go | 26 |
2 files changed, 45 insertions, 0 deletions
diff --git a/core/test/app.go b/core/test/app.go index ddce31a..e26c20c 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -50,6 +50,10 @@ var ( // and delivered are different. ErrMismatchTotalOrderingAndDelivered = fmt.Errorf( "mismatch total ordering and delivered sequence") + // ErrNotaryAckUnknownBlock means the notary ack is acking on the unknown + // block. + ErrNotaryAckUnknownBlock = fmt.Errorf( + "notary ack on unknown block") ) // AppAckedRecord caches information when this application received @@ -83,6 +87,8 @@ type App struct { Delivered map[common.Hash]*AppDeliveredRecord DeliverSequence common.Hashes deliveredLock sync.RWMutex + NotaryAckSequence []*types.NotaryAck + notaryAckLock sync.RWMutex } // NewApp constructs a TestApp instance. @@ -137,6 +143,10 @@ func (app *App) DeliverBlock(blockHash common.Hash, timestamp time.Time) { // NotaryAckDeliver implements Application interface. func (app *App) NotaryAckDeliver(notaryAck *types.NotaryAck) { + app.notaryAckLock.Lock() + defer app.notaryAckLock.Unlock() + + app.NotaryAckSequence = append(app.NotaryAckSequence, notaryAck) } // Compare performs these checks against another App instance @@ -224,6 +234,15 @@ Loop: // by total ordering. return ErrMismatchTotalOrderingAndDelivered } + + // Make sure that notaryAck is acking the correct block. + app.notaryAckLock.RLock() + defer app.notaryAckLock.RUnlock() + for _, notaryAck := range app.NotaryAckSequence { + if _, exists := app.Delivered[notaryAck.NotaryBlockHash]; !exists { + return ErrNotaryAckUnknownBlock + } + } return nil } diff --git a/core/test/app_test.go b/core/test/app_test.go index f4c4a74..6966de5 100644 --- a/core/test/app_test.go +++ b/core/test/app_test.go @@ -1,3 +1,20 @@ +// Copyright 2018 The dexon-consensus-core Authors +// This file is part of the dexon-consensus-core library. +// +// The dexon-consensus-core library is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the License, +// or (at your option) any later version. +// +// The dexon-consensus-core library is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +// General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the dexon-consensus-core library. If not, see +// <http://www.gnu.org/licenses/>. + package test import ( @@ -5,6 +22,7 @@ import ( "time" "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" ) @@ -135,6 +153,14 @@ func (s *AppTestSuite) TestVerify() { app4.StronglyAcked(hash) app4.TotalOrderingDeliver(common.Hashes{hash}, false) s.deliverBlockWithTimeFromSequenceLength(app4, hash) + // Notary ack on unknown block. + app5 := NewApp() + s.setupAppByTotalOrderDeliver(app5, s.to1) + app5.NotaryAckDeliver(&types.NotaryAck{ + Hash: common.NewRandomHash(), + NotaryBlockHash: common.NewRandomHash(), + }) + req.Equal(ErrNotaryAckUnknownBlock, app5.Verify()) } func TestApp(t *testing.T) { |