-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/node: Test vectors address test (#1336)
* test vectors address test * reused test fixture from rust --------- Co-authored-by: Thibault Martinez <[email protected]>
- Loading branch information
1 parent
d4e7d66
commit 73db566
Showing
4 changed files
with
60 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.