-
Notifications
You must be signed in to change notification settings - Fork 61
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
chore: add test to verified fetch example #290
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { CodeError } from '@libp2p/interface' | ||
import { base32 } from 'multiformats/bases/base32' | ||
import { CID } from 'multiformats/cid' | ||
import * as raw from 'multiformats/codecs/raw' | ||
import * as Digest from 'multiformats/hashes/digest' | ||
import fixtures from './fixtures.js' | ||
|
||
export class MemoryBlockstore { | ||
data | ||
|
||
constructor () { | ||
this.data = new Map() | ||
|
||
// prefill blockstore with test fixtures | ||
Object.values(fixtures).forEach((fixture) => { | ||
this.put(fixture.cid, fixture.data) | ||
}) | ||
} | ||
|
||
put (key, val) { // eslint-disable-line require-await | ||
this.data.set(base32.encode(key.multihash.bytes), val) | ||
|
||
return key | ||
} | ||
|
||
get (key) { | ||
const buf = this.data.get(base32.encode(key.multihash.bytes)) | ||
|
||
if (buf == null) { | ||
throw new CodeError('Not found', 'ERR_NOT_FOUND') | ||
} | ||
|
||
return buf | ||
} | ||
|
||
has (key) { | ||
return this.data.has(base32.encode(key.multihash.bytes)) | ||
} | ||
|
||
async delete (key) { | ||
this.data.delete(base32.encode(key.multihash.bytes)) | ||
} | ||
|
||
async * getAll () { | ||
for (const [key, value] of this.data.entries()) { | ||
yield { | ||
cid: CID.createV1(raw.code, Digest.decode(base32.decode(key))), | ||
block: value | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CID } from 'multiformats/cid' | ||
|
||
export default { | ||
json: { | ||
cid: CID.parse('bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea'), | ||
data: Uint8Array.from([123, 34, 104, 101, 108, 108, 111, 34, 58, 34, 119, 111, 114, 108, 100, 34, 125]) | ||
}, | ||
dagJson: { | ||
cid: CID.parse('baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea'), | ||
data: Uint8Array.from([123, 34, 104, 101, 108, 108, 111, 34, 58, 34, 119, 111, 114, 108, 100, 34, 125]) | ||
}, | ||
dagCbor: { | ||
cid: CID.parse('bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae'), | ||
data: Uint8Array.from([161, 101, 104, 101, 108, 108, 111, 101, 119, 111, 114, 108, 100]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,65 @@ | ||
import { setup, expect } from 'test-ipfs-example/browser' | ||
import fixtures from './fixtures.js' | ||
|
||
// Setup | ||
const test = setup() | ||
|
||
const testCidPath = 'ipfs://bagaaieracglt4ey6qsxtvzqsgwnsw3b6p2tb7nmx5wdgxur2zia7q6nnzh7q' | ||
|
||
test.describe('Use @helia/verified-fetch With react and vite', () => { | ||
// DOM | ||
const ipfsPathInput = '#ipfs-path' | ||
// const fetchOutput = '#output' | ||
// const fetchAutoBtn = '#button-fetch-auto' | ||
const fetchOutput = '#output' | ||
const fetchAutoBtn = '#button-fetch-auto' | ||
|
||
test.beforeEach(async ({ servers, page }) => { | ||
await page.goto(servers[0].url) | ||
}) | ||
|
||
test('should properly render ui with the ipfs path input', async ({ page }) => { | ||
test('should properly render ui with the ipfs path input and display JSON', async ({ page }) => { | ||
// wait for helia node to be online | ||
const ipfsPath = await page.locator(ipfsPathInput) | ||
await expect(ipfsPath).toHaveClass(/bg-gray-50/) | ||
|
||
await page.fill(ipfsPathInput, `ipfs://${fixtures.json.cid.toString()}`) | ||
await page.click(fetchAutoBtn) | ||
await page.locator(fetchOutput).waitFor('visible') | ||
|
||
const output = await page.locator(fetchOutput) | ||
await expect(output).toContainText( | ||
'{ "hello": "world" }', | ||
{ timeout: 2000 } | ||
) | ||
}) | ||
|
||
test('should properly render ui with the ipfs path input and display DAG-JSON', async ({ page }) => { | ||
// wait for helia node to be online | ||
const ipfsPath = await page.locator(ipfsPathInput) | ||
await expect(ipfsPath).toHaveClass(/bg-gray-50/) | ||
|
||
await page.fill(ipfsPathInput, testCidPath) | ||
// await page.click(fetchAutoBtn) | ||
// await page.locator(fetchOutput).waitFor('visible') | ||
await page.fill(ipfsPathInput, `ipfs://${fixtures.dagJson.cid.toString()}`) | ||
await page.click(fetchAutoBtn) | ||
await page.locator(fetchOutput).waitFor('visible') | ||
|
||
const output = await page.locator(fetchOutput) | ||
await expect(output).toContainText( | ||
'{ "hello": "world" }', | ||
{ timeout: 2000 } | ||
) | ||
}) | ||
|
||
// TODO: DAG-CBOR is broken - https://github.com/ipfs/helia/pull/426 | ||
test.skip('should properly render ui with the ipfs path input and display DAG-CBOR', async ({ page }) => { | ||
// wait for helia node to be online | ||
const ipfsPath = await page.locator(ipfsPathInput) | ||
await expect(ipfsPath).toHaveClass(/bg-gray-50/) | ||
|
||
await page.fill(ipfsPathInput, `ipfs://${fixtures.dagCbor.cid.toString()}`) | ||
await page.click(fetchAutoBtn) | ||
await page.locator(fetchOutput).waitFor('visible') | ||
|
||
const output = await page.locator(fetchOutput) | ||
await expect(output).toContainText( | ||
'{ "hello": "world" }', | ||
{ timeout: 2000 } | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { resolve } from 'path' | ||
import defaultConfig from '../vite.config.js' | ||
|
||
// override resolution of `blockstore-core` module so we can pre-fill a memory | ||
// blockstore with test data | ||
defaultConfig.resolve ??= {} | ||
defaultConfig.resolve.alias ??= {} | ||
defaultConfig.resolve.alias['blockstore-core'] = resolve(process.cwd(), 'test/blockstore.js') | ||
|
||
// https://vitejs.dev/config/ | ||
export default defaultConfig |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
That's neat!