From c09fc0c40bef8668066697567182a75f7a484886 Mon Sep 17 00:00:00 2001 From: subhod-i Date: Thu, 24 Mar 2022 13:40:40 +0000 Subject: [PATCH] fix(contract): do not check payable if contract call is init --- src/contract/aci.js | 2 +- test/integration/contract-aci.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/contract/aci.js b/src/contract/aci.js index a156932260..7341218eb0 100644 --- a/src/contract/aci.js +++ b/src/contract/aci.js @@ -235,7 +235,7 @@ export default async function getContractInstance ({ if (!fn) throw new MissingFunctionNameError() if (fn === 'init' && !opt.callStatic) throw new InvalidMethodInvocationError('"init" can be called only via dryRun') if (!contractId && fn !== 'init') throw new InvalidMethodInvocationError('You need to deploy contract before calling!') - if (opt.amount > 0 && fnACI.payable === false) throw new NotPayableFunctionError(`You try to pay "${opt.amount}" to function "${fn}" which is not payable. Only payable function can accept coins`) + if (fn !== 'init' && opt.amount > 0 && fnACI.payable === false) throw new NotPayableFunctionError(`You try to pay "${opt.amount}" to function "${fn}" which is not payable. Only payable function can accept coins`) const callerId = await this.address(opt).catch(error => { if (opt.callStatic) return DRY_RUN_ACCOUNT.pub diff --git a/test/integration/contract-aci.js b/test/integration/contract-aci.js index ee840a0b92..a5243ccbe3 100644 --- a/test/integration/contract-aci.js +++ b/test/integration/contract-aci.js @@ -182,11 +182,21 @@ describe('Contract instance', function () { .to.be.rejectedWith(InvalidMethodInvocationError, 'You need to deploy contract before calling!')) it('deploys', async () => { - const deployInfo = await testContract.deploy(['test', 1, 'hahahaha'], { amount: 42 }) + const deployInfo = await testContract.deploy(['test', 1, 'hahahaha'], { + amount: 42, + denomination: 'aettos', + gas: 16000, + deposit: 0, + ttl: 0, + gasPrice: '1e9', + strategy: 'max' + }) expect(deployInfo.address).to.satisfy(b => b.startsWith('ct_')) - expect(deployInfo.txData.tx.gas).to.be.equal(15000) + expect(deployInfo.txData.tx.gas).to.be.equal(16000) expect(deployInfo.txData.tx.amount).to.be.equal(42) expect(deployInfo.txData.gasUsed).to.be.equal(209) + expect(deployInfo.txData.gasPrice).to.be.equal(1000000000) + expect(deployInfo.txData.tx.deposit).to.be.equal(0) expect(testContract.bytecode).to.satisfy(b => b.startsWith('cb_')) testContractAddress = deployInfo.address })