bitcore/test/txout.js

108 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-11-20 13:39:02 -08:00
'use strict';
2014-09-15 18:38:21 -07:00
var should = require('chai').should();
2014-11-20 13:39:02 -08:00
var bitcore = require('..');
2014-11-21 08:26:30 -08:00
var BN = bitcore.crypto.BN;
var Varint = bitcore.encoding.Varint;
var BufferReader = bitcore.encoding.BufferReader;
2014-11-20 13:39:02 -08:00
var Txout = bitcore.Txout;
var Script = bitcore.Script;
2014-09-15 18:38:21 -07:00
describe('Txout', function() {
var valuebn = BN(5);
2014-11-27 13:30:16 -08:00
var script = Script.fromString('OP_CHECKMULTISIG');
2014-09-17 16:48:23 -07:00
var scriptvi = Varint(script.toBuffer().length);
2014-09-15 18:38:21 -07:00
it('should make a new txout', function() {
var txout = new Txout();
should.exist(txout);
txout = Txout();
should.exist(txout);
Txout(valuebn, scriptvi, script).valuebn.toString().should.equal('5');
});
2014-09-15 18:38:21 -07:00
describe('#set', function() {
it('should set this object', function() {
var txout = new Txout().set({
valuebn: valuebn,
2014-09-17 16:48:23 -07:00
scriptvi: scriptvi,
2014-09-15 18:38:21 -07:00
script: script
});
should.exist(txout.valuebn);
2014-09-17 16:48:23 -07:00
should.exist(txout.scriptvi);
2014-09-15 18:38:21 -07:00
should.exist(txout.script);
});
});
describe('#fromJSON', function() {
it('should set from this json', function() {
var txout = Txout().fromJSON({
valuebn: valuebn.toJSON(),
scriptvi: scriptvi.toJSON(),
2014-11-27 13:30:16 -08:00
script: script.toString()
});
should.exist(txout.valuebn);
should.exist(txout.scriptvi);
should.exist(txout.script);
});
});
describe('#toJSON', function() {
it('should return this json', function() {
var txout = Txout().fromJSON({
valuebn: valuebn.toJSON(),
scriptvi: scriptvi.toJSON(),
2014-11-27 13:30:16 -08:00
script: script.toString()
});
var json = txout.toJSON();
should.exist(json.valuebn);
should.exist(json.scriptvi);
should.exist(json.script);
});
});
2014-09-15 18:38:21 -07:00
describe('#fromBuffer', function() {
it('should make this txin from this known buffer', function() {
var txout = Txout().fromBuffer(new Buffer('050000000000000001ae', 'hex'));
txout.toBuffer().toString('hex').should.equal('050000000000000001ae');
});
});
describe('#fromBufferReader', function() {
it('should make this txin from this known buffer', function() {
var txout = Txout().fromBufferReader(BufferReader(new Buffer('050000000000000001ae', 'hex')));
txout.toBuffer().toString('hex').should.equal('050000000000000001ae');
});
});
describe('#toBuffer', function() {
it('should output this known buffer', function() {
var txout = Txout().fromBufferReader(BufferReader(new Buffer('050000000000000001ae', 'hex')));
txout.toBuffer().toString('hex').should.equal('050000000000000001ae');
});
});
describe('#toBufferWriter', function() {
it('should output this known buffer', function() {
var txout = Txout().fromBufferReader(BufferReader(new Buffer('050000000000000001ae', 'hex')));
txout.toBufferWriter().concat().toString('hex').should.equal('050000000000000001ae');
});
});
});