@@ -11,9 +11,7 @@ import (
11
11
"encoding/hex"
12
12
"fmt"
13
13
"math/big"
14
- "strings"
15
14
"testing"
16
- "time"
17
15
18
16
"github.com/facebookgo/clock"
19
17
"github.com/stretchr/testify/require"
@@ -644,40 +642,6 @@ func TestBlockchain_Validator(t *testing.T) {
644
642
require .NotNil (t , bc .Validator ())
645
643
}
646
644
647
- func TestBlockchain_MintNewDummyBlock (t * testing.T ) {
648
- cfg := & config .Default
649
- testutil .CleanupPath (t , cfg .Chain .TrieDBPath )
650
- defer testutil .CleanupPath (t , cfg .Chain .TrieDBPath )
651
- testutil .CleanupPath (t , cfg .Chain .ChainDBPath )
652
- defer testutil .CleanupPath (t , cfg .Chain .ChainDBPath )
653
- require := require .New (t )
654
- sf , err := state .NewFactory (cfg , state .DefaultTrieOption ())
655
- require .NoError (err )
656
- require .NoError (sf .Start (context .Background ()))
657
- val := validator {sf , "" }
658
-
659
- ctx := context .Background ()
660
- bc := NewBlockchain (cfg , InMemDaoOption (), InMemStateFactoryOption ())
661
- require .NoError (bc .Start (ctx ))
662
- defer func () {
663
- err := bc .Stop (ctx )
664
- require .Nil (err )
665
- }()
666
- require .NotNil (bc )
667
-
668
- blk := bc .MintNewDummyBlock ()
669
- require .Equal (uint64 (1 ), blk .Height ())
670
- tipHash := bc .TipHash ()
671
- require .NoError (val .Validate (blk , 0 , tipHash , true ))
672
- tsf , _ := action .NewTransfer (1 , big .NewInt (1 ), "" , "" , []byte {}, uint64 (100000 ), big .NewInt (10 ))
673
- blk .Actions = []action.Action {tsf }
674
- err = val .Validate (blk , 0 , tipHash , true )
675
- require .Error (err )
676
- require .True (
677
- strings .Contains (err .Error (), "failed to verify block's signature" ),
678
- )
679
- }
680
-
681
645
func TestBlockchainInitialCandidate (t * testing.T ) {
682
646
require := require .New (t )
683
647
@@ -870,85 +834,6 @@ func TestActions(t *testing.T) {
870
834
require .Nil (val .Validate (blk , 0 , blk .PrevHash (), true ))
871
835
}
872
836
873
- func TestDummyReplacement (t * testing.T ) {
874
- require := require .New (t )
875
- cfg := config .Default
876
-
877
- testutil .CleanupPath (t , testTriePath )
878
- defer testutil .CleanupPath (t , testTriePath )
879
- testutil .CleanupPath (t , testDBPath )
880
- defer testutil .CleanupPath (t , testDBPath )
881
-
882
- cfg .Chain .TrieDBPath = testTriePath
883
- cfg .Chain .ChainDBPath = testDBPath
884
-
885
- sf , _ := state .NewFactory (& cfg , state .InMemTrieOption ())
886
- require .NoError (sf .Start (context .Background ()))
887
- require .NoError (addCreatorToFactory (sf ))
888
-
889
- // Create a blockchain from scratch
890
- bc := NewBlockchain (& cfg , PrecreatedStateFactoryOption (sf ), BoltDBDaoOption ())
891
- require .NoError (bc .Start (context .Background ()))
892
- dummy := bc .MintNewDummyBlock ()
893
- require .Nil (bc .ValidateBlock (dummy , true ))
894
- require .NoError (bc .CommitBlock (dummy ))
895
- actualDummyBlock , err := bc .GetBlockByHeight (1 )
896
- require .NoError (err )
897
- require .Equal (dummy .HashBlock (), actualDummyBlock .HashBlock ())
898
-
899
- chain := bc .(* blockchain )
900
- chain .tipHeight = 0
901
- realBlock , err := bc .MintNewBlock (nil , ta .Addrinfo ["producer" ],
902
- nil , nil , "" )
903
- require .NotNil (realBlock )
904
- require .NoError (err )
905
- require .Nil (bc .ValidateBlock (realBlock , true ))
906
- require .NoError (bc .CommitBlock (realBlock ))
907
- actualRealBlock , err := bc .GetBlockByHeight (1 )
908
- require .NoError (err )
909
- require .Equal (realBlock .HashBlock (), actualRealBlock .HashBlock ())
910
-
911
- block2 , err := bc .MintNewBlock (nil , ta .Addrinfo ["producer" ],
912
- nil , nil , "" )
913
- require .NoError (err )
914
- require .Nil (bc .ValidateBlock (block2 , true ))
915
- require .NoError (bc .CommitBlock (block2 ))
916
- dummyBlock3 := bc .MintNewDummyBlock ()
917
- require .Nil (bc .ValidateBlock (dummyBlock3 , true ))
918
- require .NoError (bc .CommitBlock (dummyBlock3 ))
919
- block4 , err := bc .MintNewBlock (nil , ta .Addrinfo ["producer" ],
920
- nil , nil , "" )
921
- require .NoError (err )
922
- require .NoError (bc .ValidateBlock (block4 , true ))
923
- require .NoError (bc .CommitBlock (block4 ))
924
- actualDummyBlock3 , err := bc .GetBlockByHeight (3 )
925
- require .NoError (err )
926
- require .True (actualDummyBlock3 .IsDummyBlock ())
927
- chain .tipHeight = 2
928
- block3 , err := bc .MintNewBlock (nil , ta .Addrinfo ["producer" ],
929
- nil , nil , "" )
930
- require .NotNil (block3 )
931
- require .NoError (err )
932
- require .NoError (bc .ValidateBlock (block3 , true ))
933
- require .NoError (bc .CommitBlock (block3 ))
934
- actualBlock3 , err := bc .GetBlockByHeight (3 )
935
- require .NoError (err )
936
- require .Equal (block3 .HashBlock (), actualBlock3 .HashBlock ())
937
- }
938
-
939
- func TestMintNewBlock (t * testing.T ) {
940
- t .Parallel ()
941
- cfg := config .Default
942
- clk := clock .NewMock ()
943
- chain := NewBlockchain (& cfg , InMemDaoOption (), InMemStateFactoryOption (), ClockOption (clk ))
944
- require .NoError (t , chain .Start (context .Background ()))
945
- blk1 := chain .MintNewDummyBlock ()
946
- clk .Add (2 * time .Second )
947
- blk2 := chain .MintNewDummyBlock ()
948
- require .Equal (t , uint64 (2 ), blk2 .Header .timestamp - blk1 .Header .timestamp )
949
- require .Equal (t , blk1 .HashBlock (), blk2 .HashBlock ())
950
- }
951
-
952
837
func TestMintDKGBlock (t * testing.T ) {
953
838
require := require .New (t )
954
839
lastSeed , _ := hex .DecodeString ("9de6306b08158c423330f7a27243a1a5cbe39bfd764f07818437882d21241567" )
@@ -1015,10 +900,6 @@ func TestMintDKGBlock(t *testing.T) {
1015
900
}
1016
901
1017
902
// Generate dkg signature for each block
1018
- require .NoError (err )
1019
- dummy := chain .MintNewDummyBlock ()
1020
- require .NoError (chain .ValidateBlock (dummy , true ))
1021
- require .NoError (chain .CommitBlock (dummy ))
1022
903
for i := 1 ; i < numNodes ; i ++ {
1023
904
iotxAddr := iotxaddress.Address {
1024
905
PublicKey : ec283PKList [i ],
@@ -1036,7 +917,7 @@ func TestMintDKGBlock(t *testing.T) {
1036
917
}
1037
918
height , err := chain .GetFactory ().Height ()
1038
919
require .NoError (err )
1039
- require .Equal (uint64 (21 ), height )
920
+ require .Equal (uint64 (20 ), height )
1040
921
candidates , err := chain .CandidatesByHeight (height )
1041
922
require .NoError (err )
1042
923
require .Equal (21 , len (candidates ))
0 commit comments