Skip to content

Commit 02b7f3c

Browse files
committed
test(fix): enhance error handling for eth_getBalance tests with missing or null parameters (#3838)
Signed-off-by: Michał Walczak <[email protected]>
1 parent 93ab8de commit 02b7f3c

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

packages/server/tests/acceptance/rpc_batch2.spec.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -606,28 +606,38 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
606606
expect(BigInt(balanceAtTx1Block).toString()).to.eq(manuallyCalculatedBalanceAtTx1Block.toString());
607607
});
608608

609-
it('should return error when the second parameter is missing in eth_getBalance', async function () {
610-
const result = await relay.call(
611-
RelayCalls.ETH_ENDPOINTS.ETH_GET_BALANCE,
612-
[Address.NON_EXISTING_ADDRESS],
613-
Utils.formatRequestIdMessage(requestId),
614-
);
615-
616-
expect(result).to.have.property('error');
617-
expect(result.error).to.have.property('message').to.include('Missing value for required parameter');
618-
});
619-
620-
it('should return error when null is provided as the second parameter in eth_getBalance', async function () {
621-
const result = await relay.call(
622-
RelayCalls.ETH_ENDPOINTS.ETH_GET_BALANCE,
623-
[Address.NON_EXISTING_ADDRESS, null],
624-
Utils.formatRequestIdMessage(requestId),
625-
);
626-
627-
expect(result).to.have.property('error');
628-
expect(result.error)
629-
.to.have.property('message')
630-
.to.include('Invalid parameter 1: The value passed is not valid: null.');
609+
it('should return an error when the second parameter is missing in eth_getBalance', async function () {
610+
await expect(
611+
relay.call(
612+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BALANCE,
613+
[Address.NON_EXISTING_ADDRESS],
614+
Utils.formatRequestIdMessage(requestId),
615+
),
616+
).to.eventually.be.rejected.and.satisfy((err: any) => {
617+
try {
618+
const body = JSON.parse(err?.info?.responseBody || '{}');
619+
return body?.error?.message?.includes('Missing value for required parameter');
620+
} catch {
621+
return false;
622+
}
623+
}, 'Expected error message to include "Missing value for required parameter"');
624+
});
625+
626+
it('should return an error when null is provided as the second parameter in eth_getBalance', async function () {
627+
await expect(
628+
relay.call(
629+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BALANCE,
630+
[Address.NON_EXISTING_ADDRESS, null],
631+
Utils.formatRequestIdMessage(requestId),
632+
),
633+
).to.eventually.be.rejected.and.satisfy((err: any) => {
634+
try {
635+
const body = JSON.parse(err?.info?.responseBody || '{}');
636+
return body?.error?.message?.includes('Invalid parameter 1: The value passed is not valid: null.');
637+
} catch {
638+
return false;
639+
}
640+
}, 'Expected error message to include "Invalid parameter 1: The value passed is not valid: null."');
631641
});
632642
});
633643

0 commit comments

Comments
 (0)