Skip to content

Commit 330979a

Browse files
committed
fixes unit tests
Signed-off-by: Konstantina Blazhukova <[email protected]>
1 parent d614ca4 commit 330979a

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

packages/relay/src/lib/precheck.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
44
import { ethers, Transaction } from 'ethers';
5-
import { Logger } from 'pino';
65

76
import { prepend0x } from '../formatters';
87
import { MirrorNodeClient } from './clients';

packages/relay/tests/lib/eth/eth_estimateGas.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { expect, use } from 'chai';
44
import chaiAsPromised from 'chai-as-promised';
5-
import { AbiCoder, keccak256 } from 'ethers';
5+
import { AbiCoder, keccak256, Transaction } from 'ethers';
66
import { createStubInstance, SinonStub, SinonStubbedInstance, stub } from 'sinon';
77
import { v4 as uuid } from 'uuid';
88

@@ -145,7 +145,8 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
145145
await mockContractCall(callData, true, 501, { errorMessage: '', statusCode: 501 }, requestDetails);
146146

147147
const gas = await ethImpl.estimateGas({ data: '0x01' }, null, requestDetails);
148-
expect(gas).to.equal(numberTo0x(Precheck.transactionIntrinsicGasCost(callData.data!)));
148+
const tx = { data: callData.data! } as Transaction;
149+
expect(gas).to.equal(numberTo0x(Precheck.transactionIntrinsicGasCost(tx)));
149150
});
150151

151152
it('should eth_estimateGas to mirror node for transfer returns 501', async function () {
@@ -390,22 +391,22 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
390391
},
391392
};
392393
await mockContractCall(transaction, true, 400, contractCallResult, requestDetails);
393-
394+
const tx = { data: transaction.data! } as Transaction;
394395
const estimatedGas = await ethImpl.estimateGas(transaction, id, requestDetails);
395396

396-
expect(estimatedGas).to.equal(numberTo0x(Precheck.transactionIntrinsicGasCost(transaction.data!)));
397+
expect(estimatedGas).to.equal(numberTo0x(Precheck.transactionIntrinsicGasCost(tx)));
397398
});
398399

399400
withOverriddenEnvsInMochaTest({ ESTIMATE_GAS_THROWS: 'false' }, () => {
400401
it('should eth_estimateGas with contract revert and message does not equal executionReverted and ESTIMATE_GAS_THROWS is set to false', async function () {
401402
const originalEstimateGas = contractService.estimateGas;
402403
contractService.estimateGas = async () => {
403-
return numberTo0x(Precheck.transactionIntrinsicGasCost(transaction.data!));
404+
return numberTo0x(Precheck.transactionIntrinsicGasCost(transaction as Transaction));
404405
};
405406

406407
const result = await ethImpl.estimateGas(transaction, id, requestDetails);
407408

408-
expect(result).to.equal(numberTo0x(Precheck.transactionIntrinsicGasCost(transaction.data!)));
409+
expect(result).to.equal(numberTo0x(Precheck.transactionIntrinsicGasCost(transaction as Transaction)));
409410

410411
contractService.estimateGas = originalEstimateGas;
411412
});

packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ describe('@ethSendRawTransaction eth_sendRawTransaction spec', async function ()
145145
it('should emit tracking event (limiter and metrics) only for successful tx responses from FileAppend transaction', async function () {
146146
const signed = await signTransaction({
147147
...transaction,
148+
gasLimit: '0x927C0',
148149
data: '0x' + '22'.repeat(13000),
149150
});
150151
const expectedTxHash = Utils.computeTransactionHash(Buffer.from(signed.replace('0x', ''), 'hex'));

packages/relay/tests/lib/precheck.spec.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -663,49 +663,50 @@ describe('Precheck', async function () {
663663
it('should be able to calculate small contract create', function () {
664664
// This number represents the estimation for mirror node web3 module
665665
// Can be fetched by using: curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"from":"0x...","data":<greeterContractCreate>},"latest"]}'
666-
const mirrorNodeEstimation = 60364;
666+
const mirrorNodeEstimation = 70711;
667667
// This number represents the difference between the actual gas returned from the mirror node and the minimal required for deployment of this contract based only on the data field.
668-
const gasDifferenceFromOtherFactors = 37964;
669-
// @ts-ignore
670-
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost(smallestContractCreate);
668+
const gasDifferenceFromOtherFactors = 16305;
669+
670+
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost({ data: smallestContractCreate } as Transaction);
671+
671672
expect(intrinsicGasCost).to.be.equal(mirrorNodeEstimation - gasDifferenceFromOtherFactors);
672673
expect(intrinsicGasCost).to.be.greaterThan(constants.TX_BASE_COST);
673674
});
674675

675676
it('should be able to calculate normal contract create', function () {
676677
// This number represents the estimation for mirror node web3 module
677678
// Can be fetched by using: curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"from":"0x...","data":<greeterContractCreate>},"latest"]}'
678-
const mirrorNodeEstimation = 86351;
679+
const mirrorNodeEstimation = 499055;
679680
// This number represents the difference between the actual gas returned from the mirror node and the minimal required for deployment of this contract based only on the data field.
680-
const gasDifferenceFromOtherFactors = 16739;
681+
const gasDifferenceFromOtherFactors = 356525;
681682
// @ts-ignore
682-
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost(greeterContractCreate);
683+
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost({ data: greeterContractCreate } as Transaction);
684+
console.log(`intrinsicGasCost: ${intrinsicGasCost}`);
683685
expect(intrinsicGasCost).to.be.equal(mirrorNodeEstimation - gasDifferenceFromOtherFactors);
684686
expect(intrinsicGasCost).to.be.greaterThan(constants.TX_BASE_COST);
685687
});
686688

687689
it('should be able to calculate contract call', function () {
688-
// @ts-ignore
689-
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost(contractCall);
690+
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost({ data: contractCall } as Transaction);
690691
expect(intrinsicGasCost).to.be.greaterThan(constants.TX_BASE_COST);
691692
});
692693

693694
it('should be able to calucate tx without starting 0x', function () {
694695
const contractCallTrimmed = contractCall.replace('0x', '');
695-
// @ts-ignore
696-
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost(contractCallTrimmed);
696+
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost({ data: contractCallTrimmed } as Transaction);
697697
expect(intrinsicGasCost).to.be.greaterThan(constants.TX_BASE_COST);
698698
});
699699

700700
it('should be able to able to calculate transfer', function () {
701-
// @ts-ignore
702-
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost(transfer);
701+
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost({
702+
data: transfer,
703+
to: contractAddress1,
704+
} as Transaction);
703705
expect(intrinsicGasCost).to.be.equal(constants.TX_BASE_COST);
704706
});
705707

706708
it('should be able to calculate for odd length tx', function () {
707-
// @ts-ignore
708-
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost(invalidTx);
709+
const intrinsicGasCost = Precheck.transactionIntrinsicGasCost({ data: invalidTx } as Transaction);
709710
expect(intrinsicGasCost).to.be.greaterThan(constants.TX_BASE_COST);
710711
});
711712
});

0 commit comments

Comments
 (0)