Skip to content

Commit

Permalink
Faucet Polling in E2E Tests (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
usmanmani1122 authored Sep 12, 2024
1 parent b9e3e6b commit 4de72f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
37 changes: 28 additions & 9 deletions test/e2e/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 () {
Expand Down
7 changes: 0 additions & 7 deletions test/e2e/test.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4de72f7

Please sign in to comment.