Skip to content

Commit

Permalink
Merge branch 'master' into aa/feat/fuels-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaiwat10 authored Nov 3, 2023
2 parents b98d4c1 + 2ddda9f commit e356e5b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-items-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/wallet": minor
---

fix transferToContract for amounts higher than u16
7 changes: 4 additions & 3 deletions packages/fuel-gauge/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,13 +899,14 @@ describe('Contract', () => {
*/
it('should tranfer asset to a deployed contract just fine (NATIVE ASSET)', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, BaseAssetId]]);
const wallet = await generateTestWallet(provider, [[10_000_000_000, BaseAssetId]]);

const contract = await setupContract();

const initialBalance = new BN(await contract.getBalance(BaseAssetId)).toNumber();

const amountToContract = 200;
const u64Amount = bn(5_000_000_000);
const amountToContract = u64Amount;

const tx = await wallet.transferToContract(contract.id, amountToContract, BaseAssetId, {
gasPrice,
Expand All @@ -915,7 +916,7 @@ describe('Contract', () => {

const finalBalance = new BN(await contract.getBalance(BaseAssetId)).toNumber();

expect(finalBalance).toBe(initialBalance + amountToContract);
expect(finalBalance).toBe(initialBalance + amountToContract.toNumber());
});

it('should tranfer asset to a deployed contract just fine (NOT NATIVE ASSET)', async () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/wallet/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NumberCoder } from '@fuel-ts/abi-coder';
import { U64Coder } from '@fuel-ts/abi-coder';
import { BaseAssetId } from '@fuel-ts/address/configs';
import type { BigNumberish } from '@fuel-ts/math';
import * as getBytesCopyMod from 'ethers';
Expand All @@ -24,9 +24,7 @@ describe('util', () => {
it('should ensure "formatScriptDataForTransferringToContract" returns script data just fine', () => {
const byte: number[] = [0, 0, 0, 0, 0, 0, 0, 1];

const encode = jest
.spyOn(NumberCoder.prototype, 'encode')
.mockReturnValue(Uint8Array.from(byte));
const encode = jest.spyOn(U64Coder.prototype, 'encode').mockReturnValue(Uint8Array.from(byte));

const arrayify = jest
.spyOn(getBytesCopyMod, 'getBytesCopy')
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NumberCoder } from '@fuel-ts/abi-coder';
import { U64Coder } from '@fuel-ts/abi-coder';
import type { B256Address } from '@fuel-ts/interfaces';
import { BN, type BigNumberish } from '@fuel-ts/math';
import * as asm from '@fuels/vm-asm';
Expand Down Expand Up @@ -43,7 +43,7 @@ export const formatScriptDataForTransferringToContract = (
amountToTransfer: BigNumberish,
assetId: BytesLike
) => {
const numberCoder = new NumberCoder('u16');
const numberCoder = new U64Coder();

const encoded = numberCoder.encode(new BN(amountToTransfer).toNumber());

Expand Down

0 comments on commit e356e5b

Please sign in to comment.