Skip to content

Commit

Permalink
fix: ensure correct message input is returned based on spec
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Jul 17, 2024
1 parent 25587d4 commit c5049e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 16 additions & 1 deletion packages/account/src/providers/transaction-summary/input.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ZeroBytes32 } from '@fuel-ts/address/configs';
import type { InputCoin } from '@fuel-ts/transactions';
import { bn } from '@fuel-ts/math';
import type { InputCoin, InputMessage } from '@fuel-ts/transactions';
import { ASSET_A } from '@fuel-ts/utils/test-utils';

import {
Expand Down Expand Up @@ -120,4 +121,18 @@ describe('transaction-summary/input', () => {
MOCK_INPUT_MESSAGE
);
});

it('should ensure getInputFromAssetId returns input message if the coin input amount is 0', () => {
const inputMessage: InputMessage = {
...MOCK_INPUT_MESSAGE,
amount: bn(100),
};

const coinInput: InputCoin = {
...MOCK_INPUT_COIN,
amount: bn(0),
};

expect(getInputFromAssetId([inputMessage, coinInput], ASSET_A)).toEqual(inputMessage);
});
});
5 changes: 1 addition & 4 deletions packages/account/src/providers/transaction-summary/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ export function getInputFromAssetId(inputs: Input[], assetId: string) {
const coinInputs = getInputsCoin(inputs);
const messageInputs = getInputsMessage(inputs);
const coinInput = coinInputs.find((i) => i.assetId === assetId);
// TODO: should include assetId in InputMessage as well. for now we're mocking ETH
const messageInput = messageInputs.find(
(_) => assetId === '0x0000000000000000000000000000000000000000000000000000000000000000'
);
const messageInput = messageInputs.find(({ amount }) => !!amount && amount.gt(0));

return coinInput || messageInput;
}
Expand Down

0 comments on commit c5049e5

Please sign in to comment.