Skip to content

Commit

Permalink
Merge pull request #375 from Agoric/rs-refine-e2e-tests-II
Browse files Browse the repository at this point in the history
Improvements in e2e tests
  • Loading branch information
rabi-siddique authored Oct 11, 2024
2 parents f74b472 + 3213726 commit 64c6982
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 17 deletions.
94 changes: 91 additions & 3 deletions test/e2e/specs/liquidation-reconstitution.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { mnemonics, MINUTE_MS, networks, configMap } from '../test.utils';
import {
mnemonics,
MINUTE_MS,
networks,
configMap,
QUICK_WAIT,
webWalletURL,
webWalletSelectors,
} from '../test.utils';

describe('Wallet App Test Cases', () => {
let startTime;
Expand All @@ -20,6 +28,7 @@ describe('Wallet App Test Cases', () => {
const gov2Address = currentConfig.gov2Address;
const econGovURL = currentConfig.econGovURL;
const auctionURL = currentConfig.auctionURL;
let bidderAtomBalance = 0;

context('Setting up accounts', () => {
// Using exports from the synthetic-chain lib instead of hardcoding mnemonics UNTIL https://github.com/Agoric/agoric-3-proposals/issues/154
Expand Down Expand Up @@ -382,6 +391,17 @@ describe('Wallet App Test Cases', () => {
userKey: 'gov1',
});
});

it('should save bidder ATOM balance before placing bids', () => {
cy.wait(QUICK_WAIT);
cy.getATOMBalance({
walletAddress: bidderAddress,
}).then(output => {
bidderAtomBalance = Number(output.toFixed(3));
cy.task('info', `bidderAtomBalance: ${bidderAtomBalance}`);
});
});

it('should place bids from the CLI successfully', () => {
cy.switchWallet(bidderWalletName);
cy.addNewTokensFound();
Expand Down Expand Up @@ -425,7 +445,7 @@ describe('Wallet App Test Cases', () => {

context('Verify auction values while vaults are LIQUIDATING', () => {
it('should verify the value of startPrice', () => {
cy.wait(MINUTE_MS);
cy.wait(QUICK_WAIT);

if (AGORIC_NET === networks.LOCAL) {
const expectedValue = 9.99;
Expand Down Expand Up @@ -518,7 +538,7 @@ describe('Wallet App Test Cases', () => {
);

it('should verify the value of collateralAvailable', () => {
cy.wait(MINUTE_MS);
cy.wait(QUICK_WAIT);

if (AGORIC_NET === networks.LOCAL) {
const expectedValue = 31.414987;
Expand All @@ -543,6 +563,74 @@ describe('Wallet App Test Cases', () => {
},
);

context('Verification of Filled Bids', () => {
it("should see increase in the bidder's ATOM balance", () => {
const expectedValue = 13.585;
cy.task(
'info',
`Expected increase due to completely filled bids: ${expectedValue}`,
);

cy.getATOMBalance({
walletAddress: bidderAddress,
}).then(newBalance => {
cy.task('info', `Initial bidder ATOM Balance: ${bidderAtomBalance}`);
cy.task('info', `New bidder ATOM Balance: ${newBalance}`);

const balanceIncrease = Number(
(newBalance - bidderAtomBalance).toFixed(3),
);
cy.task('info', `Actual increase: ${balanceIncrease}`);
bidderAtomBalance = Number(newBalance.toFixed(2));

expect(balanceIncrease).to.eq(expectedValue);
});
});

it('should switch to the bidder wallet successfully', () => {
cy.switchWallet(bidderWalletName);
});

it('should setup the web wallet and not see any bids', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
cy.visit(webWalletURL);

cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});

cy.visit(`${webWalletURL}/wallet/`);

cy.get('input[type="checkbox"]').check();
cy.contains('Proceed').click();
cy.get('button[aria-label="Settings"]').click();

cy.contains('div', 'Mainnet').click();
cy.contains('li', webWalletSelectors[AGORIC_NET]).click();
cy.contains('button', 'Connect').click();

cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});

cy.reload();

cy.get('span')
.contains('ATOM', { timeout: DEFAULT_TIMEOUT })
.should('exist');
cy.get('span')
.contains('BLD', { timeout: DEFAULT_TIMEOUT })
.should('exist');

cy.contains('75.00 IST', { timeout: DEFAULT_TIMEOUT }).should(
'not.exist',
);
cy.contains('25.00 IST', { timeout: DEFAULT_TIMEOUT }).should(
'not.exist',
);
});
});

context(
'Close the vaults and restore ATOM price to 12.34 on TESTNET(s).',
() => {
Expand Down
60 changes: 46 additions & 14 deletions test/e2e/specs/liquidation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
configMap,
webWalletURL,
webWalletSelectors,
QUICK_WAIT,
THIRTY_SECONDS,
} from '../test.utils';

describe('Wallet App Test Cases', () => {
Expand Down Expand Up @@ -381,7 +383,7 @@ describe('Wallet App Test Cases', () => {
});

it('should save bidder ATOM balance before placing bids', () => {
cy.wait(MINUTE_MS);
cy.wait(QUICK_WAIT);
cy.getATOMBalance({
walletAddress: bidderAddress,
}).then(output => {
Expand Down Expand Up @@ -445,7 +447,7 @@ describe('Wallet App Test Cases', () => {

context('Verify auction values while vaults are LIQUIDATING', () => {
it('should verify the value of startPrice', () => {
cy.wait(MINUTE_MS);
cy.wait(THIRTY_SECONDS);

if (AGORIC_NET === networks.LOCAL) {
const expectedValue = 9.99;
Expand Down Expand Up @@ -531,7 +533,7 @@ describe('Wallet App Test Cases', () => {
);

it('should verify the value of collateralAvailable', () => {
cy.wait(MINUTE_MS);
cy.wait(QUICK_WAIT);

if (AGORIC_NET === networks.LOCAL) {
const expectedValue = 9.659301;
Expand All @@ -557,7 +559,7 @@ describe('Wallet App Test Cases', () => {

context('Claim collateral from the liquidated vaults', () => {
it('should save user1 ATOM balance before claiming collateral', () => {
cy.wait(MINUTE_MS);
cy.wait(QUICK_WAIT);

cy.getATOMBalance({
walletAddress: user1Address,
Expand All @@ -570,7 +572,7 @@ describe('Wallet App Test Cases', () => {
it('should claim collateral from the first vault successfully', () => {
cy.contains(/3.42 ATOM/, { timeout: MINUTE_MS }).click();
cy.contains('button', 'Close Out Vault').click();
cy.wait(5000); // eslint-disable-line cypress/no-unnecessary-waiting
cy.wait(QUICK_WAIT); // eslint-disable-line cypress/no-unnecessary-waiting
cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
cy.contains('button', 'Close Out Vault', {
Expand All @@ -582,7 +584,7 @@ describe('Wallet App Test Cases', () => {
it('should claim collateral from the second vault successfully', () => {
cy.contains(/3.07 ATOM/, { timeout: MINUTE_MS }).click();
cy.contains('button', 'Close Out Vault').click();
cy.wait(5000); // eslint-disable-line cypress/no-unnecessary-waiting
cy.wait(QUICK_WAIT); // eslint-disable-line cypress/no-unnecessary-waiting
cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
cy.contains('button', 'Close Out Vault', {
Expand All @@ -594,7 +596,7 @@ describe('Wallet App Test Cases', () => {
it('should claim collateral from the third vault successfully', () => {
cy.contains(/2.84 ATOM/, { timeout: MINUTE_MS }).click();
cy.contains('button', 'Close Out Vault').click();
cy.wait(5000); // eslint-disable-line cypress/no-unnecessary-waiting
cy.wait(QUICK_WAIT); // eslint-disable-line cypress/no-unnecessary-waiting
cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
cy.contains('button', 'Close Out Vault', {
Expand All @@ -604,7 +606,7 @@ describe('Wallet App Test Cases', () => {
});

it("should see increase in the user1's ATOM balance after claiming collateral", () => {
cy.wait(10000); // eslint-disable-line cypress/no-unnecessary-waiting
cy.wait(QUICK_WAIT); // eslint-disable-line cypress/no-unnecessary-waiting

const expectedValue = 9.35;
cy.task(
Expand Down Expand Up @@ -656,8 +658,7 @@ describe('Wallet App Test Cases', () => {
cy.switchWallet(bidderWalletName);
});

it('should setup the web wallet and cancel the 150IST bid', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
it('should setup the web wallet', () => {
cy.visit(webWalletURL);

cy.acceptAccess().then(taskCompleted => {
Expand Down Expand Up @@ -696,10 +697,42 @@ describe('Wallet App Test Cases', () => {
);
// Verify 150 IST Bid to exist
cy.contains('150.00 IST', { timeout: DEFAULT_TIMEOUT }).should('exist');
});

it('should cancel the 1IST bid', () => {
cy.skipWhen(AGORIC_NET !== networks.LOCAL);
cy.reload();

cy.getTokenAmount('IST').then(initialTokenValue => {
cy.contains('Exit').eq(1).click();
cy.wait(MINUTE_MS);
cy.contains('Exit').click();
cy.wait(QUICK_WAIT);
cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});
cy.contains('Accepted', { timeout: DEFAULT_TIMEOUT }).should('exist');
cy.getTokenAmount('IST').then(tokenValue => {
expect(tokenValue).to.greaterThan(initialTokenValue);
});
});
});

it('should save bidder ATOM balance', () => {
cy.skipWhen(AGORIC_NET !== networks.LOCAL);
cy.wait(QUICK_WAIT);
cy.getATOMBalance({
walletAddress: bidderAddress,
}).then(output => {
bidderAtomBalance = Number(output.toFixed(2));
cy.task('info', `bidderAtomBalance: ${bidderAtomBalance}`);
});
});

it('should cancel the 150IST bid', () => {
cy.reload();

cy.getTokenAmount('IST').then(initialTokenValue => {
cy.contains('Exit').click();
cy.wait(QUICK_WAIT);
cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});
Expand All @@ -711,8 +744,7 @@ describe('Wallet App Test Cases', () => {
});

it("should see increase in the bidder's ATOM balance because of partially filled bid", () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
cy.wait(10000); // eslint-disable-line cypress/no-unnecessary-waiting
cy.wait(QUICK_WAIT); // eslint-disable-line cypress/no-unnecessary-waiting

const expectedValue = 16.43;
cy.task(
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/test.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const accountAddresses = {

export const webWalletURL = 'https://wallet.agoric.app/';
export const MINUTE_MS = 1 * 60 * 1000;
export const QUICK_WAIT = 10 * 1000;
export const THIRTY_SECONDS = 30 * 1000;

export const agoricNetworks = {
emerynet: 'Agoric Emerynet',
Expand Down

0 comments on commit 64c6982

Please sign in to comment.