Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support web3_sha3 provider function #996

Merged
merged 11 commits into from
Jul 1, 2024
Prev Previous commit
Next Next commit
feat: add unit tests
  • Loading branch information
PanGan21 committed Jun 30, 2024
commit 904a32cc682642793d9cfec61afdff8ba8d4070f
27 changes: 27 additions & 0 deletions crates/provider/src/ext/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,30 @@ where
self.client().request("web3_sha3", (data,)).await
}
}

#[cfg(test)]
mod tests {
use crate::ProviderBuilder;

use super::*;
use alloy_node_bindings::Geth;

#[tokio::test]
async fn test_web3_client_version() {
let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap();
let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn();
let provider = ProviderBuilder::new().on_http(geth.endpoint_url());
let version = provider.web3_client_version().await.unwrap();
assert!(!version.is_empty());
}

#[tokio::test]
async fn test_web3_sha3() {
let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap();
let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn();
let provider = ProviderBuilder::new().on_http(geth.endpoint_url());
let data = Bytes::from("alloy");
let hash = provider.web3_sha3(data).await.unwrap();
assert!(!hash.is_empty());
}
}