Fix Decimal can be constructed with a negative atomics
This commit is contained in:
parent
05f89b107b
commit
6f22e00488
@ -31,6 +31,10 @@ describe("Decimal", () => {
|
||||
expect(Decimal.fromAtomics("44", 3).toString()).toEqual("0.044");
|
||||
expect(Decimal.fromAtomics("44", 4).toString()).toEqual("0.0044");
|
||||
});
|
||||
|
||||
it("throws for atomics that are not non-negative", () => {
|
||||
expect(() => Decimal.fromAtomics("-1", 0)).toThrowError(/atomics must not be negative/i);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fromUserInput", () => {
|
||||
|
||||
@ -107,8 +107,14 @@ export class Decimal {
|
||||
};
|
||||
|
||||
private constructor(atomics: string, fractionalDigits: number) {
|
||||
const _atomics = new BN(atomics);
|
||||
|
||||
if (_atomics.isNeg()) {
|
||||
throw new Error("Atomics must not be negative");
|
||||
}
|
||||
|
||||
this.data = {
|
||||
atomics: new BN(atomics),
|
||||
atomics: _atomics,
|
||||
fractionalDigits: fractionalDigits,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user