Skip to content

Commit

Permalink
Merge pull request #377 from Agoric/rs-decimal-places-verification
Browse files Browse the repository at this point in the history
Improvements when comparing decimal values
  • Loading branch information
rabi-siddique authored Oct 11, 2024
2 parents d51a4cd + 2383e3a commit 559e1ef
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 22 deletions.
53 changes: 45 additions & 8 deletions test/e2e/specs/liquidation-reconstitution.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
webWalletURL,
webWalletSelectors,
tokens,
extractNumber,
} from '../test.utils';

describe('Wallet App Test Cases', () => {
Expand Down Expand Up @@ -483,9 +484,15 @@ describe('Wallet App Test Cases', () => {
);
});
} else {
const propertyName = 'book0.startPrice';
const propertyName = 'startPrice';
const expectedValue = '9.99 IST/ATOM';
cy.verifyAuctionData(propertyName, expectedValue);
cy.task('info', `Expected Value: ${expectedValue}`);
cy.getAuctionParam(propertyName).then(value => {
const actualValue = extractNumber(value);
const expectedValueRounded = extractNumber(expectedValue);

expect(actualValue).to.eq(expectedValueRounded);
});
}
});

Expand All @@ -505,9 +512,21 @@ describe('Wallet App Test Cases', () => {
);
});
} else {
const propertyName = 'book0.startProceedsGoal';
const propertyName = 'startProceedsGoal';
const expectedValue = '309.54 IST';
cy.verifyAuctionData(propertyName, expectedValue);
cy.task('info', `Expected Value: ${expectedValue}`);
cy.getAuctionParam(propertyName).then(value => {
cy.task(
'info',
'Comparing actual and expected values rounded to one decimal place.',
);

const actualValue = Math.round(extractNumber(value) * 10) / 10;
const expectedValueRounded =
Math.round(extractNumber(expectedValue) * 10) / 10;

expect(actualValue).to.eq(expectedValueRounded);
});
}
});

Expand All @@ -527,9 +546,15 @@ describe('Wallet App Test Cases', () => {
);
});
} else {
const propertyName = 'book0.startCollateral';
const propertyName = 'startCollateral';
const expectedValue = '45 ATOM';
cy.verifyAuctionData(propertyName, expectedValue);
cy.task('info', `Expected Value: ${expectedValue}`);
cy.getAuctionParam(propertyName).then(value => {
const actualValue = extractNumber(value);
const expectedValueRounded = extractNumber(expectedValue);

expect(actualValue).to.eq(expectedValueRounded);
});
}
});
});
Expand Down Expand Up @@ -576,9 +601,21 @@ describe('Wallet App Test Cases', () => {
);
});
} else {
const propertyName = 'book0.collateralAvailable';
const propertyName = 'collateralAvailable';
const expectedValue = '31.414987 ATOM';
cy.verifyAuctionData(propertyName, expectedValue); // eslint-disable-line cypress/no-unnecessary-waiting
cy.task('info', `Expected Value: ${expectedValue}`);
cy.getAuctionParam(propertyName).then(value => {
cy.task(
'info',
'Comparing actual and expected values rounded to one decimal place.',
);

const actualValue = Math.round(extractNumber(value) * 10) / 10;
const expectedValueRounded =
Math.round(extractNumber(expectedValue) * 10) / 10;

expect(actualValue).to.eq(expectedValueRounded);
});
}
});
},
Expand Down
53 changes: 45 additions & 8 deletions test/e2e/specs/liquidation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
QUICK_WAIT,
THIRTY_SECONDS,
tokens,
extractNumber,
} from '../test.utils';

describe('Wallet App Test Cases', () => {
Expand Down Expand Up @@ -485,9 +486,15 @@ describe('Wallet App Test Cases', () => {
);
});
} else {
const propertyName = 'book0.startPrice';
const propertyName = 'startPrice';
const expectedValue = '9.99 IST/ATOM';
cy.verifyAuctionData(propertyName, expectedValue);
cy.task('info', `Expected Value: ${expectedValue}`);
cy.getAuctionParam(propertyName).then(value => {
const actualValue = extractNumber(value);
const expectedValueRounded = extractNumber(expectedValue);

expect(actualValue).to.eq(expectedValueRounded);
});
}
});

