@smartledger/bsv 7.8.0 → 7.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,10 +7,15 @@ var Interpreter = bsv.Script.Interpreter
7
7
  var Script = bsv.Script
8
8
  var Opcode = bsv.Opcode
9
9
  var Transaction = bsv.Transaction
10
+ var CHRONICLE = Interpreter.SCRIPT_ENABLE_CHRONICLE
10
11
 
11
- // OP_SUBSTR / OP_LEFT / OP_RIGHT — re-enabled BSV (Chronicle) string opcodes,
12
- // original Satoshi semantics. Declared in the opcode map at 0xb3/0xb4/0xb5 but
13
- // previously unimplemented (BAD_OPCODE). These tests verify behavior end-to-end.
12
+ // OP_SUBSTR / OP_LEFT / OP_RIGHT — Chronicle string opcodes at 0xb3/0xb4/0xb5.
13
+ //
14
+ // Every case here passes SCRIPT_ENABLE_CHRONICLE, because without it these
15
+ // bytes are UPGRADABLE NOPS, exactly as they are on a pre-Chronicle node. An
16
+ // earlier version of these tests ran them with flags=0 and passed, which is
17
+ // what hid the fact that the interpreter was executing them unconditionally —
18
+ // more permissively than the network.
14
19
  describe('String opcodes OP_SUBSTR / OP_LEFT / OP_RIGHT', function () {
15
20
  var DATA = Buffer.from('aabbccdd', 'hex')
16
21
 
@@ -20,14 +25,14 @@ describe('String opcodes OP_SUBSTR / OP_LEFT / OP_RIGHT', function () {
20
25
  buildOps(lock)
21
26
  lock.add(Buffer.from(expectedHex, 'hex')).add(Opcode.OP_EQUAL)
22
27
  var interp = new Interpreter()
23
- return interp.verify(new Script(), lock, new Transaction(), 0, 0)
28
+ return interp.verify(new Script(), lock, new Transaction(), 0, CHRONICLE)
24
29
  }
25
30
  function errors (buildOps) {
26
31
  var lock = new Script().add(DATA)
27
32
  buildOps(lock)
28
33
  var interp = new Interpreter()
29
34
  var ok
30
- try { ok = interp.verify(new Script(), lock, new Transaction(), 0, 0) } catch (e) { ok = false }
35
+ try { ok = interp.verify(new Script(), lock, new Transaction(), 0, CHRONICLE) } catch (e) { ok = false }
31
36
  return ok === false
32
37
  }
33
38
 
@@ -52,12 +57,23 @@ describe('String opcodes OP_SUBSTR / OP_LEFT / OP_RIGHT', function () {
52
57
  yields(function (s) { s.add(Opcode.OP_1).add(Opcode.OP_2).add(Opcode.OP_SUBSTR) }, 'bbcc').should.equal(true)
53
58
  })
54
59
 
55
- it('OP_LEFT clamps n greater than the length', function () {
56
- yields(function (s) { s.add(Opcode.OP_10).add(Opcode.OP_LEFT) }, 'aabbccdd').should.equal(true)
60
+ // The node ERRORS rather than clamping:
61
+ // if(len < 0 || len > size) return SCRIPT_ERR_INVALID_NUMBER_RANGE;
62
+ // Clamping made scripts the node rejects succeed here.
63
+ it('OP_LEFT rejects n greater than the length', function () {
64
+ errors(function (s) { s.add(Opcode.OP_10).add(Opcode.OP_LEFT) }).should.equal(true)
57
65
  })
58
66
 
59
- it('OP_RIGHT clamps n greater than the length', function () {
60
- yields(function (s) { s.add(Opcode.OP_10).add(Opcode.OP_RIGHT) }, 'aabbccdd').should.equal(true)
67
+ it('OP_RIGHT rejects n greater than the length', function () {
68
+ errors(function (s) { s.add(Opcode.OP_10).add(Opcode.OP_RIGHT) }).should.equal(true)
69
+ })
70
+
71
+ it('is a no-op without SCRIPT_ENABLE_CHRONICLE, as a pre-Chronicle node is', function () {
72
+ const interp = new Interpreter()
73
+ const lock = new Script().add(DATA).add(Opcode.OP_2).add(Opcode.OP_LEFT)
74
+ interp.verify(new Script(), lock, new Transaction(), 0, 0).should.equal(true)
75
+ // Untouched: the opcode did nothing, so both operands survive.
76
+ interp.stack.length.should.equal(2)
61
77
  })
62
78
 
63
79
  it('rejects a negative size', function () {
@@ -67,6 +83,6 @@ describe('String opcodes OP_SUBSTR / OP_LEFT / OP_RIGHT', function () {
67
83
  it('rejects OP_LEFT with too few stack items', function () {
68
84
  var interp = new Interpreter()
69
85
  var lock = new Script().add(Opcode.OP_LEFT) // nothing to operate on
70
- interp.verify(new Script(), lock, new Transaction(), 0, 0).should.equal(false)
86
+ interp.verify(new Script(), lock, new Transaction(), 0, CHRONICLE).should.equal(false)
71
87
  })
72
88
  })
package/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  'use strict'
2
2
  // GENERATED by scripts/sync-version.js on `npm version` — do not edit.
3
- module.exports = '7.8.0'
3
+ module.exports = '7.9.0'