fix conflics

This commit is contained in:
Matias Alejo Garcia 2014-06-19 16:34:37 -03:00
commit 44901cd635
19 changed files with 560 additions and 350 deletions

View file

@ -97,8 +97,8 @@ describe('TxProposals model', function() {
priv,
pkr
));
var k = Object.keys(w.txps)[0];
var b = w.txps[k].builder;
var ntxid = Object.keys(w.txps)[0];
var b = w.txps[ntxid].builder;
var tx = b.build();
tx.isComplete().should.equal(false);
b.sign(priv2.getAll(pkr.indexes.getReceiveIndex(), pkr.indexes.getChangeIndex()));
@ -211,15 +211,15 @@ describe('TxProposals model', function() {
priv,
pkr
));
var k = Object.keys(w.txps)[0];
var tx = w.txps[k].builder.build();
var ntxid = Object.keys(w.txps)[0];
var tx = w.txps[ntxid].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
var info = w.merge(w);
var info = w.merge(w.txps[ntxid]);
info.events.length.should.equal(0);
Object.keys(w.txps).length.should.equal(1);
@ -227,8 +227,8 @@ describe('TxProposals model', function() {
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
});
@ -261,13 +261,13 @@ describe('TxProposals model', function() {
pkr
));
var k = Object.keys(w.txps)[0];
var tx = w.txps[k].builder.build();
var ntxid = Object.keys(w.txps)[0];
var tx = w.txps[ntxid].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(1);
Object.keys(w.txps[k].signedBy).length.should.equal(0);
Object.keys(w.txps[k].seenBy).length.should.equal(1);
Object.keys(w.txps[ntxid].signedBy).length.should.equal(0);
Object.keys(w.txps[ntxid].seenBy).length.should.equal(1);
var w2 = new TxProposals({
@ -285,25 +285,25 @@ describe('TxProposals model', function() {
pkr
));
var k = Object.keys(w.txps)[0];
var tx = w2.txps[k].builder.build();
var ntxid = Object.keys(w.txps)[0];
var tx = w2.txps[ntxid].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w2.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
var info = w.merge(w2);
var info = w.merge(w2.txps[ntxid]);
info.events.length.should.equal(1);
info.events[0].type.should.equal('signed');
Object.keys(w.txps).length.should.equal(1);
var tx = w.txps[k].builder.build();
var tx = w.txps[ntxid].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
});
@ -401,7 +401,7 @@ describe('TxProposals model', function() {
(w2.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
var info = w.merge(w2);
var info = w.merge(w2.txps[ntxid]);
info.events.length.should.equal(1);
info.events[0].type.should.equal('signed');
@ -431,7 +431,7 @@ describe('TxProposals model', function() {
(w3.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
(w3.txps[ntxid].seenBy[priv2.id] - ts > 0).should.equal(true);
var info = w.merge(w3);
var info = w.merge(w3.txps[ntxid]);
info.events.length.should.equal(0);
Object.keys(w.txps).length.should.equal(1);
@ -475,12 +475,12 @@ describe('TxProposals model', function() {
priv,
pkr
));
var k = Object.keys(w.txps)[0];
var tx = w.txps[k].builder.build();
var ntxid = Object.keys(w.txps)[0];
var tx = w.txps[ntxid].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
var w2 = new TxProposals({
@ -496,11 +496,11 @@ describe('TxProposals model', function() {
priv2,
pkr
));
var tx = w2.txps[k].builder.build();
var tx = w2.txps[ntxid].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w2.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
(w2.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
(w2.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
(w2.txps[ntxid].seenBy[priv2.id] - ts > 0).should.equal(true);
var w3 = new TxProposals({
@ -516,38 +516,38 @@ describe('TxProposals model', function() {
priv3,
pkr
));
var tx = w3.txps[k].builder.build();
var tx = w3.txps[ntxid].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w3.txps[k].signedBy[priv3.id] - ts > 0).should.equal(true);
(w3.txps[k].seenBy[priv3.id] - ts > 0).should.equal(true);
(w3.txps[ntxid].signedBy[priv3.id] - ts > 0).should.equal(true);
(w3.txps[ntxid].seenBy[priv3.id] - ts > 0).should.equal(true);
var info = w.merge(w2);
var info = w.merge(w2.txps[ntxid]);
info.events.length.should.equal(0);
Object.keys(w.txps).length.should.equal(1);
var tx = w.txps[k].builder.build();
var tx = w.txps[ntxid].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(1);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
var info = w.merge(w3);
var info = w.merge(w3.txps[ntxid]);
info.events.length.should.equal(0);
var tx = w.txps[k].builder.build();
var tx = w.txps[ntxid].builder.build();
tx.isComplete().should.equal(true);
tx.countInputMissingSignatures(0).should.equal(0);
Object.keys(w.txps).length.should.equal(1);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv3.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv3.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv3.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv3.id] - ts > 0).should.equal(true);
});
@ -573,12 +573,12 @@ describe('TxProposals model', function() {
priv,
pkr
));
var k = Object.keys(w.txps)[0];
var tx = w.txps[k].builder.build();
var ntxid = Object.keys(w.txps)[0];
var tx = w.txps[ntxid].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
var o = w.toObj();
should.exist(o);
@ -593,15 +593,15 @@ describe('TxProposals model', function() {
var o2 = JSON.parse(JSON.stringify(o));
var w2 = TxProposals.fromObj(o2);
w2.walletId.should.equal(w.walletId);
var tx2 = w2.txps[k].builder.build();
var tx2 = w2.txps[ntxid].builder.build();
tx2.isComplete().should.equal(false);
tx2.countInputMissingSignatures(0).should.equal(2);
(w2.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
should.exist(w2.txps[k].builder);
should.exist(w2.txps[k].builder.valueInSat);
(w2.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
should.exist(w2.txps[ntxid].builder);
should.exist(w2.txps[ntxid].builder.valueInSat);
w2.merge(w);
w2.merge(w.txps[ntxid]);
Object.keys(w2.txps).length.should.equal(1);
});

View file

@ -37,6 +37,10 @@ describe('Wallet model', function() {
}).should.
throw();
});
it('should getNetworkName', function() {
var w = createW();
w.getNetworkName().should.equal('testnet');
});
var createW = function(netKey, N) {
@ -293,23 +297,13 @@ describe('Wallet model', function() {
it('call reconnect after interval', function(done) {
this.timeout(10000);
var w = createW2();
var testTime = 1000;
var callCount = 0;
var cT = w.reconnectDelay;
var t = 0;
do {
callCount++;
t += cT;
cT *= 2;
} while (t < testTime);
var spy = sinon.spy(w, 'scheduleConnect');
var callCount = 3;
w.netStart();
setTimeout(function() {
sinon.assert.callCount(spy, callCount);
done();
}, testTime);
}, w.reconnectDelay*callCount*(callCount+1)/2);
});
it('handle network indexes correctly', function() {
@ -357,52 +351,49 @@ describe('Wallet model', function() {
it('handle network txProposals correctly', function() {
var w = createW();
var txps = {
'txProposals': {
"txps": [{
"seenBy": {
"undefined": 1402337282806
var txp = {
'txProposal': {
"seenBy": {
"undefined": 1402337282806
},
"signedBy": {
"undefined": 1402337282841
},
"rejectedBy": {},
"sentTs": null,
"sentTxid": null,
"inputChainPaths": [],
"builderObj": {
"valueInSat": "1000000000",
"valueOutSat": "123456789",
"feeSat": "10000",
"remainderSat": "876533211",
"hashToScriptMap": {
"3QjgeBsNeiDkoVQxDAw4sSEe9BVaqhmpnd": "5321025c2951a7e94e39f2c3210fb2d71b7d79044f7daa6b007556a6feb4b2059091e921026c56eea4ef632b24c4efe9d5391ea0e15e306450e5b7db26cd1a7a33d9d4e82821026d06e532385186793121633fb365fa2f0c7246b30590db78cba795641c94734521035051d2b742263bc5257c5a4461e1a6fa32c3f1965f5ab5e8b0f0f80c9e28bc702103ddb0d39c1cd88295e7b81050dcab11ca4419bf64fba3ef9d9130ea64d6604ab055ae",
"365dPtmHPAdUUNvPBcnfidYt2Snyaka7AH": "5321020faaf739abda51e822621d42062470c5743a127186369a67fd3303f71727fb1d210237063d3b27c21767054dad203298bfed90cb08dca371950a08b88aa979c33bd22102a3780cb275b6dcb8b379514679387d4578068745f08c5799e4ee1a90aa3a70922102f4fea0cd5bc2418892278f480682690857f4d963deeb95d88febfa255e4ce0b821035d53fa74fee26873c3f5a4acf4dce53ff9d50db59e1ca4acddb82168dd429a3355ae",
"372DueknmmjVR3zcWfEfADp8FwJ3ARhGaN": "532102666c2873c9e6f58ca594cd6c8327a1515db32ebadbaff4fe75e63b917560b7d021031ca2d159ae8868a5eef6d67a5a8a5bcc6fb2e8b711669f1c1e8b05327236a3cf2103798a4ce34929cb450bf88557dd90cae538c67f9d0c76314ae18679200be9c17021039624dec23dc1bb628cea55e949ea26225949a3349346a0732fef9def6f1f75292103d1edaadb8555012b752dd7a5c6672c379ce827e4bc0d4e992ee1ab3488b445b255ae",
"3GLJbHv7RqPeFk2SqWapqJ3XibVibiKi8f": "5321021a33d48b9f5d3adc41004709313277d4c6969268cf41e3f5b695a934c676829a21031b87321307db7a0f6ea22847a538505188f1a2231eba68867e17c5f0e4434c0721035dee0a6e1df66a6c9c7592ef03aa02bba9b06742134d27bd08f356e33f21259c2103768a109d682a76c09f865912e9e64a8689b03c1a231c613d87ec9bd535fd74c22103911038638b9fc52b2d375ce207c8388bd5ee7f2d54ab9b4148bd406c6d7dcad355ae",
"3E1d1z7gJSFeZM2d3k12MJ1jGwrBRy1YTw": "5321027da98ce0407138461f4ad803a1fb67afa4246f06ad0e1256a087daeffd82a8642102e7f87f2b094ec322be2fb99d3ca81fd6ac0ab26ce081e51ab18c507f8b6d1d162102ed5d256036e10568c33e0a15021cc1806e04d7d24c8f020aaae23ec2deecb4302103b6f88231bb5a5f4629e4d097492321f86968c6aeb012196a1fe3b217fe4ae0ac2103f6b5e2c1db3124a5058a0e3e83d5d0c412b9a5b50e2ef97e2b7e1c0af57ab3e355ae",
"3QYueyPXq2QDRQCDo7agTimz9673NKV25E": "5321021543292c2942708ccc83354ebf507044b310ed0d33a19e2327a49be53e0f314221024a1a83f8c50f6cad7c134b9cded509dabf196ae49eca157a39ad95798943dc95210292698fbb97e8f6e67296b22b36367ba85c8101fcbc27bb4b00b43623639212ac2102d86980796027a00ba7aa9b53671762c908962654f969f5dec340071bb30e8d7621038fb3fa5e77dafd24c09d819dbdc7c11dca55b350511bf3bc499c09316a89286e55ae",
"372BzC1GGjziT8zGYbryja3kF2KaTeobRK": "53210214ec25e5cb42e51883d4e615316748feefe91133fcfc0f93f0b5a24a55e0a347210262336210b3173aa4ca90d292990f463e42bdeb2e73112925dc712c5a2e749bcb210277517855f512564f225e63c650dad7720565aa563901d50743be4b0f0267dcc72102d2777a9faf5d2e2b2363e1270d61021bc2e36e8cb19ca9d29dedbba9a0348b532103a57db80b6ae573e5cef2115e36e73e5ef41f8a099bfb5087d80320c04a7db72e55ae"
},
"signedBy": {
"undefined": 1402337282841
},
"rejectedBy": {},
"sentTs": null,
"sentTxid": null,
"inputChainPaths": [],
"builderObj": {
"valueInSat": "1000000000",
"valueOutSat": "123456789",
"feeSat": "10000",
"remainderSat": "876533211",
"hashToScriptMap": {
"3QjgeBsNeiDkoVQxDAw4sSEe9BVaqhmpnd": "5321025c2951a7e94e39f2c3210fb2d71b7d79044f7daa6b007556a6feb4b2059091e921026c56eea4ef632b24c4efe9d5391ea0e15e306450e5b7db26cd1a7a33d9d4e82821026d06e532385186793121633fb365fa2f0c7246b30590db78cba795641c94734521035051d2b742263bc5257c5a4461e1a6fa32c3f1965f5ab5e8b0f0f80c9e28bc702103ddb0d39c1cd88295e7b81050dcab11ca4419bf64fba3ef9d9130ea64d6604ab055ae",
"365dPtmHPAdUUNvPBcnfidYt2Snyaka7AH": "5321020faaf739abda51e822621d42062470c5743a127186369a67fd3303f71727fb1d210237063d3b27c21767054dad203298bfed90cb08dca371950a08b88aa979c33bd22102a3780cb275b6dcb8b379514679387d4578068745f08c5799e4ee1a90aa3a70922102f4fea0cd5bc2418892278f480682690857f4d963deeb95d88febfa255e4ce0b821035d53fa74fee26873c3f5a4acf4dce53ff9d50db59e1ca4acddb82168dd429a3355ae",
"372DueknmmjVR3zcWfEfADp8FwJ3ARhGaN": "532102666c2873c9e6f58ca594cd6c8327a1515db32ebadbaff4fe75e63b917560b7d021031ca2d159ae8868a5eef6d67a5a8a5bcc6fb2e8b711669f1c1e8b05327236a3cf2103798a4ce34929cb450bf88557dd90cae538c67f9d0c76314ae18679200be9c17021039624dec23dc1bb628cea55e949ea26225949a3349346a0732fef9def6f1f75292103d1edaadb8555012b752dd7a5c6672c379ce827e4bc0d4e992ee1ab3488b445b255ae",
"3GLJbHv7RqPeFk2SqWapqJ3XibVibiKi8f": "5321021a33d48b9f5d3adc41004709313277d4c6969268cf41e3f5b695a934c676829a21031b87321307db7a0f6ea22847a538505188f1a2231eba68867e17c5f0e4434c0721035dee0a6e1df66a6c9c7592ef03aa02bba9b06742134d27bd08f356e33f21259c2103768a109d682a76c09f865912e9e64a8689b03c1a231c613d87ec9bd535fd74c22103911038638b9fc52b2d375ce207c8388bd5ee7f2d54ab9b4148bd406c6d7dcad355ae",
"3E1d1z7gJSFeZM2d3k12MJ1jGwrBRy1YTw": "5321027da98ce0407138461f4ad803a1fb67afa4246f06ad0e1256a087daeffd82a8642102e7f87f2b094ec322be2fb99d3ca81fd6ac0ab26ce081e51ab18c507f8b6d1d162102ed5d256036e10568c33e0a15021cc1806e04d7d24c8f020aaae23ec2deecb4302103b6f88231bb5a5f4629e4d097492321f86968c6aeb012196a1fe3b217fe4ae0ac2103f6b5e2c1db3124a5058a0e3e83d5d0c412b9a5b50e2ef97e2b7e1c0af57ab3e355ae",
"3QYueyPXq2QDRQCDo7agTimz9673NKV25E": "5321021543292c2942708ccc83354ebf507044b310ed0d33a19e2327a49be53e0f314221024a1a83f8c50f6cad7c134b9cded509dabf196ae49eca157a39ad95798943dc95210292698fbb97e8f6e67296b22b36367ba85c8101fcbc27bb4b00b43623639212ac2102d86980796027a00ba7aa9b53671762c908962654f969f5dec340071bb30e8d7621038fb3fa5e77dafd24c09d819dbdc7c11dca55b350511bf3bc499c09316a89286e55ae",
"372BzC1GGjziT8zGYbryja3kF2KaTeobRK": "53210214ec25e5cb42e51883d4e615316748feefe91133fcfc0f93f0b5a24a55e0a347210262336210b3173aa4ca90d292990f463e42bdeb2e73112925dc712c5a2e749bcb210277517855f512564f225e63c650dad7720565aa563901d50743be4b0f0267dcc72102d2777a9faf5d2e2b2363e1270d61021bc2e36e8cb19ca9d29dedbba9a0348b532103a57db80b6ae573e5cef2115e36e73e5ef41f8a099bfb5087d80320c04a7db72e55ae"
},
"selectedUtxos": [{
"address": "3E1d1z7gJSFeZM2d3k12MJ1jGwrBRy1YTw",
"scriptPubKey": "a91487264aa41e3df76f3156c7fa587fd7d5b1f7b96b87",
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
"vout": 1,
"amount": 10,
"confirmations": 7
}],
"inputsSigned": 0,
"signaturesAdded": 1,
"signhash": 1,
"spendUnconfirmed": false,
"tx": "0100000001c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a01000000fd40010047304402201aad0ea92f929be21d60afb741b76bfcf2aa9614079cb9da76b15b3a1210f07b02205bc5c1895105da3ee682e532d2d49dfd1214fa6123fb9c9d552336f135c77eff0147304402203f02f15bb4ad4bc7d0ca4612fd9e9ae05a1331f3d62f302cf08dba56695f5dcf0220700110562fe228ebba324b120de64a7bbaddf049d67a313f749e9b32ee88787d014cad5321027da98ce0407138461f4ad803a1fb67afa4246f06ad0e1256a087daeffd82a8642102e7f87f2b094ec322be2fb99d3ca81fd6ac0ab26ce081e51ab18c507f8b6d1d162102ed5d256036e10568c33e0a15021cc1806e04d7d24c8f020aaae23ec2deecb4302103b6f88231bb5a5f4629e4d097492321f86968c6aeb012196a1fe3b217fe4ae0ac2103f6b5e2c1db3124a5058a0e3e83d5d0c412b9a5b50e2ef97e2b7e1c0af57ab3e355aeffffffff0215cd5b07000000001976a91434f8e0c5be216025a52addf18a987543cad23f7a88acdbd53e340000000017a914a09f10bc42b61ecf9d3d09550765c228f1cb808a8700000000"
}
}],
"networkName": "testnet"
"selectedUtxos": [{
"address": "3E1d1z7gJSFeZM2d3k12MJ1jGwrBRy1YTw",
"scriptPubKey": "a91487264aa41e3df76f3156c7fa587fd7d5b1f7b96b87",
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
"vout": 1,
"amount": 10,
"confirmations": 7
}],
"inputsSigned": 0,
"signaturesAdded": 1,
"signhash": 1,
"spendUnconfirmed": false,
"tx": "0100000001c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a01000000fd40010047304402201aad0ea92f929be21d60afb741b76bfcf2aa9614079cb9da76b15b3a1210f07b02205bc5c1895105da3ee682e532d2d49dfd1214fa6123fb9c9d552336f135c77eff0147304402203f02f15bb4ad4bc7d0ca4612fd9e9ae05a1331f3d62f302cf08dba56695f5dcf0220700110562fe228ebba324b120de64a7bbaddf049d67a313f749e9b32ee88787d014cad5321027da98ce0407138461f4ad803a1fb67afa4246f06ad0e1256a087daeffd82a8642102e7f87f2b094ec322be2fb99d3ca81fd6ac0ab26ce081e51ab18c507f8b6d1d162102ed5d256036e10568c33e0a15021cc1806e04d7d24c8f020aaae23ec2deecb4302103b6f88231bb5a5f4629e4d097492321f86968c6aeb012196a1fe3b217fe4ae0ac2103f6b5e2c1db3124a5058a0e3e83d5d0c412b9a5b50e2ef97e2b7e1c0af57ab3e355aeffffffff0215cd5b07000000001976a91434f8e0c5be216025a52addf18a987543cad23f7a88acdbd53e340000000017a914a09f10bc42b61ecf9d3d09550765c228f1cb808a8700000000"
}
}
};
w._handleTxProposals('senderID', txps, true);
w._handleTxProposal('senderID', txp, true);
Object.keys(w.txProposals.txps).length.should.equal(1);
w.getTxProposals().length.should.equal(1);
});
@ -514,7 +505,6 @@ describe('Wallet model', function() {
});
// tx handling
var createUTXO = function(w) {
@ -577,7 +567,6 @@ describe('Wallet model', function() {
});
});
it('should create & sign & send a transaction', function(done) {
var w = createW2(null, 1);
var utxo = createUTXO(w);
w.blockchain.fixUnspent(utxo);
@ -588,9 +577,113 @@ describe('Wallet model', function() {
});
});
});
it('#getNetworkName', function() {
var w = createW();
w.getNetworkName().should.equal('testnet');
it('should send TxProposal', function(done) {
var w = createW2();
var utxo = createUTXO(w);
w.blockchain.fixUnspent(utxo);
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
w.sendTxProposal.bind(w).should.throw('Illegal Argument.');
(function() {
w.sendTxProposal(ntxid);
}).should.not.throw();
done();
});
});
it('should send all TxProposal', function(done) {
var w = createW2();
var utxo = createUTXO(w);
w.blockchain.fixUnspent(utxo);
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
w.sendAllTxProposals.bind(w).should.not.throw();
(function() {
w.sendAllTxProposals();
}).should.not.throw();
done();
});
});
var mockFakeActivity = function(w, f) {
var ADDRESSES_CHANGE = w.deriveAddresses(0, 20, true);
var ADDRESSES_RECEIVE = w.deriveAddresses(0, 20, false);
w.blockchain.checkActivity = function(addresses, cb) {
var activity = new Array(addresses.length);
for(var i=0; i<addresses.length; i++) {
var a1 = ADDRESSES_CHANGE.indexOf(addresses[i]);
var a2 = ADDRESSES_RECEIVE.indexOf(addresses[i]);
activity[i] = f(Math.max(a1, a2));
}
cb(null, activity);
}
}
it('#indexDiscovery should work without found activities', function(done) {
var w = createW2();
mockFakeActivity(w, function(index) { return false });
w.indexDiscovery(0, false, 5, function(e, lastActive){
lastActive.should.equal(-1);
done();
});
});
it('#indexDiscovery should continue scanning', function(done) {
var w = createW2();
mockFakeActivity(w, function(index) { return index <= 7 });
w.indexDiscovery(0, false, 5, function(e, lastActive){
lastActive.should.equal(7);
done();
});
});
it('#indexDiscovery should not found beyond the scannWindow', function(done) {
var w = createW2();
mockFakeActivity(w, function(index) { return index <= 10 || index == 17 });
w.indexDiscovery(0, false, 5, function(e, lastActive){
lastActive.should.equal(10);
done();
});
});
it('#indexDiscovery should look for activity along the scannWindow', function(done) {
var w = createW2();
mockFakeActivity(w, function(index) { return index <= 14 && index % 2 == 0 });
w.indexDiscovery(0, false, 5, function(e, lastActive){
lastActive.should.equal(14);
done();
});
});
it('#updateIndexes should update correctly', function(done) {
var w = createW2();
mockFakeActivity(w, function(index) { return index <= 14 && index % 2 == 0 });
w.updateIndexes(function(err) {
w.publicKeyRing.indexes.receiveIndex.should.equal(15);
w.publicKeyRing.indexes.changeIndex.should.equal(15);
done();
});
});
it('#updateIndexes should store and emit event', function(done) {
var w = createW2();
mockFakeActivity(w, function(index) { return index <= 14 && index % 2 == 0 });
var spyStore = sinon.spy(w, 'store');
var spyEmit = sinon.spy(w, 'emit');
w.updateIndexes(function(err) {
sinon.assert.callCount(spyStore, 1);
sinon.assert.callCount(spyEmit, 1);
done();
});
});
it('#deriveAddresses', function(done) {
var w = createW2();
var addresses1 = w.deriveAddresses(0, 5, false);
var addresses2 = w.deriveAddresses(4, 5, false);
addresses1.length.should.equal(5);
addresses2.length.should.equal(5);
addresses1[4].should.equal(addresses2[0]);
done();
});
});

View file

@ -125,4 +125,35 @@ describe('Insight model', function() {
});
});
}
it('#checkActivity for innactive addreses', function(done) {
var w = new Insight();
w.getTransactions = function(addresses, cb) {
cb([]);
};
w.checkActivity(addresses, function(err, actives){
console.log(err);
actives.length.should.equal(addresses.length);
actives.filter(function(i) { return i }).length.should.equal(0);
done();
});
});
it('#checkActivity for active addreses', function(done) {
var w = new Insight();
w.getTransactions = function(addresses, cb) {
cb([
{vin: [{ addr: '2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM'}], vout: []},
{vin: [{ addr: '2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM'}], vout: []},
{vin: [{ addr: '2N9D5bcCQ2bPWUDByQ6Qb5bMgMtgsk1rw3x'}], vout: []},
{vin: [], vout: [{scriptPubKey: {addresses: ['2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY']}}]}
]);
};
w.checkActivity(addresses, function(err, actives){
actives.length.should.equal(addresses.length);
actives.filter(function(i) { return i }).length.should.equal(3);
done();
});
});
});

View file

@ -3,6 +3,8 @@
//
//
//
var sinon = require('sinon');
describe('Check config', function() {
it('unit should be set to BITS in config.js', function() {
expect(config.unitToSatoshi).to.equal(100);
@ -87,9 +89,14 @@ describe("Unit: controllerUtils", function() {
});
describe("Unit: Notification Service", function() {
beforeEach(angular.mock.module('copayApp.services'));
it('should contain a notification service', inject(function(notification) {
expect(notification).not.to.equal(null);
}));
});
describe("Unit: Backup Service", function() {
var sinon = require('sinon');
beforeEach(angular.mock.module('copayApp.services'));
it('should contain a backup service', inject(function(backupService) {
expect(backupService).not.to.equal(null);