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)
| 415 | |
| 416 | // Tests chain insertions in the face of one entity containing an invalid nonce. |
| 417 | func 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. |
| 458 | func TestChainTxReorgs(t *testing.T) { |
nothing calls this directly
no test coverage detected