Skip to content

Commit

Permalink
test: Added extracting KMS key ID from env var
Browse files Browse the repository at this point in the history
  • Loading branch information
orlowskilp committed Oct 14, 2024
1 parent d0e8ea3 commit 64bee0e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ on:
- feat/**
- fix/**
- chore/**
- test/**
- ci/**
tags:
- v[0-9]+.[0-9]+.[0-9]+

pull_request:
branches:
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ aws-sdk-kms = "1.37.0"
[dev-dependencies]
serde_json = "1.0.120"
serde_plain = "1.0.2"
tokio-test = "0.4.4"
tokio-test = "0.4.4"
lazy_static = "1.5.0"
24 changes: 17 additions & 7 deletions tests/evm_account_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod evm_account {
mod integration_tests {
use lazy_static::lazy_static;
use serde_json;
use serde_plain;
use std::env;
use std::fs::File;

use evm_signer_kms::evm_account::{
Expand All @@ -14,7 +16,15 @@ mod evm_account {
EvmAccount,
};

const KMS_KEY_ID: &str = "52c9a19f-bcfd-46a7-bd56-6d0cf98d8616";
// Reads the KMS_KEY_ID environment variable using lazy static evaluation.
// Assumes no default value and fails if the key ID is not set!
const KMS_KEY_ID_VAR_NAME: &str = "KMS_KEY_ID";
lazy_static! {
static ref KMS_KEY_ID: String = env::var(KMS_KEY_ID_VAR_NAME).expect(
format!("⚠️ `{}` environment variable not set", KMS_KEY_ID_VAR_NAME).as_str()
);
}

const TEST_TO_ADDRESS_BYTES: [u8; 20] = [
0xa9, 0xd8, 0x91, 0x86, 0xca, 0xa6, 0x63, 0xc8, 0xef, 0x03, 0x52, 0xfd, 0x1d, 0xb3,
0x59, 0x62, 0x80, 0x62, 0x55, 0x73,
Expand All @@ -23,7 +33,7 @@ mod evm_account {
// Only verifies if the signature can be generated
#[tokio::test]
async fn sign_transaction_succeed() {
let kms_key = &kms_key::KmsKey::new(KMS_KEY_ID).await;
let kms_key = &kms_key::KmsKey::new(&KMS_KEY_ID).await;
let evm_account = EvmAccount::new(kms_key);

let tx = FreeMarketTransaction {
Expand Down Expand Up @@ -52,7 +62,7 @@ mod evm_account {
async fn encode_signed_legacy_tx_succeed() {
const TX_FILE_PATH: &str = "tests/data/valid-legacy-tx-01.json";

let kms_key = &kms_key::KmsKey::new(KMS_KEY_ID).await;
let kms_key = &kms_key::KmsKey::new(&KMS_KEY_ID).await;
let evm_account = EvmAccount::new(kms_key);

let tx_file = File::open(TX_FILE_PATH).unwrap();
Expand All @@ -75,7 +85,7 @@ mod evm_account {
async fn encode_signed_access_list_tx_succeed() {
const TX_FILE_PATH: &str = "tests/data/valid-access-list-tx-02.json";

let kms_key = &kms_key::KmsKey::new(KMS_KEY_ID).await;
let kms_key = &kms_key::KmsKey::new(&KMS_KEY_ID).await;
let evm_account = EvmAccount::new(kms_key);

let tx_file = File::open(TX_FILE_PATH).unwrap();
Expand All @@ -98,7 +108,7 @@ mod evm_account {
async fn encode_signed_free_market_tx_no_access_list_succeed() {
const TX_FILE_PATH: &str = "tests/data/valid-free-market-tx-01.json";

let kms_key = &kms_key::KmsKey::new(KMS_KEY_ID).await;
let kms_key = &kms_key::KmsKey::new(&KMS_KEY_ID).await;
let evm_account = EvmAccount::new(kms_key);

let tx_file = File::open(TX_FILE_PATH).unwrap();
Expand All @@ -121,7 +131,7 @@ mod evm_account {
async fn encode_signed_free_market_tx_with_access_list_1_succeed() {
const TX_FILE_PATH: &str = "tests/data/valid-free-market-tx-03.json";

let kms_key = &kms_key::KmsKey::new(KMS_KEY_ID).await;
let kms_key = &kms_key::KmsKey::new(&KMS_KEY_ID).await;
let evm_account = EvmAccount::new(kms_key);

let tx_file = File::open(TX_FILE_PATH).unwrap();
Expand All @@ -144,7 +154,7 @@ mod evm_account {
async fn encode_signed_free_market_tx_with_access_list_2_succeed() {
const TX_FILE_PATH: &str = "tests/data/valid-free-market-tx-04.json";

let kms_key = &kms_key::KmsKey::new(KMS_KEY_ID).await;
let kms_key = &kms_key::KmsKey::new(&KMS_KEY_ID).await;
let evm_account = EvmAccount::new(kms_key);

let tx_file = File::open(TX_FILE_PATH).unwrap();
Expand Down

0 comments on commit 64bee0e

Please sign in to comment.