From 7ca0cae5b89dc641b47ea1404a244bc9db46442c Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 7 Jan 2020 14:19:37 -0500 Subject: [PATCH] Fabo/fix gas (#250) * fix gas estimate * linted * fixed test --- lib/controller/transaction/index.js | 23 +++++++++++++---------- tests/routes.test.js | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/controller/transaction/index.js b/lib/controller/transaction/index.js index c933777571..446efc4217 100644 --- a/lib/controller/transaction/index.js +++ b/lib/controller/transaction/index.js @@ -1,4 +1,4 @@ -const { getMessage } = require('./messageConstructor') +// const { getMessage } = require('./messageConstructor') const { networkMap } = require('../../networks') const Sentry = require('@sentry/node') const { publishUserTransactionAdded } = require('../../subscriptions') @@ -6,18 +6,21 @@ const reducers = require('../../reducers/cosmosV0-reducers') // TODO the whole t 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 diff --git a/tests/routes.test.js b/tests/routes.test.js index 8322e55295..dd701a8837 100644 --- a/tests/routes.test.js +++ b/tests/routes.test.js @@ -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) }) })