From 338ade9092324ed93407684535758b43dbb17749 Mon Sep 17 00:00:00 2001 From: BenRey Date: Wed, 24 Apr 2024 14:26:41 +0200 Subject: [PATCH] Improve key address generation test --- .../test/experimental/unit/key.spec.ts | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/massa-web3/test/experimental/unit/key.spec.ts b/packages/massa-web3/test/experimental/unit/key.spec.ts index 5625c259..010a4302 100644 --- a/packages/massa-web3/test/experimental/unit/key.spec.ts +++ b/packages/massa-web3/test/experimental/unit/key.spec.ts @@ -4,6 +4,8 @@ import { PublicKey, } from '../../../src/experimental/basicElements/keys' import { Version } from '../../../src/experimental/crypto/interfaces/versioner' +import { SecretKey as LegacyPrivateKey } from '../../../src/utils/keyAndAddresses' +import { Address as LegacyAddress } from '../../../src/utils/keyAndAddresses' class TestPublicKey extends PublicKey { public static callInitFromVersion(version: Version) { @@ -39,10 +41,23 @@ describe('PrivateKey and PublicKey tests', () => { }) describe('Address Generation', () => { - test('PublicKey getAddress', () => { - // TODO be sure address is right - const address = publicKey.getAddress() - expect(address).toBeInstanceOf(Address) + test('PublicKey getAddress', async () => { + // Generate address from Legacy keys objects + const legacyPrivKey = new LegacyPrivateKey( + 'S1eK3SEXGDAWN6pZhdr4Q7WJv6UHss55EB14hPy4XqBpiktfPu6' + ) + const legacyPubKey = await legacyPrivKey.getPublicKey() + const legacyAddress = LegacyAddress.fromPublicKey(legacyPubKey) + + // Generate address from new keys objects + const privKey = PrivateKey.fromString( + 'S1eK3SEXGDAWN6pZhdr4Q7WJv6UHss55EB14hPy4XqBpiktfPu6' + ) + const pubKey = await PublicKey.fromPrivateKey(privKey) + const address = Address.fromPublicKey(pubKey) + + // Verify that the addresses are the same + expect(address.toString()).toBe(legacyAddress.base58Encoded) }) })