Skip to content

Commit

Permalink
better serialization of number to float32
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jan 12, 2024
1 parent 91aa129 commit 6b95dc4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion property_tests/arbitraries/canister_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import { Test } from '../../test';
import { UpdateMethod } from './canister_methods/update_method_arb';
import { InitMethod } from './canister_methods/init_method_arb';
import { CorrespondingJSType } from './candid/corresponding_js_type';
import { TextClass } from '@dfinity/candid/lib/cjs/idl';
import { TextClass, FloatClass } from '@dfinity/candid/lib/cjs/idl';

TextClass.prototype.valueToString = function (x): string {
return `"${escapeForBash(x)}"`;
};

/**
* If a float doesn't have a decimal it won't serialize properly, so 10 while
* is a float won't serialize unless it's 10.0
*/
FloatClass.prototype.valueToString = function (x): string {
const floatString = x.toString();
if (floatString.includes('.')) {
return floatString;
}
return floatString + '.0';
};

export type Canister = {
deployArgs: string[] | undefined;
sourceCode: string;
Expand Down

0 comments on commit 6b95dc4

Please sign in to comment.