From 2aff7bd899e0fedc22dca021cebaaf034d400c8d Mon Sep 17 00:00:00 2001
From: Daniel Cousens <github@dcousens.com>
Date: Thu, 13 Aug 2015 19:00:47 +1000
Subject: [PATCH] tests: add more tests for Script compile/decompile

---
 test/script.js | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/test/script.js b/test/script.js
index 0a885b5..b3e2258 100644
--- a/test/script.js
+++ b/test/script.js
@@ -3,7 +3,6 @@
 
 var assert = require('assert')
 var Script = require('../src/script')
-var OPS = require('../src/opcodes')
 
 var fixtures = require('./fixtures/script.json')
 
@@ -21,17 +20,24 @@ describe('Script', function () {
   })
 
   describe('compile', function () {
-    it('should match expected behaviour', function () {
-      var hash = new Buffer(32)
-      hash.fill(0)
+    fixtures.valid.forEach(function (f) {
+      if (!f.asm) return
 
-      var script = Script.compile([
-        OPS.OP_HASH160,
-        hash,
-        OPS.OP_EQUAL
-      ])
+      it('decodes/encodes ' + f.description, function () {
+        var script = Script.fromASM(f.asm)
 
-      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)
+      })
     })
   })
 })