MCPcopy Create free account
hub / github.com/CPChain/chain / TestBlocksInsertNonceError

Function TestBlocksInsertNonceError

core/blockchain_test.go:417–455  ·  view source on GitHub ↗

Tests that the insertion functions detect banned hashes. func TestBadBlockHashes(t *testing.T) { // Create a pristine chain and database db := database.NewMemDatabase() blockchain, err := newCanonical(fakeDpor(db), 0, db) if err != nil { t.Fatalf("failed to create pristine chain: %v", err) }

(t *testing.T)

Source from the content-addressed store, hash-verified

415
416// Tests chain insertions in the face of one entity containing an invalid nonce.
417func TestBlocksInsertNonceError(t *testing.T) {
418 t.Skip("===TestBlocksInsertNonceError invalid block in chain")
419 for i := 1; i < 25 && !t.Failed(); i++ {
420 // Create a pristine chain and database
421 db := database.NewMemDatabase()
422 blockchain, err := newCanonical(fakeDpor(db), 0, db)
423 if err != nil {
424 t.Fatalf("failed to create pristine chain: %v", err)
425 }
426 defer blockchain.Stop()
427
428 // Create and insert a chain with a failing nonce
429 var (
430 failAt int
431 failRes int
432 failNum uint64
433 )
434 blocks := makeBlockChain(blockchain.CurrentBlock(), i, fakeDpor(db), db, 0)
435
436 failAt = rand.Int() % len(blocks)
437 failNum = blocks[failAt].NumberU64()
438
439 config := configs.ChainConfigInfo().Dpor
440 d := dpor.NewFakeFailer(config, db, failNum)
441
442 blockchain.engine = d
443 failRes, err = blockchain.InsertChain(blocks)
444 // Check that the returned error indicates the failure.
445 if failRes != failAt {
446 t.Errorf("test %d: failure index mismatch: have %d, want %d", i, failRes, failAt)
447 }
448 // Check that all no blocks after the failing block have been inserted.
449 for j := 0; j < i-failAt; j++ {
450 if block := blockchain.GetBlockByNumber(failNum + uint64(j)); block != nil {
451 t.Errorf("test %d: invalid block in chain: %v", i, block)
452 }
453 }
454 }
455}
456
457// Tests that chain reorganisations handle transaction removals and reinsertions.
458func TestChainTxReorgs(t *testing.T) {

Callers

nothing calls this directly

Calls 9

newCanonicalFunction · 0.85
fakeDporFunction · 0.85
makeBlockChainFunction · 0.85
NumberU64Method · 0.80
ChainConfigInfoMethod · 0.80
StopMethod · 0.65
CurrentBlockMethod · 0.65
InsertChainMethod · 0.65
GetBlockByNumberMethod · 0.65

Tested by

no test coverage detected