-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete the Jest DI with crypto #234
Changes from all commits
e6311df
88d6097
21e43ce
dbc3b3d
d391663
3cc7931
71a0796
376a3d6
d08d0ce
b8ffa04
f9b594c
830ae07
08d6833
4ad48db
feed976
9409e0e
39a6695
20de6bd
7015861
63bdbcc
409f287
eab6bc8
5cbfd03
c5d97ce
796acae
d475e48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
declare module 'base58-universal/main.js' | ||
declare module 'borc' | ||
declare module 'base58-universal' { | ||
export function encode(input: Uint8Array, maxline?: number): string | ||
export function decode(input: string): Uint8Array | ||
} | ||
declare module 'ipld-dag-pb' | ||
declare module 'borc' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import crypto from "crypto" | ||
import Ipfs, { IPFS } from "ipfs" | ||
import { IPFS } from "ipfs-core" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a size thing? (full IPFS includes more code than we use, etc?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, exactly. It's just much less dependencies. |
||
|
||
import MMPT from "./mmpt" | ||
import * as ipfsConfig from "../../../ipfs/config" | ||
import { createInMemoryIPFS } from "../../../../tests/helpers/in-memory-ipfs" | ||
|
||
function sha256Str(str: string): string { | ||
return crypto.createHash('sha256').update(str).digest('hex') | ||
|
@@ -12,7 +13,20 @@ function encode(str: string): Uint8Array { | |
return (new TextEncoder()).encode(str) | ||
} | ||
|
||
let ipfs: IPFS; | ||
|
||
let ipfs: IPFS | null = null | ||
|
||
beforeAll(async done => { | ||
ipfs = await createInMemoryIPFS() | ||
ipfsConfig.set(ipfs) | ||
done() | ||
}) | ||
|
||
afterAll(async done => { | ||
if (ipfs == null) return | ||
await ipfs.stop() | ||
done() | ||
}) | ||
|
||
/* | ||
Generates lots of entries for insertion into the MMPT. | ||
|
@@ -22,8 +36,8 @@ The MMPT is a glorified key-value store. | |
This returns an array of key-values sorted by the key, | ||
so that key collisions are more likely to be tested. | ||
*/ | ||
async function generateExampleEntries(amount: number): Promise<{ name: string, cid: string }[]> { | ||
let entries: { name: string, cid: string }[] = [] | ||
async function generateExampleEntries(amount: number): Promise<{ name: string; cid: string }[]> { | ||
const entries: { name: string; cid: string }[] = [] | ||
|
||
for (const i of Array(amount).keys()) { | ||
const hash = sha256Str(`${i}`) | ||
|
@@ -39,17 +53,6 @@ async function generateExampleEntries(amount: number): Promise<{ name: string, c | |
|
||
|
||
|
||
beforeAll(async done => { | ||
ipfs = await Ipfs.create({ offline: true, silent: true }) | ||
ipfsConfig.set(ipfs) | ||
done() | ||
}) | ||
|
||
afterAll(async done => { | ||
await ipfs.stop() | ||
done() | ||
}) | ||
|
||
describe("the mmpt", () => { | ||
it("can handle concurrent adds", async () => { | ||
const mmpt = MMPT.create() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm. This smells like there's something wrong with the tests... async operations not resolving?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I tried to track it down for a while, but gave up. From my testing it seems like in some edge-cases it's possible that ipfs leaves a child process and some sockets hanging after
await ipfs.stop()
. Not sure what's up with that, but after fighting with it for a while I just gave up.The IPFS we're using in the tests is basically in-memory only. It doesn't write to disk. So killing it shouldn't be an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. yeah, something we can track down and fix as a follow up later, imo.