forked from bcoin-org/bcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain-test.js
887 lines (662 loc) · 21.6 KB
/
chain-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
/* eslint-env mocha */
/* eslint prefer-arrow-callback: "off" */
'use strict';
const assert = require('./util/assert');
const consensus = require('../lib/protocol/consensus');
const Coin = require('../lib/primitives/coin');
const Script = require('../lib/script/script');
const Chain = require('../lib/blockchain/chain');
const WorkerPool = require('../lib/workers/workerpool');
const Miner = require('../lib/mining/miner');
const MTX = require('../lib/primitives/mtx');
const MemWallet = require('./util/memwallet');
const Network = require('../lib/protocol/network');
const Output = require('../lib/primitives/output');
const common = require('../lib/blockchain/common');
const Opcode = require('../lib/script/opcode');
const opcodes = Script.opcodes;
const ZERO_KEY = Buffer.alloc(33, 0x00);
const ONE_HASH = Buffer.alloc(32, 0x00);
ONE_HASH[0] = 0x01;
const network = Network.get('regtest');
const workers = new WorkerPool({
enabled: true
});
const chain = new Chain({
memory: true,
network,
workers
});
const miner = new Miner({
chain,
version: 4,
workers
});
const cpu = miner.cpu;
const wallet = new MemWallet({
network,
witness: false
});
const witWallet = new MemWallet({
network,
witness: true
});
let tip1 = null;
let tip2 = null;
async function addBlock(block, flags) {
let entry;
try {
entry = await chain.add(block, flags);
} catch (e) {
assert.strictEqual(e.type, 'VerifyError');
return e.reason;
}
if (!entry)
return 'bad-prevblk';
return 'OK';
}
async function mineBlock(job, flags) {
const block = await job.mineAsync();
return await addBlock(block, flags);
}
async function mineCSV(fund) {
const job = await cpu.createJob();
const spend = new MTX();
spend.addOutput({
script: [
Opcode.fromInt(1),
Opcode.fromSymbol('checksequenceverify')
],
value: 10000
});
spend.addTX(fund, 0);
spend.setLocktime(chain.height);
wallet.sign(spend);
const [tx, view] = spend.commit();
job.addTX(tx, view);
job.refresh();
return await job.mineAsync();
}
chain.on('connect', (entry, block) => {
wallet.addBlock(entry, block.txs);
});
chain.on('disconnect', (entry, block) => {
wallet.removeBlock(entry, block.txs);
});
describe('Chain', function() {
this.timeout(60000);
it('should open chain and miner', async () => {
await chain.open();
await miner.open();
});
it('should add addrs to miner', async () => {
miner.addresses.length = 0;
miner.addAddress(wallet.getReceive());
});
it('should mine 200 blocks', async () => {
for (let i = 0; i < 200; i++) {
const block = await cpu.mineBlock();
assert(block);
assert(await chain.add(block));
}
assert.strictEqual(chain.height, 200);
});
it('should mine competing chains', async () => {
for (let i = 0; i < 10; i++) {
const job1 = await cpu.createJob(tip1);
const job2 = await cpu.createJob(tip2);
const mtx = await wallet.create({
outputs: [{
address: wallet.getAddress(),
value: 10 * 1e8
}]
});
job1.addTX(mtx.toTX(), mtx.view);
job2.addTX(mtx.toTX(), mtx.view);
job1.refresh();
job2.refresh();
const blk1 = await job1.mineAsync();
const blk2 = await job2.mineAsync();
const hash1 = blk1.hash();
const hash2 = blk2.hash();
assert(await chain.add(blk1));
assert(await chain.add(blk2));
assert.bufferEqual(chain.tip.hash, hash1);
tip1 = await chain.getEntry(hash1);
tip2 = await chain.getEntry(hash2);
assert(tip1);
assert(tip2);
assert(!await chain.isMainChain(tip2));
}
});
it('should have correct chain value', () => {
assert.strictEqual(chain.db.state.value, 897500000000);
assert.strictEqual(chain.db.state.coin, 220);
assert.strictEqual(chain.db.state.tx, 221);
});
it('should have correct wallet balance', async () => {
assert.strictEqual(wallet.balance, 897500000000);
});
it('should handle a reorg', async () => {
assert.strictEqual(chain.height, 210);
const entry = await chain.getEntry(tip2.hash);
assert(entry);
assert.strictEqual(chain.height, entry.height);
const block = await cpu.mineBlock(entry);
assert(block);
let forked = false;
chain.once('reorganize', () => {
forked = true;
});
assert(await chain.add(block));
assert(forked);
assert.bufferEqual(chain.tip.hash, block.hash());
assert(chain.tip.chainwork.gt(tip1.chainwork));
});
it('should have correct chain value', () => {
assert.strictEqual(chain.db.state.value, 900000000000);
assert.strictEqual(chain.db.state.coin, 221);
assert.strictEqual(chain.db.state.tx, 222);
});
it('should have correct wallet balance', async () => {
assert.strictEqual(wallet.balance, 900000000000);
});
it('should check main chain', async () => {
const result = await chain.isMainChain(tip1);
assert(!result);
});
it('should mine a block after a reorg', async () => {
const block = await cpu.mineBlock();
assert(await chain.add(block));
const hash = block.hash();
const entry = await chain.getEntry(hash);
assert(entry);
assert.bufferEqual(chain.tip.hash, entry.hash);
const result = await chain.isMainChain(entry);
assert(result);
});
it('should prevent double spend on new chain', async () => {
const mtx = await wallet.create({
outputs: [{
address: wallet.getAddress(),
value: 10 * 1e8
}]
});
{
const job = await cpu.createJob();
job.addTX(mtx.toTX(), mtx.view);
job.refresh();
const block = await job.mineAsync();
assert(await chain.add(block));
}
{
const job = await cpu.createJob();
assert(mtx.outputs.length > 1);
mtx.outputs.pop();
job.addTX(mtx.toTX(), mtx.view);
job.refresh();
assert.strictEqual(await mineBlock(job),
'bad-txns-inputs-missingorspent');
}
});
it('should fail to connect coins on an alternate chain', async () => {
const block = await chain.getBlock(tip1.hash);
const cb = block.txs[0];
const mtx = new MTX();
mtx.addTX(cb, 0);
mtx.addOutput(wallet.getAddress(), 10 * 1e8);
wallet.sign(mtx);
const job = await cpu.createJob();
job.addTX(mtx.toTX(), mtx.view);
job.refresh();
assert.strictEqual(await mineBlock(job), 'bad-txns-inputs-missingorspent');
});
it('should have correct chain value', () => {
assert.strictEqual(chain.db.state.value, 905000000000);
assert.strictEqual(chain.db.state.coin, 224);
assert.strictEqual(chain.db.state.tx, 225);
});
it('should get coin', async () => {
const mtx = await wallet.send({
outputs: [
{
address: wallet.getAddress(),
value: 1e8
},
{
address: wallet.getAddress(),
value: 1e8
},
{
address: wallet.getAddress(),
value: 1e8
}
]
});
const job = await cpu.createJob();
job.addTX(mtx.toTX(), mtx.view);
job.refresh();
const block = await job.mineAsync();
assert(await chain.add(block));
const tx = block.txs[1];
const output = Coin.fromTX(tx, 2, chain.height);
const coin = await chain.getCoin(tx.hash(), 2);
assert.bufferEqual(coin.toRaw(), output.toRaw());
});
it('should have correct wallet balance', async () => {
assert.strictEqual(wallet.balance, 907500000000);
assert.strictEqual(wallet.receiveDepth, 15);
assert.strictEqual(wallet.changeDepth, 14);
assert.strictEqual(wallet.txs, 226);
});
it('should get tips and remove chains', async () => {
{
const tips = await chain.db.getTips();
let index = -1;
for (let i = 0; i < tips.length; i++) {
if (tips[i].equals(chain.tip.hash))
index = i;
}
assert.notStrictEqual(index, -1);
assert.strictEqual(tips.length, 2);
}
await chain.db.removeChains();
{
const tips = await chain.db.getTips();
let index = -1;
for (let i = 0; i < tips.length; i++) {
if (tips[i].equals(chain.tip.hash))
index = i;
}
assert.notStrictEqual(index, -1);
assert.strictEqual(tips.length, 1);
}
});
it('should rescan for transactions', async () => {
let total = 0;
await chain.scan(0, wallet.filter, async (block, txs) => {
total += txs.length;
});
assert.strictEqual(total, 226);
});
it('should activate csv', async () => {
const deployments = network.deployments;
miner.options.version = -1;
assert.strictEqual(chain.height, 214);
const prev = await chain.getPrevious(chain.tip);
const state = await chain.getState(prev, deployments.csv);
assert.strictEqual(state, 1);
for (let i = 0; i < 417; i++) {
const block = await cpu.mineBlock();
assert(await chain.add(block));
switch (chain.height) {
case 288: {
const prev = await chain.getPrevious(chain.tip);
const state = await chain.getState(prev, deployments.csv);
assert.strictEqual(state, 1);
break;
}
case 432: {
const prev = await chain.getPrevious(chain.tip);
const state = await chain.getState(prev, deployments.csv);
assert.strictEqual(state, 2);
break;
}
case 576: {
const prev = await chain.getPrevious(chain.tip);
const state = await chain.getState(prev, deployments.csv);
assert.strictEqual(state, 3);
break;
}
}
}
assert.strictEqual(chain.height, 631);
assert(chain.state.hasCSV());
assert(chain.state.hasWitness());
const cache = await chain.db.getStateCache();
assert.deepStrictEqual(cache, chain.db.stateCache);
assert.strictEqual(chain.db.stateCache.updates.length, 0);
assert(await chain.db.verifyDeployments());
});
it('should have activated segwit', async () => {
const deployments = network.deployments;
const prev = await chain.getPrevious(chain.tip);
const state = await chain.getState(prev, deployments.segwit);
assert.strictEqual(state, 3);
});
it('should test csv', async () => {
const tx = (await chain.getBlock(chain.height - 100)).txs[0];
const csvBlock = await mineCSV(tx);
assert(await chain.add(csvBlock));
const csv = csvBlock.txs[1];
const spend = new MTX();
spend.addOutput({
script: [
Opcode.fromInt(2),
Opcode.fromSymbol('checksequenceverify')
],
value: 10000
});
spend.addTX(csv, 0);
spend.setSequence(0, 1, false);
const job = await cpu.createJob();
job.addTX(spend.toTX(), spend.view);
job.refresh();
const block = await job.mineAsync();
assert(await chain.add(block));
});
it('should fail csv with bad sequence', async () => {
const csv = (await chain.getBlock(chain.height - 100)).txs[0];
const spend = new MTX();
spend.addOutput({
script: [
Opcode.fromInt(1),
Opcode.fromSymbol('checksequenceverify')
],
value: 1 * 1e8
});
spend.addTX(csv, 0);
spend.setSequence(0, 1, false);
const job = await cpu.createJob();
job.addTX(spend.toTX(), spend.view);
job.refresh();
assert.strictEqual(await mineBlock(job),
'mandatory-script-verify-flag-failed');
});
it('should mine a block', async () => {
const block = await cpu.mineBlock();
assert(block);
assert(await chain.add(block));
});
it('should fail csv lock checks', async () => {
const tx = (await chain.getBlock(chain.height - 100)).txs[0];
const csvBlock = await mineCSV(tx);
assert(await chain.add(csvBlock));
const csv = csvBlock.txs[1];
const spend = new MTX();
spend.addOutput({
script: [
Opcode.fromInt(2),
Opcode.fromSymbol('checksequenceverify')
],
value: 1 * 1e8
});
spend.addTX(csv, 0);
spend.setSequence(0, 2, false);
const job = await cpu.createJob();
job.addTX(spend.toTX(), spend.view);
job.refresh();
assert.strictEqual(await mineBlock(job), 'bad-txns-nonfinal');
});
it('should have correct wallet balance', async () => {
assert.strictEqual(wallet.balance, 1412499980000);
});
it('should fail to connect bad bits', async () => {
const job = await cpu.createJob();
job.attempt.bits = 553713663;
assert.strictEqual(await mineBlock(job), 'bad-diffbits');
});
it('should fail to connect bad MTP', async () => {
const mtp = await chain.getMedianTime(chain.tip);
const job = await cpu.createJob();
job.attempt.time = mtp - 1;
assert.strictEqual(await mineBlock(job), 'time-too-old');
});
it('should fail to connect bad time', async () => {
const job = await cpu.createJob();
const now = network.now() + 3 * 60 * 60;
job.attempt.time = now;
assert.strictEqual(await mineBlock(job), 'time-too-new');
});
it('should fail to connect bad locktime', async () => {
const job = await cpu.createJob();
const tx = await wallet.send({ locktime: 100000 });
job.pushTX(tx.toTX());
job.refresh();
assert.strictEqual(await mineBlock(job), 'bad-txns-nonfinal');
});
it('should fail to connect bad cb height', async () => {
const bip34height = network.block.bip34height;
const job = await cpu.createJob();
job.attempt.height = 10;
job.attempt.refresh();
try {
network.block.bip34height = 0;
assert.strictEqual(await mineBlock(job), 'bad-cb-height');
} finally {
network.block.bip34height = bip34height;
}
});
it('should fail to connect bad witness nonce size', async () => {
const block = await cpu.mineBlock();
const tx = block.txs[0];
const input = tx.inputs[0];
input.witness.set(0, Buffer.allocUnsafe(33));
block.refresh(true);
assert.strictEqual(await addBlock(block), 'bad-witness-nonce-size');
});
it('should fail to connect bad witness nonce', async () => {
const block = await cpu.mineBlock();
const tx = block.txs[0];
const input = tx.inputs[0];
input.witness.set(0, ONE_HASH);
block.refresh(true);
assert.strictEqual(await addBlock(block), 'bad-witness-merkle-match');
});
it('should fail to connect bad witness commitment', async () => {
const flags = common.flags.DEFAULT_FLAGS & ~common.flags.VERIFY_POW;
const block = await cpu.mineBlock();
const tx = block.txs[0];
const output = tx.outputs[1];
assert(output.script.isCommitment());
const commit = Buffer.from(output.script.getData(1));
commit.fill(0, 10);
output.script.setData(1, commit);
output.script.compile();
block.refresh(true);
block.merkleRoot = block.createMerkleRoot();
assert.strictEqual(await addBlock(block, flags),
'bad-witness-merkle-match');
});
it('should fail to connect unexpected witness', async () => {
const flags = common.flags.DEFAULT_FLAGS & ~common.flags.VERIFY_POW;
const block = await cpu.mineBlock();
const tx = block.txs[0];
const output = tx.outputs[1];
assert(output.script.isCommitment());
tx.outputs.pop();
block.refresh(true);
block.merkleRoot = block.createMerkleRoot();
assert.strictEqual(await addBlock(block, flags), 'unexpected-witness');
});
it('should add wit addrs to miner', async () => {
miner.addresses.length = 0;
miner.addAddress(witWallet.getReceive());
assert.strictEqual(witWallet.getReceive().getType(), 'witness');
});
it('should mine 2000 witness blocks', async () => {
for (let i = 0; i < 2001; i++) {
const block = await cpu.mineBlock();
assert(block);
assert(await chain.add(block));
}
assert.strictEqual(chain.height, 2636);
});
it('should mine a witness tx', async () => {
const prev = await chain.getBlock(chain.height - 2000);
const cb = prev.txs[0];
const mtx = new MTX();
mtx.addTX(cb, 0);
mtx.addOutput(witWallet.getAddress(), 1000);
witWallet.sign(mtx);
const job = await cpu.createJob();
job.addTX(mtx.toTX(), mtx.view);
job.refresh();
const block = await job.mineAsync();
assert(await chain.add(block));
});
it('should mine fail to connect too much weight', async () => {
const start = chain.height - 2000;
const end = chain.height - 200;
const job = await cpu.createJob();
for (let i = start; i <= end; i++) {
const block = await chain.getBlock(i);
const cb = block.txs[0];
const mtx = new MTX();
mtx.addTX(cb, 0);
for (let j = 0; j < 16; j++)
mtx.addOutput(witWallet.getAddress(), 1);
witWallet.sign(mtx);
job.pushTX(mtx.toTX());
}
job.refresh();
assert.strictEqual(await mineBlock(job), 'bad-blk-weight');
});
it('should mine fail to connect too much size', async () => {
const start = chain.height - 2000;
const end = chain.height - 200;
const job = await cpu.createJob();
for (let i = start; i <= end; i++) {
const block = await chain.getBlock(i);
const cb = block.txs[0];
const mtx = new MTX();
mtx.addTX(cb, 0);
for (let j = 0; j < 20; j++)
mtx.addOutput(witWallet.getAddress(), 1);
witWallet.sign(mtx);
job.pushTX(mtx.toTX());
}
job.refresh();
assert.strictEqual(await mineBlock(job), 'bad-blk-length');
});
it('should mine a big block', async () => {
const start = chain.height - 2000;
const end = chain.height - 200;
const job = await cpu.createJob();
for (let i = start; i <= end; i++) {
const block = await chain.getBlock(i);
const cb = block.txs[0];
const mtx = new MTX();
mtx.addTX(cb, 0);
for (let j = 0; j < 15; j++)
mtx.addOutput(witWallet.getAddress(), 1);
witWallet.sign(mtx);
job.pushTX(mtx.toTX());
}
job.refresh();
assert.strictEqual(await mineBlock(job), 'OK');
});
it('should fail to connect bad versions', async () => {
for (let i = 0; i <= 3; i++) {
const job = await cpu.createJob();
job.attempt.version = i;
assert.strictEqual(await mineBlock(job), 'bad-version');
}
});
it('should fail to connect bad amount', async () => {
const job = await cpu.createJob();
job.attempt.fees += 1;
job.refresh();
assert.strictEqual(await mineBlock(job), 'bad-cb-amount');
});
it('should fail to connect premature cb spend', async () => {
const job = await cpu.createJob();
const block = await chain.getBlock(chain.height - 98);
const cb = block.txs[0];
const mtx = new MTX();
mtx.addTX(cb, 0);
mtx.addOutput(witWallet.getAddress(), 1);
witWallet.sign(mtx);
job.addTX(mtx.toTX(), mtx.view);
job.refresh();
assert.strictEqual(await mineBlock(job),
'bad-txns-premature-spend-of-coinbase');
});
it('should fail to connect vout belowout', async () => {
const job = await cpu.createJob();
const block = await chain.getBlock(chain.height - 99);
const cb = block.txs[0];
const mtx = new MTX();
mtx.addTX(cb, 0);
mtx.addOutput(witWallet.getAddress(), 1e8);
witWallet.sign(mtx);
job.pushTX(mtx.toTX());
job.refresh();
assert.strictEqual(await mineBlock(job),
'bad-txns-in-belowout');
});
it('should fail to connect outtotal toolarge', async () => {
const job = await cpu.createJob();
const block = await chain.getBlock(chain.height - 99);
const cb = block.txs[0];
const mtx = new MTX();
mtx.addTX(cb, 0);
const value = Math.floor(consensus.MAX_MONEY / 2);
mtx.addOutput(witWallet.getAddress(), value);
mtx.addOutput(witWallet.getAddress(), value);
mtx.addOutput(witWallet.getAddress(), value);
witWallet.sign(mtx);
job.pushTX(mtx.toTX());
job.refresh();
assert.strictEqual(await mineBlock(job),
'bad-txns-txouttotal-toolarge');
});
it('should mine 111 multisig blocks', async () => {
const flags = common.flags.DEFAULT_FLAGS & ~common.flags.VERIFY_POW;
const redeem = new Script();
redeem.pushInt(20);
for (let i = 0; i < 20; i++)
redeem.pushData(ZERO_KEY);
redeem.pushInt(20);
redeem.pushOp(opcodes.OP_CHECKMULTISIG);
redeem.compile();
const script = Script.fromScripthash(redeem.hash160());
for (let i = 0; i < 111; i++) {
const block = await cpu.mineBlock();
const cb = block.txs[0];
const val = cb.outputs[0].value;
cb.outputs[0].value = 0;
for (let j = 0; j < Math.min(100, val); j++) {
const output = new Output();
output.script = script.clone();
output.value = 1;
cb.outputs.push(output);
}
block.refresh(true);
block.merkleRoot = block.createMerkleRoot();
assert(await chain.add(block, flags));
}
assert.strictEqual(chain.height, 2749);
});
it('should fail to connect too many sigops', async () => {
const start = chain.height - 110;
const end = chain.height - 100;
const job = await cpu.createJob();
const script = new Script();
script.pushInt(20);
for (let i = 0; i < 20; i++)
script.pushData(ZERO_KEY);
script.pushInt(20);
script.pushOp(opcodes.OP_CHECKMULTISIG);
script.compile();
for (let i = start; i <= end; i++) {
const block = await chain.getBlock(i);
const cb = block.txs[0];
if (cb.outputs.length === 2)
continue;
const mtx = new MTX();
for (let j = 2; j < cb.outputs.length; j++) {
mtx.addTX(cb, j);
mtx.inputs[j - 2].script.fromItems([script.toRaw()]);
}
mtx.addOutput(witWallet.getAddress(), 1);
job.pushTX(mtx.toTX());
}
job.refresh();
assert.strictEqual(await mineBlock(job), 'bad-blk-sigops');
});
it('should cleanup', async () => {
await miner.close();
await chain.close();
});
});