Skip to content

Commit

Permalink
fix: use Number instead of unary plus for BigInt
Browse files Browse the repository at this point in the history
Fixes bug in fdf5578
  • Loading branch information
davidyuk committed Jul 28, 2023
1 parent 3cf8c77 commit 33fcfb4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/contract/Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class Contract<M extends ContractMethodsBase> {

if (fn == null) throw new MissingFunctionNameError();
if (fn === 'init' && callStatic !== true) throw new InvalidMethodInvocationError('"init" can be called only via dryRun');
if (fn !== 'init' && opt.amount != null && +opt.amount > 0 && !fnAci.payable) {
if (fn !== 'init' && opt.amount != null && Number(opt.amount) > 0 && !fnAci.payable) {
throw new NotPayableFunctionError(opt.amount, fn);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tx/builder/field-types/u-int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { toBytes } from '../../../utils/bytes';

export default {
serialize(value: Int): Buffer {
if (+value < 0) throw new ArgumentError('value', 'greater or equal to 0', value);
if (Number(value) < 0) throw new ArgumentError('value', 'greater or equal to 0', value);
return toBytes(value, true);
},

Expand Down
9 changes: 9 additions & 0 deletions test/integration/contract-aci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,15 @@ describe('Contract instance', () => {
balanceAfter.should.be.equal(`${+contractBalance + 100}`);
});

it('pays to payable function using BigInt', async () => {
assertNotNull(testContract.$options.address);
const contractBalance = await aeSdk.getBalance(testContract.$options.address);
// bigint is not assignable to amount
await testContract.stringFn('test', { amount: 100n as unknown as string, callStatic: false });
const balanceAfter = await aeSdk.getBalance(testContract.$options.address);
balanceAfter.should.be.equal(`${+contractBalance + 100}`);
});

it('calls on specific account', async () => {
const onAccount = aeSdk.accounts[aeSdk.addresses()[1]];
const { result } = await testContract.intFn(123, { onAccount });
Expand Down

0 comments on commit 33fcfb4

Please sign in to comment.