Expand All @@ -507,9 +514,21 @@ describe('Wallet App Test Cases', () => {
);
});
} else {
const propertyName = 'book0.startProceedsGoal';
const propertyName = 'startProceedsGoal';
const expectedValue = '309.54 IST';
cy.verifyAuctionData(propertyName, expectedValue);
cy.task('info', `Expected Value: ${expectedValue}`);
cy.getAuctionParam(propertyName).then(value => {
cy.task(
'info',
'Comparing actual and expected values rounded to one decimal place.',
);

const actualValue = Math.round(extractNumber(value) * 10) / 10;
const expectedValueRounded =
Math.round(extractNumber(expectedValue) * 10) / 10;

expect(actualValue).to.eq(expectedValueRounded);
});
}
});

Expand All @@ -529,9 +548,15 @@ describe('Wallet App Test Cases', () => {
);
});
} else {
const propertyName = 'book0.startCollateral';
const propertyName = 'startCollateral';
const expectedValue = '45 ATOM';
cy.verifyAuctionData(propertyName, expectedValue);
cy.task('info', `Expected Value: ${expectedValue}`);
cy.getAuctionParam(propertyName).then(value => {
const actualValue = extractNumber(value);
const expectedValueRounded = extractNumber(expectedValue);

expect(actualValue).to.eq(expectedValueRounded);
});
}
});
});
Expand Down Expand Up @@ -571,9 +596,21 @@ describe('Wallet App Test Cases', () => {
);
});
} else {
const propertyName = 'book0.collateralAvailable';
const propertyName = 'collateralAvailable';
const expectedValue = '9.659301 ATOM';
cy.verifyAuctionData(propertyName, expectedValue); // eslint-disable-line cypress/no-unnecessary-waiting
cy.task('info', `Expected Value: ${expectedValue}`);
cy.getAuctionParam(propertyName).then(value => {
cy.task(
'info',
'Comparing actual and expected values rounded to one decimal place.',
);

const actualValue = Math.round(extractNumber(value) * 10) / 10;
const expectedValueRounded =
Math.round(extractNumber(expectedValue) * 10) / 10;

expect(actualValue).to.eq(expectedValueRounded);
});
}
});
});
Expand Down
22 changes: 16 additions & 6 deletions test/e2e/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,32 @@ Cypress.Commands.add('placeBidByDiscount', params => {
});
});

Cypress.Commands.add('verifyAuctionData', (propertyName, expectedValue) => {
Cypress.Commands.add('getAuctionParam', propertyName => {
return cy
.exec(`${agops} inter auction status`, {
env: { AGORIC_NET },
failOnNonZeroExit: false,
timeout: COMMAND_TIMEOUT,
})
.then(({ stdout }) => {
const output = JSON.parse(stdout);
const propertyValue = Cypress._.get(output, propertyName);
.then(({ stdout, stderr }) => {
if (stderr && !stdout) {
cy.task('error', `STDERR: ${stderr}`);
throw Error(stderr);
}
cy.task('info', `STDOUT: ${stdout}`);

const output = JSON.parse(stdout)['book0'];
cy.task('info', `book0: ${JSON.stringify(output)}`);

const propertyValue = output[propertyName];

if (!propertyValue) {
throw new Error(`Error: ${propertyName} property is missing or empty`);
}

expect(propertyValue).to.equal(expectedValue);
cy.task('info', `${propertyName}: ${propertyValue}`);

cy.wrap(propertyValue);
});
});

Expand Down Expand Up @@ -309,6 +319,6 @@ afterEach(function () {
if (this.currentTest.state === 'failed') {
const testName = this.currentTest.title;
const errorMessage = this.currentTest.err.message;
cy.task('info', `Test "${testName}" failed with error: ${errorMessage}`);
cy.task('error', `Test "${testName}" failed with error: ${errorMessage}`);
}
});
5 changes: 5 additions & 0 deletions test/e2e/test.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,8 @@ export const tokens = {
IST: 'IST',
BLD: 'BLD',
};

export const extractNumber = expectedValue => {
const match = expectedValue.match(/[\d.]+/);
return match ? parseFloat(match[0]) : null;
};

0 comments on commit 559e1ef

Please sign in to comment.