Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: contract created operation with input message #1635

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spotty-berries-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/providers": patch
---

Fix operations contract created with input of type message
10 changes: 10 additions & 0 deletions packages/providers/src/transaction-summary/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors';
import type { Input, InputCoin, InputContract, InputMessage } from '@fuel-ts/transactions';
import { InputType } from '@fuel-ts/transactions';

/** @hidden */
export function getInputsByTypes<T = Input>(inputs: Input[], types: Array<InputType>) {
return inputs.filter((i) => types.includes(i.type)) as T[];
}

/** @hidden */
export function getInputsByType<T = Input>(inputs: Input[], type: InputType) {
return inputs.filter((i) => i.type === type) as T[];
Expand All @@ -17,6 +22,11 @@ export function getInputsMessage(inputs: Input[]) {
return getInputsByType<InputMessage>(inputs, InputType.Message);
}

/** @hidden */
export function getInputsCoinAndMessage(inputs: Input[]) {
return getInputsByTypes<InputCoin | InputMessage>(inputs, [InputType.Coin, InputType.Message]);
}

/** @hidden */
export function getInputsContract(inputs: Input[]) {
return getInputsByType<InputContract>(inputs, InputType.Contract);
Expand Down
24 changes: 24 additions & 0 deletions packages/providers/src/transaction-summary/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,30 @@ describe('operations', () => {
expect(operations.length).toEqual(1);
expect(operations[0]).toStrictEqual(expected);
});

it('should getOperations return contract created operations with input type message', () => {
const expected: Operation = {
from: {
address: '0x06300e686a5511c7ba0399fc68dcbe0ca2d8f54f7e6afea73c505dd3bcacf33b',
type: 1,
},
name: OperationName.contractCreated,
to: {
address: '0xef066899413ef8dc7c3073a50868bafb3d039d9bad8006c2635b7f0efa992553',
type: 0,
},
};
const operations = getOperations({
transactionType: TransactionType.Create,
inputs: [MOCK_INPUT_MESSAGE],
outputs: [MOCK_OUTPUT_CONTRACT_CREATED, MOCK_OUTPUT_CHANGE],
receipts: [],
maxInputs: bn(255),
});

expect(operations.length).toEqual(1);
expect(operations[0]).toStrictEqual(expected);
});
});

describe('addOperation', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/providers/src/transaction-summary/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
getInputFromAssetId,
getInputAccountAddress,
getInputContractFromIndex,
getInputsCoin,
getInputsContract,
getInputsCoinAndMessage,
} from './input';
import {
getOutputsChange,
Expand Down Expand Up @@ -427,7 +427,7 @@ export function getPayProducerOperations(outputs: Output[]): Operation[] {
/** @hidden */
export function getContractCreatedOperations({ inputs, outputs }: InputOutputParam): Operation[] {
const contractCreatedOutputs = getOutputsContractCreated(outputs);
const input = getInputsCoin(inputs)[0];
const input = getInputsCoinAndMessage(inputs)[0];
const fromAddress = getInputAccountAddress(input);
const contractCreatedOperations = contractCreatedOutputs.reduce((prev, contractCreatedOutput) => {
const operations = addOperation(prev, {
Expand Down
Loading