From d0b4f0adf785afda82c4ad59a7388df15ad00dc7 Mon Sep 17 00:00:00 2001 From: Thomas Kerin Date: Thu, 15 Dec 2016 13:04:31 +0100 Subject: [PATCH] Add tests ensuring stacks can be converted back to ASM --- test/script.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/script.js b/test/script.js index 438e3cf..e164cb7 100644 --- a/test/script.js +++ b/test/script.js @@ -45,13 +45,15 @@ describe('script', function () { fixtures.valid.forEach(function (f) { it('returns ' + !!f.stack + ' for ' + f.asm, function () { var script = bscript.fromASM(f.asm) - var chunks = bscript.decompile(script) - try { - var stack = bscript.toStack(chunks).map(function (x) { return x.toString('hex') }) - assert.deepEqual(stack, f.stack) - } catch (e) { - assert.strictEqual(f.stack, undefined) + if (f.stack && f.asm) { + try { + var stack = bscript.toStack(script) + assert.deepEqual(stack.map(function (x) { return x.toString('hex') }), f.stack) + assert.equal(bscript.toASM(bscript.compile(stack)), f.asm, 'should rebuild same script from stack') + } catch (e) { + assert.strictEqual(f.stack, undefined) + } } }) })