add encrypted Storage component
This commit is contained in:
parent
f84180e76c
commit
241fb3aeb7
6 changed files with 84 additions and 51 deletions
|
|
@ -10,14 +10,15 @@
|
|||
<div id="mocha"></div>
|
||||
<script src="../node_modules/mocha/mocha.js"></script>
|
||||
<script src="../node_modules/chai/chai.js"></script>
|
||||
<script src="../lib/crypto-js/rollups/aes.js"></script>
|
||||
<script>mocha.setup('bdd')</script>
|
||||
<script src="../lib/bitcore.js"></script>
|
||||
<script src="../js/copayBundle.js"></script>
|
||||
<script>
|
||||
|
||||
var copay = require('copay');
|
||||
var copay = require('copay');
|
||||
</script>
|
||||
<script src="test.storage-plain.js"></script>
|
||||
<script src="test.storage-encrypted.js"></script>
|
||||
<script src="test.Wallet.js"></script>
|
||||
<script src="test.PublicKeyRing.js"></script>
|
||||
<!--
|
||||
|
|
|
|||
49
test/test.storage-encrypted.js
Normal file
49
test/test.storage-encrypted.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
'use strict';
|
||||
|
||||
if (typeof process === 'undefined' || !process.version) {
|
||||
// browser
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var copay = copay || require('../copay');
|
||||
var Encrypted = copay.StorageEncrypted;
|
||||
|
||||
describe('Storage/Encrypted model', function() {
|
||||
var wid = 'fake-wallet-id';
|
||||
var s = new Encrypted();
|
||||
s._setPassphrase('mysupercoolpassword');
|
||||
|
||||
it('should create an instance', function() {
|
||||
var s = new Encrypted();
|
||||
should.exist(s);
|
||||
});
|
||||
it.skip('should fail when encrypting without a password', function() {
|
||||
var s = new Encrypted();
|
||||
(function(){s.set(wid, 'x', 1);}).should.throw();
|
||||
});
|
||||
it('should be able to encrypt and decrypt', function() {
|
||||
s._write('key', 'value');
|
||||
s._read('key').should.equal('value');
|
||||
});
|
||||
it('should be able to set a value', function() {
|
||||
s.set(wid, 'x', 1);
|
||||
});
|
||||
var getSetData = [
|
||||
1,1000,-15, -1000,
|
||||
0.1, -0.5, -0.5e-10, Math.PI,
|
||||
'hi', 'auydoaiusyodaisudyoa', '0b5b8556a0c2ce828c9ccfa58b3dd0a1ae879b9b',
|
||||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC', 'OP_DUP OP_HASH160 80ad90d4035',
|
||||
[1,2,3,4,5,6],
|
||||
{ x: 1, y: 2},
|
||||
{ x: 'hi', y: null},
|
||||
{ a: {}, b: [], c: [1,2,'hi']},
|
||||
null
|
||||
];
|
||||
getSetData.forEach(function(obj) {
|
||||
it('should be able to set a value and get it for '+JSON.stringify(obj), function() {
|
||||
s.set(wid, 'x', obj);
|
||||
var obj2 = s.get(wid, 'x');
|
||||
JSON.stringify(obj2).should.equal(JSON.stringify(obj));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue