@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/facebookgo/clock"
14
14
"github.com/iotexproject/go-pkgs/crypto"
15
+ "github.com/iotexproject/go-pkgs/hash"
15
16
"github.com/iotexproject/iotex-proto/golang/iotextypes"
16
17
"github.com/pkg/errors"
17
18
"github.com/stretchr/testify/require"
@@ -25,6 +26,7 @@ import (
25
26
"github.com/iotexproject/iotex-core/v2/db"
26
27
"github.com/iotexproject/iotex-core/v2/endorsement"
27
28
"github.com/iotexproject/iotex-core/v2/state"
29
+ "github.com/iotexproject/iotex-core/v2/state/factory"
28
30
"github.com/iotexproject/iotex-core/v2/test/identityset"
29
31
)
30
32
@@ -159,7 +161,7 @@ func TestCheckVoteEndorser(t *testing.T) {
159
161
func TestCheckBlockProposer (t * testing.T ) {
160
162
require := require .New (t )
161
163
g := genesis .TestDefault ()
162
- b , sf , _ , rp , pp := makeChain (t )
164
+ b , sf , ap , rp , pp := makeChain (t )
163
165
c := clock .New ()
164
166
g .Blockchain .BlockInterval = time .Second * 20
165
167
delegatesByEpochFunc := func (epochnum uint64 , _ []byte ) ([]string , error ) {
@@ -203,7 +205,7 @@ func TestCheckBlockProposer(t *testing.T) {
203
205
true ,
204
206
time .Second ,
205
207
true ,
206
- NewChainManager (b , sf , & dummyBlockBuildFactory {} ),
208
+ NewChainManager (b , sf , factory . NewMinter ( sf , ap ) ),
207
209
block .NewDeserializer (0 ),
208
210
rp ,
209
211
nil ,
@@ -215,7 +217,8 @@ func TestCheckBlockProposer(t *testing.T) {
215
217
)
216
218
require .NoError (err )
217
219
require .NotNil (rctx )
218
- block := getBlockforctx (t , 0 , false )
220
+ prevHash := b .TipHash ()
221
+ block := getBlockforctx (t , 0 , false , prevHash )
219
222
en := endorsement .NewEndorsement (time .Unix (1596329600 , 0 ), identityset .PrivateKey (10 ).PublicKey (), nil )
220
223
bp := newBlockProposal (& block , []* endorsement.Endorsement {en })
221
224
@@ -240,20 +243,20 @@ func TestCheckBlockProposer(t *testing.T) {
240
243
require .Error (rctx .CheckBlockProposer (51 , bp , en ))
241
244
242
245
// case 6:invalid block signature
243
- block = getBlockforctx (t , 1 , false )
246
+ block = getBlockforctx (t , 1 , false , prevHash )
244
247
en = endorsement .NewEndorsement (time .Unix (1596329600 , 0 ), identityset .PrivateKey (1 ).PublicKey (), nil )
245
248
bp = newBlockProposal (& block , []* endorsement.Endorsement {en })
246
249
require .Error (rctx .CheckBlockProposer (51 , bp , en ))
247
250
248
251
// case 7:invalid endorsement for the vote when call AddVoteEndorsement
249
- block = getBlockforctx (t , 1 , true )
252
+ block = getBlockforctx (t , 1 , true , prevHash )
250
253
en = endorsement .NewEndorsement (time .Unix (1596329600 , 0 ), identityset .PrivateKey (1 ).PublicKey (), nil )
251
254
en2 := endorsement .NewEndorsement (time .Unix (1596329600 , 0 ), identityset .PrivateKey (7 ).PublicKey (), nil )
252
255
bp = newBlockProposal (& block , []* endorsement.Endorsement {en2 , en })
253
256
require .Error (rctx .CheckBlockProposer (51 , bp , en2 ))
254
257
255
258
// case 8:Insufficient endorsements
256
- block = getBlockforctx (t , 1 , true )
259
+ block = getBlockforctx (t , 1 , true , prevHash )
257
260
hash := block .HashBlock ()
258
261
vote := NewConsensusVote (hash [:], COMMIT )
259
262
ens , err := endorsement .Endorse (vote , time .Unix (1562382592 , 0 ), identityset .PrivateKey (7 ))
@@ -263,7 +266,7 @@ func TestCheckBlockProposer(t *testing.T) {
263
266
require .Error (rctx .CheckBlockProposer (51 , bp , ens [0 ]))
264
267
265
268
// case 9:normal
266
- block = getBlockforctx (t , 1 , true )
269
+ block = getBlockforctx (t , 1 , true , prevHash )
267
270
bp = newBlockProposal (& block , []* endorsement.Endorsement {en })
268
271
require .NoError (rctx .CheckBlockProposer (51 , bp , en ))
269
272
}
@@ -349,14 +352,14 @@ func TestNotProducingMultipleBlocks(t *testing.T) {
349
352
require .Equal (height1 , height2 )
350
353
}
351
354
352
- func getBlockforctx (t * testing.T , i int , sign bool ) block.Block {
355
+ func getBlockforctx (t * testing.T , i int , sign bool , prevHash hash. Hash256 ) block.Block {
353
356
require := require .New (t )
354
357
ts := & timestamppb.Timestamp {Seconds : 1596329600 , Nanos : 10 }
355
358
hcore := & iotextypes.BlockHeaderCore {
356
359
Version : 1 ,
357
360
Height : 51 ,
358
361
Timestamp : ts ,
359
- PrevBlockHash : [] byte ( "" ) ,
362
+ PrevBlockHash : prevHash [:] ,
360
363
TxRoot : []byte ("" ),
361
364
DeltaStateDigest : []byte ("" ),
362
365
ReceiptRoot : []byte ("" ),
0 commit comments