Skip to content

Commit

Permalink
fix(Contract/Chain): Using { waitMined: false } with Contract high lv…
Browse files Browse the repository at this point in the history
…l API (#828)
  • Loading branch information
nduchak authored Dec 13, 2019
1 parent 843f189 commit 475c2aa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
8 changes: 6 additions & 2 deletions es/ae/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ function sendAndProcess (tx, options) {
return async function (onSuccess, onError) {
// Send transaction and get transaction info
const txData = await this.send(tx, options)
const result = await this.getTxInfo(txData.hash)

if (typeof options.waitMined === 'boolean' && !options.waitMined) {
return onSuccess({ hash: txData.hash, rawTx: txData.rawTx })
}

const result = await this.getTxInfo(txData.hash)
return result.returnType === 'ok'
? onSuccess({ hash: txData.hash, rawTx: txData.rawTx, result, txData })
: typeof onError === 'function' ? onError(result) : this.handleCallError(result)
Expand Down Expand Up @@ -219,7 +223,7 @@ async function contractCall (source, address, name, args = [], options = {}) {
rawTx,
result,
txData,
decode: () => this.contractDecodeData(source, name, result.returnValue, result.returnType, opt)
decode: () => result ? this.contractDecodeData(source, name, result.returnValue, result.returnType, opt) : {}
})
)
}
Expand Down
4 changes: 2 additions & 2 deletions es/contract/aci/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ const call = ({ client, instance }) => async (fn, params = [], options = {}) =>
: await client.contractCall(source, instance.deployInfo.address, fn, params, opt)
return {
...result,
decodedResult: await transformDecodedData(
decodedResult: opt.waitMined ? await transformDecodedData(
fnACI.returns,
await result.decode(),
{ ...opt, bindings: fnACI.bindings }
)
) : null
}
}

Expand Down
19 changes: 19 additions & 0 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ describe('Contract', function () {
return result.decode().should.eventually.become(42)
})

it('call contract/deploy with `waitMined: false`', async () => {
const deployed = await bytecode.deploy([], { waitMined: false })
await contract.poll(deployed.transaction)
Boolean(deployed.result === undefined).should.be.equal(true)
Boolean(deployed.txData === undefined).should.be.equal(true)
const result = await deployed.call('main', ['42'], { waitMined: false, verify: false })
Boolean(result.result === undefined).should.be.equal(true)
Boolean(result.txData === undefined).should.be.equal(true)
})

it('calls deployed contracts static', async () => {
const result = await deployed.callStatic('main', ['42'])
return result.decode().should.eventually.become(42)
Expand Down Expand Up @@ -344,6 +354,15 @@ describe('Contract', function () {
const isCompiled = contractObject.compiled.length && contractObject.compiled.slice(0, 3) === 'cb_'
isCompiled.should.be.equal(true)
})
it('Deploy/Call contract with { waitMined: false }', async () => {
const deployed = await contractObject.methods.init('123', 1, 'hahahaha', { waitMined: false })
await contract.poll(deployed.transaction)
Boolean(deployed.result === undefined).should.be.equal(true)
Boolean(deployed.txData === undefined).should.be.equal(true)
const result = await contractObject.methods.intFn.send(2, { waitMined: false })
Boolean(result.result === undefined).should.be.equal(true)
Boolean(result.txData === undefined).should.be.equal(true)
})
it('Generate ACI object with corresponding bytecode', async () => {
await contract.getContractInstance(testContract, { contractAddress: contractObject.deployInfo.address, filesystem, opt: { ttl: 0 } })
})
Expand Down

0 comments on commit 475c2aa

Please sign in to comment.