js-libp2p-noise/test/keycache.test.ts

35 lines
991 B
TypeScript
Raw Normal View History

2020-01-13 15:38:14 +01:00
import { expect, assert } from "chai";
import { KeyCache } from "../src/keycache";
2020-01-13 16:18:10 +01:00
import {createPeerIds, createPeerIdsFromFixtures} from "./fixtures/peer";
2020-01-13 15:38:14 +01:00
describe("KeyCache", () => {
let peerA, peerB;
before(async () => {
[peerA, peerB] = await createPeerIdsFromFixtures(2);
});
it("should store and load same key successfully", async() => {
try {
const key = Buffer.from("this is id 007");
await KeyCache.store(peerA, key);
const result = await KeyCache.load(peerA);
assert(result.equals(key), "Stored and loaded key are not the same");
} catch (e) {
console.error(e);
assert(false, `Test failed - ${e.message}`)
}
});
2020-01-13 16:18:10 +01:00
it("should return undefined if key not found", async() => {
try {
const [newPeer] = await createPeerIds(1);
const result = await KeyCache.load(newPeer);
assert(!result);
} catch (e) {
console.error(e);
assert(false, `Test failed - ${e.message}`)
}
});
2020-01-13 15:38:14 +01:00
});