mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 16:54:08 +00:00
Implement host API for big decimal equals (#476)
* Implement host api for big decimal equals * Add test cases for big decimal equals * Use boolean type conversion --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
@@ -478,7 +478,23 @@ export const instantiate = async (
|
||||
|
||||
return powResultBigDecimal;
|
||||
},
|
||||
'bigDecimal.equals': async (x: number, y: number) => {
|
||||
// Create decimal x string.
|
||||
const xBigDecimal = await BigDecimal.wrap(x);
|
||||
const xStringPtr = await xBigDecimal.toString();
|
||||
const xDecimalString = __getString(xStringPtr);
|
||||
const xDecimal = new GraphDecimal(xDecimalString);
|
||||
|
||||
// Create decimal y string.
|
||||
const yBigDecimal = await BigDecimal.wrap(y);
|
||||
const yStringPtr = await yBigDecimal.toString();
|
||||
const yDecimalString = __getString(yStringPtr);
|
||||
|
||||
// Perform the decimal equal operation.
|
||||
const isEqual = xDecimal.equals(yDecimalString);
|
||||
|
||||
return isEqual;
|
||||
},
|
||||
'bigInt.fromString': async (s: number) => {
|
||||
const string = __getString(s);
|
||||
|
||||
|
||||
@@ -638,4 +638,22 @@ describe('numbers wasm tests', () => {
|
||||
expect(__getString(ptr)).to.equal(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should execute bigDecimal equals API', () => {
|
||||
let testBigDecimalEquals: any, __newString: any;
|
||||
|
||||
before(() => {
|
||||
({ testBigDecimalEquals, __newString } = exports);
|
||||
});
|
||||
|
||||
it('should check given bigDecimals are equal', async () => {
|
||||
const ptr = await testBigDecimalEquals(await __newString('231543212.2132354'), await __newString('231543212.2132354'));
|
||||
expect(Boolean(ptr)).to.equal(true);
|
||||
});
|
||||
|
||||
it('should check given bigDecimals are not equal', async () => {
|
||||
const ptr = await testBigDecimalEquals(await __newString('231543212.2132354'), await __newString('54652.65645'));
|
||||
expect(Boolean(ptr)).to.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user