Skip to content

Commit

Permalink
test: add test for receivers account precheck
Browse files Browse the repository at this point in the history
Signed-off-by: Nadezhda Popova <[email protected]>
  • Loading branch information
nadezhdapopovaa committed Dec 11, 2024
1 parent 4604f1f commit 3b85b1a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/relay/src/lib/errors/JsonRpcError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ export const predefined = {
code: -39013,
message: 'Invalid block range',
}),
RECEIVER_SIGNATURE_REQUIRED: new JsonRpcError({
code: -32000,
message: "Receiver's signature is required.",
}),
FILTER_NOT_FOUND: new JsonRpcError({
code: -32001,
message: 'Filter not found',
Expand Down
49 changes: 48 additions & 1 deletion packages/server/tests/acceptance/rpc_batch1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ import Constants from '@hashgraph/json-rpc-relay/dist/lib/constants';
// Errors and constants from local resources
import { predefined } from '@hashgraph/json-rpc-relay/dist/lib/errors/JsonRpcError';
import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types';
import { FileInfo, FileInfoQuery, Hbar, TransferTransaction } from '@hashgraph/sdk';
import {
AccountCreateTransaction,
FileInfo,
FileInfoQuery,
Hbar,
PrivateKey,
TransferTransaction,
} from '@hashgraph/sdk';
import { expect } from 'chai';
import { ethers } from 'ethers';

Expand Down Expand Up @@ -1586,6 +1593,46 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
const error = predefined.NONCE_TOO_LOW(nonce, nonce + 1);
await Assertions.assertPredefinedRpcError(error, sendRawTransaction, true, relay, [signedTx, requestDetails]);
});

it('should fail "eth_sendRawTransaction" if receiver\'s account has receiver_sig_required enabled', async function () {
const newPrivateKey = PrivateKey.generateED25519();
const newAccount = await new AccountCreateTransaction()
.setKey(newPrivateKey.publicKey)
.setInitialBalance(100)
.setReceiverSignatureRequired(true)
.freezeWith(servicesNode.client)
.sign(newPrivateKey);

const transaction = await newAccount.execute(servicesNode.client);
const receipt = await transaction.getReceipt(servicesNode.client);

if (!receipt.accountId) {
throw new Error('Failed to create new account - accountId is null');
}

const toAddress = Utils.idToEvmAddress(receipt.accountId.toString());
const tx = {
nonce: await accounts[0].wallet.getNonce(),
chainId: CHAIN_ID,
to: toAddress,
from: accounts[0].address,
value: '0x2E90EDD000',
gasLimit: defaultGasLimit,
accessList: [],
maxPriorityFeePerGas: defaultGasPrice,
maxFeePerGas: defaultGasPrice,
};

const signedTx = await accounts[0].wallet.signTransaction(tx);
await new Promise((r) => setTimeout(r, 3000));

const error = predefined.RECEIVER_SIGNATURE_REQUIRED;

await Assertions.assertPredefinedRpcError(error, sendRawTransaction, false, relay, [
signedTx,
requestDetails,
]);
});
});

it('@release should execute "eth_getTransactionByHash" for existing transaction', async function () {
Expand Down

0 comments on commit 3b85b1a

Please sign in to comment.