Skip to content

Commit

Permalink
fix(contract): do not check payable if contract call is init
Browse files Browse the repository at this point in the history
  • Loading branch information
subhod-i authored and davidyuk committed Apr 6, 2022
1 parent 996dc29 commit c09fc0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/contract/aci.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions test/integration/contract-aci.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down

0 comments on commit c09fc0c

Please sign in to comment.