Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change compare logic in draft donation service #1823

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/services/chains/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1022,13 +1022,16 @@ function getTransactionDetailTestCases() {
}

function closeToTestCases() {
it('should 0.0008436 and 0.0008658 consider as closed amount', function () {
assert.isTrue(closeTo(0.0008436, 0.0008658));
it('should not consider 0.0008436 and 0.0008658 as closed amount', function () {
assert.isFalse(closeTo(0.0008436, 0.0008658));
});
it('should 0.0001 and 0.00011 consider as closed amount', function () {
assert.isTrue(closeTo(0.0001, 0.00011));
it('should not consider 0.0001 and 0.00011 as closed amount', function () {
assert.isFalse(closeTo(0.0001, 0.00011));
});
it('should not consider 0.001 and 0.003 consider as closed amount', function () {
assert.isFalse(closeTo(0.001, 0.003));
});
it('should consider 1000.1 and 1000 consider as closed amount', function () {
assert.isTrue(closeTo(1000.1, 1000));
});
}
2 changes: 1 addition & 1 deletion src/services/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ export function getAppropriateNetworkId(params: {

// This function is used to compare two numbers with a delta as a margin of error
export const closeTo = (a: number, b: number, delta = 0.001) => {
return Math.abs(a - b) < delta;
return Math.abs(1 - a / b) < delta;
};
Loading