fixed outpoint bug and added first test

This commit is contained in:
Buck 2017-11-03 14:51:37 -07:00
parent bab42bbed8
commit 68b3ddf482
2 changed files with 27 additions and 1 deletions

View File

@ -69,7 +69,7 @@ Outpoint.fromOptions = function fromOptions(options) {
Outpoint.prototype.clone = function clone() {
const outpoint = new Outpoint();
outpoint.hash = this.value;
outpoint.hash = this.hash;
outpoint.index = this.index;
return outpoint;
};

26
test/outpoint-test.js Normal file
View File

@ -0,0 +1,26 @@
/* eslint-env mocha */
'use strict';
const Outpoint = require('../lib/primitives/outpoint');
const assert = require('./util/assert');
const common = require('./util/common');
const OUTPOINT_SIZE = 36;
const tx1 = common.readTX('tx1').getRaw();
const rawOutpoint1 = tx1.slice(5, 5+OUTPOINT_SIZE);
const tx2 = common.readTX('tx2').getRaw();
const rawOutpoint2 = tx2.slice(5, 5+OUTPOINT_SIZE);
describe('Outpoint', () => {
it('should clone the outpoint correctly', () => {
const raw = rawOutpoint1.slice();
const outpointObject = Outpoint.fromRaw(raw);
const clone = outpointObject.clone();
const equals = outpointObject.equals(clone);
assert.strictEqual(outpointObject !== clone, true);
assert.strictEqual(equals, true);
});
});