-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for fetching filecoin deal info from w3up. This is definitely not my best work - ideally we'd abstract this w3up mocking logic in a way that makes it less stateful, but I'm hesitant to do that when we will likely not be making many changes here in the future.
- Loading branch information
Showing
9 changed files
with
190 additions
and
44 deletions.
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
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
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,22 +1,133 @@ | ||
import test from 'ava' | ||
import { createServer } from 'node:http' | ||
import { ed25519 } from '@ucanto/principal' | ||
import { delegate, parseLink } from '@ucanto/core' | ||
import { base64 } from 'multiformats/bases/base64' | ||
import { createClientWithUser } from './scripts/helpers.js' | ||
import { fixtures } from './scripts/fixtures.js' | ||
import { | ||
getMiniflareContext, | ||
setupMiniflareContext, | ||
} from './scripts/test-context.js' | ||
import { read } from '@web3-storage/content-claims/client' | ||
import { parseLink } from '@ucanto/core' | ||
import { | ||
createMockW3up, | ||
locate, | ||
encodeDelegationAsCid, | ||
} from './utils/w3up-testing.js' | ||
|
||
const nftStorageSpace = ed25519.generate() | ||
const nftStorageApiPrincipal = ed25519.generate() | ||
const nftStorageAccountEmailAllowListedForW3up = '[email protected]' | ||
const mockW3upDID = 'did:web:test.web3.storage' | ||
/** | ||
* @type {import('@web3-storage/access').PieceLink} | ||
*/ | ||
const mockPieceLink = parseLink( | ||
'bafkzcibeslzwmewd4pugjanyiayot5m76a67dvdir25v6ms6kbuozy2sxotplrrrce' | ||
) | ||
/** | ||
* @type {import('@web3-storage/access').FilecoinInfoAcceptedDeal[]} | ||
*/ | ||
const mockDeals = [ | ||
{ | ||
aggregate: parseLink( | ||
'bafkzcibcaapen7lfjgljzi523a5rau2l5pwpwseita6uunqy5otrlxa2l2pouca' | ||
), | ||
aux: { | ||
dataSource: { | ||
dealID: BigInt(1), | ||
}, | ||
dataType: BigInt(1), | ||
}, | ||
provider: 'f01240', | ||
}, | ||
] | ||
const mockW3up = Promise.resolve( | ||
(async function () { | ||
const server = createServer( | ||
await createMockW3up({ | ||
did: mockW3upDID, | ||
// @ts-expect-error not returning a full upload get response for now | ||
async onHandleUploadGet(cid) { | ||
return { | ||
// grabbed this shard CID from staging, it should correspond to a piece named bafkzcibeslzwmewd4pugjanyiayot5m76a67dvdir25v6ms6kbuozy2sxotplrrrce | ||
shards: [ | ||
parseLink( | ||
'bagbaieragf62xatg3bqrfafdy3lpk2fte7526kvxnltqsnhjr45cz6jjk7mq' | ||
), | ||
], | ||
} | ||
}, | ||
async onHandleFilecoinInfo(invocation) { | ||
return { | ||
deals: mockDeals, | ||
aggregates: [], | ||
piece: mockPieceLink, | ||
} | ||
}, | ||
}) | ||
) | ||
server.listen(0) | ||
await new Promise((resolve) => | ||
server.addListener('listening', () => resolve(undefined)) | ||
) | ||
return { | ||
server, | ||
} | ||
})() | ||
) | ||
|
||
test.before(async (t) => { | ||
await setupMiniflareContext(t) | ||
await setupMiniflareContext(t, { | ||
overrides: { | ||
W3UP_URL: locate((await mockW3up).server).url.toString(), | ||
W3UP_DID: mockW3upDID, | ||
W3_NFTSTORAGE_SPACE: (await nftStorageSpace).did(), | ||
W3_NFTSTORAGE_PRINCIPAL: ed25519.format(await nftStorageApiPrincipal), | ||
W3_NFTSTORAGE_PROOF: ( | ||
await encodeDelegationAsCid( | ||
await delegate({ | ||
issuer: await nftStorageSpace, | ||
audience: await nftStorageApiPrincipal, | ||
capabilities: [ | ||
{ can: 'upload/get', with: (await nftStorageSpace).did() }, | ||
{ can: 'filecoin/info', with: (await nftStorageSpace).did() }, | ||
], | ||
}) | ||
) | ||
).toString(base64), | ||
W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS: JSON.stringify([ | ||
nftStorageAccountEmailAllowListedForW3up, | ||
]), | ||
}, | ||
}) | ||
}) | ||
|
||
test.only('should fetch deal details from w3up', async (t) => { | ||
const testCid = 'bafybeiccy35oi3gajocq5bbg7pnaxb3kv5ibtdz3tc3kari53qhbjotzey' | ||
const link = parseLink(testCid) | ||
const claims = await read(link) | ||
console.log('CLAIMS', claims) | ||
test.serial('should fetch deal details from w3up', async (t) => { | ||
const cid = 'bafybeiccy35oi3gajocq5bbg7pnaxb3kv5ibtdz3tc3kari53qhbjotzey' | ||
const client = await createClientWithUser(t) | ||
const mf = getMiniflareContext(t) | ||
await client.addPin({ | ||
cid, | ||
name: 'test-filecoin-info', | ||
}) | ||
|
||
const res = await mf.dispatchFetch(`http://miniflare.test/${cid}`, { | ||
headers: { Authorization: `Bearer ${client.token}` }, | ||
}) | ||
const { ok, value } = await res.json() | ||
t.assert(ok) | ||
t.deepEqual( | ||
value.deals, | ||
mockDeals.map((deal) => ({ | ||
pieceCid: mockPieceLink.toString(), | ||
status: 'published', | ||
datamodelSelector: '', | ||
batchRootCid: deal.aggregate.toString(), | ||
miner: deal.provider, | ||
chainDealID: Number(deal.aux.dataSource.dealID), | ||
})) | ||
) | ||
}) | ||
|
||
test.serial('should return proper response for cid v1', async (t) => { | ||
|
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 |
---|---|---|
|
@@ -5903,26 +5903,6 @@ | |
resolved "https://registry.yarnpkg.com/@web3-storage/multipart-parser/-/multipart-parser-1.0.0.tgz#6b69dc2a32a5b207ba43e556c25cc136a56659c4" | ||
integrity sha512-BEO6al7BYqcnfX15W2cnGR+Q566ACXAT9UQykORCWW80lmkpWsnEob6zJS1ZVBKsSJC8+7vJkHwlp+lXG1UCdw== | ||
|
||
"@web3-storage/upload-client@^13.1.0": | ||
version "13.1.0" | ||
resolved "https://registry.yarnpkg.com/@web3-storage/upload-client/-/upload-client-13.1.0.tgz#e29beb5ab0991682c28bcfe8c318aca42e43041c" | ||
integrity sha512-RK67hUFviFG7KdupTwbMJCPdIsGEBSzpllybIOzbip3FKVH4fKDq4Sb2kXLptXeeqQfPJ86uRTmFtHTAVGVbZw== | ||
dependencies: | ||
"@ipld/car" "^5.2.2" | ||
"@ipld/dag-cbor" "^9.0.6" | ||
"@ipld/dag-ucan" "^3.4.0" | ||
"@ipld/unixfs" "^2.1.1" | ||
"@ucanto/client" "^9.0.0" | ||
"@ucanto/interface" "^9.0.0" | ||
"@ucanto/transport" "^9.1.0" | ||
"@web3-storage/capabilities" "^13.2.0" | ||
"@web3-storage/data-segment" "^5.1.0" | ||
"@web3-storage/filecoin-client" "^3.3.0" | ||
ipfs-utils "^9.0.14" | ||
multiformats "^12.1.2" | ||
p-retry "^5.1.2" | ||
varint "^6.0.0" | ||
|
||
"@web3-storage/upload-client@^13.2.0": | ||
version "13.2.0" | ||
resolved "https://registry.yarnpkg.com/@web3-storage/upload-client/-/upload-client-13.2.0.tgz#b6781344f405d84a6575d4880c3abe73e20d8e67" | ||
|
@@ -5943,10 +5923,10 @@ | |
p-retry "^5.1.2" | ||
varint "^6.0.0" | ||
|
||
"@web3-storage/w3up-client@^12.5.0": | ||
version "12.5.0" | ||
resolved "https://registry.yarnpkg.com/@web3-storage/w3up-client/-/w3up-client-12.5.0.tgz#67663f6c024bb7d198b2030f7752b139e5d3f9ae" | ||
integrity sha512-SLpXXgA0TZJNSGtLHeq2kF+uwaHYfsH5068utikeRccCXJRrKQnCN1y2FpCe01H4SjLMTIQK13vga6DgSfJiuA== | ||
"@web3-storage/w3up-client@^12.5.1": | ||
version "12.5.1" | ||
resolved "https://registry.yarnpkg.com/@web3-storage/w3up-client/-/w3up-client-12.5.1.tgz#a5722c9b8ca0e1ea2c1a2b7c7749512938eda16d" | ||
integrity sha512-fv53VEWOcDxNi2qsE5uHvOWDXbXstlYQ505uMN5vcpdetxo3FcxIkVqGBIIQDpsXLyloRNA8+ZXOy8+rKeOPVw== | ||
dependencies: | ||
"@ipld/dag-ucan" "^3.4.0" | ||
"@ucanto/client" "^9.0.0" | ||
|
@@ -5958,7 +5938,7 @@ | |
"@web3-storage/capabilities" "^13.2.0" | ||
"@web3-storage/did-mailto" "^2.1.0" | ||
"@web3-storage/filecoin-client" "^3.3.0" | ||
"@web3-storage/upload-client" "^13.1.0" | ||
"@web3-storage/upload-client" "^13.2.0" | ||
|
||
"@webassemblyjs/[email protected]": | ||
version "1.11.1" | ||
|