Skip to content

Commit

Permalink
add json input to test sign_transaction_with_kms_signer
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasArrachea committed Sep 12, 2024
1 parent 982758b commit 1c80df4
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions crates/signer/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ mod test {
}

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

Expand All @@ -162,6 +162,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 +186,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 Down

0 comments on commit 1c80df4

Please sign in to comment.