Skip to content

Commit

Permalink
refactor(contract)!: remove deprecated contractCallStatic
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jan 28, 2022
1 parent 08e423e commit 1e3ac6d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 36 deletions.
28 changes: 0 additions & 28 deletions src/ae/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,6 @@ import getContractInstance from '../contract/aci'
import { AMOUNT, DEPOSIT, MIN_GAS_PRICE } from '../tx/builder/schema'
import { decode, produceNameId } from '../tx/builder/helpers'

/**
* Static contract call(using dry-run)
* @function
* @alias module:@aeternity/aepp-sdk/es/ae/contract
* @category async
* @deprecated
* @param {String} source Contract source code
* @param {String} contractAddress Contract address
* @param {String} name Name of function to call
* @param {Array} args Arguments array for call/deploy transaction
* @param {Object} [options]
* @param {Number|String} [options.top] Block height or hash on which you want to call contract
* @param {String} [options.bytecode] Block hash on which you want to call contract
* @param {Object} [options.filesystem] Contract external namespaces map
* @return {Promise<Object>} Result object
* @example
* const callResult = await client.contractCallStatic(source, address, fnName, args)
* {
* result: TX_DATA,
* decode: (type) => Decode call result
* }
*/
async function contractCallStatic (source, contractAddress, name, args = [], options) {
const contract = await this.getContractInstance({ ...options, source, contractAddress })
return contract.call(name, args, { ...options, callStatic: true })
}

/**
* Utility method to create a delegate signature for a contract
* @function
Expand Down Expand Up @@ -155,7 +128,6 @@ async function createOracleDelegationSignature ({ contractId, queryId }, opt = {
export default Ae.compose(ContractCompilerHttp, {
methods: {
getContractInstance,
contractCallStatic,
// Delegation for contract
delegateSignatureCommon,
// AENS
Expand Down
2 changes: 1 addition & 1 deletion src/contract/aci.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default async function getContractInstance ({
call: (name, args = [], options) =>
instance.methods[name].send(...args, { ...opt, ...options }),
callStatic: (name, args, options) =>
this.contractCallStatic(instance.source, contractId, name, args, { ...opt, ...options }),
instance.methods[name].get(...args, { ...opt, ...options }),
createdAt: new Date()
})
return instance.deployInfo
Expand Down
17 changes: 10 additions & 7 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ describe('Contract', function () {
})

it('Call-Static deploy transaction', async () => {
const res = await sdk.contractCallStatic(identityContract, null, 'init', [], { bytecode })
const res = await contract.deploy([], { callStatic: true })
res.result.should.have.property('gasUsed')
res.result.should.have.property('returnType')
})

it('Call-Static deploy transaction on specific hash', async () => {
const { hash } = await sdk.api.getTopHeader()
const res = await sdk.contractCallStatic(identityContract, null, 'init', [], { bytecode, top: hash })
const res = await contract.deploy([], { callStatic: true, top: hash })
res.result.should.have.property('gasUsed')
res.result.should.have.property('returnType')
})
Expand All @@ -196,12 +196,15 @@ describe('Contract', function () {
})

it('Dry-run without accounts', async () => {
const client = await BaseAe()
client.removeAccount(publicKey)
client.addresses().length.should.be.equal(0)
const address = await client.address().catch(e => false)
const sdk = await BaseAe()
sdk.removeAccount(publicKey)
sdk.addresses().length.should.be.equal(0)
const address = await sdk.address().catch(e => false)
address.should.be.equal(false)
const { result } = await client.contractCallStatic(identityContract, deployed.address, 'getArg', [42])
const contract = await sdk.getContractInstance({
source: identityContract, contractAddress: deployed.address
})
const { result } = await contract.methods.getArg(42)
result.callerId.should.be.equal(DRY_RUN_ACCOUNT.pub)
})

Expand Down

0 comments on commit 1e3ac6d

Please sign in to comment.