Skip to content

Commit

Permalink
feat/node: Test vectors address test (#1336)
Browse files Browse the repository at this point in the history
* test vectors address test

* reused test fixture from rust

---------

Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
Brord van Wierst and thibault-martinez authored Sep 27, 2023
1 parent d4e7d66 commit 73db566
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 18 deletions.
59 changes: 59 additions & 0 deletions bindings/nodejs/tests/client/addresses.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
17 changes: 0 additions & 17 deletions bindings/nodejs/tests/client/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
File renamed without changes.

0 comments on commit 73db566

Please sign in to comment.