From ef8f1eabd259781d84fe1dbf031d77a16b804bbf Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 2 Dec 2014 14:19:56 -0300 Subject: [PATCH] add script.isStandard() --- lib/script.js | 9 +++++++++ test/script.js | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/script.js b/lib/script.js index 94cb9c8..2474a5b 100644 --- a/lib/script.js +++ b/lib/script.js @@ -329,6 +329,15 @@ Script.prototype.classify = function() { return Script.types.UNKNOWN; }; + +/** + * @returns true if script is one of the known types + */ +Script.prototype.isStandard = function() { + return this.classify() !== Script.types.UNKNOWN; +}; + + // Script construction methods /** diff --git a/test/script.js b/test/script.js index d61e53a..ce0d896 100644 --- a/test/script.js +++ b/test/script.js @@ -166,6 +166,11 @@ describe('Script', function() { describe('#toString', function() { + it('should work with an empty script', function() { + var script = new Script(); + script.toString().should.equal(''); + }); + it('should output this buffer an OP code, data, and another OP code', function() { var buf = new Buffer([0, 0, 0, 0, 0, 0, 1, 2, 3, 0]); buf[0] = Opcode('OP_0').toNumber(); @@ -361,4 +366,13 @@ describe('Script', function() { }); }); + describe('#isStandard', function() { + it('should classify correctly standard script', function() { + Script('OP_RETURN 1 0x00').isStandard().should.equal(true); + }); + it('should classify correctly non standard script', function() { + Script('OP_TRUE OP_FALSE').isStandard().should.equal(false); + }); + }); + });