Skip to content

Commit

Permalink
Test fixes + removing docker images after tests + Oracle composition …
Browse files Browse the repository at this point in the history
…on Wallet
  • Loading branch information
nduchak authored and ricricucit committed Dec 11, 2018
1 parent 7e829c2 commit 4ac6017
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pipeline {
always {
junit 'test-results.xml'
archive 'dist/*'
sh 'docker-compose -H localhost:2376 down -v ||:'
sh 'docker-compose -H localhost:2376 down -v --rmi local ||:'
}
}
}
3 changes: 2 additions & 1 deletion es/ae/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Selector from '../account/selector'
import * as R from 'ramda'
import Tx from '../tx/tx'
import EpochContract from '../contract/epoch'
import EpochOracle from '../oracle/epoch'

const contains = R.flip(R.contains)
const isTxMethod = contains(Tx.compose.deepConfiguration.Ae.methods)
Expand Down Expand Up @@ -131,7 +132,7 @@ async function rpcAddress ({ params, session }) {
onContract: confirm
})
*/
const Wallet = Ae.compose(Accounts, Chain, Tx, EpochContract, Contract, Rpc, Selector, {
const Wallet = Ae.compose(Accounts, Chain, Tx, EpochContract, Contract, EpochOracle, Rpc, Selector, {
init ({ onTx = this.onTx, onChain = this.onChain, onAccount = this.onAccount, onContract = this.onContract }, { stamp }) {
this.onTx = onTx
this.onChain = onChain
Expand Down
22 changes: 17 additions & 5 deletions es/tx/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ async function contractCreateTx ({ ownerId, nonce, code, vmVersion, deposit, amo
fee = this.calculateFee(fee, 'contractCreateTx', gas)

return this.nativeMode
? this.contractCreateTxNative(R.merge(R.head(arguments), { nonce, ttl, fee }))
: this.api.postContractCreate(R.merge(R.head(arguments), { nonce, ttl, fee: parseInt(fee) }))
? this.contractCreateTxNative(R.merge(R.merge(this.Ae.defaults, R.head(arguments)), { nonce, ttl, fee }))
: this.api.postContractCreate(R.merge(R.merge(this.Ae.defaults, R.head(arguments)), { nonce, ttl, fee: parseInt(fee), gas: parseInt(gas) }))
}

async function contractCallTx ({ callerId, nonce, contractId, vmVersion, fee, ttl, amount, gas, gasPrice, callData }) {
Expand All @@ -119,8 +119,8 @@ async function contractCallTx ({ callerId, nonce, contractId, vmVersion, fee, tt
fee = this.calculateFee(fee, 'contractCallTx', gas)

const { tx } = this.nativeMode
? await this.contractCallTxNative(R.merge(R.head(arguments), { nonce, ttl, fee }))
: await this.api.postContractCall(R.merge(R.head(arguments), { nonce, ttl, fee: parseInt(fee) }))
? await this.contractCallTxNative(R.merge(R.merge(this.Ae.defaults, R.head(arguments)), { nonce, ttl, fee }))
: await this.api.postContractCall(R.merge(R.merge(this.Ae.defaults, R.head(arguments)), { nonce, ttl, fee: parseInt(fee), gas: parseInt(gas) }))

return tx
}
Expand Down Expand Up @@ -222,7 +222,7 @@ async function calculateNonce (accountId, nonce) {
* @example calculateFee(null, 'spendtx')
*/
function calculateFee (fee, txType, gas = 0) {
const BASE_GAS = 15000
const BASE_GAS = 20000 // Increase BASE_GAS util we are implemented fee calculation
const GAS_PER_BYTE = 20
// MAP WITH TX BYTE SIZE
const TX_BYTE_SIZE = {
Expand Down Expand Up @@ -275,6 +275,18 @@ const Transaction = Epoch.compose(Tx, JsTx, {
init ({ nativeMode = true }) {
this.nativeMode = nativeMode
},
deepProps: {
Ae: {
defaults: {
deposit: 4,
vmVersion: 1,
gasPrice: 1,
amount: 1,
gas: 1600000 - 21000, // MAX GAS
options: ''
}
}
},
props: {
fee: 20000,
nativeMode: null
Expand Down
2 changes: 1 addition & 1 deletion test/integration/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Accounts', function () {
})

it('spends big amount of tokens', async () => {
const bigAmount = '2702702702700000000123'
const bigAmount = '10000000000000100000000000000000'
const genesis = await BaseAe({ networkId })
const balanceBefore = await wallet.balance(await wallet.address())
const receiverId = await wallet.address()
Expand Down
8 changes: 3 additions & 5 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ describe('Contract', function () {
contract = await ready(this)
})

describe('precompiled bytecode', () => {
it('can be deployed', async () => {
const { bytecode } = await contract.contractCompile(identityContract)
return contract.contractDeploy(bytecode, 'sophia').should.eventually.have.property('address')
})
it('precompiled bytecode can be deployed', async () => {
const { bytecode } = await contract.contractCompile(identityContract)
return contract.contractDeploy(bytecode, 'sophia').should.eventually.have.property('address')
})

it('compiles Sophia code', async () => {
Expand Down
44 changes: 20 additions & 24 deletions test/integration/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { encodeBase58Check, encodeBase64Check, generateKeyPair, salt } from '../
import { ready } from './index'

const nonce = 1
const ttl = 500
const nameTtl = 1
const clientTtl = 1
const fee = 20000
Expand Down Expand Up @@ -81,14 +80,14 @@ describe('Native Transaction', function () {
})

it('native build of spend tx', async () => {
const txFromAPI = await client.spendTx({ senderId, recipientId, amount, fee, ttl, nonce, payload: 'test' })
const nativeTx = await clientNative.spendTx({ senderId, recipientId, amount, fee, ttl, nonce, payload: 'test' })
const txFromAPI = await client.spendTx({ senderId, recipientId, amount, fee, nonce, payload: 'test' })
const nativeTx = await clientNative.spendTx({ senderId, recipientId, amount, fee, nonce, payload: 'test' })
txFromAPI.should.be.equal(nativeTx)
})

it('native build of name pre-claim tx', async () => {
const txFromAPI = await client.namePreclaimTx({ accountId: senderId, nonce, fee, ttl, commitmentId })
const nativeTx = await clientNative.namePreclaimTx( {accountId: senderId, nonce, fee, ttl, commitmentId })
const txFromAPI = await client.namePreclaimTx({ accountId: senderId, nonce, fee, commitmentId })
const nativeTx = await clientNative.namePreclaimTx( {accountId: senderId, nonce, fee, commitmentId })
txFromAPI.should.be.equal(nativeTx)
})

Expand All @@ -98,35 +97,33 @@ describe('Native Transaction', function () {
nonce,
name: nameHash,
nameSalt: _salt,
fee,
ttl
fee
})
const nativeTx = await clientNative.nameClaimTx({
accountId: senderId,
nonce,
name: nameHash,
nameSalt: _salt,
fee,
ttl
fee
})
txFromAPI.should.be.equal(nativeTx)
})

it('native build of update tx', async () => {
const nativeTx = await clientNative.nameUpdateTx({ accountId: senderId, nonce, nameId, nameTtl, pointers, clientTtl, fee, ttl })
const txFromAPI = await client.nameUpdateTx({ accountId: senderId, nonce, nameId, nameTtl, pointers, clientTtl, fee, ttl })
const nativeTx = await clientNative.nameUpdateTx({ accountId: senderId, nonce, nameId, nameTtl, pointers, clientTtl, fee })
const txFromAPI = await client.nameUpdateTx({ accountId: senderId, nonce, nameId, nameTtl, pointers, clientTtl, fee })
txFromAPI.should.be.equal(nativeTx)
})

it('native build of revoke tx', async () => {
const txFromAPI = await client.nameRevokeTx({ accountId: senderId, nonce, nameId, fee, ttl })
const nativeTx = await clientNative.nameRevokeTx({ accountId: senderId, nonce, nameId, fee, ttl })
const txFromAPI = await client.nameRevokeTx({ accountId: senderId, nonce, nameId, fee })
const nativeTx = await clientNative.nameRevokeTx({ accountId: senderId, nonce, nameId, fee })
txFromAPI.should.be.equal(nativeTx)
})

it('native build of transfer tx', async () => {
const txFromAPI = await client.nameTransferTx({ accountId: senderId, nonce, nameId, recipientId, fee, ttl })
const nativeTx = await clientNative.nameTransferTx({ accountId: senderId, nonce, nameId, recipientId, fee, ttl })
const txFromAPI = await client.nameTransferTx({ accountId: senderId, nonce, nameId, recipientId, fee })
const nativeTx = await clientNative.nameTransferTx({ accountId: senderId, nonce, nameId, recipientId, fee })
txFromAPI.should.be.equal(nativeTx)
})

Expand All @@ -135,8 +132,8 @@ describe('Native Transaction', function () {
const callData = await client.contractEncodeCall(bytecode, 'sophia', 'init', '()')
const owner = await client.address()

const txFromAPI = await client.contractCreateTx({ ownerId: owner, code: bytecode, vmVersion, deposit, amount, gas, gasPrice, ttl, callData })
const nativeTx = await clientNative.contractCreateTx({ ownerId: owner, code: bytecode, vmVersion, deposit, amount, gas, gasPrice, ttl, callData })
const txFromAPI = await client.contractCreateTx({ ownerId: owner, code: bytecode, vmVersion, deposit, amount, gas, gasPrice, callData })
const nativeTx = await clientNative.contractCreateTx({ ownerId: owner, code: bytecode, vmVersion, deposit, amount, gas, gasPrice, callData })

txFromAPI.tx.should.be.equal(nativeTx.tx)
txFromAPI.contractId.should.be.equal(nativeTx.contractId)
Expand All @@ -151,8 +148,8 @@ describe('Native Transaction', function () {
const callData = await client.contractEncodeCall(bytecode, 'sophia', 'main', '(2)')
const owner = await client.address()

const txFromAPI = await client.contractCallTx({ callerId: owner, contractId, vmVersion, amount, gas, gasPrice, ttl, callData })
const nativeTx = await clientNative.contractCallTx({ callerId: owner, contractId, vmVersion, amount, gas, gasPrice, ttl, callData })
const txFromAPI = await client.contractCallTx({ callerId: owner, contractId, vmVersion, amount, gas, gasPrice, callData })
const nativeTx = await clientNative.contractCallTx({ callerId: owner, contractId, vmVersion, amount, gas, gasPrice, callData })

txFromAPI.should.be.equal(nativeTx)
const { hash } = await client.send(nativeTx)
Expand All @@ -168,8 +165,7 @@ describe('Native Transaction', function () {
queryFormat,
responseFormat,
queryFee,
oracleTtl,
ttl,
oracleTtl
}

const txFromAPI = await client.oracleRegisterTx(params)
Expand All @@ -184,7 +180,7 @@ describe('Native Transaction', function () {

it('native build of oracle extends tx', async () => {
const callerId = await client.address()
const params = { oracleId, callerId, oracleTtl, ttl }
const params = { oracleId, callerId, oracleTtl }
const orTtl = (await client.getOracle(oracleId)).ttl

const txFromAPI = await client.oracleExtendTx(params)
Expand All @@ -200,7 +196,7 @@ describe('Native Transaction', function () {
it('native build of oracle post query tx', async () => {
const senderId = await client.address()

const params = { oracleId, responseTtl, query, queryTtl, queryFee, ttl, senderId, fee }
const params = { oracleId, responseTtl, query, queryTtl, queryFee, senderId, fee }

const { tx: txFromAPI, queryId: oracleQueryId } = await client.oraclePostQueryTx(params)
const { tx: nativeTx } = await clientNative.oraclePostQueryTx(params)
Expand All @@ -216,7 +212,7 @@ describe('Native Transaction', function () {

it('native build of oracle respond query tx', async () => {
const callerId = await client.address()
const params = { oracleId, callerId, responseTtl, queryId, response: queryResponse, ttl, fee}
const params = { oracleId, callerId, responseTtl, queryId, response: queryResponse, fee}

const txFromAPI = await client.oracleRespondTx(params)
const nativeTx = await clientNative.oracleRespondTx(params)
Expand Down

0 comments on commit 4ac6017

Please sign in to comment.