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

Add signer test to compliance #112

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ url.workspace = true
[dev-dependencies]
alloy-node-bindings.workspace = true
aws-config.workspace = true
eigen-testing-utils.workspace = true
testcontainers.workspace = true
tokio.workspace = true
30 changes: 16 additions & 14 deletions crates/signer/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod test {
config::{Credentials, SharedCredentialsProvider},
types::KeyMetadata,
};
use eigen_testing_utils::test_data::TestData;
use std::str::FromStr;
use testcontainers::{
core::{IntoContainerPort, WaitFor},
Expand Down Expand Up @@ -149,7 +150,7 @@ mod test {
}

#[tokio::test]
async fn sign_transaction_with_aws_signer() {
async fn test_sign_transaction_with_kms_signer() {
// Start the container running Localstack
let _container = start_localstack_container().await;

Expand All @@ -162,6 +163,17 @@ mod test {
)
.await;

let default_tx = TxLegacy {
to: address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into(),
value: U256::from(1_000_000_000),
gas_limit: 2_000_000,
nonce: 0,
gas_price: 21_000_000_000,
input: bytes!(),
chain_id: Some(1),
};
let mut test_data: TestData<TxLegacy> = TestData::new(default_tx);

// Create an AWS KMS Client
let client = aws_sdk_kms::Client::new(&config);

Expand All @@ -175,22 +187,12 @@ mod test {
.await
.unwrap();

let mut tx = TxLegacy {
to: address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into(),
value: U256::from(1_000_000_000),
gas_limit: 2_000_000,
nonce: 0,
gas_price: 21_000_000_000,
input: bytes!(),
chain_id: Some(1),
};

// Sign the transaction
let signature = signer.sign_transaction(&mut tx).await.unwrap();
let signature = signer.sign_transaction(&mut test_data.input).await.unwrap();

// Recover the address
let mut encoded_tx = Vec::new();
tx.encode_for_signing(&mut encoded_tx);
test_data.input.encode_for_signing(&mut encoded_tx);
let prehash = keccak256(encoded_tx);
let recovered_address = signature.recover_address_from_prehash(&prehash).unwrap();

Expand All @@ -199,7 +201,7 @@ mod test {
}

#[tokio::test]
async fn sign_legacy_transaction_with_web3_signer() {
async fn test_sign_legacy_transaction_with_web3_signer() {
let anvil = Anvil::default().spawn();

let endpoint = anvil.endpoint();
Expand Down
Loading