bitcore/test/test.Transaction.js

69 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-02-06 07:57:47 -08:00
'use strict';
var chai = require('chai');
var bitcore = require('../bitcore');
var should = chai.should();
var TransactionModule = bitcore.Transaction;
var Transaction;
2014-02-27 13:09:02 -08:00
var In;
var Out;
var Script = bitcore.Script.class();
var buffertools = require('buffertools');
var test_data = require('./testdata');
2014-02-06 07:57:47 -08:00
2014-02-18 06:39:47 -08:00
describe('Transaction', function() {
2014-02-06 07:57:47 -08:00
it('should initialze the main object', function() {
should.exist(TransactionModule);
});
it('should be able to create class', function() {
Transaction = TransactionModule.class();
should.exist(Transaction);
2014-02-27 13:09:02 -08:00
In = Transaction.In;
Out = Transaction.Out;
should.exist(In);
should.exist(Out);
2014-02-06 07:57:47 -08:00
});
it('should be able to create instance', function() {
var t = new Transaction();
should.exist(t);
});
2014-02-27 13:09:02 -08:00
// Read tests from test/data/tx_valid.json
// Format is an array of arrays
// Inner arrays are either [ "comment" ]
// or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], ...],"], serializedTransaction, enforceP2SH
// ... where all scripts are stringified scripts.
test_data.dataTxValid.forEach(function(datum) {
if (datum.length === 3) {
it('valid tx=' + datum[1], function() {
var inputs = datum[0];
var mapprevOutScriptPubKeys = {};
var ins = [];
inputs.forEach(function(vin) {
var hash = vin[0];
var index = vin[1];
var scriptPubKey = vin[2];
var input = new In({
s: scriptPubKey,
q: 0xffffffff,
oTxHash: hash,
oIndex: index
});
//mapprevOutScriptPubKeys[input] = new Script(scriptPubKey);
ins.push(input);
2014-02-06 07:57:47 -08:00
2014-02-27 13:09:02 -08:00
});
var raw = new Buffer(datum[1]);
var tx = new Transaction();
tx.parse(raw);
buffertools.toHex(tx.serialize()).should.equal(buffertools.toHex(raw));
2014-02-06 07:57:47 -08:00
2014-02-27 13:09:02 -08:00
});
}
});
});