Skip to content

Commit

Permalink
fix: Include transaction type in the transaction receipt (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc authored Jun 27, 2024
1 parent f8e2b97 commit dd6d2f4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions e2e-tests/test/eth-apis.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from "chai";
import { Wallet } from "zksync-web3";
import { expectThrowsAsync, getTestProvider } from "../helpers/utils";
import { RichAccounts } from "../helpers/constants";
import { ethers } from "ethers";
Expand All @@ -17,6 +18,33 @@ describe("eth_accounts", function () {
// Assert
expect(accounts).to.deep.equal(richAccounts);
});

it("Should have required fields in transaction receipt", async function () {
// Arrange
const wallet = new Wallet(RichAccounts[0].PrivateKey, provider);
const tx = await wallet.sendTransaction({
to: wallet.address,
value: ethers.utils.parseEther("3"),
});
const response = await tx.wait();
const txHash = response.transactionHash;

// Act
const receipt = await provider.send("eth_getTransactionReceipt", [txHash]);

// Assert
expect(receipt).to.have.property("blockHash");
expect(receipt).to.have.property("blockNumber");
expect(receipt).to.have.property("transactionHash");
expect(receipt).to.have.property("transactionIndex");
expect(receipt).to.have.property("from");
expect(receipt).to.have.property("to");
expect(receipt).to.have.property("cumulativeGasUsed");
expect(receipt).to.have.property("gasUsed");
expect(receipt).to.have.property("logs");
expect(receipt).to.have.property("logsBloom");
expect(receipt).to.have.property("type");
});
});

describe("eth_sendTransaction", function () {
Expand Down
4 changes: 3 additions & 1 deletion src/node/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
/// Runs L2 transaction and commits it to a new block.
pub fn run_l2_tx(&self, l2_tx: L2Tx, execution_mode: TxExecutionMode) -> Result<(), String> {
let tx_hash = l2_tx.hash();
let transaction_type = l2_tx.common_data.transaction_type;

tracing::info!("");
tracing::info!("Validating {}", format!("{:?}", tx_hash).bold());
Expand Down Expand Up @@ -1672,7 +1673,8 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
U64::from(1)
},
effective_gas_price: Some(inner.fee_input_provider.l2_gas_price.into()),
..Default::default()
transaction_type: Some((transaction_type as u32).into()),
logs_bloom: Default::default(),
};
let debug = create_debug_output(&l2_tx, &result, call_traces).expect("create debug output"); // OK to unwrap here as Halt is handled above
inner.tx_results.insert(
Expand Down

0 comments on commit dd6d2f4

Please sign in to comment.