Skip to content

Commit

Permalink
refactor(RelayServer): isCustom handler
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Jun 6, 2024
1 parent cd74baa commit 1f9baa0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/RelayServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -472,7 +482,7 @@ export class RelayServer extends EventEmitter {
);

const conversionResult = await convertGasToTokenAndNative(
envelopingRequest.relayRequest,
relayRequest,
maxPossibleGas
);
log.debug(
Expand Down
2 changes: 2 additions & 0 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const deployTransactionRequestShape = {
relayHubAddress: ow.string,
relayMaxNonce: ow.number,
signature: ow.string,
isCustom: ow.optional.boolean,
},
};

Expand Down Expand Up @@ -178,5 +179,6 @@ export const relayTransactionRequestShape = {
relayHubAddress: ow.string,
relayMaxNonce: ow.number,
signature: ow.string,
isCustom: ow.optional.boolean,
},
};
1 change: 1 addition & 0 deletions src/definitions/httpEnvelopingRequest.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export declare type EnvelopingMetadata = {
relayHubAddress: RelayRequestBody['relayHub'];
relayMaxNonce: number;
signature: string;
isCustom?: boolean;
};

export declare type EnvelopingRequestData = {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/RelayServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -220,6 +221,7 @@ describe('RelayServer tests', function () {
gasPrice: GAS_PRICE,
},
},
metadata: {},
} as HttpEnvelopingRequest
);

Expand All @@ -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(
{
Expand All @@ -243,6 +246,7 @@ describe('RelayServer tests', function () {
gasPrice: GAS_PRICE,
},
},
metadata: {},
} as HttpEnvelopingRequest
);

Expand Down Expand Up @@ -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: {
Expand All @@ -320,6 +326,7 @@ describe('RelayServer tests', function () {
gasPrice: GAS_PRICE,
},
},
metadata: {},
} as HttpEnvelopingRequest);

const { maxPossibleGasWithFee } = await relayServer.getMaxPossibleGas({
Expand All @@ -331,6 +338,7 @@ describe('RelayServer tests', function () {
gasPrice: GAS_PRICE,
},
},
metadata: {},
} as HttpEnvelopingRequest);

expect(estimatedGas.estimation.toString()).to.be.eq(
Expand Down

0 comments on commit 1f9baa0

Please sign in to comment.