add failing test for Block#toObject
This commit is contained in:
parent
c53b9861d3
commit
dff0891871
|
@ -55,13 +55,16 @@ Input.prototype._fromObject = function(params) {
|
|||
};
|
||||
|
||||
Input.prototype.toObject = function toObject() {
|
||||
return {
|
||||
var obj = {
|
||||
prevTxId: this.prevTxId.toString('hex'),
|
||||
outputIndex: this.outputIndex,
|
||||
sequenceNumber: this.sequenceNumber,
|
||||
script: this.script.toString(),
|
||||
output: this.output ? this.output.toObject() : undefined
|
||||
};
|
||||
if (this.output) {
|
||||
obj.output = this.output.toObject();
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
Input.fromObject = function(obj) {
|
||||
|
|
|
@ -32,6 +32,9 @@ describe('Block', function() {
|
|||
var genesishex = '0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000';
|
||||
var genesisbuf = new Buffer(genesishex, 'hex');
|
||||
var genesisidhex = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f';
|
||||
var blockOneHex = '010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e362990101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000';
|
||||
var blockOneBuf = new Buffer(blockOneHex, 'hex');
|
||||
var blockOneId = '00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048';
|
||||
|
||||
it('should make a new block', function() {
|
||||
var b = Block(blockbuf);
|
||||
|
@ -164,6 +167,40 @@ describe('Block', function() {
|
|||
|
||||
});
|
||||
|
||||
describe.only('#toObject', function() {
|
||||
|
||||
it('should recover a block from genesis block buffer', function() {
|
||||
var block = Block.fromBuffer(blockOneBuf);
|
||||
block.id.should.equal(blockOneId);
|
||||
block.toObject().should.deep.equal({
|
||||
header: {
|
||||
version: 1,
|
||||
prevHash: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
|
||||
merkleRoot: '0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098',
|
||||
time: 1231469665,
|
||||
bits: 486604799,
|
||||
nonce: 2573394689
|
||||
},
|
||||
transactions: [{
|
||||
version: 1,
|
||||
inputs: [{
|
||||
prevTxId: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
outputIndex: 4294967295,
|
||||
sequenceNumber: 4294967295,
|
||||
script: '4 0xffff001d 1 0x04'
|
||||
}],
|
||||
outputs: [{
|
||||
satoshis: 5000000000,
|
||||
script: '65 0x0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be' +
|
||||
'63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee OP_CHECKSIG'
|
||||
}],
|
||||
nLockTime: 0
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#_getHash', function() {
|
||||
|
||||
it('should return the correct hash of the genesis block', function() {
|
||||
|
|
Loading…
Reference in New Issue