Skip to content

Commit

Permalink
Merge pull request #1150 from aeternity/feature/remove-legacy-compiler
Browse files Browse the repository at this point in the history
remove legacy contractDecodeDataAPI compiler method and related stuff
  • Loading branch information
davidyuk authored Apr 28, 2021
2 parents f1e3099 + 184566f commit a4d13bd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/ae/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ async function contractDeploy (code, source, initState = [], options = {}) {
* @param {String} source Contract sourece code
* @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit)
* @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object
* @param {Object} [options.backend='aevm'] Contract backend version (aevm|fate)
* @param {Object} [options.backend='fate'] Contract backend version (aevm|fate)
* @return {Promise<Object>} Result object
* @example
* const compiled = await client.contractCompile(SOURCE_CODE)
Expand Down
4 changes: 2 additions & 2 deletions src/channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ function deposit (amount, sign, { onOnChainTx, onOwnDepositLocked, onDepositLock
* @param {String} options.code - Api encoded compiled AEVM byte code
* @param {String} options.callData - Api encoded compiled AEVM call data for the code
* @param {Number} options.deposit - Initial amount the owner of the contract commits to it
* @param {Number} options.vmVersion - Version of the AEVM
* @param {Number} options.abiVersion - Version of the ABI
* @param {Number} options.vmVersion - Version of the Virtual Machine
* @param {Number} options.abiVersion - Version of the Application Binary Interface
* @param {Function} sign - Function which verifies and signs create contract transaction
* @return {Promise<Object>}
* @example channel.createContract({
Expand Down
4 changes: 0 additions & 4 deletions src/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ export default AsyncInit.compose(ContractBase, {
})
return calldata
},
async contractDecodeDataAPI (type, data) {
this._ensureCompilerReady()
return (await this._compilerApi.decodeData({ data, 'sophia-type': type })).data
},
async compileContractAPI (code, options) {
this._ensureCompilerReady()
const { bytecode } = await this._compilerApi.compileContract({
Expand Down
25 changes: 6 additions & 19 deletions src/contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { required } from '@stamp/required'
const ContractBase = stampit(required({
methods: {
contractEncodeCallDataAPI: required,
contractDecodeDataAPI: required,
compileContractAPI: required,
contractGetACI: required,
setCompilerUrl: required,
Expand All @@ -62,7 +61,7 @@ const ContractBase = stampit(required({
* @param {String} source - Contract source code
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm(default: aevm)
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {Object} - Contract aci object
*/

Expand All @@ -78,22 +77,10 @@ const ContractBase = stampit(required({
* @param {Array} args - Function argument's
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm(default: aevm)
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {String} - Contract encoded data
*/

/**
* Decode data
* @function contractDecodeDataAPI
* @instance
* @abstract
* @category async
* @rtype (type: String, data: String) => decodedResult: Promise[String]
* @param {String} type - Contract call result type
* @param {String} data - Encoded contract call result
* @return {String} - Decoded contract call result
*/

/**
* Decode contract call result data
* @function contractDecodeCallResultAPI
Expand All @@ -107,7 +94,7 @@ const ContractBase = stampit(required({
* @param {String} callResult - contract call result status('ok', 'revert', ...)
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm(default: aevm)
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {String} - Decoded contract call result
*/

Expand All @@ -123,7 +110,7 @@ const ContractBase = stampit(required({
* @param {String} callData - Encoded contract call data
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm(default: aevm)
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {String} - Decoded contract call data
*/

Expand All @@ -136,7 +123,7 @@ const ContractBase = stampit(required({
* @rtype (code: String, callData: String) => decodedResult: Promise[String]
* @param {String} code - contract byte code
* @param {String} callData - Encoded contract call data
* @param {String} backend - Contract vm(default: aevm)
* @param {String} backend - Contract vm (default: fate)
* @return {String} - Decoded contract call data
*/

Expand All @@ -150,7 +137,7 @@ const ContractBase = stampit(required({
* @param {String} code - Contract source code
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm(default: aevm)
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {Object} Object which contain bytecode of contract
*/

Expand Down
58 changes: 29 additions & 29 deletions test/integration/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,62 +843,62 @@ describe('Channel', function () {
sign: responderSign
})
await Promise.all([waitForChannel(initiatorCh), waitForChannel(responderCh)])
const code = await initiator.compileContractAPI(identityContract, { backend: 'aevm' })
const callData = await initiator.contractEncodeCallDataAPI(identityContract, 'init', [], { backend: 'aevm' })
const code = await initiator.compileContractAPI(identityContract)
const callData = await initiator.contractEncodeCallDataAPI(identityContract, 'init', [])
const roundBefore = initiatorCh.round()
const result = await initiatorCh.createContract({
code,
callData,
deposit: 1000,
vmVersion: 6,
abiVersion: 1
vmVersion: 5,
abiVersion: 3
}, async (tx) => initiator.signTransaction(tx))
result.should.eql({ accepted: true, address: result.address, signedTx: (await initiatorCh.state()).signedTx })
initiatorCh.round().should.equal(roundBefore + 1)
contractAddress = result.address
contractEncodeCall = (method, args) => initiator.contractEncodeCallDataAPI(identityContract, method, args, { backend: 'aevm' })
contractEncodeCall = (method, args) => initiator.contractEncodeCallDataAPI(identityContract, method, args)
})

it('can create a contract and reject', async () => {
responderShouldRejectUpdate = true
const code = await initiator.compileContractAPI(identityContract, { backend: 'aevm' })
const callData = await initiator.contractEncodeCallDataAPI(identityContract, 'init', [], { backend: 'aevm' })
const code = await initiator.compileContractAPI(identityContract)
const callData = await initiator.contractEncodeCallDataAPI(identityContract, 'init', [])
const roundBefore = initiatorCh.round()
const result = await initiatorCh.createContract({
code,
callData,
deposit: BigNumber('10e18'),
vmVersion: 4,
abiVersion: 1
vmVersion: 5,
abiVersion: 3
}, async (tx) => initiator.signTransaction(tx))
initiatorCh.round().should.equal(roundBefore)
result.should.eql({ ...result, accepted: false })
})

it('can abort contract sign request', async () => {
const errorCode = 12345
const code = await initiator.compileContractAPI(identityContract, { backend: 'aevm' })
const callData = await initiator.contractEncodeCallDataAPI(identityContract, 'init', [], { backend: 'aevm' })
const code = await initiator.compileContractAPI(identityContract)
const callData = await initiator.contractEncodeCallDataAPI(identityContract, 'init', [])
const result = await initiatorCh.createContract({
code,
callData,
deposit: BigNumber('10e18'),
vmVersion: 4,
abiVersion: 1
vmVersion: 5,
abiVersion: 3
}, () => errorCode)
result.should.eql({ accepted: false })
})

it('can abort contract with custom error code', async () => {
responderShouldRejectUpdate = 12345
const code = await initiator.compileContractAPI(identityContract, { backend: 'aevm' })
const callData = await initiator.contractEncodeCallDataAPI(identityContract, 'init', [], { backend: 'aevm' })
const code = await initiator.compileContractAPI(identityContract)
const callData = await initiator.contractEncodeCallDataAPI(identityContract, 'init', [])
const result = await initiatorCh.createContract({
code,
callData,
deposit: BigNumber('10e18'),
vmVersion: 4,
abiVersion: 1
vmVersion: 5,
abiVersion: 3
}, async (tx) => initiator.signTransaction(tx))
result.should.eql({
accepted: false,
Expand All @@ -913,7 +913,7 @@ describe('Channel', function () {
amount: 0,
callData: await contractEncodeCall('main', ['42']),
contract: contractAddress,
abiVersion: 1
abiVersion: 3
}, async (tx) => initiator.signTransaction(tx))
result.should.eql({ accepted: true, signedTx: (await initiatorCh.state()).signedTx })
initiatorCh.round().should.equal(roundBefore + 1)
Expand All @@ -925,7 +925,7 @@ describe('Channel', function () {
amount: 0,
callData: await contractEncodeCall('main', ['42']),
contract: contractAddress,
abiVersion: 1
abiVersion: 3
}, async (tx) => initiator.signTransaction(tx))
console.log('after done')
const hash = buildTxHash(forceTx.tx)
Expand All @@ -940,7 +940,7 @@ describe('Channel', function () {
amount: 0,
callData: await contractEncodeCall('main', ['42']),
contract: contractAddress,
abiVersion: 1
abiVersion: 3
}, async (tx) => initiator.signTransaction(tx))
initiatorCh.round().should.equal(roundBefore)
result.should.eql({ ...result, accepted: false })
Expand All @@ -952,7 +952,7 @@ describe('Channel', function () {
amount: 0,
callData: await contractEncodeCall('main', ['42']),
contract: contractAddress,
abiVersion: 1
abiVersion: 3
}, () => errorCode)
result.should.eql({ accepted: false })
})
Expand All @@ -963,7 +963,7 @@ describe('Channel', function () {
amount: 0,
callData: await contractEncodeCall('main', ['42']),
contract: contractAddress,
abiVersion: 1
abiVersion: 3
}, async (tx) => initiator.signTransaction(tx))
result.should.eql({
accepted: false,
Expand All @@ -989,16 +989,16 @@ describe('Channel', function () {
returnType: 'ok',
returnValue: result.returnValue
})
const value = await initiator.contractDecodeDataAPI('int', result.returnValue)
value.should.eql({ type: 'word', value: 42 })
const value = await initiator.contractDecodeCallResultAPI(identityContract, 'main', result.returnValue, result.returnType)
value.should.equal(42)
})

it('can call a contract using dry-run', async () => {
const result = await initiatorCh.callContractStatic({
amount: 0,
callData: await contractEncodeCall('main', ['42']),
contract: contractAddress,
abiVersion: 1
abiVersion: 3
})
result.should.eql({
callerId: await initiator.address(),
Expand All @@ -1011,8 +1011,8 @@ describe('Channel', function () {
returnType: 'ok',
returnValue: result.returnValue
})
const value = await initiator.contractDecodeDataAPI('int', result.returnValue)
value.should.eql({ type: 'word', value: 42 })
const value = await initiator.contractDecodeCallResultAPI(identityContract, 'main', result.returnValue, result.returnType)
value.should.equal(42)
})

it('can clean contract calls', async () => {
Expand All @@ -1028,13 +1028,13 @@ describe('Channel', function () {
const result = await initiatorCh.getContractState(contractAddress)
result.should.eql({
contract: {
abiVersion: 1,
abiVersion: 3,
active: true,
deposit: 1000,
id: contractAddress,
ownerId: await initiator.address(),
referrerIds: [],
vmVersion: 6
vmVersion: 5
},
contractState: result.contractState
})
Expand Down
6 changes: 1 addition & 5 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ describe('Contract', function () {
isString.should.be.equal(true)
})
it('decode call result', async () => {
return contract.contractDecodeCallResultAPI(identityContract, 'main', encodedNumberSix, 'ok', { backend: 'fate' }).should.eventually.become(6)
return contract.contractDecodeCallResultAPI(identityContract, 'main', encodedNumberSix, 'ok').should.eventually.become(6)
})
it('Decode call-data using source', async () => {
const decodedCallData = await contract.contractDecodeCallDataBySourceAPI(identityContract, 'init', callData)
Expand All @@ -532,10 +532,6 @@ describe('Contract', function () {
decodedCallData.arguments.length.should.be.equal(0)
decodedCallData.function.should.be.equal('init')
})
it('Decode data API', async () => {
const returnData = 'cb_bzvA9Af6'
return contract.contractDecodeDataAPI('string', returnData).catch(e => 1).should.eventually.become(1)
})
it('validate bytecode', async () => {
return contract.validateByteCodeAPI(bytecode, identityContract).should.eventually.become(true)
})
Expand Down

0 comments on commit a4d13bd

Please sign in to comment.