From 4de72f74ce57d2e2520b84be4f5e4c142c15f1db Mon Sep 17 00:00:00 2001 From: Usman Saleem <57341641+usmanmani1122@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:02:27 +0500 Subject: [PATCH] Faucet Polling in E2E Tests (#363) --- test/e2e/support.js | 37 ++++++++++++++++++++++++++++--------- test/e2e/test.utils.js | 7 ------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/test/e2e/support.js b/test/e2e/support.js index 060ff190..ca61b857 100644 --- a/test/e2e/support.js +++ b/test/e2e/support.js @@ -3,9 +3,7 @@ import { networks, configMap, FACUET_HEADERS, - MINUTE_MS, agoricNetworks, - FAUCET_URL_MAP, } from './test.utils'; const AGORIC_NET = Cypress.env('AGORIC_NET') || 'local'; @@ -176,20 +174,41 @@ Cypress.Commands.add('connectWithWallet', (options = {}) => { }); Cypress.Commands.add('provisionFromFaucet', (walletAddress, command) => { + const TRANSACTION_STATUS = { + FAILED: 1000, + NOT_FOUND: 1001, + SUCCESSFUL: 1002, + }; + + const getStatus = txHash => + cy + .request({ + method: 'GET', + url: `https://${AGORIC_NET}.faucet.agoric.net/api/transaction-status/${txHash}`, + }) + .then(resp => { + const { transactionStatus } = resp.body; + if (transactionStatus === TRANSACTION_STATUS.NOT_FOUND) + // eslint-disable-next-line cypress/no-unnecessary-waiting + return cy.wait(2000).then(() => getStatus(txHash)); + else return cy.wrap(transactionStatus); + }); + cy.request({ - method: 'POST', - url: FAUCET_URL_MAP[AGORIC_NET], body: { address: walletAddress, command, clientType: 'SMART_WALLET', }, + followRedirect: false, headers: FACUET_HEADERS, - timeout: 4 * MINUTE_MS, - retryOnStatusCodeFailure: true, - }).then(resp => { - expect(resp.body).to.eq('success'); - }); + method: 'POST', + url: `https://${AGORIC_NET}.faucet.agoric.net/go`, + }) + .then(resp => + getStatus(/\/transaction-status\/(.*)/.exec(resp.headers.location)[1]), + ) + .then(status => expect(status).to.eq(TRANSACTION_STATUS.SUCCESSFUL)); }); afterEach(function () { diff --git a/test/e2e/test.utils.js b/test/e2e/test.utils.js index ce75b441..c92f16ff 100644 --- a/test/e2e/test.utils.js +++ b/test/e2e/test.utils.js @@ -73,13 +73,6 @@ export const configMap = { }, }; -export const FAUCET_URL_MAP = { - emerynet: 'https://emerynet.faucet.agoric.net/go', - devnet: 'https://devnet.faucet.agoric.net/go', - ollinet: 'https://ollinet.faucet.agoric.net/go', - xnet: 'https://xnet.faucet.agoric.net/go', -}; - export const FACUET_HEADERS = { Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',