Skip to content

Commit

Permalink
Fabo/fix gas (#250)
Browse files Browse the repository at this point in the history
* fix gas estimate

* linted

* fixed test
  • Loading branch information
faboweb authored Jan 7, 2020
1 parent fc7a072 commit 7ca0cae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
23 changes: 13 additions & 10 deletions lib/controller/transaction/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
const { getMessage } = require('./messageConstructor')
// const { getMessage } = require('./messageConstructor')
const { networkMap } = require('../../networks')
const Sentry = require('@sentry/node')
const { publishUserTransactionAdded } = require('../../subscriptions')
const reducers = require('../../reducers/cosmosV0-reducers') // TODO the whole transaction service only works for cosmos rn

global.fetch = require('node-fetch')

async function estimate(tx) {
const context = {
userAddress: tx.address,
networkId: tx.networkId,
url: networkMap[tx.networkId].api_url,
chainId: networkMap[tx.networkId].chain_id
}
async function estimate() {
// const context = {
// userAddress: tx.address,
// networkId: tx.networkId,
// url: networkMap[tx.networkId].api_url,
// chainId: networkMap[tx.networkId].chain_id
// }

const message = getMessage(tx.messageType, tx.txProperties, context)
// const message = getMessage(tx.messageType, tx.txProperties, context)

try {
const gasEstimate = (await message.simulate({ memo: tx.memo })) * 4 // we quadrupled the gas to be safe. rn there are several txs failing on cosmoshub-3
// const gasEstimate = (await message.simulate({ memo: tx.memo })) * 4 // we quadrupled the gas to be safe. rn there are several txs failing on cosmoshub-3
// HACK: fixed to this value for now. too high gas can lead to transactions never being included. too low gas can lead to rejected txs and cost the user money.
const gasEstimate = 450000

return {
gasEstimate,
success: true
Expand Down
3 changes: 2 additions & 1 deletion tests/routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('POST /transaction', function() {
.send({ payload })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect({ gasEstimate: 74072, success: true })
// .expect({ gasEstimate: 74072, success: true })
.expect({ gasEstimate: 450000, success: true }) // fixed for now
.expect(200, done)
})
})
Expand Down

0 comments on commit 7ca0cae

Please sign in to comment.