diff --git a/package-lock.json b/package-lock.json index 7832235..56a04fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2104,7 +2104,7 @@ }, "node_modules/@rsksmart/rif-relay-client": { "version": "2.2.1", - "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#cf173b8372afea5a400fbdcfc1ffb0c66c99ca8f", + "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#e634dc7b14ebd130538738257a7dec326000feca", "license": "MIT", "dependencies": { "bignumber.js": "^9.1.1", @@ -13447,7 +13447,7 @@ "integrity": "sha512-z0zMCjyhhp4y7XKAcDAi3Vgms4T2PstwBdahiO0+9NaGICQKjynK3wduSRplTgk4LXmoO1yfDGO5RbjKYxtuxA==" }, "@rsksmart/rif-relay-client": { - "version": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#cf173b8372afea5a400fbdcfc1ffb0c66c99ca8f", + "version": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#e634dc7b14ebd130538738257a7dec326000feca", "from": "@rsksmart/rif-relay-client@github:rsksmart/rif-relay-client#fix/payment-gas-estimation", "requires": { "bignumber.js": "^9.1.1", diff --git a/src/RelayServer.ts b/src/RelayServer.ts index 5c28453..520a8b0 100644 --- a/src/RelayServer.ts +++ b/src/RelayServer.ts @@ -447,16 +447,26 @@ export class RelayServer extends EventEmitter { `EnvelopingRequest:${JSON.stringify(envelopingRequest, undefined, 4)}` ); + this.validateInputTypes(envelopingRequest); + + const { + relayRequest, + metadata: { isCustom }, + } = envelopingRequest; + const initialGasEstimation = await estimateRelayMaxPossibleGas( envelopingRequest, - this.workerAddress + this.workerAddress, + { + isCustom, + } ); log.debug( `Gas estimation before fees: ${initialGasEstimation.toString()}` ); const fee = await calculateFee( - envelopingRequest.relayRequest, + relayRequest, initialGasEstimation, this.config.app ); @@ -472,7 +482,7 @@ export class RelayServer extends EventEmitter { ); const conversionResult = await convertGasToTokenAndNative( - envelopingRequest.relayRequest, + relayRequest, maxPossibleGas ); log.debug( diff --git a/src/Utils.ts b/src/Utils.ts index efbd28d..ca8acf8 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -148,6 +148,7 @@ export const deployTransactionRequestShape = { relayHubAddress: ow.string, relayMaxNonce: ow.number, signature: ow.string, + isCustom: ow.optional.boolean, }, }; @@ -178,5 +179,6 @@ export const relayTransactionRequestShape = { relayHubAddress: ow.string, relayMaxNonce: ow.number, signature: ow.string, + isCustom: ow.optional.boolean, }, }; diff --git a/src/definitions/httpEnvelopingRequest.type.ts b/src/definitions/httpEnvelopingRequest.type.ts index 9004ace..771750e 100644 --- a/src/definitions/httpEnvelopingRequest.type.ts +++ b/src/definitions/httpEnvelopingRequest.type.ts @@ -18,6 +18,7 @@ export declare type EnvelopingMetadata = { relayHubAddress: RelayRequestBody['relayHub']; relayMaxNonce: number; signature: string; + isCustom?: boolean; }; export declare type EnvelopingRequestData = { diff --git a/test/unit/RelayServer.test.ts b/test/unit/RelayServer.test.ts index 3f7a2f7..4afcabb 100644 --- a/test/unit/RelayServer.test.ts +++ b/test/unit/RelayServer.test.ts @@ -209,6 +209,7 @@ describe('RelayServer tests', function () { describe('Function estimateMaxPossibleGas()', function () { it('should return only the initial estimation when there are no additional fees', async function () { sinon.stub(relayServerUtils, 'calculateFee').resolves(BigNumberJs(0)); + sinon.stub(relayServer, 'validateInputTypes').returns(); const maxPossibleGasEstimation = await relayServer.estimateMaxPossibleGas( { @@ -220,6 +221,7 @@ describe('RelayServer tests', function () { gasPrice: GAS_PRICE, }, }, + metadata: {}, } as HttpEnvelopingRequest ); @@ -232,6 +234,7 @@ describe('RelayServer tests', function () { sinon .stub(relayServerUtils, 'calculateFee') .resolves(BigNumberJs(FAKE_FEE_AMOUNT)); + sinon.stub(relayServer, 'validateInputTypes').returns(); const maxPossibleGasEstimation = await relayServer.estimateMaxPossibleGas( { @@ -243,6 +246,7 @@ describe('RelayServer tests', function () { gasPrice: GAS_PRICE, }, }, + metadata: {}, } as HttpEnvelopingRequest ); @@ -311,6 +315,8 @@ describe('RelayServer tests', function () { .stub(relayServerUtils, 'calculateFee') .resolves(BigNumberJs(FAKE_FEE_AMOUNT)); + sinon.stub(relayServer, 'validateInputTypes').returns(); + const estimatedGas = await relayServer.estimateMaxPossibleGas({ relayRequest: { request: { @@ -320,6 +326,7 @@ describe('RelayServer tests', function () { gasPrice: GAS_PRICE, }, }, + metadata: {}, } as HttpEnvelopingRequest); const { maxPossibleGasWithFee } = await relayServer.getMaxPossibleGas({ @@ -331,6 +338,7 @@ describe('RelayServer tests', function () { gasPrice: GAS_PRICE, }, }, + metadata: {}, } as HttpEnvelopingRequest); expect(estimatedGas.estimation.toString()).to.be.eq(