Skip to content

Commit 7aff97d

Browse files
committed
test: added transactionSize, callDataSize, contractCodeSize acceptance test suites
Signed-off-by: Logan Nguyen <[email protected]>
1 parent 402d938 commit 7aff97d

File tree

1 file changed

+173
-0
lines changed

1 file changed

+173
-0
lines changed

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

+173
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,179 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
17781778
requestDetails,
17791779
]);
17801780
});
1781+
1782+
describe('transactionSize', function () {
1783+
it('@release should execute "eth_sendRawTransaction" with regular transaction size within the limit', async function () {
1784+
const gasPrice = await relay.gasPrice(requestId);
1785+
const transaction = {
1786+
type: 2,
1787+
chainId: Number(CHAIN_ID),
1788+
nonce: await relay.getAccountNonce(accounts[1].address, requestId),
1789+
maxPriorityFeePerGas: gasPrice,
1790+
maxFeePerGas: gasPrice,
1791+
gasLimit: defaultGasLimit,
1792+
to: accounts[0].address,
1793+
};
1794+
1795+
const signedTx = await accounts[1].wallet.signTransaction(transaction);
1796+
expect(signedTx.length).to.be.lt(Constants.SEND_RAW_TRANSACTION_SIZE_LIMIT);
1797+
1798+
const transactionHash = await relay.sendRawTransaction(signedTx, requestId);
1799+
await relay.pollForValidTransactionReceipt(transactionHash);
1800+
1801+
const info = await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);
1802+
expect(info).to.exist;
1803+
expect(info.result).to.equal('SUCCESS');
1804+
});
1805+
1806+
it('@release should fail "eth_sendRawTransaction" when transaction size exceeds the limit', async function () {
1807+
const gasPrice = await relay.gasPrice(requestId);
1808+
const transaction = {
1809+
type: 2,
1810+
chainId: Number(CHAIN_ID),
1811+
nonce: await relay.getAccountNonce(accounts[1].address, requestId),
1812+
maxPriorityFeePerGas: gasPrice,
1813+
maxFeePerGas: gasPrice,
1814+
gasLimit: defaultGasLimit,
1815+
to: accounts[0].address,
1816+
data: '0x' + '00'.repeat(Constants.SEND_RAW_TRANSACTION_SIZE_LIMIT + 1024), // exceeds the limit by 1KB
1817+
};
1818+
1819+
const signedTx = await accounts[1].wallet.signTransaction(transaction);
1820+
const totalRawTransactionSizeInBytes = signedTx.replace('0x', '').length / 2;
1821+
const error = predefined.TRANSACTION_SIZE_LIMIT_EXCEEDED(
1822+
totalRawTransactionSizeInBytes,
1823+
Constants.SEND_RAW_TRANSACTION_SIZE_LIMIT,
1824+
);
1825+
1826+
await Assertions.assertPredefinedRpcError(error, sendRawTransaction, false, relay, [
1827+
signedTx,
1828+
requestDetails,
1829+
]);
1830+
});
1831+
});
1832+
1833+
describe('callDataSize', function () {
1834+
it('@release should execute "eth_sendRawTransaction" with regular transaction size within the limit', async function () {
1835+
const gasPrice = await relay.gasPrice(requestId);
1836+
const transaction = {
1837+
type: 2,
1838+
chainId: Number(CHAIN_ID),
1839+
nonce: await relay.getAccountNonce(accounts[1].address, requestId),
1840+
maxPriorityFeePerGas: gasPrice,
1841+
maxFeePerGas: gasPrice,
1842+
gasLimit: defaultGasLimit,
1843+
to: accounts[0].address,
1844+
};
1845+
1846+
const signedTx = await accounts[1].wallet.signTransaction(transaction);
1847+
expect(signedTx.length).to.be.lt(Constants.CALL_DATA_SIZE_LIMIT);
1848+
1849+
const transactionHash = await relay.sendRawTransaction(signedTx, requestId);
1850+
await relay.pollForValidTransactionReceipt(transactionHash);
1851+
1852+
const info = await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);
1853+
expect(info).to.exist;
1854+
expect(info.result).to.equal('SUCCESS');
1855+
});
1856+
1857+
it('@release should fail "eth_sendRawTransaction" when transaction size exceeds the limit', async function () {
1858+
const gasPrice = await relay.gasPrice(requestId);
1859+
const transaction = {
1860+
type: 2,
1861+
chainId: Number(CHAIN_ID),
1862+
nonce: await relay.getAccountNonce(accounts[1].address, requestId),
1863+
maxPriorityFeePerGas: gasPrice,
1864+
maxFeePerGas: gasPrice,
1865+
gasLimit: defaultGasLimit,
1866+
to: accounts[0].address,
1867+
data: '0x' + '00'.repeat(Constants.CALL_DATA_SIZE_LIMIT + 1024), // exceeds the limit by 1KB
1868+
};
1869+
1870+
const signedTx = await accounts[1].wallet.signTransaction(transaction);
1871+
const totalRawTransactionSizeInBytes = transaction.data.replace('0x', '').length / 2;
1872+
const error = predefined.CALL_DATA_SIZE_LIMIT_EXCEEDED(
1873+
totalRawTransactionSizeInBytes,
1874+
Constants.CALL_DATA_SIZE_LIMIT,
1875+
);
1876+
1877+
await Assertions.assertPredefinedRpcError(error, sendRawTransaction, false, relay, [
1878+
signedTx,
1879+
requestDetails,
1880+
]);
1881+
});
1882+
});
1883+
1884+
describe('contractCodeSize', function () {
1885+
it('@release should execute "eth_sendRawTransaction" and deploy a contract with code size within the limit', async function () {
1886+
const gasPrice = await relay.gasPrice(requestId);
1887+
const transaction = {
1888+
type: 2,
1889+
chainId: Number(CHAIN_ID),
1890+
nonce: await relay.getAccountNonce(accounts[1].address, requestId),
1891+
maxPriorityFeePerGas: gasPrice,
1892+
maxFeePerGas: gasPrice,
1893+
gasLimit: defaultGasLimit,
1894+
data: '0x' + '00'.repeat(Constants.CONTRACT_CODE_SIZE_LIMIT), // Within the CONTRACT_CODE_SIZE_LIMIT limit
1895+
};
1896+
1897+
const signedTx = await accounts[1].wallet.signTransaction(transaction);
1898+
const transactionHash = await relay.sendRawTransaction(signedTx, requestId);
1899+
await relay.pollForValidTransactionReceipt(transactionHash);
1900+
1901+
const info = await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);
1902+
expect(info).to.have.property('contract_id');
1903+
expect(info.contract_id).to.not.be.null;
1904+
expect(info).to.have.property('created_contract_ids');
1905+
expect(info.created_contract_ids.length).to.be.equal(1);
1906+
});
1907+
1908+
it('@release should fail "eth_sendRawTransaction" for contract with code size exceeding the limit', async function () {
1909+
const gasPrice = await relay.gasPrice(requestId);
1910+
// Create a transaction with contract code size exceeding CONTRACT_CODE_SIZE_LIMIT
1911+
const transaction = {
1912+
type: 2,
1913+
chainId: Number(CHAIN_ID),
1914+
nonce: await relay.getAccountNonce(accounts[1].address, requestId),
1915+
maxPriorityFeePerGas: gasPrice,
1916+
maxFeePerGas: gasPrice,
1917+
gasLimit: defaultGasLimit,
1918+
data: '0x' + '00'.repeat(Constants.CONTRACT_CODE_SIZE_LIMIT + 1),
1919+
};
1920+
1921+
const signedTx = await accounts[1].wallet.signTransaction(transaction);
1922+
const contractCodeSize = (transaction.data.length - 2) / 2;
1923+
const error = predefined.CONTRACT_CODE_SIZE_LIMIT_EXCEEDED(
1924+
contractCodeSize,
1925+
Constants.CONTRACT_CODE_SIZE_LIMIT,
1926+
);
1927+
1928+
await Assertions.assertPredefinedRpcError(error, sendRawTransaction, false, relay, [
1929+
signedTx,
1930+
requestDetails,
1931+
]);
1932+
});
1933+
1934+
it('@release should pass precheck and execute "eth_sendRawTransaction" for a regular transaction i.e. non contract deployment transaction with data exceeding the limit', async function () {
1935+
const gasPrice = await relay.gasPrice(requestId);
1936+
// Create a transaction with large data but sent to an existing address (not contract creation)
1937+
const transaction = {
1938+
type: 2,
1939+
chainId: Number(CHAIN_ID),
1940+
nonce: await relay.getAccountNonce(accounts[1].address, requestId),
1941+
maxPriorityFeePerGas: gasPrice,
1942+
maxFeePerGas: gasPrice,
1943+
gasLimit: defaultGasLimit,
1944+
to: accounts[0].address, // Sending to existing address, so code size check doesn't apply
1945+
data: '0x' + '00'.repeat(Constants.CONTRACT_CODE_SIZE_LIMIT + 1024), // exceeds the limit by 1KB
1946+
};
1947+
1948+
const signedTx = await accounts[1].wallet.signTransaction(transaction);
1949+
const transactionHash = await relay.sendRawTransaction(signedTx, requestId);
1950+
const info = await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);
1951+
expect(info).to.exist;
1952+
});
1953+
});
17811954
});
17821955

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

0 commit comments

Comments
 (0)