Skip to content

Commit 154e907

Browse files
committed
test: fix unit tests
Signed-off-by: Logan Nguyen <[email protected]>
1 parent 329ea96 commit 154e907

File tree

2 files changed

+299
-295
lines changed

2 files changed

+299
-295
lines changed

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

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -129,52 +129,54 @@ describe('@ethSendRawTransaction eth_sendRawTransaction spec', async function ()
129129
clock.restore();
130130
});
131131

132-
it('should emit tracking event (limiter and metrics) only for successful tx responses from FileAppend transaction', async function () {
133-
const signed = await signTransaction({
134-
...transaction,
135-
data: '0x' + '22'.repeat(13000),
136-
});
137-
const expectedTxHash = Utils.computeTransactionHash(Buffer.from(signed.replace('0x', ''), 'hex'));
132+
withOverriddenEnvsInMochaTest({ JUMBO_TX_ENABLED: false }, () => {
133+
it('should emit tracking event (limiter and metrics) only for successful tx responses from FileAppend transaction', async function () {
134+
const signed = await signTransaction({
135+
...transaction,
136+
data: '0x' + '22'.repeat(13000),
137+
});
138+
const expectedTxHash = Utils.computeTransactionHash(Buffer.from(signed.replace('0x', ''), 'hex'));
138139

139-
const FILE_ID = new FileId(0, 0, 5644);
140-
sdkClientStub.submitEthereumTransaction.restore();
141-
sdkClientStub.createFile.restore();
142-
sdkClientStub.executeAllTransaction.restore();
140+
const FILE_ID = new FileId(0, 0, 5644);
141+
sdkClientStub.submitEthereumTransaction.restore();
142+
sdkClientStub.createFile.restore();
143+
sdkClientStub.executeAllTransaction.restore();
143144

144-
sdkClientStub.fileAppendChunkSize = 2048;
145-
sdkClientStub.clientMain = { operatorAccountId: '', operatorKey: null };
145+
sdkClientStub.fileAppendChunkSize = 2048;
146+
sdkClientStub.clientMain = { operatorAccountId: '', operatorKey: null };
146147

147-
const fileInfoMock = sinon.stub(FileInfo);
148-
fileInfoMock.size = new Long(26000);
149-
sdkClientStub.executeQuery.resolves(fileInfoMock);
148+
const fileInfoMock = sinon.stub(FileInfo);
149+
fileInfoMock.size = new Long(26000);
150+
sdkClientStub.executeQuery.resolves(fileInfoMock);
150151

151-
// simulates error after first append by returning only one transaction response
152-
sinon.stub(FileAppendTransaction.prototype, 'executeAll').resolves([{ transactionId: transactionId }]);
152+
// simulates error after first append by returning only one transaction response
153+
sinon.stub(FileAppendTransaction.prototype, 'executeAll').resolves([{ transactionId: transactionId }]);
153154

154-
const eventEmitterMock = sinon.createStubInstance(EventEmitter);
155-
sdkClientStub.eventEmitter = eventEmitterMock;
155+
const eventEmitterMock = sinon.createStubInstance(EventEmitter);
156+
sdkClientStub.eventEmitter = eventEmitterMock;
156157

157-
const hbarLimiterMock = sinon.createStubInstance(HbarLimitService);
158-
sdkClientStub.hbarLimitService = hbarLimiterMock;
158+
const hbarLimiterMock = sinon.createStubInstance(HbarLimitService);
159+
sdkClientStub.hbarLimitService = hbarLimiterMock;
159160

160-
const txResponseMock = sinon.createStubInstance(TransactionResponse);
161-
sdkClientStub.executeTransaction.resolves(txResponseMock);
161+
const txResponseMock = sinon.createStubInstance(TransactionResponse);
162+
sdkClientStub.executeTransaction.resolves(txResponseMock);
162163

163-
txResponseMock.getReceipt.restore();
164-
sinon.stub(txResponseMock, 'getReceipt').onFirstCall().resolves({ fileId: FILE_ID });
165-
txResponseMock.transactionId = TransactionId.fromString(transactionIdServicesFormat);
164+
txResponseMock.getReceipt.restore();
165+
sinon.stub(txResponseMock, 'getReceipt').onFirstCall().resolves({ fileId: FILE_ID });
166+
txResponseMock.transactionId = TransactionId.fromString(transactionIdServicesFormat);
166167

167-
sdkClientStub.logger = pino({ level: 'silent' });
168-
sdkClientStub.deleteFile.resolves();
168+
sdkClientStub.logger = pino({ level: 'silent' });
169+
sdkClientStub.deleteFile.resolves();
169170

170-
restMock.onGet(contractResultEndpoint).reply(200, JSON.stringify({ hash: expectedTxHash }));
171+
restMock.onGet(contractResultEndpoint).reply(200, JSON.stringify({ hash: expectedTxHash }));
171172

172-
const resultingHash = await ethImpl.sendRawTransaction(signed, requestDetails);
173-
if (useAsyncTxProcessing) await clock.tickAsync(1);
173+
const resultingHash = await ethImpl.sendRawTransaction(signed, requestDetails);
174+
if (useAsyncTxProcessing) await clock.tickAsync(1);
174175

175-
expect(eventEmitterMock.emit.callCount).to.equal(1);
176-
expect(hbarLimiterMock.shouldLimit.callCount).to.equal(1);
177-
expect(resultingHash).to.equal(expectedTxHash);
176+
expect(eventEmitterMock.emit.callCount).to.equal(1);
177+
expect(hbarLimiterMock.shouldLimit.callCount).to.equal(1);
178+
expect(resultingHash).to.equal(expectedTxHash);
179+
});
178180
});
179181

180182
it('should return a predefined GAS_LIMIT_TOO_HIGH instead of NUMERIC_FAULT as precheck exception', async function () {

0 commit comments

Comments
 (0)