Skip to content

Commit

Permalink
test: verify shortfall balance and debt burned
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Oct 11, 2024
1 parent 401b002 commit 688493f
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 1 deletion.
71 changes: 71 additions & 0 deletions test/e2e/specs/liquidation-reconstitution.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,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 bidderIstBalance = 0;
let debtBurned = 0;
let shortfallBalance = 0;

context('Verify if both bidder and user1 have sufficient balance', () => {
// Note: Transaction fees are not considered in these calculations.
Expand Down Expand Up @@ -434,6 +437,28 @@ describe('Wallet App Test Cases', () => {
});
});

it('should save current value of debt burned', () => {
cy.fetchVStorageData({
url: reserveURL,
field: 'totalFeeBurned',
latest: true,
}).then(output => {
debtBurned = Number(Number(output.value.slice(1)).toFixed(2));
cy.task('info', `Current Debt Burned: ${debtBurned}`);
});
});

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 Debt Burned: ${shortfallBalance}`);
});
});

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

context('Verification of Debt Burned and Shortfall balance', () => {
it('should see an increase of 100IST in debt burned', () => {
const expectedValue = 100;
cy.task('info', `Expected increase: ${expectedValue}`);

cy.fetchVStorageData({
url: reserveURL,
field: 'totalFeeBurned',
latest: true,
}).then(newBalance => {
debtBurned = Number(Number(newBalance.value.slice(1)).toFixed(2));

cy.task('info', `Initial debtBurned: ${debtBurned}`);
cy.task('info', `New debtBurned: ${JSON.stringify(newBalance)}`);

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

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

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(newBalance => {
shortfallBalance = Number(Number(newBalance.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;
Expand Down
71 changes: 71 additions & 0 deletions test/e2e/specs/liquidation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ 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 debtBurned = 0;
let shortfallBalance = 0;

context('Verify if both bidder and user1 have sufficient balance', () => {
// Note: Transaction fees are not considered in these calculations.
Expand Down Expand Up @@ -430,6 +433,28 @@ describe('Wallet App Test Cases', () => {
});
});

it('should save current value of debt burned', () => {
cy.fetchVStorageData({
url: reserveURL,
field: 'totalFeeBurned',
latest: true,
}).then(output => {
debtBurned = Number(Number(output.value.slice(1)).toFixed(2));
cy.task('info', `Current Debt Burned: ${debtBurned}`);
});
});

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 Debt Burned: ${shortfallBalance}`);
});
});

it(
'should place bids from the CLI successfully',
{
Expand Down Expand Up @@ -714,6 +739,52 @@ describe('Wallet App Test Cases', () => {
});
});

context('Verification of Debt Burned and Shortfall balance', () => {
it('should see an increase of 309.54IST in debt burned', () => {
const expectedValue = 309.54;
cy.task('info', `Expected increase: ${expectedValue}`);

cy.fetchVStorageData({
url: reserveURL,
field: 'totalFeeBurned',
latest: true,
}).then(newBalance => {
debtBurned = Number(Number(newBalance.value.slice(1)).toFixed(2));

cy.task('info', `Initial debtBurned: ${debtBurned}`);
cy.task('info', `New debtBurned: ${JSON.stringify(newBalance)}`);

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

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

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(newBalance => {
shortfallBalance = Number(Number(newBalance.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;
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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);
});
});
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 @@ -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,
Expand All @@ -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`,
},
};

Expand Down

0 comments on commit 688493f

Please sign in to comment.