Skip to content

Commit

Permalink
fix(common): fix undefined utxoSum nanoErgs result.
Browse files Browse the repository at this point in the history
  • Loading branch information
capt-nemo429 committed May 24, 2023
1 parent 5b3d4df commit 448c4e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/common/src/utils/boxUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,13 @@ describe("UTxO sum", () => {
).toBe(3819n);
});

it("Should return zero for empty arrays", () => {
it("Should not return undefined results for empty arrays", () => {
expect(utxoSum([], "0cd8c9f416e5b1ca9f986a7f10a84191dfb85941619e49e53c0dc30ebf83324b")).toBe(
0n
);

expect(utxoSum([]).nanoErgs).toBe(0n);
expect(utxoSum([]).tokens).toStrictEqual([]);
});

it("Should sum all tokens and nanoErgs", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/utils/boxUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function utxoSum(boxes: MinimalBoxAmounts, tokenId?: TokenId): BoxAmounts
}

return {
nanoErgs: balances[NANOERGS_TOKEN_ID],
nanoErgs: balances[NANOERGS_TOKEN_ID] || _0n,
tokens: Object.keys(balances)
.filter((x) => x !== NANOERGS_TOKEN_ID)
.map((tokenId) => ({ tokenId, amount: balances[tokenId] }))
Expand Down

0 comments on commit 448c4e4

Please sign in to comment.