Skip to content

Commit

Permalink
Improve key address generation test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Apr 24, 2024
1 parent b86fa5c commit 338ade9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/massa-web3/test/experimental/unit/key.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
})

Expand Down

1 comment on commit 338ade9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for experimental massa-web3

St.
Category Percentage Covered / Total
🔴 Statements 43.31% 615/1420
🔴 Branches 18.33% 68/371
🔴 Functions 34.74% 99/285
🔴 Lines 43.1% 603/1399

Test suite run success

36 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from 338ade9

Please sign in to comment.