-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathblockchain_reactor_test.go
61 lines (54 loc) · 1.91 KB
/
blockchain_reactor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2021 The Alaya Network Authors
// This file is part of the Alaya-Go library.
//
// The Alaya-Go 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 Alaya-Go 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 Alaya-Go library. If not, see <http://www.gnu.org/licenses/>.
package core
import (
"math/big"
"testing"
"time"
"github.com/AlayaNetwork/Alaya-Go/common"
"github.com/AlayaNetwork/Alaya-Go/core/cbfttypes"
"github.com/AlayaNetwork/Alaya-Go/core/snapshotdb"
"github.com/AlayaNetwork/Alaya-Go/core/types"
"github.com/AlayaNetwork/Alaya-Go/event"
)
func TestBlockChainReactorClose(t *testing.T) {
t.Run("close after commit", func(t *testing.T) {
eventmux := new(event.TypeMux)
reacter := NewBlockChainReactor(eventmux, big.NewInt(100))
reacter.Start(common.PPOS_VALIDATOR_MODE)
var parenthash common.Hash
cbftress := make(chan cbfttypes.CbftResult, 5)
go func() {
for i := 1; i < 11; i++ {
header := new(types.Header)
header.Number = big.NewInt(int64(i))
header.Time = uint64(i)
header.ParentHash = parenthash
block := types.NewBlock(header, nil, nil)
snapshotdb.Instance().NewBlock(header.Number, header.ParentHash, block.Hash())
parenthash = block.Hash()
cbftress <- cbfttypes.CbftResult{Block: block}
}
close(cbftress)
}()
for value := range cbftress {
eventmux.Post(value)
}
reacter.Close()
time.Sleep(time.Second)
snapshotdb.Instance().Clear()
})
}