Browse Source

tests: add more tests for Script compile/decompile

hk-custom-address
Daniel Cousens 10 years ago
parent
commit
2aff7bd899
  1. 26
      test/script.js

26
test/script.js

@ -3,7 +3,6 @@
var assert = require('assert') var assert = require('assert')
var Script = require('../src/script') var Script = require('../src/script')
var OPS = require('../src/opcodes')
var fixtures = require('./fixtures/script.json') var fixtures = require('./fixtures/script.json')
@ -21,17 +20,24 @@ describe('Script', function () {
}) })
describe('compile', function () { describe('compile', function () {
it('should match expected behaviour', function () { fixtures.valid.forEach(function (f) {
var hash = new Buffer(32) if (!f.asm) return
hash.fill(0)
var script = Script.compile([ it('decodes/encodes ' + f.description, function () {
OPS.OP_HASH160, var script = Script.fromASM(f.asm)
hash,
OPS.OP_EQUAL
])
assert.strictEqual(script.toString('hex'), 'a920000000000000000000000000000000000000000000000000000000000000000087') assert.strictEqual(Script.compile(script).toString('hex'), f.hex)
})
})
})
describe('decompile', function () {
fixtures.valid.forEach(function (f) {
it('decodes/encodes ' + f.description, function () {
var script = Script.decompile(new Buffer(f.hex, 'hex'))
assert.strictEqual(Script.toASM(script), f.asm)
})
}) })
}) })
}) })

Loading…
Cancel
Save