Skip to content

Commit

Permalink
fix(tests): disable flaky filecoin test for now
Browse files Browse the repository at this point in the history
currently, seed.run fails 90%+ of the time because of the Filecoin test.

until we have a more reliable way to test the filecoin flow, the PR disables it.

the inserted comment suggests a few solutions -- either spinning up
custom infra for w3filecoin pipeline on each pr to get more reliable
results, or mocking out the pipeline
  • Loading branch information
hannahhoward committed Aug 30, 2024
1 parent e626c59 commit 346fd91
Showing 1 changed file with 81 additions and 71 deletions.
152 changes: 81 additions & 71 deletions test/filecoin.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
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'
Expand All @@ -24,7 +22,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 Down Expand Up @@ -147,6 +145,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 @@ -190,61 +189,72 @@ test('w3filecoin integration flow', async t => {
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(
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)
)
// 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

// 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 `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)
// )

// @ts-ignore no type for aggregate
const aggregate = receiptAggregateOfferRes.ok?.out.ok?.aggregate
// // 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)
// )

// 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)
// // @ts-ignore no type for aggregate
// const aggregate = receiptAggregateOfferRes.ok?.out.ok?.aggregate

// 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 })
// // 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)

return receiptStoreFilecoin.get(aggregateAcceptReceiptCid)
// return agentStoreFilecoin.receipts.get(aggregateAcceptReceiptCid)
},
(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 })

// 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)
// }

0 comments on commit 346fd91

Please sign in to comment.