You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.4 KiB
85 lines
2.4 KiB
10 years ago
|
var Varint = require('../lib/varint');
|
||
|
var Transaction = require('../lib/transaction');
|
||
|
var Txin = require('../lib/txin');
|
||
|
var Txout = require('../lib/txout');
|
||
|
var should = require('chai').should();
|
||
|
var BufferReader = require('../lib/bufferreader');
|
||
|
var BufferWriter = require('../lib/bufferwriter');
|
||
|
|
||
|
describe('Transaction', function() {
|
||
|
|
||
|
it('should make a new transaction', function() {
|
||
|
var tx = new Transaction();
|
||
|
should.exist(tx);
|
||
|
tx = Transaction();
|
||
|
should.exist(tx);
|
||
|
});
|
||
|
|
||
|
var txin = Txin().fromBuffer(new Buffer('00000000000000000000000000000000000000000000000000000000000000000000000001ae00000000', 'hex'));
|
||
|
var txout = Txout().fromBuffer(new Buffer('050000000000000001ae', 'hex'));
|
||
|
var tx = Transaction().set({
|
||
|
version: 0,
|
||
|
txinsvarint: Varint(1),
|
||
|
txins: [txin],
|
||
|
txoutsvarint: Varint(1),
|
||
|
txouts: [txout],
|
||
|
nlocktime: 0
|
||
|
});
|
||
|
var txhex = '000000000100000000000000000000000000000000000000000000000000000000000000000000000001ae0000000001050000000000000001ae00000000';
|
||
|
var txbuf = new Buffer(txhex, 'hex');
|
||
|
|
||
|
describe('#set', function() {
|
||
|
|
||
|
it('should set all the basic parameters', function() {
|
||
|
var tx = Transaction().set({
|
||
|
version: 0,
|
||
|
txinsvarint: Varint(1),
|
||
|
txins: [txin],
|
||
|
txoutsvarint: Varint(1),
|
||
|
txouts: [txout],
|
||
|
nlocktime: 0
|
||
|
});
|
||
|
should.exist(tx.version);
|
||
|
should.exist(tx.txinsvarint);
|
||
|
should.exist(tx.txins);
|
||
|
should.exist(tx.txoutsvarint);
|
||
|
should.exist(tx.txouts);
|
||
|
should.exist(tx.nlocktime);
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
describe('#fromBuffer', function() {
|
||
|
|
||
|
it('should recover from this known tx', function() {
|
||
|
Transaction().fromBuffer(txbuf).toBuffer().toString('hex').should.equal(txhex);
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
describe('#fromBufferReader', function() {
|
||
|
|
||
|
it('should recover from this known tx', function() {
|
||
|
Transaction().fromBufferReader(BufferReader(txbuf)).toBuffer().toString('hex').should.equal(txhex);
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
describe('#toBuffer', function() {
|
||
|
|
||
|
it('should produce this known tx', function() {
|
||
|
Transaction().fromBuffer(txbuf).toBuffer().toString('hex').should.equal(txhex);
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
describe('#toBufferWriter', function() {
|
||
|
|
||
|
it('should produce this known tx', function() {
|
||
|
Transaction().fromBuffer(txbuf).toBufferWriter().concat().toString('hex').should.equal(txhex);
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
});
|