From 37ea8625535404b367d7faf33a9f4ed46d043837 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Fri, 11 Oct 2024 16:24:05 +0500 Subject: [PATCH] chore: verify shortfall balance --- .../specs/liquidation-reconstitution.spec.js | 40 +++++++++++++++++++ test/e2e/specs/liquidation.spec.js | 40 +++++++++++++++++++ test/e2e/support.js | 7 +++- test/e2e/test.utils.js | 2 + 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/liquidation-reconstitution.spec.js b/test/e2e/specs/liquidation-reconstitution.spec.js index e06d0f64..a9851160 100644 --- a/test/e2e/specs/liquidation-reconstitution.spec.js +++ b/test/e2e/specs/liquidation-reconstitution.spec.js @@ -30,8 +30,10 @@ describe('Wallet App Test Cases', () => { const gov2Address = currentConfig.gov2Address; const econGovURL = currentConfig.econGovURL; const auctionURL = currentConfig.auctionURL; + const reserveURL = currentConfig.reserveURL; let bidderAtomBalance = 0; let bidderIstBalance = 0; + let shortfallBalance = 0; context('Verify if both bidder and user1 have sufficient balance', () => { // Note: Transaction fees are not considered in these calculations. @@ -434,6 +436,17 @@ describe('Wallet App Test Cases', () => { }); }); + it('should save current value of shortfall balance', () => { + cy.fetchVStorageData({ + url: reserveURL, + field: 'shortfallBalance', + latest: true, + }).then(output => { + shortfallBalance = Number(Number(output.value.slice(1)).toFixed(2)); + cy.task('info', `Current Shortfall balance: ${shortfallBalance}`); + }); + }); + it('should place bids from the CLI successfully', () => { cy.switchWallet(bidderWalletName); cy.addNewTokensFound(); @@ -639,6 +652,33 @@ describe('Wallet App Test Cases', () => { }, ); + context('Verification of Shortfall balance', () => { + it('should see an increase of 5.525 IST in shortfall balance', () => { + const expectedValue = 5.525; + cy.task('info', `Expected: ${expectedValue}`); + + cy.fetchVStorageData({ + url: reserveURL, + field: 'shortfallBalance', + latest: true, + }).then(newBalanceObj => { + let newBalance = Number( + Number(newBalanceObj.value.slice(1)).toFixed(2), + ); + + cy.task('info', `Initial shortfallBalance: ${shortfallBalance}`); + cy.task('info', `New shortfallBalance: ${JSON.stringify(newBalance)}`); + + const balanceIncrease = Number( + (newBalance - shortfallBalance).toFixed(2), + ); + cy.task('info', `Actual increase: ${balanceIncrease}`); + + expect(balanceIncrease).to.eq(expectedValue); + }); + }); + }); + context('Verification of Filled Bids', () => { it("should see increase in the bidder's ATOM balance", () => { const expectedValue = 13.585; diff --git a/test/e2e/specs/liquidation.spec.js b/test/e2e/specs/liquidation.spec.js index 0ee22e7b..d38968cd 100644 --- a/test/e2e/specs/liquidation.spec.js +++ b/test/e2e/specs/liquidation.spec.js @@ -31,9 +31,11 @@ describe('Wallet App Test Cases', () => { const gov2Address = currentConfig.gov2Address; const econGovURL = currentConfig.econGovURL; const auctionURL = currentConfig.auctionURL; + const reserveURL = currentConfig.reserveURL; let bidderAtomBalance = 0; let user1AtomBalance = 0; let bidderIstBalance = 0; + let shortfallBalance = 0; context('Verify if both bidder and user1 have sufficient balance', () => { // Note: Transaction fees are not considered in these calculations. @@ -430,6 +432,17 @@ describe('Wallet App Test Cases', () => { }); }); + it('should save current value of shortfall balance', () => { + cy.fetchVStorageData({ + url: reserveURL, + field: 'shortfallBalance', + latest: true, + }).then(output => { + shortfallBalance = Number(Number(output.value.slice(1)).toFixed(2)); + cy.task('info', `Current Shortfall balance: ${shortfallBalance}`); + }); + }); + it( 'should place bids from the CLI successfully', { @@ -714,6 +727,33 @@ describe('Wallet App Test Cases', () => { }); }); + context('Verification of Shortfall balance', () => { + it('should not see an increase in shortfall balance', () => { + const expectedValue = 0; + cy.task('info', `Expected: ${expectedValue}`); + + cy.fetchVStorageData({ + url: reserveURL, + field: 'shortfallBalance', + latest: true, + }).then(newBalanceObj => { + let newBalance = Number( + Number(newBalanceObj.value.slice(1)).toFixed(2), + ); + + cy.task('info', `Initial shortfallBalance: ${shortfallBalance}`); + cy.task('info', `New shortfallBalance: ${JSON.stringify(newBalance)}`); + + const balanceIncrease = Number( + (newBalance - shortfallBalance).toFixed(2), + ); + cy.task('info', `Actual increase: ${balanceIncrease}`); + + expect(balanceIncrease).to.eq(expectedValue); + }); + }); + }); + context('Verification of Fully and Partially Filled Bids', () => { it("should see increase in the bidder's ATOM balance after liquidation", () => { const expectedValue = 18.908; diff --git a/test/e2e/support.js b/test/e2e/support.js index 235fe1b1..b9a576e5 100644 --- a/test/e2e/support.js +++ b/test/e2e/support.js @@ -252,7 +252,7 @@ Cypress.Commands.add('provisionFromFaucet', (walletAddress, command) => { }); Cypress.Commands.add('fetchVStorageData', params => { - const { url, field } = params; + const { url, field, latest = false } = params; cy.request(url).then(response => { expect(response.status).to.eq(200); cy.task('info', `Data fetched successfully for ${field}`); @@ -267,6 +267,11 @@ Cypress.Commands.add('fetchVStorageData', params => { }); cy.task('info', `Filtered Data: ${JSON.stringify(arr)}`); + + if (latest) { + return cy.wrap(arr.at(-1)); + } + cy.wrap(arr); }); }); diff --git a/test/e2e/test.utils.js b/test/e2e/test.utils.js index 931b3c24..34d47600 100644 --- a/test/e2e/test.utils.js +++ b/test/e2e/test.utils.js @@ -55,6 +55,7 @@ export const configMap = { gov2WalletName: 'gov2', econGovURL: `https://econ-gov.inter.trade/?agoricNet=${Cypress.env('AGORIC_NET')}`, auctionURL: `https://${Cypress.env('AGORIC_NET')?.trim()}.api.agoric.net/agoric/vstorage/data/published.auction.book0`, + reserveURL: `https://${Cypress.env('AGORIC_NET')?.trim()}.api.agoric.net/agoric/vstorage/data/published.reserve.metrics`, }, local: { DEFAULT_TIMEOUT: 1 * 60 * 1000, @@ -76,6 +77,7 @@ export const configMap = { econGovURL: 'https://econ-gov.inter.trade/?agoricNet=local', auctionURL: 'http://localhost:1317/agoric/vstorage/data/published.auction.book0', + reserveURL: `http://localhost:1317/agoric/vstorage/data/published.reserve.metrics`, }, };