Skip to content

Commit

Permalink
feat: export with lower address
Browse files Browse the repository at this point in the history
  • Loading branch information
XuNeal committed Mar 5, 2024
1 parent 84fe2f8 commit 07bdeed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
14 changes: 8 additions & 6 deletions token-core/tcx-migration/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -491,18 +496,15 @@ 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]
fn test_address_not_match() {
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(),
Expand Down
4 changes: 2 additions & 2 deletions token-core/tcx/tests/import_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
})
}

Expand Down Expand Up @@ -1271,6 +1271,6 @@ pub fn test_import_v3_keystore_json() {
assert!(export_result
.json
.to_string()
.contains("0x6031564e7b2F5cc33737807b2E58DaFF870B590b"));
.contains("6031564e7b2f5cc33737807b2e58daff870b590b"));
})
}
3 changes: 2 additions & 1 deletion token-core/test-data/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
!testnet-identity
!testnet-identity/*
!migrate-duplication-fixtures
!migrate-duplication-fixtures/wallets/**
!migrate-duplication-fixtures/wallets/**
wallets/_migrated.json

0 comments on commit 07bdeed

Please sign in to comment.