UNPKG

@bajetech/digitalbits-wallet-sdk

Version:

A library to make it easier to write wallets that interact with the DigitalBits blockchain

91 lines 3.65 kB
import { __assign, __awaiter, __generator } from "tslib"; import os from "os"; import path from "path"; import sinon from "sinon"; import { LocalStorage } from "node-localstorage"; import { testKeyStore } from "../PluginTesting"; import { LocalStorageKeyStore } from "./LocalStorageKeyStore"; // tslint:disable-next-line describe("LocalStorageKeyStore", function () { var _this = this; var clock; var testStore; var localStorage; beforeEach(function () { clock = sinon.useFakeTimers(); testStore = new LocalStorageKeyStore(); localStorage = new LocalStorage(path.resolve(os.tmpdir(), "js-digitalbits-wallets")); testStore.configure({ storage: localStorage }); }); afterEach(function () { clock.restore(); localStorage.clear(); }); it("properly stores keys", function () { return __awaiter(_this, void 0, void 0, function () { var encryptedKey, keyMetadata, testMetadata, allKeys; return __generator(this, function (_a) { switch (_a.label) { case 0: encryptedKey = { id: "PURIFIER", encryptedBlob: "BLOB", encrypterName: "Test", salt: "SLFKJSDLKFJLSKDJFLKSJD", }; keyMetadata = { id: "PURIFIER", }; return [4 /*yield*/, testStore.storeKeys([encryptedKey])]; case 1: testMetadata = _a.sent(); expect(testMetadata).toEqual([keyMetadata]); return [4 /*yield*/, testStore.loadAllKeys()]; case 2: allKeys = _a.sent(); expect(allKeys).toEqual([__assign(__assign({}, encryptedKey), keyMetadata)]); return [2 /*return*/]; } }); }); }); it("properly deletes keys", function () { return __awaiter(_this, void 0, void 0, function () { var encryptedKey, keyMetadata, allKeys, removalMetadata, noKeys; return __generator(this, function (_a) { switch (_a.label) { case 0: encryptedKey = { id: "PURIFIER", encrypterName: "Test", encryptedBlob: "BLOB", salt: "SLFKJSDLKFJLSKDJFLKSJD", }; keyMetadata = { id: "PURIFIER", }; return [4 /*yield*/, testStore.storeKeys([encryptedKey])]; case 1: _a.sent(); return [4 /*yield*/, testStore.loadAllKeys()]; case 2: allKeys = _a.sent(); expect(allKeys).toEqual([__assign(__assign({}, encryptedKey), keyMetadata)]); return [4 /*yield*/, testStore.removeKey("PURIFIER")]; case 3: removalMetadata = _a.sent(); expect(removalMetadata).toEqual(keyMetadata); return [4 /*yield*/, testStore.loadAllKeys()]; case 4: noKeys = _a.sent(); expect(noKeys).toEqual([]); return [2 /*return*/]; } }); }); }); it("passes PluginTesting", function (done) { testKeyStore(testStore) .then(function () { done(); }) .catch(done); }); }); //# sourceMappingURL=LocalStorageKeyStore.test.js.map