Browse Source

make tests pass with Script refactor

patch-2
Manuel Araoz 10 years ago
parent
commit
66e96e5fa4
  1. 17
      lib/script.js
  2. 6
      lib/txin.js
  3. 6
      lib/txout.js
  4. 4
      test/address.js
  5. 121
      test/script.js
  6. 2
      test/txin.js
  7. 6
      test/txout.js

17
lib/script.js

@ -12,9 +12,9 @@ var Script = function Script(from) {
this.chunks = []; this.chunks = [];
if (Buffer.isBuffer(from)) { if (Buffer.isBuffer(from)) {
this.fromBuffer(from); return Script.fromBuffer(from);
} else if (typeof from === 'string') { } else if (typeof from === 'string') {
this.fromString(from); return Script.fromString(from);
} else if (typeof from !== 'undefined') { } else if (typeof from !== 'undefined') {
this.set(from); this.set(from);
} }
@ -103,8 +103,9 @@ Script.prototype.toBuffer = function() {
return bw.concat(); return bw.concat();
}; };
Script.prototype.fromString = function(str) { Script.fromString = function(str) {
this.chunks = []; var script = new Script();
script.chunks = [];
var tokens = str.split(' '); var tokens = str.split(' ');
var i = 0; var i = 0;
@ -116,7 +117,7 @@ Script.prototype.fromString = function(str) {
if (typeof opcodenum === 'undefined') { if (typeof opcodenum === 'undefined') {
opcodenum = parseInt(token); opcodenum = parseInt(token);
if (opcodenum > 0 && opcodenum < Opcode.map.OP_PUSHDATA1) { if (opcodenum > 0 && opcodenum < Opcode.map.OP_PUSHDATA1) {
this.chunks.push({ script.chunks.push({
buf: new Buffer(tokens[i + 1].slice(2), 'hex'), buf: new Buffer(tokens[i + 1].slice(2), 'hex'),
len: opcodenum, len: opcodenum,
opcodenum: opcodenum opcodenum: opcodenum
@ -129,18 +130,18 @@ Script.prototype.fromString = function(str) {
if (tokens[i + 2].slice(0, 2) !== '0x') { if (tokens[i + 2].slice(0, 2) !== '0x') {
throw new Error('Pushdata data must start with 0x'); throw new Error('Pushdata data must start with 0x');
} }
this.chunks.push({ script.chunks.push({
buf: new Buffer(tokens[i + 2].slice(2), 'hex'), buf: new Buffer(tokens[i + 2].slice(2), 'hex'),
len: parseInt(tokens[i + 1]), len: parseInt(tokens[i + 1]),
opcodenum: opcodenum opcodenum: opcodenum
}); });
i = i + 3; i = i + 3;
} else { } else {
this.chunks.push(opcodenum); script.chunks.push(opcodenum);
i = i + 1; i = i + 1;
} }
} }
return this; return script;
}; };
Script.prototype.toString = function() { Script.prototype.toString = function() {

6
lib/txin.js

@ -36,7 +36,7 @@ Txin.prototype.fromJSON = function(json) {
txidbuf: new Buffer(json.txidbuf, 'hex'), txidbuf: new Buffer(json.txidbuf, 'hex'),
txoutnum: json.txoutnum, txoutnum: json.txoutnum,
scriptvi: Varint().fromJSON(json.scriptvi), scriptvi: Varint().fromJSON(json.scriptvi),
script: Script().fromJSON(json.script), script: Script.fromString(json.script),
seqnum: json.seqnum seqnum: json.seqnum
}); });
return this; return this;
@ -47,7 +47,7 @@ Txin.prototype.toJSON = function() {
txidbuf: this.txidbuf.toString('hex'), txidbuf: this.txidbuf.toString('hex'),
txoutnum: this.txoutnum, txoutnum: this.txoutnum,
scriptvi: this.scriptvi.toJSON(), scriptvi: this.scriptvi.toJSON(),
script: this.script.toJSON(), script: this.script.toString(),
seqnum: this.seqnum seqnum: this.seqnum
}; };
}; };
@ -60,7 +60,7 @@ Txin.prototype.fromBufferReader = function(br) {
this.txidbuf = br.read(32); this.txidbuf = br.read(32);
this.txoutnum = br.readUInt32LE(); this.txoutnum = br.readUInt32LE();
this.scriptvi = Varint(br.readVarintBuf()); this.scriptvi = Varint(br.readVarintBuf());
this.script = Script().fromBuffer(br.read(this.scriptvi.toNumber())); this.script = Script.fromBuffer(br.read(this.scriptvi.toNumber()));
this.seqnum = br.readUInt32LE(); this.seqnum = br.readUInt32LE();
return this; return this;
}; };

6
lib/txout.js

@ -32,7 +32,7 @@ Txout.prototype.fromJSON = function(json) {
this.set({ this.set({
valuebn: BN().fromJSON(json.valuebn), valuebn: BN().fromJSON(json.valuebn),
scriptvi: Varint().fromJSON(json.scriptvi), scriptvi: Varint().fromJSON(json.scriptvi),
script: Script().fromJSON(json.script) script: Script.fromString(json.script)
}); });
return this; return this;
}; };
@ -41,7 +41,7 @@ Txout.prototype.toJSON = function() {
return { return {
valuebn: this.valuebn.toJSON(), valuebn: this.valuebn.toJSON(),
scriptvi: this.scriptvi.toJSON(), scriptvi: this.scriptvi.toJSON(),
script: this.script.toJSON() script: this.script.toString()
}; };
}; };
@ -52,7 +52,7 @@ Txout.prototype.fromBuffer = function(buf) {
Txout.prototype.fromBufferReader = function(br) { Txout.prototype.fromBufferReader = function(br) {
this.valuebn = br.readUInt64LEBN(); this.valuebn = br.readUInt64LEBN();
this.scriptvi = Varint(br.readVarintNum()); this.scriptvi = Varint(br.readVarintNum());
this.script = Script().fromBuffer(br.read(this.scriptvi.toNumber())); this.script = Script.fromBuffer(br.read(this.scriptvi.toNumber()));
return this; return this;
}; };

4
test/address.js

@ -294,7 +294,7 @@ describe('Address', function() {
}); });
it('should make this address from a script', function() { it('should make this address from a script', function() {
var s = Script().fromString("OP_CHECKMULTISIG"); var s = Script.fromString("OP_CHECKMULTISIG");
var buf = s.toBuffer(); var buf = s.toBuffer();
var a = Address.fromScript(s); var a = Address.fromScript(s);
a.toString().should.equal('3BYmEwgV2vANrmfRymr1mFnHXgLjD6gAWm'); a.toString().should.equal('3BYmEwgV2vANrmfRymr1mFnHXgLjD6gAWm');
@ -305,7 +305,7 @@ describe('Address', function() {
}); });
it('should make this address from other script', function() { it('should make this address from other script', function() {
var s = Script().fromString("OP_CHECKSIG OP_HASH160"); var s = Script.fromString("OP_CHECKSIG OP_HASH160");
var a = Address.fromScript(s); var a = Address.fromScript(s);
a.toString().should.equal('347iRqVwks5r493N1rsLN4k9J7Ljg488W7'); a.toString().should.equal('347iRqVwks5r493N1rsLN4k9J7Ljg488W7');
var b = new Address(s); var b = new Address(s);

121
test/script.js

@ -6,18 +6,18 @@ var Script = bitcore.Script;
var Opcode = bitcore.Opcode; var Opcode = bitcore.Opcode;
describe('Script', function() { describe('Script', function() {
it('should make a new script', function() { it('should make a new script', function() {
var script = new Script(); var script = new Script();
should.exist(script); should.exist(script);
}); });
describe('#fromBuffer', function() { describe('#fromBuffer', function() {
it('should parse this buffer containing an OP code', function() { it('should parse this buffer containing an OP code', function() {
var buf = new Buffer(1); var buf = new Buffer(1);
buf[0] = Opcode('OP_0').toNumber(); buf[0] = Opcode('OP_0').toNumber();
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].should.equal(buf[0]); script.chunks[0].should.equal(buf[0]);
}); });
@ -25,14 +25,14 @@ describe('Script', function() {
it('should parse this buffer containing another OP code', function() { it('should parse this buffer containing another OP code', function() {
var buf = new Buffer(1); var buf = new Buffer(1);
buf[0] = Opcode('OP_CHECKMULTISIG').toNumber(); buf[0] = Opcode('OP_CHECKMULTISIG').toNumber();
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].should.equal(buf[0]); script.chunks[0].should.equal(buf[0]);
}); });
it('should parse this buffer containing three bytes of data', function() { it('should parse this buffer containing three bytes of data', function() {
var buf = new Buffer([3, 1, 2, 3]); var buf = new Buffer([3, 1, 2, 3]);
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].buf.toString('hex').should.equal('010203'); script.chunks[0].buf.toString('hex').should.equal('010203');
}); });
@ -41,7 +41,7 @@ describe('Script', function() {
var buf = new Buffer([0, 0, 1, 2, 3]); var buf = new Buffer([0, 0, 1, 2, 3]);
buf[0] = Opcode('OP_PUSHDATA1').toNumber(); buf[0] = Opcode('OP_PUSHDATA1').toNumber();
buf.writeUInt8(3, 1); buf.writeUInt8(3, 1);
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].buf.toString('hex').should.equal('010203'); script.chunks[0].buf.toString('hex').should.equal('010203');
}); });
@ -50,7 +50,7 @@ describe('Script', function() {
var buf = new Buffer([0, 0, 0, 1, 2, 3]); var buf = new Buffer([0, 0, 0, 1, 2, 3]);
buf[0] = Opcode('OP_PUSHDATA2').toNumber(); buf[0] = Opcode('OP_PUSHDATA2').toNumber();
buf.writeUInt16LE(3, 1); buf.writeUInt16LE(3, 1);
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].buf.toString('hex').should.equal('010203'); script.chunks[0].buf.toString('hex').should.equal('010203');
}); });
@ -59,7 +59,7 @@ describe('Script', function() {
var buf = new Buffer([0, 0, 0, 0, 0, 1, 2, 3]); var buf = new Buffer([0, 0, 0, 0, 0, 1, 2, 3]);
buf[0] = Opcode('OP_PUSHDATA4').toNumber(); buf[0] = Opcode('OP_PUSHDATA4').toNumber();
buf.writeUInt16LE(3, 1); buf.writeUInt16LE(3, 1);
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].buf.toString('hex').should.equal('010203'); script.chunks[0].buf.toString('hex').should.equal('010203');
}); });
@ -70,7 +70,7 @@ describe('Script', function() {
buf[1] = Opcode('OP_PUSHDATA4').toNumber(); buf[1] = Opcode('OP_PUSHDATA4').toNumber();
buf.writeUInt16LE(3, 2); buf.writeUInt16LE(3, 2);
buf[buf.length - 1] = Opcode('OP_0').toNumber(); buf[buf.length - 1] = Opcode('OP_0').toNumber();
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(3); script.chunks.length.should.equal(3);
script.chunks[0].should.equal(buf[0]); script.chunks[0].should.equal(buf[0]);
script.chunks[1].buf.toString('hex').should.equal('010203'); script.chunks[1].buf.toString('hex').should.equal('010203');
@ -80,11 +80,11 @@ describe('Script', function() {
}); });
describe('#toBuffer', function() { describe('#toBuffer', function() {
it('should output this buffer containing an OP code', function() { it('should output this buffer containing an OP code', function() {
var buf = new Buffer(1); var buf = new Buffer(1);
buf[0] = Opcode('OP_0').toNumber(); buf[0] = Opcode('OP_0').toNumber();
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].should.equal(buf[0]); script.chunks[0].should.equal(buf[0]);
script.toBuffer().toString('hex').should.equal(buf.toString('hex')); script.toBuffer().toString('hex').should.equal(buf.toString('hex'));
@ -93,7 +93,7 @@ describe('Script', function() {
it('should output this buffer containing another OP code', function() { it('should output this buffer containing another OP code', function() {
var buf = new Buffer(1); var buf = new Buffer(1);
buf[0] = Opcode('OP_CHECKMULTISIG').toNumber(); buf[0] = Opcode('OP_CHECKMULTISIG').toNumber();
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].should.equal(buf[0]); script.chunks[0].should.equal(buf[0]);
script.toBuffer().toString('hex').should.equal(buf.toString('hex')); script.toBuffer().toString('hex').should.equal(buf.toString('hex'));
@ -101,7 +101,7 @@ describe('Script', function() {
it('should output this buffer containing three bytes of data', function() { it('should output this buffer containing three bytes of data', function() {
var buf = new Buffer([3, 1, 2, 3]); var buf = new Buffer([3, 1, 2, 3]);
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].buf.toString('hex').should.equal('010203'); script.chunks[0].buf.toString('hex').should.equal('010203');
script.toBuffer().toString('hex').should.equal(buf.toString('hex')); script.toBuffer().toString('hex').should.equal(buf.toString('hex'));
@ -111,7 +111,7 @@ describe('Script', function() {
var buf = new Buffer([0, 0, 1, 2, 3]); var buf = new Buffer([0, 0, 1, 2, 3]);
buf[0] = Opcode('OP_PUSHDATA1').toNumber(); buf[0] = Opcode('OP_PUSHDATA1').toNumber();
buf.writeUInt8(3, 1); buf.writeUInt8(3, 1);
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].buf.toString('hex').should.equal('010203'); script.chunks[0].buf.toString('hex').should.equal('010203');
script.toBuffer().toString('hex').should.equal(buf.toString('hex')); script.toBuffer().toString('hex').should.equal(buf.toString('hex'));
@ -121,7 +121,7 @@ describe('Script', function() {
var buf = new Buffer([0, 0, 0, 1, 2, 3]); var buf = new Buffer([0, 0, 0, 1, 2, 3]);
buf[0] = Opcode('OP_PUSHDATA2').toNumber(); buf[0] = Opcode('OP_PUSHDATA2').toNumber();
buf.writeUInt16LE(3, 1); buf.writeUInt16LE(3, 1);
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].buf.toString('hex').should.equal('010203'); script.chunks[0].buf.toString('hex').should.equal('010203');
script.toBuffer().toString('hex').should.equal(buf.toString('hex')); script.toBuffer().toString('hex').should.equal(buf.toString('hex'));
@ -131,7 +131,7 @@ describe('Script', function() {
var buf = new Buffer([0, 0, 0, 0, 0, 1, 2, 3]); var buf = new Buffer([0, 0, 0, 0, 0, 1, 2, 3]);
buf[0] = Opcode('OP_PUSHDATA4').toNumber(); buf[0] = Opcode('OP_PUSHDATA4').toNumber();
buf.writeUInt16LE(3, 1); buf.writeUInt16LE(3, 1);
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(1); script.chunks.length.should.equal(1);
script.chunks[0].buf.toString('hex').should.equal('010203'); script.chunks[0].buf.toString('hex').should.equal('010203');
script.toBuffer().toString('hex').should.equal(buf.toString('hex')); script.toBuffer().toString('hex').should.equal(buf.toString('hex'));
@ -143,7 +143,7 @@ describe('Script', function() {
buf[1] = Opcode('OP_PUSHDATA4').toNumber(); buf[1] = Opcode('OP_PUSHDATA4').toNumber();
buf.writeUInt16LE(3, 2); buf.writeUInt16LE(3, 2);
buf[buf.length - 1] = Opcode('OP_0').toNumber(); buf[buf.length - 1] = Opcode('OP_0').toNumber();
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(3); script.chunks.length.should.equal(3);
script.chunks[0].should.equal(buf[0]); script.chunks[0].should.equal(buf[0]);
script.chunks[1].buf.toString('hex').should.equal('010203'); script.chunks[1].buf.toString('hex').should.equal('010203');
@ -156,10 +156,10 @@ describe('Script', function() {
describe('#fromString', function() { describe('#fromString', function() {
it('should parse these known scripts', function() { it('should parse these known scripts', function() {
Script().fromString('OP_0 OP_PUSHDATA4 3 0x010203 OP_0').toString().should.equal('OP_0 OP_PUSHDATA4 3 0x010203 OP_0'); Script.fromString('OP_0 OP_PUSHDATA4 3 0x010203 OP_0').toString().should.equal('OP_0 OP_PUSHDATA4 3 0x010203 OP_0');
Script().fromString('OP_0 OP_PUSHDATA2 3 0x010203 OP_0').toString().should.equal('OP_0 OP_PUSHDATA2 3 0x010203 OP_0'); Script.fromString('OP_0 OP_PUSHDATA2 3 0x010203 OP_0').toString().should.equal('OP_0 OP_PUSHDATA2 3 0x010203 OP_0');
Script().fromString('OP_0 OP_PUSHDATA1 3 0x010203 OP_0').toString().should.equal('OP_0 OP_PUSHDATA1 3 0x010203 OP_0'); Script.fromString('OP_0 OP_PUSHDATA1 3 0x010203 OP_0').toString().should.equal('OP_0 OP_PUSHDATA1 3 0x010203 OP_0');
Script().fromString('OP_0 3 0x010203 OP_0').toString().should.equal('OP_0 3 0x010203 OP_0'); Script.fromString('OP_0 3 0x010203 OP_0').toString().should.equal('OP_0 3 0x010203 OP_0');
}); });
}); });
@ -172,7 +172,7 @@ describe('Script', function() {
buf[1] = Opcode('OP_PUSHDATA4').toNumber(); buf[1] = Opcode('OP_PUSHDATA4').toNumber();
buf.writeUInt16LE(3, 2); buf.writeUInt16LE(3, 2);
buf[buf.length - 1] = Opcode('OP_0').toNumber(); buf[buf.length - 1] = Opcode('OP_0').toNumber();
var script = Script().fromBuffer(buf); var script = Script.fromBuffer(buf);
script.chunks.length.should.equal(3); script.chunks.length.should.equal(3);
script.chunks[0].should.equal(buf[0]); script.chunks[0].should.equal(buf[0]);
script.chunks[1].buf.toString('hex').should.equal('010203'); script.chunks[1].buf.toString('hex').should.equal('010203');
@ -182,24 +182,8 @@ describe('Script', function() {
}); });
describe('#fromJSON', function() {
it('should parse this known script', function() {
Script().fromJSON('OP_0 OP_PUSHDATA4 3 0x010203 OP_0').toString().should.equal('OP_0 OP_PUSHDATA4 3 0x010203 OP_0');
});
});
describe('#toJSON', function() {
it('should output this known script', function() {
Script().fromString('OP_0 OP_PUSHDATA4 3 0x010203 OP_0').toJSON().should.equal('OP_0 OP_PUSHDATA4 3 0x010203 OP_0');
});
});
describe('#isOpReturn', function() { describe('#isOpReturn', function() {
it('should know this is a (blank) OP_RETURN script', function() { it('should know this is a (blank) OP_RETURN script', function() {
Script('OP_RETURN').isOpReturn().should.equal(true); Script('OP_RETURN').isOpReturn().should.equal(true);
}); });
@ -219,7 +203,7 @@ describe('Script', function() {
}); });
describe('#isPublicKeyHashIn', function() { describe('#isPublicKeyHashIn', function() {
it('should classify this known pubkeyhashin', function() { it('should classify this known pubkeyhashin', function() {
Script('73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 65 0x04e365859b3c78a8b7c202412b949ebca58e147dba297be29eee53cd3e1d300a6419bc780cc9aec0dc94ed194e91c8f6433f1b781ee00eac0ead2aae1e8e0712c6').isPublicKeyHashIn().should.equal(true); Script('73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 65 0x04e365859b3c78a8b7c202412b949ebca58e147dba297be29eee53cd3e1d300a6419bc780cc9aec0dc94ed194e91c8f6433f1b781ee00eac0ead2aae1e8e0712c6').isPublicKeyHashIn().should.equal(true);
}); });
@ -243,7 +227,7 @@ describe('Script', function() {
}); });
describe('#isScripthashIn', function() { describe('#isScripthashIn', function() {
it('should classify this known scripthashin', function() { it('should classify this known scripthashin', function() {
Script('20 0000000000000000000000000000000000000000').isScriptHashIn().should.equal(true); Script('20 0000000000000000000000000000000000000000').isScriptHashIn().should.equal(true);
}); });
@ -267,44 +251,37 @@ describe('Script', function() {
}); });
describe('#writeOp', function() { describe('#add', function() {
it('should write these ops', function() { it('should add these ops', function() {
Script().writeOp('OP_CHECKMULTISIG').toString().should.equal('OP_CHECKMULTISIG'); Script().add('OP_CHECKMULTISIG').toString().should.equal('OP_CHECKMULTISIG');
Script().writeOp(Opcode.map.OP_CHECKMULTISIG).toString().should.equal('OP_CHECKMULTISIG'); Script().add(Opcode.map.OP_CHECKMULTISIG).toString().should.equal('OP_CHECKMULTISIG');
}); });
}); });
describe('#writeBuffer', function() { it('should add these push data', function() {
var buf = new Buffer(1);
it('should write these push data', function() { buf.fill(0);
var buf = new Buffer(1); Script().add(buf).toString().should.equal('1 0x00');
buf.fill(0); buf = new Buffer(255);
Script().writeBuffer(buf).toString().should.equal('1 0x00'); buf.fill(0);
buf = new Buffer(255); Script().add(buf).toString().should.equal('OP_PUSHDATA1 255 0x' + buf.toString('hex'));
buf.fill(0); buf = new Buffer(256);
Script().writeBuffer(buf).toString().should.equal('OP_PUSHDATA1 255 0x' + buf.toString('hex')); buf.fill(0);
buf = new Buffer(256); Script().add(buf).toString().should.equal('OP_PUSHDATA2 256 0x' + buf.toString('hex'));
buf.fill(0); buf = new Buffer(Math.pow(2, 16));
Script().writeBuffer(buf).toString().should.equal('OP_PUSHDATA2 256 0x' + buf.toString('hex')); buf.fill(0);
buf = new Buffer(Math.pow(2, 16)); Script().add(buf).toString().should.equal('OP_PUSHDATA4 ' + Math.pow(2, 16) + ' 0x' + buf.toString('hex'));
buf.fill(0);
Script().writeBuffer(buf).toString().should.equal('OP_PUSHDATA4 ' + Math.pow(2, 16) + ' 0x' + buf.toString('hex'));
});
}); });
describe('#write', function() { it('should add both pushdata and non-pushdata chunks', function() {
Script().add('OP_CHECKMULTISIG').toString().should.equal('OP_CHECKMULTISIG');
it('should write both pushdata and non-pushdata chunks', function() { Script().add(Opcode.map.OP_CHECKMULTISIG).toString().should.equal('OP_CHECKMULTISIG');
Script().write('OP_CHECKMULTISIG').toString().should.equal('OP_CHECKMULTISIG'); var buf = new Buffer(1);
Script().write(Opcode.map.OP_CHECKMULTISIG).toString().should.equal('OP_CHECKMULTISIG'); buf.fill(0);
var buf = new Buffer(1); Script().add(buf).toString().should.equal('1 0x00');
buf.fill(0);
Script().write(buf).toString().should.equal('1 0x00');
});
}); });
}); });

2
test/txin.js

@ -12,7 +12,7 @@ describe('Txin', function() {
var txidbuf = new Buffer(32); var txidbuf = new Buffer(32);
txidbuf.fill(0); txidbuf.fill(0);
var txoutnum = 0; var txoutnum = 0;
var script = Script().fromString('OP_CHECKMULTISIG'); var script = Script.fromString('OP_CHECKMULTISIG');
var scriptvi = Varint(script.toBuffer().length); var scriptvi = Varint(script.toBuffer().length);
var seqnum = 0; var seqnum = 0;
var txin = Txin().set({ var txin = Txin().set({

6
test/txout.js

@ -11,7 +11,7 @@ var Script = bitcore.Script;
describe('Txout', function() { describe('Txout', function() {
var valuebn = BN(5); var valuebn = BN(5);
var script = Script().fromString('OP_CHECKMULTISIG'); var script = Script.fromString('OP_CHECKMULTISIG');
var scriptvi = Varint(script.toBuffer().length); var scriptvi = Varint(script.toBuffer().length);
it('should make a new txout', function() { it('should make a new txout', function() {
@ -43,7 +43,7 @@ describe('Txout', function() {
var txout = Txout().fromJSON({ var txout = Txout().fromJSON({
valuebn: valuebn.toJSON(), valuebn: valuebn.toJSON(),
scriptvi: scriptvi.toJSON(), scriptvi: scriptvi.toJSON(),
script: script.toJSON() script: script.toString()
}); });
should.exist(txout.valuebn); should.exist(txout.valuebn);
should.exist(txout.scriptvi); should.exist(txout.scriptvi);
@ -58,7 +58,7 @@ describe('Txout', function() {
var txout = Txout().fromJSON({ var txout = Txout().fromJSON({
valuebn: valuebn.toJSON(), valuebn: valuebn.toJSON(),
scriptvi: scriptvi.toJSON(), scriptvi: scriptvi.toJSON(),
script: script.toJSON() script: script.toString()
}); });
var json = txout.toJSON(); var json = txout.toJSON();
should.exist(json.valuebn); should.exist(json.valuebn);

Loading…
Cancel
Save