Skip to content

Commit

Permalink
fix: integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed May 23, 2024
1 parent 3e49629 commit 247cff1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions test/api.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test } from './helpers/context.js'

import * as Signer from '@ucanto/principal/ed25519'
import delay from 'delay'
import pRetry from 'p-retry'
import git from 'git-rev-sync'
Expand Down Expand Up @@ -58,7 +59,7 @@ test('POST /', async t => {

// Client connection config for w3filecoin pipeline entrypoint, i.e. API Storefront relies on
const { invocationConfig, connection } = await getClientConfig(new URL(t.context.api.aggregator))
const group = invocationConfig.with
const group = (await Signer.generate()).did()

// Create random pieces to add
const pieces = await randomCargo(10, 1024)
Expand Down Expand Up @@ -96,7 +97,7 @@ test('POST /', async t => {
}
// Validate piece entry content
t.truthy(storedPiece.ok.piece.equals(p.link))
t.is(storedPiece.ok.group, invocationConfig.with)
t.is(storedPiece.ok.group, group)
t.is(storedPiece.ok.status, 'offered')
t.truthy(storedPiece.ok.insertedAt)
t.truthy(storedPiece.ok.updatedAt)
Expand Down
22 changes: 21 additions & 1 deletion test/helpers/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { connect } from '@ucanto/client'
*/
export async function getClientConfig (url) {
// UCAN actors
const storefront = await Signer.generate()
const storefront = getServiceSigner({
did: 'did:web:staging.web3.storage',
privateKey: process.env.AGGREGATOR_PRIVATE_KEY || ''
})
const aggregatorService = DID.parse('did:web:staging.web3.storage')

return {
Expand All @@ -29,3 +32,20 @@ export async function getClientConfig (url) {
})
}
}

/**
* Given a config, return a ucanto Signer object representing the service
*
* @param {object} config
* @param {string} config.privateKey - multiformats private key of primary signing key
* @param {string} [config.did] - public DID for the service (did:key:... derived from PRIVATE_KEY if not set)
* @returns {import('@ucanto/principal/ed25519').Signer.Signer}
*/
export function getServiceSigner(config) {
const signer = Signer.parse(config.privateKey)
if (config.did) {
const did = DID.parse(config.did).did()
return signer.withDID(did)
}
return signer
}

0 comments on commit 247cff1

Please sign in to comment.