add WalletLock class
This commit is contained in:
parent
c804083f89
commit
d8e0d50dce
4 changed files with 151 additions and 3 deletions
72
test/test.WalletLock.js
Normal file
72
test/test.WalletLock.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var sinon = require('sinon');
|
||||
var is_browser = (typeof process == 'undefined' || typeof process.versions === 'undefined');
|
||||
if (is_browser) {
|
||||
var copay = require('copay'); //browser
|
||||
} else {
|
||||
var copay = require('../copay'); //node
|
||||
}
|
||||
var copayConfig = require('../config');
|
||||
var WalletLock = copay.WalletLock;
|
||||
|
||||
var PrivateKey = copay.PrivateKey;
|
||||
var Storage = require('./mocks/FakeStorage');
|
||||
|
||||
describe('WalletLock model', function() {
|
||||
var storage = new Storage();
|
||||
|
||||
it('should fail with missing args', function() {
|
||||
(function() {
|
||||
new WalletLock()
|
||||
}).should.throw('Argument');
|
||||
});
|
||||
|
||||
|
||||
it('should fail with missing args (case 2)', function() {
|
||||
(function() {
|
||||
new WalletLock(storage)
|
||||
}).should.throw('Argument');
|
||||
});
|
||||
|
||||
it('should create an instance', function() {
|
||||
var w = new WalletLock(storage, 'id');
|
||||
should.exist(w);
|
||||
});
|
||||
|
||||
it('should fail if locked already', function() {
|
||||
var w = new WalletLock(storage, 'walletId');
|
||||
storage.sessionId = 'xxx';
|
||||
(function() {
|
||||
new WalletLock(storage, 'walletId')
|
||||
}).should.throw('adquire lock');
|
||||
});
|
||||
|
||||
it('should not fail if locked by me', function() {
|
||||
var s = new Storage();
|
||||
var w = new WalletLock(s, 'walletId');
|
||||
var w2 = new WalletLock(s, 'walletId')
|
||||
should.exist(w2);
|
||||
});
|
||||
|
||||
it('should not fail if locked by me', function() {
|
||||
var s = new Storage();
|
||||
var w = new WalletLock(s, 'walletId');
|
||||
var w2 = new WalletLock(s, 'walletId')
|
||||
should.exist(w2);
|
||||
});
|
||||
it('should not fail if expired', function() {
|
||||
var s = new Storage();
|
||||
var w = new WalletLock(s, 'walletId');
|
||||
s.storage[Object.keys(s.storage)[0]].expireTs = Date.now() - 60 * 6 * 1000;
|
||||
|
||||
s.sessionId = 'xxx';
|
||||
var w2 = new WalletLock(s, 'walletId')
|
||||
should.exist(w2);
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue