copay/test/test.TxProposals.js

117 lines
3.2 KiB
JavaScript
Raw Normal View History

2014-04-09 13:28:35 -07:00
'use strict';
2014-06-10 06:39:57 -07:00
var chai = chai || require('chai');
var should = chai.should();
var bitcore = bitcore || require('bitcore');
var Transaction = bitcore.Transaction;
var buffertools = bitcore.buffertools;
var WalletKey = bitcore.WalletKey;
var Key = bitcore.Key;
2014-06-17 09:39:41 -07:00
var bignum = bitcore.Bignum;
2014-06-10 06:39:57 -07:00
var Script = bitcore.Script;
2014-07-24 15:41:40 -07:00
var TransactionBuilder = bitcore.TransactionBuilder;
2014-06-10 06:39:57 -07:00
var util = bitcore.util;
var networks = bitcore.networks;
var sinon = require('sinon');
2014-08-14 08:25:15 -07:00
try {
var copay = require('copay'); //browser
} catch (e) {
var copay = require('../copay'); //node
}
var FakeBuilder = require('./mocks/FakeBuilder');
var TxProposal = copay.TxProposal;
2014-07-31 21:09:46 -07:00
var TxProposals = copay.TxProposals;
var dummyProposal = new TxProposal({
creator: 1,
createdTs: 1,
builder: new FakeBuilder(),
inputChainPaths: ['m/1'],
});
2014-04-21 16:28:57 -07:00
var someKeys = ["03b39d61dc9a504b13ae480049c140dcffa23a6cc9c09d12d6d1f332fee5e18ca5", "022929f515c5cf967474322468c3bd945bb6f281225b2c884b465680ef3052c07e"];
2014-04-21 16:28:57 -07:00
2014-07-31 21:09:46 -07:00
describe('TxProposals', function() {
describe('constructor', function() {
it('should create an instance', function() {
2014-07-31 21:09:46 -07:00
var txps = new TxProposals();
should.exist(txps);
txps.network.name.should.equal('testnet');
2014-04-21 16:28:57 -07:00
});
});
describe('#fromObj', function() {
it('should create an instance from an Object', function() {
2014-07-31 21:09:46 -07:00
var txps = TxProposals.fromObj({
networkName:'livenet',
walletId: '123a12',
txps: [],
});
should.exist(txps);
txps.network.name.should.equal('livenet');
2014-04-09 13:28:35 -07:00
});
it('should fail create an instance from an Object with errors', function() {
2014-07-31 21:09:46 -07:00
(function() {var txps = TxProposals.fromObj({
networkName:'livenet',
walletId: '123a12',
txps: [ { a: 1 }],
}) }).should.throw('Illegal');
2014-04-21 08:00:14 -07:00
});
2014-04-10 21:09:42 -07:00
});
describe('#getNtxids', function() {
it('should return keys', function() {
2014-07-31 21:09:46 -07:00
var txps = new TxProposals();
txps.txps = {a:1, b:2};
txps.getNtxids().should.deep.equal(['a','b']);
2014-04-10 21:09:42 -07:00
});
});
describe('#toObj', function() {
it('should an object', function() {
2014-07-31 21:09:46 -07:00
var txps = TxProposals.fromObj({
networkName:'livenet',
walletId: '123a12',
txps: [],
});
var o = txps.toObj();
o.walletId.should.equal('123a12');
o.networkName.should.equal('livenet');
});
it('should export txps', function() {
2014-07-31 21:09:46 -07:00
var txps = TxProposals.fromObj({
networkName:'livenet',
walletId: '123a12',
txps: [],
});
txps.txps = {
'hola' : dummyProposal,
'chau' : dummyProposal,
};
var o = txps.toObj();
o.txps.length.should.equal(2);
2014-04-09 19:04:22 -07:00
});
it('should filter sent txp', function() {
2014-07-31 21:09:46 -07:00
var txps = TxProposals.fromObj({
networkName:'livenet',
walletId: '123a12',
txps: [],
2014-07-24 15:41:40 -07:00
});
var d = JSON.parse(JSON.stringify(dummyProposal));
d.sent=1;
txps.txps = {
'hola' : dummyProposal,
'chau' : d,
2014-07-24 15:41:40 -07:00
};
var o = txps.toObj();
o.txps.length.should.equal(1);
2014-07-24 15:41:40 -07:00
});
});
2014-07-31 21:09:46 -07:00
describe.skip('#merge', function() {
2014-08-06 11:56:17 -07:00
it('should merge', function() {
2014-07-31 21:09:46 -07:00
var txps = new TxProposals();
2014-08-06 11:56:17 -07:00
var d = dummyProposal;
txps.merge(d.toObj(),{});
2014-07-31 21:09:46 -07:00
});
});
2014-04-09 13:28:35 -07:00
});