UNPKG

@bajetech/digitalbits-wallet-sdk

Version:

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

84 lines 3.4 kB
import { __assign, __awaiter, __generator } from "tslib"; import sinon from "sinon"; import { testKeyStore } from "../PluginTesting"; import { MemoryKeyStore } from "./MemoryKeyStore"; // tslint:disable-next-line describe("MemoryKeyStore", function () { var _this = this; var clock; beforeEach(function () { clock = sinon.useFakeTimers(); }); afterEach(function () { clock.restore(); }); it("properly stores keys", function () { return __awaiter(_this, void 0, void 0, function () { var testStore, encryptedKey, keyMetadata, testMetadata, allKeys; return __generator(this, function (_a) { switch (_a.label) { case 0: testStore = new MemoryKeyStore(); 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 testStore, encryptedKey, keyMetadata, allKeys, removalMetadata, noKeys; return __generator(this, function (_a) { switch (_a.label) { case 0: testStore = new MemoryKeyStore(); 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(new MemoryKeyStore()) .then(function () { done(); }) .catch(done); }); }); //# sourceMappingURL=MemoryKeyStore.test.js.map