Skip to content

Commit

Permalink
chore(scheduler-utils): eagerly check su-router for process, before l…
Browse files Browse the repository at this point in the history
…oading from gateway
  • Loading branch information
TillaTheHun0 committed Nov 22, 2024
1 parent e2a563d commit 840317e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scheduler-utils/src/client/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,24 @@ export function loadProcessSchedulerWith ({ fetch, GRAPHQL_URL, GRAPHQL_MAX_RETR
}
`

const TESTNET_SU_ROUTER = 'https://su-router.ao-testnet.xyz'
return async (process) => {
/**
* TODO: remove eagerly checking testnet su router once
* gateway issues have been mitigated
*/
const eagerTestnet = await fetch(`https://su-router.ao-testnet.xyz?process-id=${process}`)
.then((res) => !res.ok
? undefined
: res.json()
.then(({ address }) => ({
url: TESTNET_SU_ROUTER,
ttl: 1000 * 60 * 60 * 48,
address
}))
)
if (eagerTestnet) return eagerTestnet

return gateway({ query: GET_TRANSACTIONS_QUERY, variables: { transactionIds: [process] } })
.then(path(['data', 'transactions', 'edges', '0', 'node']))
.then(findTransactionTags(`Process ${process} was not found on gateway`))
Expand Down
31 changes: 31 additions & 0 deletions scheduler-utils/src/client/gateway.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ const GRAPHQL_URL = globalThis.GRAPHQL_URL || 'https://arweave.net/graphql'
const PROCESS = 'zc24Wpv_i6NNCEdxeKt7dcNrqL5w0hrShtSCcFGGL24'
const SCHEDULER = 'gnVg6A6S8lfB10P38V7vOia52lEhTX3Uol8kbTGUT8w'
const TWO_DAYS = 1000 * 60 * 60 * 48
const TESTNET_SU_ROUTER = 'https://su-router.ao-testnet.xyz'

const mockFetch = async (url, options) => {
/**
* TODO: remove eagerly checking testnet su router once
* gateway issues have been mitigated
*/
if (url.startsWith(TESTNET_SU_ROUTER)) {
const [, process] = url.split('process-id=')
if (process === 'Found') return new Response(JSON.stringify({ address: 'su-router', timestamp: new Date().getTime() }))
return new Response('', { status: 400 })
}

assert.equal(url, GRAPHQL_URL)
const body = JSON.parse(options.body)
if (body.query.includes('GetTransactions')) return new Response(JSON.stringify(mockFetch.GetTransactions))
Expand All @@ -20,6 +31,26 @@ const mockFetch = async (url, options) => {

describe('gateway', () => {
describe('loadProcessSchedulerWith', () => {
/**
* TODO: remove eagerly checking testnet su router once
* gateway issues have been mitigated
*/
test('eagerly load the su-router if found on router', async () => {
const loadProcessScheduler = loadProcessSchedulerSchema.implement(
loadProcessSchedulerWith({
GRAPHQL_URL,
fetch: mockFetch
})
)

await loadProcessScheduler('Found')
.then((res) => {
assert.equal(res.url, TESTNET_SU_ROUTER)
assert.equal(res.ttl, `${TWO_DAYS}`)
assert.equal(res.address, 'su-router')
})
})

test('load the Scheduler-Location for the process', async () => {
mockFetch.GetTransactions = {
data: {
Expand Down

0 comments on commit 840317e

Please sign in to comment.