Skip to content

Commit 098c487

Browse files
committed
Check for read-only in sendRawTransaction
Signed-off-by: Luis Mastrangelo <[email protected]>
1 parent 43efbff commit 098c487

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/relay/src/lib/services/ethService/transactionService/TransactionService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ export class TransactionService implements ITransactionService {
262262
* @returns {Promise<string | JsonRpcError>} A promise that resolves to the transaction hash or a JsonRpcError if an error occurs
263263
*/
264264
async sendRawTransaction(transaction: string, requestDetails: RequestDetails): Promise<string | JsonRpcError> {
265+
if (ConfigService.get('READ_ONLY')) {
266+
throw predefined.UNSUPPORTED_OPERATION('Relay is in read-only mode');
267+
}
268+
265269
const transactionBuffer = Buffer.from(this.prune0x(transaction), 'hex');
266270
const parsedTx = Precheck.parseRawTransaction(transaction);
267271
const networkGasPriceInWeiBars = Utils.addPercentageBufferToGasPrice(

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { expect, use } from 'chai';
1616
import chaiAsPromised from 'chai-as-promised';
1717
import { EventEmitter } from 'events';
1818
import pino from 'pino';
19-
import { Counter } from 'prom-client';
2019
import sinon, { useFakeTimers } from 'sinon';
2120

2221
import { Eth, JsonRpcError, predefined } from '../../../src';
@@ -455,5 +454,18 @@ describe('@ethSendRawTransaction eth_sendRawTransaction spec', async function ()
455454
});
456455
});
457456
});
457+
458+
withOverriddenEnvsInMochaTest({ READ_ONLY: true }, () => {
459+
it('should throw `UNSUPPORTED_OPERATION` when Relay is in Read-Only mode', async function () {
460+
const signed = await signTransaction({ ...transaction, value: '0x1234567890' });
461+
await RelayAssertions.assertRejection(
462+
predefined.UNSUPPORTED_OPERATION('Relay is in read-only mode'),
463+
ethImpl.sendRawTransaction,
464+
false,
465+
ethImpl,
466+
[signed, requestDetails],
467+
);
468+
});
469+
});
458470
});
459471
});

0 commit comments

Comments
 (0)