@@ -27,8 +27,6 @@ import (
27
27
"testing"
28
28
"time"
29
29
30
- "github.com/ethereum/go-ethereum/consensus/clique"
31
-
32
30
"golang.org/x/crypto/sha3"
33
31
34
32
"github.com/ethereum/go-ethereum/common"
@@ -647,118 +645,3 @@ func TestGetRootByDiffHash(t *testing.T) {
647
645
testGetRootByDiffHash (t , chain1 , chain2 , 24 , types .StatusBlockNewer )
648
646
testGetRootByDiffHash (t , chain1 , chain2 , 35 , types .StatusBlockTooNew )
649
647
}
650
-
651
- func newBlockChainWithCliqueEngine (blocks int ) * BlockChain {
652
- signer := types.HomesteadSigner {}
653
- db := rawdb .NewMemoryDatabase ()
654
- engine := clique .New (params .AllCliqueProtocolChanges .Clique , db )
655
- genspec := & Genesis {
656
- //Config: params.TestChainConfig,
657
- ExtraData : make ([]byte , 32 + common .AddressLength + 65 ),
658
- Alloc : GenesisAlloc {testAddr : {Balance : big .NewInt (100000000000000000 )}},
659
- }
660
- copy (genspec .ExtraData [32 :], testAddr [:])
661
- genesis := genspec .MustCommit (db )
662
-
663
- chain , _ := NewBlockChain (db , nil , params .AllCliqueProtocolChanges , engine , vm.Config {}, nil , nil , EnableBlockValidator (params .AllCliqueProtocolChanges , engine , 0 /*LocalVerify*/ , nil ))
664
- generator := func (i int , block * BlockGen ) {
665
- // The chain maker doesn't have access to a chain, so the difficulty will be
666
- // lets unset (nil). Set it here to the correct value.
667
- // block.SetCoinbase(testAddr)
668
- block .SetDifficulty (big .NewInt (2 ))
669
-
670
- for idx , testBlock := range testBlocks {
671
- // Specific block setting, the index in this generator has 1 diff from specified blockNr.
672
- if i + 1 == testBlock .blockNr {
673
- for _ , testTransaction := range testBlock .txs {
674
- var transaction * types.Transaction
675
- if testTransaction .to == nil {
676
- transaction = types .NewContractCreation (block .TxNonce (testAddr ),
677
- testTransaction .value , uint64 (commonGas ), nil , testTransaction .data )
678
- } else {
679
- transaction = types .NewTransaction (block .TxNonce (testAddr ), * testTransaction .to ,
680
- testTransaction .value , uint64 (commonGas ), nil , testTransaction .data )
681
- }
682
- tx , err := types .SignTx (transaction , signer , testKey )
683
- if err != nil {
684
- panic (err )
685
- }
686
- block .AddTxWithChain (chain , tx )
687
- }
688
- break
689
- }
690
-
691
- // Default block setting.
692
- if idx == len (testBlocks )- 1 {
693
- // We want to simulate an empty middle block, having the same state as the
694
- // first one. The last is needs a state change again to force a reorg.
695
- for _ , testTransaction := range testBlocks [0 ].txs {
696
- tx , err := types .SignTx (types .NewTransaction (block .TxNonce (testAddr ), * testTransaction .to ,
697
- testTransaction .value , uint64 (commonGas ), nil , testTransaction .data ), signer , testKey )
698
- if err != nil {
699
- panic (err )
700
- }
701
- block .AddTxWithChain (chain , tx )
702
- }
703
- }
704
- }
705
-
706
- }
707
- bs , _ := GenerateChain (params .AllCliqueProtocolChanges , genesis , engine , db , blocks , generator )
708
- for i , block := range bs {
709
- header := block .Header ()
710
- if i > 0 {
711
- header .ParentHash = bs [i - 1 ].Hash ()
712
- }
713
- header .Extra = make ([]byte , 32 + 65 )
714
- header .Difficulty = big .NewInt (2 )
715
-
716
- sig , _ := crypto .Sign (clique .SealHash (header ).Bytes (), testKey )
717
- copy (header .Extra [len (header .Extra )- 65 :], sig )
718
- bs [i ] = block .WithSeal (header )
719
- }
720
-
721
- if _ , err := chain .InsertChain (bs ); err != nil {
722
- panic (err )
723
- }
724
-
725
- return chain
726
- }
727
-
728
- func TestGenerateDiffLayer (t * testing.T ) {
729
- blockNum := 32
730
- chain := newBlockChainWithCliqueEngine (blockNum )
731
- defer chain .Stop ()
732
-
733
- for blockNr := 1 ; blockNr <= blockNum ; blockNr ++ {
734
- block := chain .GetBlockByNumber (uint64 (blockNr ))
735
- if block == nil {
736
- t .Fatal ("block should not be nil" )
737
- }
738
-
739
- expDiffLayer := chain .GetTrustedDiffLayer (block .Hash ())
740
- if expDiffLayer == nil {
741
- // Skip empty block.
742
- if blockNr == 15 {
743
- continue
744
- }
745
- t .Fatalf ("unexpected nil diff layer, block number: %v, block hash: %v" , blockNr , block .Hash ())
746
- }
747
- expDiffHash , err := CalculateDiffHash (expDiffLayer )
748
- if err != nil {
749
- t .Fatalf ("compute diff hash failed: %v" , err )
750
- }
751
-
752
- diffLayer , err := chain .GenerateDiffLayer (block .Hash ())
753
- if err != nil || diffLayer == nil {
754
- t .Fatalf ("generate diff layer failed: %v" , err )
755
- }
756
- diffHash , err := CalculateDiffHash (diffLayer )
757
- if err != nil {
758
- t .Fatalf ("compute diff hash failed: %v" , err )
759
- }
760
- if expDiffHash != diffHash {
761
- t .Fatalf ("generated wrong diff layer for block: %d, expected hash: %v, real hash: %v" , blockNr , expDiffHash , diffHash )
762
- }
763
- }
764
- }
0 commit comments