Skip to content

Commit

Permalink
fixup! 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 12, 2024
1 parent 3b85b1a commit 62b7885
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/relay/src/lib/precheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import { ethers, Transaction } from 'ethers';
import { Logger } from 'pino';

import { prepend0x } from '../formatters';
import { MirrorNodeClient } from './clients';
import constants from './constants';
Expand Down Expand Up @@ -384,7 +385,7 @@ export class Precheck {
*/
async receiverAccount(tx: Transaction, requestDetails: RequestDetails) {
if (tx.to) {
const verifyAccount = await this.mirrorNodeClient.getAccount(tx.to!, requestDetails);
const verifyAccount = await this.mirrorNodeClient.getAccount(tx.to, requestDetails);

// When `receiver_sig_required` is set to true, the receiver's account must sign all incoming transactions.
if (verifyAccount !== null && verifyAccount.receiver_sig_required === true) {
Expand Down
41 changes: 35 additions & 6 deletions packages/server/tests/acceptance/rpc_batch1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1612,15 +1612,11 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {

const toAddress = Utils.idToEvmAddress(receipt.accountId.toString());
const tx = {
...defaultLegacyTransactionData,
chainId: Number(CHAIN_ID),
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);
Expand All @@ -1633,6 +1629,39 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
requestDetails,
]);
});

it('should execute "eth_sendRawTransaction" if receiver\'s account has receiver_sig_required disabled', async function () {
const newPrivateKey = PrivateKey.generateED25519();
const newAccount = await new AccountCreateTransaction()
.setKey(newPrivateKey.publicKey)
.setInitialBalance(100)
.setReceiverSignatureRequired(false)
.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 = {
...defaultLegacyTransactionData,
chainId: Number(CHAIN_ID),
nonce: await accounts[0].wallet.getNonce(),
to: toAddress,
from: accounts[0].address,
};

const signedTx = await accounts[0].wallet.signTransaction(tx);
const transactionHash = await relay.sendRawTransaction(signedTx, requestId);
const info = await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);

expect(info).to.exist;
expect(info.result).to.equal('SUCCESS');
});
});

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

0 comments on commit 62b7885

Please sign in to comment.