diff --git a/bindings/nodejs/tests/client/addresses.spec.ts b/bindings/nodejs/tests/client/addresses.spec.ts new file mode 100644 index 0000000000..cb4b2bfe7a --- /dev/null +++ b/bindings/nodejs/tests/client/addresses.spec.ts @@ -0,0 +1,59 @@ +// Copyright 2023 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { describe, it } from '@jest/globals'; +import { SecretManager } from '../../out'; +import '../customMatchers'; + +import * as mnemonicAddressTestCases from '../../../../sdk/tests/client/fixtures/test_vectors.json'; + +const secretManager = { + mnemonic: + 'endorse answer radar about source reunion marriage tag sausage weekend frost daring base attack because joke dream slender leisure group reason prepare broken river', +}; + +describe('Address tests', () => { + + it('calculates addresses according a fixture', async () => { + + for (const test of mnemonicAddressTestCases.general.address_generations) { + const secretManager = await new SecretManager({ + mnemonic: test['mnemonic'] + }); + + const generatedAddress = await secretManager.generateEd25519Addresses({ + coinType: test['coin_type'], + accountIndex: test['account_index'], + range: { + start: test['address_index'], + end: test['address_index'] + 1, + }, + bech32Hrp: test['bech32_hrp'], + options: { + internal: test['internal'], + } + }); + + if (test['bech32_address'] !== generatedAddress[0]) { + throw new Error('Test failed: Bech32 address does not match generated address.'); + } + } + }); + + it('generates addresses', async () => { + const addresses = await new SecretManager(secretManager).generateEd25519Addresses({ + accountIndex: 0, + range: { + start: 0, + end: 5, + }, + bech32Hrp: 'rms', + }); + + expect(addresses.length).toBe(5); + + addresses.forEach((address) => { + expect(address).toBeValidAddress(); + }); + }); +}); diff --git a/bindings/nodejs/tests/client/examples.spec.ts b/bindings/nodejs/tests/client/examples.spec.ts index 2a135c1a3d..a695c671af 100644 --- a/bindings/nodejs/tests/client/examples.spec.ts +++ b/bindings/nodejs/tests/client/examples.spec.ts @@ -36,23 +36,6 @@ describe.skip('Main examples', () => { expect(mnemonic).toBeDefined(); }); - it('generates addresses', async () => { - const addresses = await new SecretManager(secretManager).generateEd25519Addresses({ - accountIndex: 0, - range: { - start: 0, - end: 5, - }, - bech32Hrp: 'rms', - }); - - expect(addresses.length).toBe(5); - - addresses.forEach((address) => { - expect(address).toBeValidAddress(); - }); - }); - it('gets address outputs', async () => { const outputIdsResponse = await client.basicOutputIds([ { diff --git a/bindings/nodejs/tests/client/offlineSigningExamples.spec.ts b/bindings/nodejs/tests/client/offlineSigningExamples.spec.ts index fef52089ff..5e94180979 100644 --- a/bindings/nodejs/tests/client/offlineSigningExamples.spec.ts +++ b/bindings/nodejs/tests/client/offlineSigningExamples.spec.ts @@ -16,7 +16,7 @@ import { Utils } from '../../'; import '../customMatchers'; -import { addresses } from '../fixtures/addresses'; +import { addresses } from '../fixtures/offlineSigningAddresses'; import * as signedTransactionJson from '../fixtures/signedTransaction.json'; import * as sigUnlockPreparedTx from '../fixtures/sigUnlockPreparedTx.json'; diff --git a/bindings/nodejs/tests/fixtures/addresses.ts b/bindings/nodejs/tests/fixtures/offlineSigningAddresses.ts similarity index 100% rename from bindings/nodejs/tests/fixtures/addresses.ts rename to bindings/nodejs/tests/fixtures/offlineSigningAddresses.ts