Wallet/test/TxProposals.js

124 lines
3.4 KiB
JavaScript
Raw Normal View History

2014-04-09 17:28:35 -03:00
'use strict';
2014-06-10 10:39:57 -03:00
var Transaction = bitcore.Transaction;
var WalletKey = bitcore.WalletKey;
var Key = bitcore.Key;
2014-06-17 09:39:41 -07:00
var bignum = bitcore.Bignum;
2014-06-10 10:39:57 -03:00
var Script = bitcore.Script;
2014-07-24 19:41:40 -03:00
var TransactionBuilder = bitcore.TransactionBuilder;
2014-06-10 10:39:57 -03:00
var util = bitcore.util;
var networks = bitcore.networks;
var TxProposal = copay.TxProposal;
2014-08-01 01:09:46 -03:00
var TxProposals = copay.TxProposals;
var dummyProposal = new TxProposal({
creator: 1,
createdTs: 1,
2014-11-26 15:15:12 -03:00
builder: {
toObj: sinon.stub().returns({}),
},
inputChainPaths: ['m/1'],
});
2014-04-21 20:28:57 -03:00
var someKeys = ["03b39d61dc9a504b13ae480049c140dcffa23a6cc9c09d12d6d1f332fee5e18ca5", "022929f515c5cf967474322468c3bd945bb6f281225b2c884b465680ef3052c07e"];
2014-04-21 20:28:57 -03:00
2014-08-01 01:09:46 -03:00
describe('TxProposals', function() {
describe('constructor', function() {
it('should create an instance', function() {
2014-08-01 01:09:46 -03:00
var txps = new TxProposals();
should.exist(txps);
txps.network.name.should.equal('testnet');
2014-04-21 20:28:57 -03:00
});
});
describe('#fromObj', function() {
it('should create an instance from an Object', function() {
2014-08-01 01:09:46 -03:00
var txps = TxProposals.fromObj({
networkName:'livenet',
walletId: '123a12',
txps: [],
});
should.exist(txps);
txps.network.name.should.equal('livenet');
2014-04-09 17:28:35 -03:00
});
2014-10-01 12:42:56 -03:00
it('should skip Objects with errors', function() {
var txps = TxProposals.fromObj({
networkName:'livenet',
walletId: '123a12',
txps: [ { a: 1 }],
2014-10-01 12:42:56 -03:00
});
should.exist(txps);
Object.keys(txps.txps).length.should.equal(0);
2014-04-21 12:00:14 -03:00
});
2014-04-11 01:09:42 -03:00
});
describe('#getNtxids', function() {
it('should return keys', function() {
2014-08-01 01:09:46 -03:00
var txps = new TxProposals();
txps.txps = {a:1, b:2};
txps.getNtxids().should.deep.equal(['a','b']);
2014-04-11 01:09:42 -03:00
});
});
2014-08-28 11:04:45 -03:00
describe('#deleteOne', function() {
it('should delete specified ntxid', function() {
var txps = new TxProposals();
txps.txps = {a:1, b:2};
txps.deleteOne('a');
txps.getNtxids().should.deep.equal(['b']);
});
it('should fail on non-existent ntxid', function() {
var txps = new TxProposals();
txps.txps = {a:1, b:2};
(function () {
txps.deleteOne('c');
}).should.throw('Unknown TXP: c');
});
});
describe('#toObj', function() {
it('should an object', function() {
2014-08-01 01:09:46 -03: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-08-01 01:09:46 -03: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 23:04:22 -03:00
});
it('should filter sent txp', function() {
2014-08-01 01:09:46 -03:00
var txps = TxProposals.fromObj({
networkName:'livenet',
walletId: '123a12',
txps: [],
2014-07-24 19:41:40 -03:00
});
var d = JSON.parse(JSON.stringify(dummyProposal));
d.sent=1;
txps.txps = {
'hola' : dummyProposal,
'chau' : d,
2014-07-24 19:41:40 -03:00
};
var o = txps.toObj();
o.txps.length.should.equal(1);
2014-07-24 19:41:40 -03:00
});
});
2014-08-01 01:09:46 -03:00
describe.skip('#merge', function() {
2014-08-06 15:56:17 -03:00
it('should merge', function() {
2014-08-01 01:09:46 -03:00
var txps = new TxProposals();
2014-08-06 15:56:17 -03:00
var d = dummyProposal;
txps.merge(d.toObj(),{});
2014-08-01 01:09:46 -03:00
});
});
2014-04-09 17:28:35 -03:00
});