File tree Expand file tree Collapse file tree 4 files changed +13
-7
lines changed Expand file tree Collapse file tree 4 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export interface BlockchainInterface {
41
41
* @param onBlock - Function called on each block with params (block: Block,
42
42
* reorg: boolean)
43
43
*/
44
- iterator ( name : string , onBlock : OnBlock ) : Promise < void | number >
44
+ iterator ( name : string , onBlock : OnBlock ) : Promise < number >
45
45
}
46
46
47
47
/**
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export class VMExecution extends Execution {
24
24
25
25
public receiptsManager ?: ReceiptsManager
26
26
private pendingReceipts ?: Map < string , TxReceipt [ ] >
27
- private vmPromise ?: Promise < number | undefined >
27
+ private vmPromise ?: Promise < number >
28
28
29
29
/** Number of maximum blocks to run per iteration of {@link VMExecution.run} */
30
30
private NUM_BLOCKS_PER_ITERATION = 50
@@ -154,7 +154,6 @@ export class VMExecution extends Execution {
154
154
headBlock = undefined
155
155
parentState = undefined
156
156
errorBlock = undefined
157
-
158
157
this . vmPromise = blockchain . iterator (
159
158
'vm' ,
160
159
async ( block : Block , reorg : boolean ) => {
@@ -242,15 +241,15 @@ export class VMExecution extends Execution {
242
241
} ,
243
242
this . NUM_BLOCKS_PER_ITERATION
244
243
)
245
- numExecuted = ( await this . vmPromise ) as number
244
+ numExecuted = await this . vmPromise
246
245
247
246
if ( errorBlock ) {
248
247
await this . chain . blockchain . setIteratorHead ( 'vm' , ( errorBlock as Block ) . header . parentHash )
249
248
return 0
250
249
}
251
250
252
251
const endHeadBlock = await this . vm . blockchain . getIteratorHead ( 'vm' )
253
- if ( numExecuted > 0 ) {
252
+ if ( numExecuted && numExecuted > 0 ) {
254
253
const firstNumber = startHeadBlock . header . number
255
254
const firstHash = short ( startHeadBlock . hash ( ) )
256
255
const lastNumber = endHeadBlock . header . number
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export default async function runBlockchain(
9
9
this : VM ,
10
10
blockchain ?: Blockchain ,
11
11
maxBlocks ?: number
12
- ) : Promise < void | number > {
12
+ ) : Promise < number > {
13
13
let headBlock : Block
14
14
let parentState : Buffer
15
15
Original file line number Diff line number Diff line change @@ -101,6 +101,9 @@ tape('runBlockchain', (t) => {
101
101
102
102
await vm . runBlockchain ( )
103
103
104
+ const head = await vm . blockchain . getIteratorHead ( )
105
+ st . equal ( head . hash ( ) . toString ( 'hex' ) , testData . blocks [ 0 ] . blockHeader . hash . slice ( 2 ) )
106
+
104
107
st . end ( )
105
108
} )
106
109
@@ -138,12 +141,16 @@ tape('runBlockchain', (t) => {
138
141
await blockchain . putBlock ( b2 )
139
142
await blockchain . putBlock ( b3 )
140
143
144
+ let head = await blockchain . getIteratorHead ( )
145
+ st . deepEqual ( head . hash ( ) , genesisBlock . hash ( ) , 'Iterator head should still be at genesis' )
146
+
141
147
try {
142
148
await vm . runBlockchain ( )
143
149
st . fail ( 'should have returned error' )
144
150
} catch ( e : any ) {
145
151
st . equal ( e . message , 'test' )
146
-
152
+ head = await blockchain . getIteratorHead ( )
153
+ st . deepEqual ( head . hash ( ) , b2 . hash ( ) , 'should have removed invalid block from head' )
147
154
st . end ( )
148
155
}
149
156
} )
You can’t perform that action at this time.
0 commit comments