-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Output should be rounded by math rules instead of "round to floor". Signed-off-by: Eugene Panteleymonchuk <[email protected]> * Revert changes. Change logic for format amount. Add tests. Signed-off-by: Eugene Panteleymonchuk <[email protected]> * Add tests. Signed-off-by: Eugene Panteleymonchuk <[email protected]> * All tests passed (included tests before); Signed-off-by: Eugene Panteleymonchuk <[email protected]> * Improve toFixedNoRound function. Signed-off-by: Eugene Panteleymonchuk <[email protected]> * Revert unchanged files. Signed-off-by: Eugene Panteleymonchuk <[email protected]> * feat: Improve valueFormatHelper test naming. Refactor naming. Fix transactionHelper test unable to run with @iota/sdk-wasm --------- Signed-off-by: Eugene Panteleymonchuk <[email protected]> Co-authored-by: Mario Sarcevic <[email protected]>
- Loading branch information
1 parent
b8314f3
commit 2b481f6
Showing
5 changed files
with
121 additions
and
39 deletions.
There are no files selected for viewing
12 changes: 6 additions & 6 deletions
12
...lpers/stardust/transactionsHelper.spec.ts → ...lpers/stardust/convertToBigEndian.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import { TransactionsHelper } from "./transactionsHelper"; | ||
import { Converter } from "./convertUtils"; | ||
|
||
describe("Transaction helper", () => { | ||
describe("convertToBigEndian", () => { | ||
it("should convert little endian encoded hex to big endian", () => { | ||
const outputIndex = "0200"; | ||
expect(TransactionsHelper.convertToBigEndian(outputIndex)).toBe("0002"); | ||
expect(Converter.convertToBigEndian(outputIndex)).toBe("0002"); | ||
}); | ||
|
||
it("should convert to big endian when the index length is 6", () => { | ||
const outputIndex = "9F8601"; | ||
expect(TransactionsHelper.convertToBigEndian(outputIndex)).toBe("01869F"); | ||
expect(Converter.convertToBigEndian(outputIndex)).toBe("01869F"); | ||
}); | ||
|
||
it("should convert to big endian when the index length is 8", () => { | ||
const outputIndex = "9F860101"; | ||
expect(TransactionsHelper.convertToBigEndian(outputIndex)).toBe("0101869F"); | ||
expect(Converter.convertToBigEndian(outputIndex)).toBe("0101869F"); | ||
}); | ||
|
||
it("should convert to big endian if the index has odd length", () => { | ||
const outputIndex = "9F86010"; | ||
expect(TransactionsHelper.convertToBigEndian(outputIndex)).toBe("1060F809"); | ||
expect(Converter.convertToBigEndian(outputIndex)).toBe("1060F809"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { formatAmount } from "./valueFormatHelper"; | ||
|
||
const tokenInfo = { | ||
"name": "IOTA", | ||
"tickerSymbol": "IOTA", | ||
"unit": "IOTA", | ||
"subunit": "micro", | ||
"decimals": 6, | ||
"useMetricPrefix": false | ||
}; | ||
|
||
describe("formatAmount", () => { | ||
it("should format 1 subunit properly", () => { | ||
expect(formatAmount(1, tokenInfo)).toBe("0.000001 IOTA"); | ||
}); | ||
|
||
it("should format 10 subunit properly", () => { | ||
expect(formatAmount(10, tokenInfo)).toBe("0.00001 IOTA"); | ||
}); | ||
|
||
it("should format 100 subunit properly", () => { | ||
expect(formatAmount(100, tokenInfo)).toBe("0.0001 IOTA"); | ||
}); | ||
|
||
it("should format 1000 subunit properly", () => { | ||
expect(formatAmount(1000, tokenInfo)).toBe("0.001 IOTA"); | ||
}); | ||
|
||
it("should format 10000 subunit properly", () => { | ||
expect(formatAmount(10000, tokenInfo)).toBe("0.01 IOTA"); | ||
}); | ||
|
||
it("should format 100000 subunit properly", () => { | ||
expect(formatAmount(100000, tokenInfo)).toBe("0.1 IOTA"); | ||
}); | ||
|
||
it("should format 1 unit properly", () => { | ||
expect(formatAmount(1000000, tokenInfo)).toBe("1 IOTA"); | ||
}); | ||
|
||
it("should format 1 unit with fraction properly", () => { | ||
expect(formatAmount(1234567, tokenInfo)).toBe("1.23 IOTA"); | ||
}); | ||
|
||
it("should handle edge case from issue 'explorer/issues/822'", () => { | ||
expect(formatAmount(1140000, tokenInfo)).toBe("1.14 IOTA"); | ||
}); | ||
|
||
it("should honour precision 3", () => { | ||
expect(formatAmount(9999, tokenInfo, false, 3)).toBe("0.009 IOTA"); | ||
}); | ||
|
||
it("should honour precision 4", () => { | ||
expect(formatAmount(9999, tokenInfo, false, 4)).toBe("0.0099 IOTA"); | ||
}); | ||
|
||
it("should honour precision 0", () => { | ||
expect(formatAmount(1450896407249092, tokenInfo, false, 0)).toBe("1450896407 IOTA"); | ||
}); | ||
|
||
it("should format big values properly", () => { | ||
expect(formatAmount(1450896407249092, tokenInfo)).toBe("1450896407.24 IOTA"); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters