flocore/test/test.Transaction.js
Ryan X. Charles c19fb7a3ce Merge remote-tracking branch 'matiu/feature/support-soop-browser'
Conflicts:
	Script.js
	ScriptInterpreter.js
	Transaction.js
	test/testdata.js

...conflicts resolved by taking Manuel's changes, and then manually including
Matias's changes on those same files. The conflicts resulted from differences
in indentation, which is because Matias' changes unindendented all the code
that had been but is not now inside a function.
2014-03-08 19:30:21 -05:00

68 lines
2.0 KiB
JavaScript

'use strict';
var chai = chai || require('chai');
var bitcore = bitcore || require('../bitcore');
var should = chai.should();
var TransactionModule = bitcore.Transaction;
var Transaction;
var In;
var Out;
var Script = bitcore.Script;
var buffertools = require('buffertools');
var test_data = require('./testdata');
describe('Transaction', function() {
it('should initialze the main object', function() {
should.exist(TransactionModule);
});
it('should be able to create class', function() {
Transaction = TransactionModule;
should.exist(Transaction);
In = Transaction.In;
Out = Transaction.Out;
should.exist(In);
should.exist(Out);
});
it('should be able to create instance', function() {
var t = new Transaction();
should.exist(t);
});
// 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.skip('valid tx=' + datum[1], function(done) {
var inputs = datum[0];
var map = {};
inputs.forEach(function(vin) {
var hash = vin[0];
var index = vin[1];
var scriptPubKey = new Script(new Buffer(vin[2]));
map[[hash, index]] = scriptPubKey; //Script.fromStringContent(scriptPubKey);
console.log(scriptPubKey.getStringContent());
console.log('********************************');
});
var raw = new Buffer(datum[1], 'hex');
var tx = new Transaction();
tx.parse(raw);
buffertools.toHex(tx.serialize()).should.equal(buffertools.toHex(raw));
var i = 0;
var stx = tx.getStandardizedObject();
tx.ins.forEach(function(txin) {
var scriptPubKey = map[[stx. in [i].prev_out.hash, stx. in [i].prev_out.n]];
i += 1;
});
});
}
});
});