Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Compiler): make FATE by default #693

Merged
merged 2 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TAG=v5.0.0-rc.2
COMPILER_TAG=v4.0.0-rc2
COMPILER_TAG=v4.0.0-rc4
7 changes: 3 additions & 4 deletions es/ae/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,22 @@ 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)) {
top = (await this.getKeyBlock(top)).hash
}
// 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, {
callData,
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 {
Expand All @@ -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 })
}
Expand Down
2 changes: 1 addition & 1 deletion es/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const ContractCompilerAPI = AsyncInit.compose(ContractBase, {
props: {
compilerVersion: null,
compilerOptions: {
backend: VM_TYPE.AEVM
backend: VM_TYPE.FATE
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions es/tx/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions es/utils/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
Expand Down
59 changes: 32 additions & 27 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand All @@ -46,7 +48,7 @@ namespace Test =


contract Voting =
entrypoint test() : int = 1
entrypoint test : () => int

include "testLib"
contract StateContract =
Expand Down Expand Up @@ -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 () {
Expand All @@ -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')
Expand All @@ -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')
})

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 {
Expand All @@ -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')
Expand All @@ -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)
Expand All @@ -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'), {})
Expand Down