@@ -41,8 +41,7 @@ class BranchResolutionSpec
41
41
val headers = getChainHeadersNel(5 , 10 )
42
42
43
43
setGenesisHeader(genesisHeader) // Check genesis block
44
- setBestBlockNumber(10 )
45
- setHeaderByHash(headers.head.parentHash, None )
44
+ setHeaderInChain(headers.head.parentHash, result = false )
46
45
47
46
ledger.resolveBranch(headers) shouldEqual UnknownBranch
48
47
}
@@ -52,21 +51,21 @@ class BranchResolutionSpec
52
51
val headers = getChainHeadersNel(1 , 10 )
53
52
54
53
setBestBlockNumber(10 )
55
- setHeaderByHash (headers.head.parentHash, Some (getBlock( 0 ).header) )
54
+ setHeaderInChain (headers.head.parentHash)
56
55
setChainWeightByHash(headers.head.parentHash, ChainWeight .zero)
57
56
58
57
val oldBlocks = getChain(1 , 10 , headers.head.parentHash, headers.head.difficulty - 1 )
59
58
oldBlocks.map(b => setBlockByNumber(b.header.number, Some (b)))
60
59
61
- ledger.resolveBranch(headers) shouldEqual NewBetterBranch (oldBlocks.toList )
60
+ ledger.resolveBranch(headers) shouldEqual NewBetterBranch (oldBlocks)
62
61
}
63
62
64
63
" report no need for a chain switch the headers do not have chain weight greater than currently known branch" in
65
64
new BranchResolutionTestSetup {
66
65
val headers = getChainHeadersNel(1 , 10 )
67
66
68
67
setBestBlockNumber(10 )
69
- setHeaderByHash (headers.head.parentHash, Some (getBlock( 0 ).header) )
68
+ setHeaderInChain (headers.head.parentHash)
70
69
setChainWeightByHash(headers.head.parentHash, ChainWeight .zero)
71
70
72
71
val oldBlocks = getChain(1 , 10 , headers.head.parentHash, headers.head.difficulty)
@@ -78,6 +77,7 @@ class BranchResolutionSpec
78
77
" correctly handle a branch that goes up to the genesis block" in new BranchResolutionTestSetup {
79
78
val headers = genesisHeader :: getChainHeadersNel(1 , 10 , genesisHeader.hash)
80
79
80
+ setHeaderInChain(genesisHeader.parentHash, result = false )
81
81
setGenesisHeader(genesisHeader)
82
82
setBestBlockNumber(10 )
83
83
setChainWeightByHash(genesisHeader.hash, ChainWeight .zero)
@@ -93,6 +93,7 @@ class BranchResolutionSpec
93
93
val differentGenesis : BlockHeader = genesisHeader.copy(extraData = ByteString (" I'm different ;(" ))
94
94
val headers = differentGenesis :: getChainHeadersNel(1 , 10 , differentGenesis.hash)
95
95
96
+ setHeaderInChain(differentGenesis.parentHash, result = false )
96
97
setGenesisHeader(genesisHeader)
97
98
setBestBlockNumber(10 )
98
99
@@ -104,7 +105,7 @@ class BranchResolutionSpec
104
105
val commonParent = headers.toList(1 )
105
106
106
107
setBestBlockNumber(8 )
107
- setHeaderByHash (headers.head.parentHash, Some (getBlock( 0 ).header) )
108
+ setHeaderInChain (headers.head.parentHash)
108
109
setChainWeightByHash(commonParent.hash, ChainWeight .zero)
109
110
110
111
val oldBlocks = getChain(3 , 8 , commonParent.hash)
@@ -123,7 +124,7 @@ class BranchResolutionSpec
123
124
val longerBranchLowerWeight = getChain(2 , 10 , commonParent.hash, difficulty = 100 )
124
125
val shorterBranchHigherWeight = getChainNel(2 , 8 , commonParent.hash, difficulty = 200 )
125
126
126
- setHeaderByHash (commonParent.hash, Some (commonParent.header) )
127
+ setHeaderInChain (commonParent.hash)
127
128
setChainWeightForBlock(commonParent, parentWeight)
128
129
setBestBlockNumber(longerBranchLowerWeight.last.number)
129
130
longerBranchLowerWeight.foreach(b => setBlockByNumber(b.number, Some (b)))
@@ -150,7 +151,7 @@ class BranchResolutionSpec
150
151
151
152
val noCheckpointBranch = getChain(2 , checkpointBranchLength + 2 , commonParent.hash)
152
153
153
- setHeaderByHash (commonParent.hash, Some (commonParent.header) )
154
+ setHeaderInChain (commonParent.hash)
154
155
setChainWeightForBlock(commonParent, parentWeight)
155
156
setBestBlockNumber(noCheckpointBranch.last.number)
156
157
noCheckpointBranch.foreach(b => setBlockByNumber(b.number, Some (b)))
@@ -176,7 +177,7 @@ class BranchResolutionSpec
176
177
177
178
val noCheckpointBranch = getChainNel(2 , checkpointBranchLength + 2 , commonParent.hash)
178
179
179
- setHeaderByHash (commonParent.hash, Some (commonParent.header) )
180
+ setHeaderInChain (commonParent.hash)
180
181
setChainWeightForBlock(commonParent, parentWeight)
181
182
setBestBlockNumber(checkpointBranch.last.number)
182
183
checkpointBranch.map(b => setBlockByNumber(b.number, Some (b)))
0 commit comments