Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix: do not prepend a 0 for Legacy txs & test
Browse files Browse the repository at this point in the history
  • Loading branch information
gakonst committed Aug 9, 2021
1 parent 63558a6 commit 8b320ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
6 changes: 2 additions & 4 deletions ethers-core/src/types/transaction/eip2718.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ impl TypedTransaction {
use TypedTransaction::*;
let mut encoded = vec![];
match self {
TypedTransaction::Legacy(ref tx) => {
encoded.extend_from_slice(&[0x0]);
encoded.extend_from_slice(tx.rlp(chain_id).as_ref());
Legacy(ref tx) => {
encoded.extend_from_slice(tx.rlp_signed(signature).as_ref());
}
Eip2930(inner) => {
encoded.extend_from_slice(&[0x1]);
Expand All @@ -171,7 +170,6 @@ impl TypedTransaction {
use TypedTransaction::*;
match self {
Legacy(inner) => {
encoded.extend_from_slice(&[0x0]);
encoded.extend_from_slice(inner.rlp(chain_id).as_ref());
}
Eip2930(inner) => {
Expand Down
61 changes: 30 additions & 31 deletions ethers-providers/tests/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod eth_tests {
use super::*;
use ethers::{
middleware::SignerMiddleware,
prelude::transaction::eip2718::TypedTransaction,
signers::{LocalWallet, Signer},
types::{BlockId, TransactionRequest, H256},
utils::Ganache,
Expand Down Expand Up @@ -165,40 +166,38 @@ mod eth_tests {
let address = wallet.address();
let provider = SignerMiddleware::new(provider, wallet);

let tx = TransactionRequest::new()
async fn check_tx<M: Middleware>(provider: &M, tx: TypedTransaction, expected: u64) {
let receipt = provider
.send_transaction(tx, None)
.await
.unwrap()
.await
.unwrap()
.unwrap();
let tx = provider
.get_transaction(receipt.transaction_hash)
.await
.unwrap()
.unwrap();
assert_eq!(receipt.transaction_type, Some(expected.into()));
assert_eq!(tx.transaction_type, Some(expected.into()));
}

let tx: TypedTransaction = TransactionRequest::new().from(address).to(address).into();
check_tx(&provider, tx, 0).await;

let tx: TypedTransaction = TransactionRequest::new()
.from(address)
.to(address)
.with_access_list(vec![]);
let receipt = provider
.send_transaction(tx, None)
.await
.unwrap()
.await
.unwrap()
.unwrap();
let tx = provider
.get_transaction(receipt.transaction_hash)
.await
.unwrap()
.unwrap();
assert_eq!(receipt.transaction_type, Some(1.into()));
assert_eq!(tx.transaction_type, Some(1.into()));
.with_access_list(vec![])
.into();
check_tx(&provider, tx, 1).await;

let tx = Eip1559TransactionRequest::new().from(address).to(address);
let receipt = provider
.send_transaction(tx, None)
.await
.unwrap()
.await
.unwrap()
.unwrap();
let tx = provider
.get_transaction(receipt.transaction_hash)
.await
.unwrap()
.unwrap();
assert_eq!(receipt.transaction_type, Some(2.into()));
assert_eq!(tx.transaction_type, Some(2.into()));
let tx: TypedTransaction = Eip1559TransactionRequest::new()
.from(address)
.to(address)
.into();
check_tx(&provider, tx, 2).await;
}
}

Expand Down

0 comments on commit 8b320ef

Please sign in to comment.