diff --git a/.env b/.env index 1e21aba19f..df1bf496a6 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ TAG=v5.0.0-rc.2 -COMPILER_TAG=v4.0.0-rc2 +COMPILER_TAG=v4.0.0-rc4 diff --git a/es/ae/contract.js b/es/ae/contract.js index 2b177ddf88..5e89773807 100644 --- a/es/ae/contract.js +++ b/es/ae/contract.js @@ -119,7 +119,7 @@ async function contractCallStatic (source, address, name, args = [], { top, opti : await this.address().catch(e => opt.dryRunAccount.pub) // Prepare call-data - const callData = await this.contractEncodeCall(source, name, args, options) + const callData = await this.contractEncodeCall(source, name, args, opt) // Get block hash by height if (top && !isNaN(top)) { @@ -127,7 +127,6 @@ async function contractCallStatic (source, address, name, args = [], { top, opti } // Prepare nonce const nonce = top ? (await this.getAccount(callerId, { hash: top })).nonce + 1 : undefined - if (name === 'init') { // Prepare deploy transaction const { tx } = await this.contractCreateTx(R.merge(opt, { @@ -135,7 +134,7 @@ async function contractCallStatic (source, address, name, args = [], { top, opti code: bytecode, ownerId: callerId, nonce, - backend: opt.backend || this.compilerOptions + backend: opt.backend || this.compilerOptions.backend })) return this.dryRunContractTx(tx, callerId, source, name, { ...opt, top }) } else { @@ -145,7 +144,7 @@ async function contractCallStatic (source, address, name, args = [], { top, opti contractId: address, callData, nonce, - backend: opt.backend || this.compilerOptions + backend: opt.backend || this.compilerOptions.backend })) return this.dryRunContractTx(tx, callerId, source, name, { ...opt, top }) } diff --git a/es/contract/compiler.js b/es/contract/compiler.js index 4f97d5b0ea..408b80c825 100644 --- a/es/contract/compiler.js +++ b/es/contract/compiler.js @@ -143,7 +143,7 @@ const ContractCompilerAPI = AsyncInit.compose(ContractBase, { props: { compilerVersion: null, compilerOptions: { - backend: VM_TYPE.AEVM + backend: VM_TYPE.FATE } } }) diff --git a/es/tx/tx.js b/es/tx/tx.js index fabb876a9f..029c051bee 100644 --- a/es/tx/tx.js +++ b/es/tx/tx.js @@ -356,9 +356,9 @@ async function gaAttachTx ({ ownerId, code, vmVersion, abiVersion, authFun, gas, * * @param {string} txType Type of transaction * @param {object} vmAbi Object with vm and abi version fields - * @return {object} Object with vm/abi version ({ vmVersion: number, abiVersion: number }) + * @return {object} Object with vm/abi version ({ vmVersion: number, abiVersion: number, backend: string }) */ -function getVmVersion (txType, { vmVersion, abiVersion, backend } = {}) { +function getVmVersion (txType, { vmVersion, abiVersion, backend = VM_TYPE.FATE } = {}) { const { consensusProtocolVersion } = this.getNodeInfo() const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion] if (!supportedProtocol) throw new Error('Not supported consensus protocol version') diff --git a/es/utils/swagger.js b/es/utils/swagger.js index ecd756ad58..c46f3ad2d3 100644 --- a/es/utils/swagger.js +++ b/es/utils/swagger.js @@ -327,8 +327,8 @@ function assertOne (coll) { */ function destructureClientError (error) { const { method, url } = error.config - const { status, data } = error.response - const reason = R.has('reason', data) ? data.reason : R.toString(data) + const { status, data, statusText } = error.response + const reason = R.has('reason', data) ? data.reason : data ? R.toString(data) : statusText return `${method.toUpperCase()} to ${url} failed with ${status}: ${reason}` } diff --git a/test/integration/contract.js b/test/integration/contract.js index cee1637f98..c0bd1fae68 100644 --- a/test/integration/contract.js +++ b/test/integration/contract.js @@ -23,6 +23,8 @@ import * as R from 'ramda' const identityContract = ` contract Identity = + record state = { a: int } + entrypoint init() = { a = 1 } entrypoint main(x : int) = x ` const stateContract = ` @@ -46,7 +48,7 @@ namespace Test = contract Voting = - entrypoint test() : int = 1 + entrypoint test : () => int include "testLib" contract StateContract = @@ -94,8 +96,10 @@ contract StateContract = entrypoint datTypeFn(s: dateUnit): dateUnit = s ` -const encodedNumberSix = 'cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaKNdnK' - +const encodedNumberSix = 'cb_DA6sWJo=' +const filesystem = { + testLib: libContract +} plan('1000000000000000000000') describe('Contract', function () { @@ -110,26 +114,12 @@ describe('Contract', function () { }) it('precompiled bytecode can be deployed', async () => { - console.log(contract.getNodeInfo()) + const { version, consensusProtocolVersion } = contract.getNodeInfo() + console.log(`Node => ${version}, consensus => ${consensusProtocolVersion}, compiler => ${contract.compilerVersion}`) const code = await contract.contractCompile(identityContract) return contract.contractDeploy(code.bytecode, identityContract).should.eventually.have.property('address') }) - it('Fate: Deploy', async () => { - bytecode = await contract.contractCompile(identityContract, { backend: 'fate' }) - const res = await bytecode.deployStatic([]) - res.result.should.have.property('gasUsed') - res.result.should.have.property('returnType') - deployed = await bytecode.deploy([]) - }) - it('Fate: Call', async () => { - const result = await deployed.callStatic('main', ['42']) - const decoded = await result.decode() - decoded.should.be.equal(42) - const result2 = await deployed.call('main', ['42']) - const decoded2 = await result2.decode() - decoded2.should.be.equal(42) - }) it('compiles Sophia code', async () => { bytecode = await contract.contractCompile(identityContract) return bytecode.should.have.property('bytecode') @@ -142,7 +132,7 @@ describe('Contract', function () { }) it('deploys compiled contracts', async () => { - deployed = await bytecode.deploy([], { blocks: 2 }) + deployed = await bytecode.deploy([]) return deployed.should.have.property('address') }) @@ -210,7 +200,7 @@ describe('Contract', function () { try { await contract.contractCompile(contractWithLib) } catch (e) { - e.message.indexOf('could not find include file').should.not.be.equal(-1) + e.message.indexOf('Couldn\'t find include file').should.not.be.equal(-1) } }) it('Can deploy contract with external deps', async () => { @@ -259,7 +249,7 @@ describe('Contract', function () { isString.should.be.equal(true) }) it('decode call-data', async () => { - return contract.contractDecodeCallResultAPI(identityContract, 'main', encodedNumberSix, 'ok').should.eventually.become(6) + return contract.contractDecodeCallResultAPI(identityContract, 'main', encodedNumberSix, 'ok', { backend: 'fate' }).should.eventually.become(6) }) it('Use invalid compiler url', async () => { try { @@ -275,10 +265,7 @@ describe('Contract', function () { let contractObject it('Generate ACI object', async () => { - const filesystem = { - testLib: libContract - } - contractObject = await contract.getContractInstance(testContract, { filesystem, opt: { ttl: 10 } }) + contractObject = await contract.getContractInstance(testContract, { filesystem, opt: { ttl: 0 } }) contractObject.should.have.property('interface') contractObject.should.have.property('aci') contractObject.should.have.property('source') @@ -287,7 +274,7 @@ describe('Contract', function () { contractObject.should.have.property('compile') contractObject.should.have.property('call') contractObject.should.have.property('deploy') - contractObject.options.ttl.should.be.equal(10) + contractObject.options.ttl.should.be.equal(0) contractObject.options.should.have.property('filesystem') contractObject.options.filesystem.should.have.property('testLib') const functionsFromACI = contractObject.aci.functions.map(({ name }) => name) @@ -313,6 +300,24 @@ describe('Contract', function () { result.callerId.should.be.equal(onAccount) }) + it.skip('Can deploy using AEVM', async () => { + console.log(contract.compilerVersion) + const deployStatic = await contractObject.methods.init.get('123', 1, Promise.resolve('hahahaha')).catch(e => console.log(e)) + console.log(deployStatic) + // deployStatic.result.should.have.property('gasUsed') + // deployStatic.result.should.have.property('returnType') + deployed = await contractObject.methods.init('123', 1, Promise.resolve('hahahaha')).catch(async e => console.log(await e.verifyTx())) + console.log(deployed) + }) + // it('Can call using AEVM', async () => { + // const result = await deployed.callStatic('main', ['42']) + // const decoded = await result.decode() + // decoded.should.be.equal(42) + // const result2 = await deployed.call('main', ['42']) + // const decoded2 = await result2.decode() + // decoded2.should.be.equal(42) + // }) + it('Deploy contract before compile', async () => { contractObject.compiled = null await contractObject.methods.init('123', 1, Promise.resolve('hahahaha'), {})