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

chore: add e2e tests for transaction summary operations #2931

Merged
merged 11 commits into from
Sep 3, 2024
4 changes: 4 additions & 0 deletions .changeset/lazy-lemons-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: add e2e tests for transaction summary operations
77 changes: 77 additions & 0 deletions packages/fuel-gauge/src/transaction-summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
Wallet,
AddressType,
OperationName,
Address,
ChainName,
bn,
OutputType,
} from 'fuels';
import { ASSET_A, ASSET_B, launchTestNode, TestMessage } from 'fuels/test-utils';
Expand Down Expand Up @@ -728,5 +731,79 @@ describe('TransactionSummary', () => {
],
});
});

it('should ensure contract call operations are correctly assembled [WITHDRAW TO BASE LAYER]', async () => {
using launched = await launchTestNode();

const {
provider,
wallets: [sender],
} = launched;

const recipient = Address.fromB256(
'0x00000000000000000000000047ba61eec8e5e65247d717ff236f504cf3b0a263'
);

const amountToWithdraw = 10;

const tx = await sender.withdrawToBaseLayer(recipient, amountToWithdraw);
const result = await tx.waitForResult();

const { operations } = result;

expect(operations[0].name).toEqual(OperationName.withdrawFromFuel);
expect(operations[0].from?.type).toEqual(AddressType.account);
expect(operations[0].from?.address).toEqual(sender.address.toB256());
expect(operations[0].to?.type).toEqual(AddressType.account);
expect(operations[0].to?.address).toEqual(recipient.toB256());
expect(operations[0].to?.chain).toEqual(ChainName.ethereum);
expect(operations[0].assetsSent).toHaveLength(1);
expect(operations[0].assetsSent?.[0].amount).toEqual(bn(amountToWithdraw));
expect(operations[0].assetsSent?.[0].assetId).toEqual(provider.getBaseAssetId());
});

it('Should return contract created operations', async () => {
using launched = await launchTestNode();

const {
wallets: [wallet],
} = launched;

const tx = await MultiTokenContractFactory.deploy(wallet);
const result = await tx.waitForResult();

expect(result.transactionResult.operations).toHaveLength(1);
expect(result.transactionResult.operations[0].name).toEqual(OperationName.contractCreated);
expect(result.transactionResult.operations[0].from?.type).toEqual(AddressType.account);
expect(result.transactionResult.operations[0].from?.address).toEqual(wallet.address.toB256());
expect(result.transactionResult.operations[0].to?.type).toEqual(AddressType.contract);
expect(result.transactionResult.isTypeCreate).toEqual(true);
});

it('should have no assets returned for contract call operations', async () => {
using launched = await launchTestNode({
contractsConfigs: [
{
factory: TokenContractFactory,
maschad marked this conversation as resolved.
Show resolved Hide resolved
},
],
});

const {
wallets: [wallet],
contracts: [contract],
} = launched;

const tx = await contract.functions.mint_coins(100).call();
const result = await tx.waitForResult();

expect(result.transactionResult.operations).toHaveLength(1);
expect(result.transactionResult.operations[0].name).toEqual(OperationName.contractCall);
expect(result.transactionResult.operations[0].from?.type).toEqual(AddressType.account);
expect(result.transactionResult.operations[0].from?.address).toEqual(wallet.address.toB256());
expect(result.transactionResult.operations[0].to?.address).toEqual(contract.id.toB256());
expect(result.transactionResult.operations[0].to?.type).toEqual(AddressType.contract);
expect(result.transactionResult.operations[0].assetsSent).toBeUndefined();
});
});
});