Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/node: Test vectors address test #1336

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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