Skip to content

Commit

Permalink
chore: add e2e tests for transaction summary operations
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Aug 21, 2024
1 parent c2fa2a5 commit 090eaec
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 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,11 @@ import {
Wallet,
AddressType,
OperationName,
Address,
ChainName,
bn,
ZeroBytes32,
TransactionType,
OutputType,
} from 'fuels';
import { ASSET_A, ASSET_B, launchTestNode, TestMessage } from 'fuels/test-utils';
Expand Down Expand Up @@ -715,5 +720,101 @@ 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 tx = await sender.withdrawToBaseLayer(recipient, 10);
const result = await tx.waitForResult();

const { operations } = result;

expect(operations[0].name).toEqual(OperationName.withdrawFromFuel);
expect(operations[0].from?.type).toEqual(1);
expect(operations[0].from?.address).toEqual(sender.address.toB256());
expect(operations[0].to?.type).toEqual(1);
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('10'));
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(1);
expect(result.transactionResult.operations[0].from?.address).toEqual(wallet.address.toB256());
expect(result.transactionResult.operations[0].to?.type).toEqual(0);
expect(result.transactionResult.isTypeCreate).toEqual(true);
});

it('should have no assets returned for contract call operations', async () => {
using launched = await launchTestNode({
contractsConfigs: [
{
factory: TokenContractFactory,
},
],
});

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(1);
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(0);
expect(result.transactionResult.operations[0].assetsSent).toBeUndefined();
});

it('should return the correct operations for a mint transaction', async () => {
using launched = await launchTestNode({
nodeOptions: {
args: ['--poa-instant', 'false', '--poa-interval-period', '1ms'],
loggingEnabled: false,
},
});
const { provider } = launched;

const txnInfo = await provider.getTransactions({ first: 1 });

const transactions = txnInfo.transactions[0];

expect(transactions.type).toEqual(TransactionType.Mint);
expect(transactions.txPointer?.blockHeight).toEqual(1);
expect(transactions.txPointer?.txIndex).toEqual(0);
expect(transactions.inputContract?.txID).toEqual(ZeroBytes32);
expect(transactions.inputContract?.balanceRoot).toEqual(ZeroBytes32);
expect(transactions.inputContract?.stateRoot).toEqual(ZeroBytes32);
expect(transactions.inputContract?.type).toEqual(TransactionType.Create);
expect(transactions.mintAmount?.eq(bn(0))).toBe(true);
expect(transactions.mintAssetId).toEqual(provider.getBaseAssetId());
});
});
});

0 comments on commit 090eaec

Please sign in to comment.