-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional OP tests, still some TODOs
- Loading branch information
1 parent
aac3345
commit b0da3f2
Showing
7 changed files
with
167 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
//! tests for OP chain support | ||
use anvil::{spawn, NodeConfig}; | ||
use ethers_core::types::{H256, Bytes}; | ||
use ethers::{ | ||
types::{transaction::eip2718::TypedTransaction, transaction::optimism::DepositTransaction, TransactionRequest, U256}, | ||
providers::Middleware, abi::Address | ||
}; | ||
use std::str::FromStr; | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn test_deposits_not_supported_if_optimism_disabled() { | ||
// optimism disabled by default | ||
let (_, handle) = spawn(NodeConfig::test()).await; | ||
let provider = handle.http_provider(); | ||
|
||
let from_addr: Address = "cf7f9e66af820a19257a2108375b180b0ec49167".parse().unwrap(); | ||
let to_addr: Address = "71562b71999873db5b286df957af199ec94617f7".parse().unwrap(); | ||
let deposit_tx: TypedTransaction = TypedTransaction::DepositTransaction(DepositTransaction { | ||
tx: TransactionRequest { | ||
chain_id: None, | ||
from: Some(from_addr), | ||
to: Some(ethers::types::NameOrAddress::Address(to_addr)), | ||
value: Some("1234".parse().unwrap()), | ||
gas: Some(U256::from(21000)), | ||
gas_price: None, | ||
data: Some(Bytes::default()), | ||
nonce: None, | ||
}, | ||
source_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(), | ||
mint: Some(U256::zero()), | ||
is_system_tx: true, | ||
}); | ||
|
||
// sending the deposit transaction should fail with error saying not supported | ||
let res = provider.send_transaction(deposit_tx.clone(), None).await; | ||
assert!(res.is_err()); | ||
assert!(res.unwrap_err().to_string().contains("op-stack deposit tx received but is not supported")); | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn test_send_value_deposit_transaction() { | ||
// enable the Optimism flag | ||
let (api, handle) = spawn(NodeConfig::test().with_optimism(true)).await; | ||
let provider = handle.http_provider(); | ||
|
||
let send_value: U256 = "1234".parse().unwrap(); | ||
let from_addr: Address = "cf7f9e66af820a19257a2108375b180b0ec49167".parse().unwrap(); | ||
let to_addr: Address = "71562b71999873db5b286df957af199ec94617f7".parse().unwrap(); | ||
|
||
// fund the sender | ||
api.anvil_set_balance(from_addr, send_value).await.unwrap(); | ||
|
||
let deposit_tx: TypedTransaction = TypedTransaction::DepositTransaction(DepositTransaction { | ||
tx: TransactionRequest { | ||
chain_id: None, | ||
from: Some(from_addr), | ||
to: Some(ethers::types::NameOrAddress::Address(to_addr)), | ||
value: Some(send_value), | ||
gas: Some(U256::from(21000)), | ||
gas_price: None, | ||
data: Some(Bytes::default()), | ||
nonce: None, | ||
}, | ||
source_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(), | ||
mint: Some(U256::zero()), | ||
is_system_tx: true, | ||
}); | ||
provider.send_transaction(deposit_tx.clone(), None).await.unwrap().await.unwrap().unwrap(); | ||
|
||
// mine block | ||
api.evm_mine(None).await.unwrap(); | ||
|
||
// the recipient should have received the value | ||
let balance = provider.get_balance(to_addr, None).await.unwrap(); | ||
assert_eq!(balance, send_value); | ||
} | ||
|
||
|
||
// // TODO: get this working - it tests eth_sendRawTransaction | ||
// #[tokio::test(flavor = "multi_thread")] | ||
// async fn test_send_value_raw_deposit_transaction() { | ||
// // enable the Optimism flag | ||
// let (api, handle) = spawn(NodeConfig::test().with_optimism(true)).await; | ||
// let provider = handle.http_provider(); | ||
|
||
// let send_value: U256 = "1234".parse().unwrap(); | ||
// let from_addr: Address = "cf7f9e66af820a19257a2108375b180b0ec49167".parse().unwrap(); | ||
// let to_addr: Address = "71562b71999873db5b286df957af199ec94617f7".parse().unwrap(); | ||
|
||
// // fund the sender | ||
// api.anvil_set_balance(from_addr, send_value).await.unwrap(); | ||
|
||
// let deposit_tx: TypedTransaction = TypedTransaction::DepositTransaction(DepositTransaction { | ||
// tx: TransactionRequest { | ||
// chain_id: None, | ||
// from: Some(from_addr), | ||
// to: Some(ethers::types::NameOrAddress::Address(to_addr)), | ||
// value: Some(send_value), | ||
// gas: Some(U256::from(21000)), | ||
// gas_price: None, | ||
// data: Some(Bytes::default()), | ||
// nonce: None, | ||
// }, | ||
// source_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(), | ||
// mint: Some(U256::zero()), | ||
// is_system_tx: true, | ||
// }); | ||
|
||
// let rlpbytes = deposit_tx.rlp(); | ||
// provider.send_raw_transaction(rlpbytes).await.unwrap().await.unwrap().unwrap(); | ||
|
||
// // mine block | ||
// api.evm_mine(None).await.unwrap(); | ||
|
||
// // the recipient should have received the value | ||
// let balance = provider.get_balance(to_addr, None).await.unwrap(); | ||
// assert_eq!(balance, send_value); | ||
// } |