2019-05-27 10:33:22 -07:00
|
|
|
describe('explorer', function() {
|
|
|
|
|
var lib = require('../lib/explorer');
|
2020-12-20 20:33:07 -07:00
|
|
|
var data = require('./testData.js');
|
2019-05-27 10:33:22 -07:00
|
|
|
|
|
|
|
|
describe('convert_to_satoshi', function() {
|
|
|
|
|
it('should be able to convert round numbers', function() {
|
2025-02-02 19:10:17 -07:00
|
|
|
const amount_sat = lib.convert_to_satoshi(500);
|
|
|
|
|
expect(amount_sat).toEqual(50000000000);
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should be able to convert decimals above 1', function() {
|
2025-02-02 19:10:17 -07:00
|
|
|
const amount_sat = lib.convert_to_satoshi(500.12564);
|
|
|
|
|
expect(amount_sat).toEqual(50012564000);
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should be able to convert decimals below 1', function() {
|
2025-02-02 19:10:17 -07:00
|
|
|
const amount_sat = lib.convert_to_satoshi(0.0005);
|
|
|
|
|
expect(amount_sat).toEqual(50000);
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('is_unique', function() {
|
2020-12-20 20:33:07 -07:00
|
|
|
var arrayStrMap = [
|
2019-05-27 10:33:22 -07:00
|
|
|
{'addresses' : 'XsF8k8s5CoS3XATqW2FkuTsznbJJzFAC2U'},
|
|
|
|
|
{'addresses' : 'XsF8k8s5C14FbhqW2FkuATsznFACAfVhUn'},
|
|
|
|
|
{'addresses' : 'XsF8k8s5CoAF5gTqW2FkuTsznbJJzhkj5A'},
|
|
|
|
|
{'addresses' : 'XfuW2K9QiGMSsq5eXgtimEQvTvz9dzBCzb'}
|
|
|
|
|
];
|
|
|
|
|
|
2020-12-20 20:33:07 -07:00
|
|
|
var arrayArrMap = [
|
2019-05-27 10:33:22 -07:00
|
|
|
{'addresses' : ['XsF8k8s5CoS3XATqW2FkuTsznbJJzFAC2U']},
|
|
|
|
|
{'addresses' : ['XsF8k8s5C14FbhqW2FkuATsznFACAfVhUn']},
|
|
|
|
|
{'addresses' : ['XsF8k8s5CoAF5gTqW2FkuTsznbJJzhkj5A']},
|
|
|
|
|
{'addresses' : ['XfuW2K9QiGMSsq5eXgtimEQvTvz9dzBCzb']}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
it('should return index of matching string object', function() {
|
2025-02-02 19:10:17 -07:00
|
|
|
const index = lib.is_unique(arrayStrMap, arrayStrMap[2].addresses, 'addresses');
|
|
|
|
|
expect(index).toEqual(2);
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return index of matching array object', function() {
|
2025-02-02 19:10:17 -07:00
|
|
|
const index = lib.is_unique(arrayArrMap, arrayArrMap[2].addresses, 'addresses');
|
|
|
|
|
expect(index).toEqual(2);
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
|
2025-02-02 19:10:17 -07:00
|
|
|
it('should return index of -1 if no matching string object', function() {
|
|
|
|
|
const index = lib.is_unique(arrayStrMap, 'unique', 'addresses');
|
|
|
|
|
expect(index).toEqual(-1);
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
|
2025-02-02 19:10:17 -07:00
|
|
|
it('should return index of -1 if no matching array object', function() {
|
|
|
|
|
const index = lib.is_unique(arrayArrMap, ['unique'], 'addresses');
|
|
|
|
|
expect(index).toEqual(-1);
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('prepare_vout', function() {
|
|
|
|
|
var originalTimeout;
|
2021-03-17 17:54:09 -06:00
|
|
|
|
2019-05-27 10:33:22 -07:00
|
|
|
beforeEach(function() {
|
|
|
|
|
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should ignore nonstandard outputs', function(done) {
|
2020-12-20 20:33:07 -07:00
|
|
|
lib.prepare_vout(data.txA().vout, data.txA().txid, data.txA().vin, ((typeof data.txA().vjoinsplit === 'undefined' || data.txA().vjoinsplit == null) ? [] : data.txA().vjoinsplit), function(prepared) {
|
|
|
|
|
expect(prepared.length).toEqual(2);
|
|
|
|
|
done();
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should maintain order', function(done) {
|
2020-12-20 20:33:07 -07:00
|
|
|
lib.prepare_vout(data.txA().vout, data.txA().txid, data.txA().vin, ((typeof data.txA().vjoinsplit === 'undefined' || data.txA().vjoinsplit == null) ? [] : data.txA().vjoinsplit), function(prepared) {
|
|
|
|
|
expect(prepared[1].amount).toEqual(17499989908960);
|
|
|
|
|
expect(prepared[1].addresses).toEqual('ENpRvyLpLFEyrMZthAGABhxZi3N4Byk3Ab');
|
|
|
|
|
done();
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('calculate_total', function() {
|
|
|
|
|
var originalTimeout;
|
|
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should calculate correct total', function(done) {
|
2020-12-20 20:33:07 -07:00
|
|
|
lib.prepare_vout(data.txA().vout, data.txA().txid, data.txA().vin, ((typeof data.txA().vjoinsplit === 'undefined' || data.txA().vjoinsplit == null) ? [] : data.txA().vjoinsplit), function(prepared) {
|
2025-02-02 19:10:17 -07:00
|
|
|
const total = lib.calculate_total(prepared)
|
|
|
|
|
expect(total).toEqual(19499989908960);
|
|
|
|
|
done();
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('prepare_vin', function() {
|
|
|
|
|
var originalTimeout;
|
|
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return array of correct length', function(done) {
|
|
|
|
|
lib.prepare_vin(data.txB(), function(prepared) {
|
2020-12-20 20:33:07 -07:00
|
|
|
expect(prepared.length).toEqual(1);
|
|
|
|
|
done();
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should get correct input addresses', function(done) {
|
|
|
|
|
lib.prepare_vin(data.txB(), function(prepared) {
|
2020-12-20 20:33:07 -07:00
|
|
|
expect(prepared[0].amount).toEqual(27499989920000);
|
|
|
|
|
expect(prepared[0].addresses).toEqual('coinbase');
|
|
|
|
|
done();
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|