diff --git a/scheduler-utils/src/client/gateway.js b/scheduler-utils/src/client/gateway.js index 045eafc5e..f9f044429 100644 --- a/scheduler-utils/src/client/gateway.js +++ b/scheduler-utils/src/client/gateway.js @@ -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`)) diff --git a/scheduler-utils/src/client/gateway.test.js b/scheduler-utils/src/client/gateway.test.js index 0a439c143..7e720d210 100644 --- a/scheduler-utils/src/client/gateway.test.js +++ b/scheduler-utils/src/client/gateway.test.js @@ -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)) @@ -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: {