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;
|
2014-07-31 19:32:24 -07:00
|
|
|
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
|
|
|
|
}
|
2014-07-30 17:19:39 -07:00
|
|
|
|
2014-07-31 19:32:24 -07:00
|
|
|
var FakeBuilder = require('./mocks/FakeBuilder');
|
|
|
|
var TxProposal = copay.TxProposal;
|
2014-07-31 21:09:46 -07:00
|
|
|
var TxProposals = copay.TxProposals;
|
2014-07-30 17:19:39 -07:00
|
|
|
|
2014-07-31 19:32:24 -07:00
|
|
|
var dummyProposal = new TxProposal({
|
|
|
|
creator: 1,
|
|
|
|
createdTs: 1,
|
|
|
|
builder: new FakeBuilder(),
|
|
|
|
inputChainPaths: ['m/1'],
|
|
|
|
});
|
2014-04-21 16:28:57 -07:00
|
|
|
|
2014-07-31 19:32:24 -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() {
|
2014-07-31 19:32:24 -07:00
|
|
|
describe('constructor', function() {
|
|
|
|
it('should create an instance', function() {
|
2014-07-31 21:09:46 -07:00
|
|
|
var txps = new TxProposals();
|
2014-07-31 19:32:24 -07:00
|
|
|
should.exist(txps);
|
|
|
|
txps.network.name.should.equal('testnet');
|
2014-04-21 16:28:57 -07:00
|
|
|
});
|
|
|
|
});
|
2014-07-31 19:32:24 -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({
|
2014-07-31 19:32:24 -07:00
|
|
|
networkName:'livenet',
|
|
|
|
walletId: '123a12',
|
|
|
|
txps: [],
|
|
|
|
});
|
|
|
|
should.exist(txps);
|
|
|
|
txps.network.name.should.equal('livenet');
|
2014-04-09 13:28:35 -07:00
|
|
|
});
|
2014-07-31 19:32:24 -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({
|
2014-07-31 19:32:24 -07:00
|
|
|
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
|
|
|
});
|
2014-07-31 19:32:24 -07:00
|
|
|
describe('#getNtxids', function() {
|
|
|
|
it('should return keys', function() {
|
2014-07-31 21:09:46 -07:00
|
|
|
var txps = new TxProposals();
|
2014-07-31 19:32:24 -07:00
|
|
|
txps.txps = {a:1, b:2};
|
|
|
|
txps.getNtxids().should.deep.equal(['a','b']);
|
2014-04-10 21:09:42 -07:00
|
|
|
});
|
2014-07-31 19:32:24 -07:00
|
|
|
});
|
|
|
|
describe('#toObj', function() {
|
|
|
|
it('should an object', function() {
|
2014-07-31 21:09:46 -07:00
|
|
|
var txps = TxProposals.fromObj({
|
2014-07-31 19:32:24 -07:00
|
|
|
networkName:'livenet',
|
|
|
|
walletId: '123a12',
|
|
|
|
txps: [],
|
2014-07-30 17:19:39 -07:00
|
|
|
});
|
2014-07-31 19:32:24 -07:00
|
|
|
var o = txps.toObj();
|
|
|
|
o.walletId.should.equal('123a12');
|
|
|
|
o.networkName.should.equal('livenet');
|
2014-07-30 17:19:39 -07:00
|
|
|
});
|
2014-07-31 19:32:24 -07:00
|
|
|
it('should export txps', function() {
|
2014-07-31 21:09:46 -07:00
|
|
|
var txps = TxProposals.fromObj({
|
2014-07-31 19:32:24 -07:00
|
|
|
networkName:'livenet',
|
|
|
|
walletId: '123a12',
|
|
|
|
txps: [],
|
2014-07-30 17:19:39 -07:00
|
|
|
});
|
2014-07-31 19:32:24 -07:00
|
|
|
txps.txps = {
|
|
|
|
'hola' : dummyProposal,
|
|
|
|
'chau' : dummyProposal,
|
2014-07-30 17:19:39 -07:00
|
|
|
};
|
2014-07-31 19:32:24 -07:00
|
|
|
var o = txps.toObj();
|
|
|
|
o.txps.length.should.equal(2);
|
2014-04-09 19:04:22 -07:00
|
|
|
});
|
2014-07-31 19:32:24 -07:00
|
|
|
it('should filter sent txp', function() {
|
2014-07-31 21:09:46 -07:00
|
|
|
var txps = TxProposals.fromObj({
|
2014-07-31 19:32:24 -07:00
|
|
|
networkName:'livenet',
|
|
|
|
walletId: '123a12',
|
|
|
|
txps: [],
|
2014-07-24 15:41:40 -07:00
|
|
|
});
|
2014-07-31 19:32:24 -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
|
|
|
};
|
2014-07-31 19:32:24 -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
|
|
|
});
|
2014-07-25 13:45:56 -07:00
|
|
|
|