Skip to content

Commit

Permalink
oraclePostQueryTx: Make consistent output
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jul 8, 2020
1 parent 570365b commit 179f59f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion es/ae/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import Ae from './'
import * as R from 'ramda'
import { decodeBase64Check, assertedType } from '../utils/crypto'
import { pause } from '../utils/other'
import { oracleQueryId } from '../tx/builder/helpers'
import { unpackTx } from '../tx/builder'
import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from '../tx/builder/schema'

/**
Expand Down Expand Up @@ -178,11 +180,12 @@ async function postQueryToOracle (oracleId, query, options = {}) {
const opt = R.merge(this.Ae.defaults, options)
const senderId = await this.address(opt)

const { tx: oracleRegisterTx, queryId } = await this.oraclePostQueryTx(R.merge(opt, {
const oracleRegisterTx = await this.oraclePostQueryTx(R.merge(opt, {
oracleId,
senderId,
query
}))
const queryId = oracleQueryId(senderId, unpackTx(oracleRegisterTx).tx.nonce, oracleId)
return {
...await this.send(oracleRegisterTx, opt),
...await this.getQueryObject(oracleId, queryId)
Expand Down
4 changes: 2 additions & 2 deletions es/tx/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Tx from './'

import { buildTx, calculateFee } from './builder'
import { ABI_VERSIONS, MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE, VM_TYPE, TX_TTL } from './builder/schema'
import { buildContractId, oracleQueryId } from './builder/helpers'
import { buildContractId } from './builder/helpers'
import { TxObject } from './tx-object'

async function spendTx ({ senderId, recipientId, amount, payload = '' }) {
Expand Down Expand Up @@ -269,7 +269,7 @@ async function oraclePostQueryTx ({ oracleId, responseTtl, query, queryTtl, quer
senderId
})

return { tx, queryId: oracleQueryId(senderId, nonce, oracleId) }
return tx
}

async function oracleRespondTx ({ oracleId, callerId, responseTtl, queryId, response }) {
Expand Down
12 changes: 6 additions & 6 deletions test/integration/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { describe, it, before } from 'mocha'
import { encodeBase58Check, encodeBase64Check, generateKeyPair, salt } from '../../es/utils/crypto'
import { getSdk } from './index'
import { commitmentHash, isNameValid } from '../../es/tx/builder/helpers'
import { commitmentHash, isNameValid, oracleQueryId } from '../../es/tx/builder/helpers'
import { MemoryAccount } from '../../es'
import { AE_AMOUNT_FORMATS } from '../../es/utils/amount-formatter'
import { unpackTx } from '../../es/tx/builder'
Expand Down Expand Up @@ -225,16 +225,16 @@ describe('Native Transaction', function () {

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

const { tx: txFromAPI, queryId: oracleQueryId } = await client.oraclePostQueryTx(params)
const { tx: nativeTx } = await clientNative.oraclePostQueryTx(params)
const txFromAPI = await client.oraclePostQueryTx(params)
const nativeTx = await clientNative.oraclePostQueryTx(params)
queryId = oracleQueryId(senderId, unpackTx(txFromAPI).tx.nonce, oracleId)

txFromAPI.should.be.equal(nativeTx)

await client.send(nativeTx)

const oracleQuery = (await client.getOracleQuery(oracleId, oracleQueryId))
oracleQuery.id.should.be.equal(oracleQueryId)
queryId = oracleQueryId
const oracleQuery = (await client.getOracleQuery(oracleId, queryId))
oracleQuery.id.should.be.equal(queryId)
})

it('native build of oracle respond query tx', async () => {
Expand Down

0 comments on commit 179f59f

Please sign in to comment.