From 07bdeedac2cd02627986629fce00daa1195698ac Mon Sep 17 00:00:00 2001 From: XuNeal Date: Tue, 5 Mar 2024 18:27:49 +0800 Subject: [PATCH] feat: export with lower address --- token-core/tcx-migration/src/migration.rs | 14 ++++++++------ token-core/tcx/tests/import_test.rs | 4 ++-- token-core/test-data/.gitignore | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/token-core/tcx-migration/src/migration.rs b/token-core/tcx-migration/src/migration.rs index 7d47e9b6..19571937 100644 --- a/token-core/tcx-migration/src/migration.rs +++ b/token-core/tcx-migration/src/migration.rs @@ -110,7 +110,12 @@ impl LegacyKeystore { let sec_key = Secp256k1PrivateKey::from_slice(private_key)?; let pub_key = TypedPublicKey::Secp256k1(sec_key.public_key()); let coin_info = coin_info_from_param("ETHEREUM", "", "", CurveType::SECP256k1.as_str())?; - let address = EthAddress::from_public_key(&pub_key, &coin_info)?.to_string(); + let checksumed_address = EthAddress::from_public_key(&pub_key, &coin_info)?.to_string(); + let address = checksumed_address + .to_lowercase() + .strip_prefix("0x") + .unwrap() + .to_string(); let id = uuid::Uuid::new_v4().to_string(); Ok(LegacyKeystore { version: 3, @@ -491,10 +496,7 @@ mod tests { let json: Value = serde_json::from_str(&keystore_json).expect("json"); assert_eq!(json["version"], 3); - assert_eq!( - json["address"], - "0x6031564e7b2F5cc33737807b2E58DaFF870B590b" - ); + assert_eq!(json["address"], "6031564e7b2f5cc33737807b2e58daff870b590b"); } #[test] @@ -502,7 +504,7 @@ mod tests { let private_key_bytes = Vec::from_hex_auto(TEST_PRIVATE_KEY).unwrap(); let mut v3_keystore = LegacyKeystore::new_v3(&private_key_bytes, TEST_PASSWORD).expect("v3 keystore"); - v3_keystore.address = Some("0x6031564e7b2F5cc33737807b2E58DaFF870B5900".to_string()); //wrong address + v3_keystore.address = Some("6031564e7b2f5cc33737807b2e58daff870b5900".to_string()); //wrong address let validate_result = v3_keystore.validate_v3(TEST_PASSWORD); assert_eq!( validate_result.err().unwrap().to_string(), diff --git a/token-core/tcx/tests/import_test.rs b/token-core/tcx/tests/import_test.rs index d5c88910..874af504 100644 --- a/token-core/tcx/tests/import_test.rs +++ b/token-core/tcx/tests/import_test.rs @@ -1148,7 +1148,7 @@ pub fn test_import_hex_private_key() { assert_eq!(export_result.id, import_result.id); assert!(export_result .json - .contains("0x6031564e7b2F5cc33737807b2E58DaFF870B590b")); + .contains("6031564e7b2f5cc33737807b2e58daff870b590b")); }) } @@ -1271,6 +1271,6 @@ pub fn test_import_v3_keystore_json() { assert!(export_result .json .to_string() - .contains("0x6031564e7b2F5cc33737807b2E58DaFF870B590b")); + .contains("6031564e7b2f5cc33737807b2e58daff870b590b")); }) } diff --git a/token-core/test-data/.gitignore b/token-core/test-data/.gitignore index 7ab37ee1..4a9c1f52 100644 --- a/token-core/test-data/.gitignore +++ b/token-core/test-data/.gitignore @@ -15,4 +15,5 @@ !testnet-identity !testnet-identity/* !migrate-duplication-fixtures -!migrate-duplication-fixtures/wallets/** \ No newline at end of file +!migrate-duplication-fixtures/wallets/** +wallets/_migrated.json \ No newline at end of file