Skip to content

Commit

Permalink
feat(Contract): Enable test's for contract
Browse files Browse the repository at this point in the history
  • Loading branch information
nduchak committed Apr 10, 2020
1 parent ae723d5 commit ed48a83
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions test/cli/contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import fs from 'fs'
import { before, describe, it } from 'mocha'

import { configure, plan, ready, WALLET_NAME, execute as exec } from './index'
import { configure, plan, ready, WALLET_NAME, execute as exec, parseBlock } from './index'
import KEY_PAIR from '@aeternity/aepp-sdk/es/account/memory';

// CONTRACT SOURCE
const testContract = `contract Identity =
Expand Down Expand Up @@ -85,7 +86,7 @@ describe('CLI Contract Module', function () {
fs.writeFileSync(contractFile, testContract)

// Deploy contract
const res = await execute(['contract', 'deploy', WALLET_NAME, '--password', 'test', contractFile])
const res = await exec(['contract', 'deploy', WALLET_NAME, '--password', 'test', contractFile])
const { contract_address, transaction_hash, deploy_descriptor } = (parseBlock(res))
deployDescriptor = deploy_descriptor
const [name, pref, address] = deployDescriptor.split('.')
Expand All @@ -96,32 +97,32 @@ describe('CLI Contract Module', function () {
pref.should.equal('deploy')
address.should.equal(KEY_PAIR.publicKey.split('_')[1])
})
//
// it('Call Contract by descriptor', async () => {
// // Call contract
// const callResponse = (parseBlock(await execute(['contract', 'call', WALLET_NAME, '--password', 'test', '--descrPath', deployDescriptor, 'main', 'int', '1', '2'])))
// const isValid = callResponse['return_value_(encoded)'].indexOf('cb_') !== -1
// isValid.should.be.equal(true)
// callResponse['return_value_(decoded)'].should.equal('3')
// })
// it('Call Contract static by descriptor', async () => {
// // Call contract
// const callResponse = (parseBlock(await execute(['contract', 'call', WALLET_NAME, '--password', 'test', '--descrPath', deployDescriptor, 'main', 'int', '1', '2', '--callStatic'])))
// const isValid = callResponse['return_value_(encoded)'].indexOf('cb_') !== -1
// isValid.should.be.equal(true)
// callResponse['return_value_(decoded)'].should.equal('3')
// })
// it('Call Contract by contract address', async () => {
// const callResponse = (parseBlock(await execute(['contract', 'call', WALLET_NAME, '--password', 'test', '--contractAddress', cAddress, '--contractSource', contractFile, 'main', 'int', '1', '2'])))
// const isValid = callResponse['return_value_(encoded)'].indexOf('cb_') !== -1
// isValid.should.be.equal(true)
// callResponse['return_value_(decoded)'].should.equal('3')
// })
// it('Call Contract static by contract address', async () => {
// const callResponse = (parseBlock(await execute(['contract', 'call', WALLET_NAME, '--password', 'test', '--contractAddress', cAddress, '--contractSource', contractFile, 'main', 'int', '1', '2', '--callStatic'])))
// const isValid = callResponse['return_value_(encoded)'].indexOf('cb_') !== -1
//
// isValid.should.be.equal(true)
// callResponse['return_value_(decoded)'].should.equal('3')
// })

it('Call Contract by descriptor', async () => {
// Call contract
const callResponse = (parseBlock(await exec(['contract', 'call', WALLET_NAME, '--password', 'test', '--descrPath', deployDescriptor, 'main', 'int', '1', '2'])))
const isValid = callResponse['return_value_(encoded)'].indexOf('cb_') !== -1
isValid.should.be.equal(true)
callResponse['return_value_(decoded)'].should.equal('3')
})
it('Call Contract static by descriptor', async () => {
// Call contract
const callResponse = (parseBlock(await exec(['contract', 'call', WALLET_NAME, '--password', 'test', '--descrPath', deployDescriptor, 'main', 'int', '1', '2', '--callStatic'])))
const isValid = callResponse['return_value_(encoded)'].indexOf('cb_') !== -1
isValid.should.be.equal(true)
callResponse['return_value_(decoded)'].should.equal('3')
})
it('Call Contract by contract address', async () => {
const callResponse = (parseBlock(await exec(['contract', 'call', WALLET_NAME, '--password', 'test', '--contractAddress', cAddress, '--contractSource', contractFile, 'main', 'int', '1', '2'])))
const isValid = callResponse['return_value_(encoded)'].indexOf('cb_') !== -1
isValid.should.be.equal(true)
callResponse['return_value_(decoded)'].should.equal('3')
})
it('Call Contract static by contract address', async () => {
const callResponse = (parseBlock(await exec(['contract', 'call', WALLET_NAME, '--password', 'test', '--contractAddress', cAddress, '--contractSource', contractFile, 'main', 'int', '1', '2', '--callStatic'])))
const isValid = callResponse['return_value_(encoded)'].indexOf('cb_') !== -1

isValid.should.be.equal(true)
callResponse['return_value_(decoded)'].should.equal('3')
})
})

0 comments on commit ed48a83

Please sign in to comment.