Transaction new tests not working
This commit is contained in:
parent
d77cc28f7a
commit
6755b84fbf
|
@ -25,6 +25,14 @@ function spec(b) {
|
||||||
}
|
}
|
||||||
if (data.o) {
|
if (data.o) {
|
||||||
this.o = data.o;
|
this.o = data.o;
|
||||||
|
} else {
|
||||||
|
if (data.oTxHash && typeof data.oIndex !== 'undefined') {
|
||||||
|
var hash = new Buffer(data.oTxHash, 'hex');
|
||||||
|
hash = buffertools.reverse(hash);
|
||||||
|
var voutBuf = new Buffer(4);
|
||||||
|
voutBuf.writeUInt32LE(data.oIndex, 0);
|
||||||
|
this.o = Buffer.concat([hash, voutBuf]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.s = Buffer.isBuffer(data.s) ? data.s :
|
this.s = Buffer.isBuffer(data.s) ? data.s :
|
||||||
Buffer.isBuffer(data.script) ? data.script : util.EMPTY_BUFFER;
|
Buffer.isBuffer(data.script) ? data.script : util.EMPTY_BUFFER;
|
||||||
|
@ -44,7 +52,8 @@ function spec(b) {
|
||||||
var qbuf = new Buffer(4);
|
var qbuf = new Buffer(4);
|
||||||
qbuf.writeUInt32LE(this.q, 0);
|
qbuf.writeUInt32LE(this.q, 0);
|
||||||
|
|
||||||
return Buffer.concat([this.o, slen, this.s, qbuf]);
|
var ret = Buffer.concat([this.o, slen, this.s, qbuf]);
|
||||||
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
TransactionIn.prototype.getOutpointHash = function getOutpointHash() {
|
TransactionIn.prototype.getOutpointHash = function getOutpointHash() {
|
||||||
|
@ -144,6 +153,7 @@ function spec(b) {
|
||||||
bufs.push(buf);
|
bufs.push(buf);
|
||||||
|
|
||||||
bufs.push(util.varIntBuf(this.ins.length));
|
bufs.push(util.varIntBuf(this.ins.length));
|
||||||
|
console.log(this.ins.length);
|
||||||
this.ins.forEach(function (txin) {
|
this.ins.forEach(function (txin) {
|
||||||
bufs.push(txin.serialize());
|
bufs.push(txin.serialize());
|
||||||
});
|
});
|
||||||
|
@ -640,6 +650,8 @@ function spec(b) {
|
||||||
|
|
||||||
Transaction.prototype.parse = function (parser) {
|
Transaction.prototype.parse = function (parser) {
|
||||||
if (Buffer.isBuffer(parser)) {
|
if (Buffer.isBuffer(parser)) {
|
||||||
|
console.dir(parser);
|
||||||
|
this._buffer = parser;
|
||||||
parser = new Parser(parser);
|
parser = new Parser(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,11 @@ var should = chai.should();
|
||||||
|
|
||||||
var TransactionModule = bitcore.Transaction;
|
var TransactionModule = bitcore.Transaction;
|
||||||
var Transaction;
|
var Transaction;
|
||||||
|
var In;
|
||||||
|
var Out;
|
||||||
|
var Script = bitcore.Script.class();
|
||||||
|
var buffertools = require('buffertools');
|
||||||
|
var test_data = require('./testdata');
|
||||||
|
|
||||||
describe('Transaction', function() {
|
describe('Transaction', function() {
|
||||||
it('should initialze the main object', function() {
|
it('should initialze the main object', function() {
|
||||||
|
@ -15,14 +20,49 @@ describe('Transaction', function() {
|
||||||
it('should be able to create class', function() {
|
it('should be able to create class', function() {
|
||||||
Transaction = TransactionModule.class();
|
Transaction = TransactionModule.class();
|
||||||
should.exist(Transaction);
|
should.exist(Transaction);
|
||||||
|
In = Transaction.In;
|
||||||
|
Out = Transaction.Out;
|
||||||
|
should.exist(In);
|
||||||
|
should.exist(Out);
|
||||||
});
|
});
|
||||||
it('should be able to create instance', function() {
|
it('should be able to create instance', function() {
|
||||||
var t = new Transaction();
|
var t = new Transaction();
|
||||||
should.exist(t);
|
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('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);
|
||||||
|
|
||||||
|
});
|
||||||
|
var raw = new Buffer(datum[1]);
|
||||||
|
var tx = new Transaction();
|
||||||
|
tx.parse(raw);
|
||||||
|
buffertools.toHex(tx.serialize()).should.equal(buffertools.toHex(raw));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,11 @@ var fs = require('fs');
|
||||||
var dataValid = JSON.parse(fs.readFileSync('test/data/base58_keys_valid.json'));
|
var dataValid = JSON.parse(fs.readFileSync('test/data/base58_keys_valid.json'));
|
||||||
var dataInvalid = JSON.parse(fs.readFileSync('test/data/base58_keys_invalid.json'));
|
var dataInvalid = JSON.parse(fs.readFileSync('test/data/base58_keys_invalid.json'));
|
||||||
var dataEncodeDecode = JSON.parse(fs.readFileSync('test/data/base58_encode_decode.json'));
|
var dataEncodeDecode = JSON.parse(fs.readFileSync('test/data/base58_encode_decode.json'));
|
||||||
|
var dataTxValid = JSON.parse(fs.readFileSync('test/data/tx_valid.json'));
|
||||||
|
var dataTxInvalid = JSON.parse(fs.readFileSync('test/data/tx_invalid.json'));
|
||||||
|
|
||||||
module.exports.dataValid = dataValid;
|
module.exports.dataValid = dataValid;
|
||||||
module.exports.dataInvalid = dataInvalid;
|
module.exports.dataInvalid = dataInvalid;
|
||||||
module.exports.dataEncodeDecode = dataEncodeDecode;
|
module.exports.dataEncodeDecode = dataEncodeDecode;
|
||||||
|
module.exports.dataTxValid = dataTxValid;
|
||||||
|
module.exports.dataTxInvalid = dataTxInvalid;
|
||||||
|
|
Loading…
Reference in New Issue