diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index df3180d..21cdcf7 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -7,7 +7,10 @@ on: - feat/** - fix/** - chore/** + - test/** - ci/** + tags: + - v[0-9]+.[0-9]+.[0-9]+ pull_request: branches: diff --git a/Cargo.toml b/Cargo.toml index ff64c32..8a3fad1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" \ No newline at end of file +tokio-test = "0.4.4" +lazy_static = "1.5.0" \ No newline at end of file diff --git a/tests/evm_account_test.rs b/tests/evm_account_test.rs index 813be7e..e14709b 100644 --- a/tests/evm_account_test.rs +++ b/tests/evm_account_test.rs @@ -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::{ @@ -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, @@ -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 { @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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();