Skip to content
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

Disable flaky filecoin test for now #419

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 88 additions & 78 deletions test/filecoin.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { testFilecoin as test } from './helpers/context.js'
import { fetch } from '@web-std/fetch'
import pWaitFor from 'p-wait-for'
import pRetry from 'p-retry'
import * as CAR from '@ucanto/transport/car'
import { Storefront } from '@web3-storage/filecoin-client'
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
import * as Link from 'multiformats/link'
import * as raw from 'multiformats/codecs/raw'
import { base58btc } from 'multiformats/bases/base58'

import * as AgentStore from '../upload-api/stores/agent.js'
import { useReceiptStore } from '../filecoin/store/receipt.js'

import {
getApiEndpoint,
Expand All @@ -24,7 +21,7 @@ import {
import { createMailSlurpInbox, setupNewClient } from './helpers/up-client.js'
import { getClientConfig } from './helpers/fil-client.js'
import { randomFile } from './helpers/random.js'
import { putTableItem, pollQueryTable } from './helpers/table.js'
import { pollQueryTable } from './helpers/table.js'
import { waitForStoreOperationOkResult } from './helpers/store.js'

/**
Expand All @@ -42,7 +39,7 @@ test.before(t => {
test('w3filecoin integration flow', async t => {
const stage = getStage()
const s3Client = getAwsBucketClient()
const s3ClientFilecoin = getAwsBucketClient('us-east-2')
// const s3ClientFilecoin = getAwsBucketClient('us-east-2')
const inbox = await createMailSlurpInbox()
const endpoint = t.context.apiEndpoint

Expand Down Expand Up @@ -147,6 +144,7 @@ test('w3filecoin integration flow', async t => {
const workflowWithReceiptResponseAfterRedirect = await fetch(workflowLocation)
// Get receipt from Message Archive
const agentMessageBytes = new Uint8Array((await workflowWithReceiptResponseAfterRedirect.arrayBuffer()))
console.log(agentMessageBytes.length)
const agentMessage = await CAR.request.decode({
body: agentMessageBytes,
headers: {},
Expand Down Expand Up @@ -175,7 +173,7 @@ test('w3filecoin integration flow', async t => {
name: '',
},
})
const receiptStoreFilecoin = useReceiptStore(s3ClientFilecoin, 'invocation-store-staging-0', 'workflow-store-staging-0')
// const receiptStoreFilecoin = useReceiptStore(s3ClientFilecoin, 'invocation-store-staging-0', 'workflow-store-staging-0')

// Await for `filecoin/submit` receipt
console.log(`wait for filecoin/submit receipt ${filecoinSubmitReceiptCid.toString()} ...`)
Expand All @@ -189,62 +187,74 @@ test('w3filecoin integration flow', async t => {
if (!pieceOfferReceiptCid) {
throw new Error('filecoin/submit receipt has no effect for piece/offer')
}
console.log(`wait for piece/offer receipt ${pieceOfferReceiptCid.toString()} ...`)
const receiptPieceOfferRes = await waitForStoreOperationOkResult(
() => receiptStoreFilecoin.get(pieceOfferReceiptCid),
(res) => Boolean(res.ok)
)

// Await for `piece/accept` receipt
const pieceAcceptReceiptCid = receiptPieceOfferRes.ok?.fx.join?.link()
if (!pieceAcceptReceiptCid) {
throw new Error('piece/offer receipt has no effect for piece/accept')
}
console.log(`wait for piece/accept receipt ${pieceAcceptReceiptCid.toString()} ...`)
const receiptPieceAcceptRes = await waitForStoreOperationOkResult(
() => receiptStoreFilecoin.get(pieceAcceptReceiptCid),
(res) => Boolean(res.ok)
)

// Await for `aggregate/offer` receipt
const aggregateOfferReceiptCid = receiptPieceAcceptRes.ok?.fx.join?.link()
if (!aggregateOfferReceiptCid) {
throw new Error('piece/accept receipt has no effect for aggregate/offer')
}
console.log(`wait for aggregate/offer receipt ${aggregateOfferReceiptCid.toString()} ...`)
const receiptAggregateOfferRes = await waitForStoreOperationOkResult(
() => receiptStoreFilecoin.get(aggregateOfferReceiptCid),
(res) => Boolean(res.ok)
)
// TODO: This code is disabled as it tests running, real, shared infrastructure
// that is maintained outside of this repo, and could fail for reasons unrelated
// to what's happening in this repo
// To the extent we want a kitchen-sink test, it should happen with
// infra deployed specifically for the test, with predictable performance
// Alternatively, if we're simply testing interactions with expected behavior
// for w3-filecoininfra, we should use a mocked version of the service with
// predictable responses.
// This rest of this test is disabled until one of these solutions is put
// in place

// @ts-ignore no type for aggregate
const aggregate = receiptAggregateOfferRes.ok?.out.ok?.aggregate
// console.log(`wait for piece/offer receipt ${pieceOfferReceiptCid.toString()} ...`)
// await waitForStoreOperationOkResult(
// () => receiptStoreFilecoin.get(pieceOfferReceiptCid),
// (res) => Boolean(res.ok)
// )
// // Await for `piece/accept` receipt
// const pieceAcceptReceiptCid = receiptPieceOfferRes.ok?.fx.join?.link()
// if (!pieceAcceptReceiptCid) {
// throw new Error('piece/offer receipt has no effect for piece/accept')
// }
// console.log(`wait for piece/accept receipt ${pieceAcceptReceiptCid.toString()} ...`)
// const receiptPieceAcceptRes = await waitForStoreOperationOkResult(
// () => receiptStoreFilecoin.get(pieceAcceptReceiptCid),
// (res) => Boolean(res.ok)
// )

// Put FAKE value in table to issue final receipt via cron?
const dealId = 1111
console.log(`put deal on deal tracker for aggregate ${aggregate}`)
await putDealToDealTracker(aggregate.toString(), dealId)
// // Await for `aggregate/offer` receipt
// const aggregateOfferReceiptCid = receiptPieceAcceptRes.ok?.fx.join?.link()
// if (!aggregateOfferReceiptCid) {
// throw new Error('piece/accept receipt has no effect for aggregate/offer')
// }
// console.log(`wait for aggregate/offer receipt ${aggregateOfferReceiptCid.toString()} ...`)
// const receiptAggregateOfferRes = await waitForStoreOperationOkResult(
// () => receiptStoreFilecoin.get(aggregateOfferReceiptCid),
// (res) => Boolean(res.ok)
// )

// Await for `aggregate/accept` receipt
const aggregateAcceptReceiptCid = receiptAggregateOfferRes.ok?.fx.join?.link()
if (!aggregateAcceptReceiptCid) {
throw new Error('aggregate/offer receipt has no effect for aggregate/accept')
}
console.log(`wait for aggregate/accept receipt ${aggregateAcceptReceiptCid.toString()} ...`)
await waitForStoreOperationOkResult(
async () => {
// Trigger cron to update and issue receipts based on deals
await pRetry(async () => {
const url = 'https://staging.dealer.web3.storage/cron'
const res = await fetch(url)
if (!res.ok) throw new Error(`failed request to ${url}: ${res.status}`)
}, { onFailedAttempt: console.warn })
// // @ts-ignore no type for aggregate
// const aggregate = receiptAggregateOfferRes.ok?.out.ok?.aggregate

return receiptStoreFilecoin.get(aggregateAcceptReceiptCid)
// return agentStoreFilecoin.receipts.get(aggregateAcceptReceiptCid)
},
(res) => Boolean(res.ok)
)
// // Put FAKE value in table to issue final receipt via cron?
// const dealId = 1111
// console.log(`put deal on deal tracker for aggregate ${aggregate}`)
// await putDealToDealTracker(aggregate.toString(), dealId)

// // Await for `aggregate/accept` receipt
// const aggregateAcceptReceiptCid = receiptAggregateOfferRes.ok?.fx.join?.link()
// if (!aggregateAcceptReceiptCid) {
// throw new Error('aggregate/offer receipt has no effect for aggregate/accept')
// }
// console.log(`wait for aggregate/accept receipt ${aggregateAcceptReceiptCid.toString()} ...`)
// await waitForStoreOperationOkResult(
// async () => {
// // Trigger cron to update and issue receipts based on deals
// await pRetry(async () => {
// const url = 'https://staging.dealer.web3.storage/cron'
// const res = await fetch(url)
// if (!res.ok) throw new Error(`failed request to ${url}: ${res.status}`)
// }, { onFailedAttempt: console.warn })

// return receiptStoreFilecoin.get(aggregateAcceptReceiptCid)
// // return agentStoreFilecoin.receipts.get(aggregateAcceptReceiptCid)
// },
// (res) => Boolean(res.ok)
// )
}))
})

Expand All @@ -270,25 +280,25 @@ async function getPiecesByContent (t, content) {
return item
}

/**
* @param {string} piece
* @param {number} dealId
*/
async function putDealToDealTracker (piece, dealId) {
const region = 'us-east-2'
const endpoint = `https://dynamodb.${region}.amazonaws.com`
const tableName = 'staging-w3filecoin-deal-tracker-deal-store-v1'
const client = new DynamoDBClient({
region,
endpoint
})
const record = {
piece,
provider: 'f0001',
dealId,
expirationEpoch: Date.now() + 10e9,
insertedAt: (new Date()).toISOString(),
source: 'testing'
}
await putTableItem(client, tableName, record)
}
// /**
// * @param {string} piece
// * @param {number} dealId
// */
// async function putDealToDealTracker (piece, dealId) {
// const region = 'us-east-2'
// const endpoint = `https://dynamodb.${region}.amazonaws.com`
// const tableName = 'staging-w3filecoin-deal-tracker-deal-store-v1'
// const client = new DynamoDBClient({
// region,
// endpoint
// })
// const record = {
// piece,
// provider: 'f0001',
// dealId,
// expirationEpoch: Date.now() + 10e9,
// insertedAt: (new Date()).toISOString(),
// source: 'testing'
// }
// await putTableItem(client, tableName, record)
// }
Loading