Skip to content

Commit

Permalink
refactor(contract)!: remove contractGetACI
Browse files Browse the repository at this point in the history
use sdk.compilerApi.generateACI instead
  • Loading branch information
davidyuk committed Jan 24, 2022
1 parent 2fe798a commit 23ada71
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/contract/aci/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export default async function getContractInstance ({
validateBytecode,
...otherOptions
} = {}) {
aci = aci || (source && await this.contractGetACI(source, { filesystem }))
if (!aci && source) {
aci = await this.compilerApi.generateACI({ code: source, options: { filesystem } })
}
if (!aci) throw new MissingContractDefError()
contractAddress = contractAddress && await this.resolveName(
contractAddress, 'contract_pubkey', { resolveByNode: true }
Expand Down
4 changes: 0 additions & 4 deletions src/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ export default AsyncInit.compose(ContractBase, {
this._ensureCompilerReady()
const { bytecode } = await this.compilerApi.compileContract({ code, options })
return bytecode
},
contractGetACI (code, options) {
this._ensureCompilerReady()
return this.compilerApi.generateACI({ code, options })
}
},
props: {
Expand Down
14 changes: 0 additions & 14 deletions src/contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,11 @@ const ContractBase = stampit(required({
methods: {
contractEncodeCallDataAPI: required,
compileContractAPI: required,
contractGetACI: required,
setCompilerUrl: required,
getCompilerVersion: required
}
}))

/**
* Get contract ACI
* @function contractGetACI
* @instance
* @abstract
* @category async
* @rtype (source: String, options: Array) => aciObject: Promise[Object]
* @param {String} source - Contract source code
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @return {Object} - Contract aci object
*/

/**
* Encode contract data
* @function contractEncodeCallDataAPI
Expand Down
6 changes: 4 additions & 2 deletions test/integration/contract-aci.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ describe('Contract instance', function () {

before(async function () {
sdk = await getSdk()
testContractAci = await sdk.contractGetACI(testContractSource, { filesystem })
testContractAci = await sdk.compilerApi
.generateACI({ code: testContractSource, options: { filesystem } })
testContractBytecode = (await sdk.contractCompile(testContractSource, { filesystem })).bytecode
})

Expand Down Expand Up @@ -230,7 +231,8 @@ describe('Contract instance', function () {

it('rejects not matching bytecode with enabled validation', async () => expect(sdk.getContractInstance({
bytecode: (await sdk.contractCompile(identityContractSource)).bytecode,
aci: await sdk.contractGetACI(identityContractSource, { filesystem }),
aci: await sdk.compilerApi
.generateACI({ code: identityContractSource, options: { filesystem } }),
contractAddress: testContractAddress,
validateBytecode: true
})).to.be.rejectedWith(BytecodeMismatchError, 'Contract bytecode do not correspond to the bytecode deployed on the chain'))
Expand Down
10 changes: 6 additions & 4 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,15 @@ describe('Contract', function () {
)
})

it('get contract ACI', async () => {
const aci = await sdk.contractGetACI(identityContract)
aci.should.have.property('interface')
it('generate contract ACI', async () => {
const aci = await sdk.compilerApi.generateACI({ code: identityContract })
expect(aci).to.have.property('encoded_aci')
expect(aci).to.have.property('external_encoded_aci')
expect(aci).to.have.property('interface')
})

it('throws clear exception if generating ACI with no arguments', async () => {
await expect(sdk.contractGetACI())
await expect(sdk.compilerApi.generateACI())
.to.be.rejectedWith('validation_error in body ({"error":"missing_required_property","data":"code","path":[]})')
})

Expand Down

0 comments on commit 23ada71

Please sign in to comment.