From 744d5c055ea90c6881a68d8d865d6000aed98942 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Sun, 4 Sep 2022 13:59:53 -0400 Subject: [PATCH] fix: incorrect encoding on TransactionReceipt (#1661) * fix TransactionReceipt rlp encoding * add tests * update changelog --- CHANGELOG.md | 1 + ethers-core/src/types/transaction/response.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f015c10b..fa26373d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Unreleased +- Fix RLP encoding of `TransactionReceipt` - Add `Unit8` helper type [#1639](https://github.com/gakonst/ethers-rs/pull/1639) - Add `evm.deployedBytecode.immutableReferences` output selector [#1523](https://github.com/gakonst/ethers-rs/pull/1523) - Added `get_erc1155_token_transfer_events` function for etherscan client [#1503](https://github.com/gakonst/ethers-rs/pull/1503) diff --git a/ethers-core/src/types/transaction/response.rs b/ethers-core/src/types/transaction/response.rs index bb61aaf1..b127bbef 100644 --- a/ethers-core/src/types/transaction/response.rs +++ b/ethers-core/src/types/transaction/response.rs @@ -425,7 +425,7 @@ pub struct TransactionReceipt { impl rlp::Encodable for TransactionReceipt { fn rlp_append(&self, s: &mut RlpStream) { s.begin_list(4); - s.append(&self.status); + rlp_opt(s, &self.status); s.append(&self.cumulative_gas_used); s.append(&self.logs_bloom); s.append_list(&self.logs); @@ -457,6 +457,8 @@ impl PartialOrd for TransactionReceipt { #[cfg(test)] #[cfg(not(feature = "celo"))] mod tests { + use rlp::Encodable; + use crate::types::transaction::eip2930::AccessListItem; use super::*; @@ -907,6 +909,17 @@ mod tests { assert_eq!(v, receipt); } + #[test] + fn rlp_encode_receipt() { + let receipt = TransactionReceipt { status: Some(1u64.into()), ..Default::default() }; + let encoded = receipt.rlp_bytes(); + + assert_eq!( + encoded, + hex::decode("f901060180b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0").unwrap(), + ); + } + #[test] fn can_sort_receipts() { let mut a = TransactionReceipt { block_number: Some(0u64.into()), ..Default::default() };