From: Chris Duncan Date: Thu, 5 Dec 2024 16:14:43 +0000 (-0800) Subject: Switch to jest 'test' syntax from node 'it' alias. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=6f0984780c5dcf26c20dbcb4e3b04a40de1f8e2a;p=libnemo.git Switch to jest 'test' syntax from node 'it' alias. --- diff --git a/test/create-wallet.test.js b/test/create-wallet.test.js index 529addb..c2e590f 100644 --- a/test/create-wallet.test.js +++ b/test/create-wallet.test.js @@ -9,7 +9,7 @@ import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '#dist/main.js' describe('creating a new wallet', async () => { - it('BIP-44 wallet with random entropy', async () => { + test('BIP-44 wallet with random entropy', async () => { const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -21,7 +21,7 @@ describe('creating a new wallet', async () => { assert.ok(/[A-Fa-f0-9]{32,64}/.test(wallet.seed)) }) - it('BLAKE2b wallet with random entropy', async () => { + test('BLAKE2b wallet with random entropy', async () => { const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -33,7 +33,7 @@ describe('creating a new wallet', async () => { assert.ok(/[A-Fa-f0-9]{32,64}/.test(wallet.seed)) }) - it('BIP-44 replace invalid salt with empty string', async () => { + test('BIP-44 replace invalid salt with empty string', async () => { const invalidArgs = [null, true, false, 0, 1, 2, { "foo": "bar" }] for (const arg of invalidArgs) { //@ts-expect-error @@ -41,7 +41,7 @@ describe('creating a new wallet', async () => { } }) - it('fail when using new', async () => { + test('fail when using new', async () => { //@ts-expect-error assert.throws(() => new Bip44Wallet()) //@ts-expect-error @@ -50,14 +50,14 @@ describe('creating a new wallet', async () => { assert.throws(() => new LedgerWallet()) }) - it('fail without a password', async () => { + test('fail without a password', async () => { //@ts-expect-error await assert.rejects(Bip44Wallet.create()) //@ts-expect-error await assert.rejects(Blake2bWallet.create()) }) - it('connect to ledger', { skip: true }, async () => { + test('connect to ledger', { skip: true }, async () => { const wallet = await LedgerWallet.create() assert.ok(wallet) }) diff --git a/test/derive-accounts.test.js b/test/derive-accounts.test.js index f9fe583..67a6171 100644 --- a/test/derive-accounts.test.js +++ b/test/derive-accounts.test.js @@ -12,7 +12,7 @@ describe('derive child accounts from the same seed', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) - it('should derive the first account from the given BIP-44 seed', async () => { + test('should derive the first account from the given BIP-44 seed', async () => { const accounts = await wallet.accounts() assert.equal(accounts.length, 1) @@ -21,7 +21,7 @@ describe('derive child accounts from the same seed', async () => { assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0) }) - it('should derive low indexed accounts from the given BIP-44 seed', async () => { + test('should derive low indexed accounts from the given BIP-44 seed', async () => { const accounts = await wallet.accounts(1, 2) assert.equal(accounts.length, 2) @@ -33,7 +33,7 @@ describe('derive child accounts from the same seed', async () => { assert.equal(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_2) }) - it('should derive high indexed accounts from the given seed', async () => { + test('should derive high indexed accounts from the given seed', async () => { const accounts = await wallet.accounts(0x70000000, 0x700000ff) assert.equal(accounts.length, 0x100) @@ -46,7 +46,7 @@ describe('derive child accounts from the same seed', async () => { } }) - it('should derive accounts for a BLAKE2b wallet', async () => { + test('should derive accounts for a BLAKE2b wallet', async () => { const bwallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD) await bwallet.unlock(NANO_TEST_VECTORS.PASSWORD) const lowAccounts = await bwallet.accounts(0, 2) @@ -76,7 +76,7 @@ describe('derive child accounts from the same seed', async () => { describe('Ledger device accounts', { skip: true }, async () => { const wallet = await LedgerWallet.create() - it('should fetch the first account from a Ledger device', async () => { + test('should fetch the first account from a Ledger device', async () => { const accounts = await wallet.accounts() assert.equal(accounts.length, 1) diff --git a/test/import-wallet.test.js b/test/import-wallet.test.js index 68f0495..56d913a 100644 --- a/test/import-wallet.test.js +++ b/test/import-wallet.test.js @@ -9,7 +9,7 @@ import { BIP32_TEST_VECTORS, CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS, TREZOR_TEST import { Account, Bip44Wallet, Blake2bWallet } from '#dist/main.js' describe('import wallet with test vectors test', () => { - it('should successfully import a wallet with the official Nano test vectors mnemonic', async () => { + test('should successfully import a wallet with the official Nano test vectors mnemonic', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -24,13 +24,13 @@ describe('import wallet with test vectors test', () => { assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0) }) - it('should successfully import a wallet with the checksum starting with a zero', async () => { + test('should successfully import a wallet with the checksum starting with a zero', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, 'food define cancel major spoon trash cigar basic aim bless wolf win ability seek paddle bench seed century group they mercy address monkey cake') await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) assert.equal(wallet.seed, 'F665F804E5907985455D1E5A7AD344843A2ED4179A7E06EEF263DE925FF6F4C0991B0A9344FCEE939FE0F1B1841B8C9B20FEACF6B954B74B2D26A01906B758E2') }) - it('should successfully import a wallet with a 12-word phrase', async () => { + test('should successfully import a wallet with a 12-word phrase', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_0) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -43,7 +43,7 @@ describe('import wallet with test vectors test', () => { assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_0) }) - it('should successfully import a wallet with a 15-word phrase', async () => { + test('should successfully import a wallet with a 15-word phrase', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -56,7 +56,7 @@ describe('import wallet with test vectors test', () => { assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_1) }) - it('should successfully import a wallet with a 18-word phrase', async () => { + test('should successfully import a wallet with a 18-word phrase', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_2) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -69,7 +69,7 @@ describe('import wallet with test vectors test', () => { assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_2) }) - it('should successfully import a wallet with a 21-word phrase', async () => { + test('should successfully import a wallet with a 21-word phrase', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_3) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -82,7 +82,7 @@ describe('import wallet with test vectors test', () => { assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_3) }) - it('should successfully import a wallet with the official Nano test vectors seed', async () => { + test('should successfully import a wallet with the official Nano test vectors seed', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -97,7 +97,7 @@ describe('import wallet with test vectors test', () => { assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0) }) - it('should successfully import a BIP-44 wallet with the zero seed', async () => { + test('should successfully import a BIP-44 wallet with the zero seed', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0, TREZOR_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts(0, 3) @@ -116,7 +116,7 @@ describe('import wallet with test vectors test', () => { } }) - it('should successfully import a BLAKE2b wallet with the zero seed', async () => { + test('should successfully import a BLAKE2b wallet with the zero seed', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts(0, 3) @@ -135,7 +135,7 @@ describe('import wallet with test vectors test', () => { } }) - it('should successfully import a BLAKE2b wallet with Trezor test vectors', async () => { + test('should successfully import a BLAKE2b wallet with Trezor test vectors', async () => { const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts(0, 1) @@ -156,7 +156,7 @@ describe('import wallet with test vectors test', () => { assert.equal(accounts[1].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1) }) - it('should get identical BLAKE2b wallets when created with a seed versus with its derived mnemonic', async () => { + test('should get identical BLAKE2b wallets when created with a seed versus with its derived mnemonic', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_2) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const walletAccounts = await wallet.accounts() @@ -178,7 +178,7 @@ describe('import wallet with test vectors test', () => { assert.equal(importedAccount.publicKey, walletAccount.publicKey) }) - it('should get identical BLAKE2b wallets when created with max entropy value', async () => { + test('should get identical BLAKE2b wallets when created with max entropy value', async () => { const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_3) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -196,20 +196,20 @@ describe('import wallet with test vectors test', () => { }) describe('invalid wallet', async () => { - it('throw when given invalid entropy', async () => { + test('throw when given invalid entropy', async () => { assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C797')) assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C79701')) assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0.replaceAll(/./g, 'x'))) }) - it('should throw when given a seed with an invalid length', async () => { + test('should throw when given a seed with an invalid length', async () => { await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED + 'f'), { message: `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length + 1}-character string.` }) await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED.slice(0, -1)), { message: `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length - 1}-character string.` }) }) - it('should throw when given a seed containing non-hex characters', async () => { + test('should throw when given a seed containing non-hex characters', async () => { await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.SEED_0.replace(/./, 'g')), { message: 'Seed contains invalid hexadecimal characters.' }) await assert.rejects(Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1.replace(/./, 'g')), @@ -218,7 +218,7 @@ describe('invalid wallet', async () => { }) describe('import from storage', async () => { - it('should retrieve a Bip44Wallet from storage using an ID', async () => { + test('should retrieve a Bip44Wallet from storage using an ID', async () => { const id = (await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)).id const wallet = await Bip44Wallet.restore(id) @@ -236,7 +236,7 @@ describe('import from storage', async () => { assert.equal(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) - it('should retrieve a Blake2bWallet from storage using an ID', async () => { + test('should retrieve a Blake2bWallet from storage using an ID', async () => { const id = (await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)).id const wallet = await Blake2bWallet.restore(id) diff --git a/test/lock-unlock-wallet.js b/test/lock-unlock-wallet.js index e8cedc9..3c271e5 100644 --- a/test/lock-unlock-wallet.js +++ b/test/lock-unlock-wallet.js @@ -9,7 +9,7 @@ import { NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { Bip44Wallet, Blake2bWallet } from '#dist/main.js' describe('locking and unlocking a Bip44Wallet', async () => { - it('should succeed with a password', async () => { + test('should succeed with a password', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) assert.ok('mnemonic' in wallet) @@ -26,7 +26,7 @@ describe('locking and unlocking a Bip44Wallet', async () => { assert.equal(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) - it('should succeed with a random CryptoKey', async () => { + test('should succeed with a random CryptoKey', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -47,7 +47,7 @@ describe('locking and unlocking a Bip44Wallet', async () => { assert.equal(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) - it('should fail to unlock with different passwords', async () => { + test('should fail to unlock with different passwords', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const lockResult = await wallet.lock(TREZOR_TEST_VECTORS.PASSWORD) @@ -60,7 +60,7 @@ describe('locking and unlocking a Bip44Wallet', async () => { assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) - it('should fail to unlock with different keys', async () => { + test('should fail to unlock with different keys', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const rightKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -75,7 +75,7 @@ describe('locking and unlocking a Bip44Wallet', async () => { assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) - it('should fail to unlock with different valid inputs', async () => { + test('should fail to unlock with different valid inputs', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -86,7 +86,7 @@ describe('locking and unlocking a Bip44Wallet', async () => { assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) - it('should fail with no input', async () => { + test('should fail with no input', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -107,7 +107,7 @@ describe('locking and unlocking a Bip44Wallet', async () => { assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) - it('should fail with invalid input', async () => { + test('should fail with invalid input', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -130,7 +130,7 @@ describe('locking and unlocking a Bip44Wallet', async () => { }) describe('locking and unlocking a Blake2bWallet', async () => { - it('should succeed with a password', async () => { + test('should succeed with a password', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0) assert.ok('mnemonic' in wallet) @@ -147,7 +147,7 @@ describe('locking and unlocking a Blake2bWallet', async () => { assert.equal(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_0) }) - it('should succeed with a random CryptoKey', async () => { + test('should succeed with a random CryptoKey', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -169,7 +169,7 @@ describe('locking and unlocking a Blake2bWallet', async () => { assert.equal(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) - it('should fail to unlock with different passwords', async () => { + test('should fail to unlock with different passwords', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await assert.rejects(wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' }) @@ -179,7 +179,7 @@ describe('locking and unlocking a Blake2bWallet', async () => { assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) - it('should fail to unlock with different keys', async () => { + test('should fail to unlock with different keys', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const rightKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -194,7 +194,7 @@ describe('locking and unlocking a Blake2bWallet', async () => { assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) - it('should fail to unlock with different valid inputs', async () => { + test('should fail to unlock with different valid inputs', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -205,7 +205,7 @@ describe('locking and unlocking a Blake2bWallet', async () => { assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) - it('should fail with no input', async () => { + test('should fail with no input', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -226,7 +226,7 @@ describe('locking and unlocking a Blake2bWallet', async () => { assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) - it('should fail with invalid input', async () => { + test('should fail with invalid input', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) diff --git a/test/manage-rolodex.js b/test/manage-rolodex.js index 399bf76..e15d22d 100644 --- a/test/manage-rolodex.js +++ b/test/manage-rolodex.js @@ -9,7 +9,7 @@ import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { Rolodex, Tools } from '#dist/main.js' describe('rolodex valid contact management', async () => { - it('should create a rolodex and add two contacts', async () => { + test('should create a rolodex and add two contacts', async () => { const rolodex = new Rolodex() assert.equal(rolodex.constructor, Rolodex) await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) @@ -24,13 +24,13 @@ describe('rolodex valid contact management', async () => { assert.equal(rolodex.getAddresses('JaneSmith')[0], NANO_TEST_VECTORS.ADDRESS_1) }) - it('should get a name from an address', async () => { + test('should get a name from an address', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) assert.equal(rolodex.getName(NANO_TEST_VECTORS.ADDRESS_0), 'JohnDoe') }) - it('should add three addresses to the same contact', async () => { + test('should add three addresses to the same contact', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_1) await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_2) @@ -41,7 +41,7 @@ describe('rolodex valid contact management', async () => { assert.equal(rolodex.getAddresses('JohnDoe')[2], NANO_TEST_VECTORS.ADDRESS_0) }) - it('should update the name on an existing entry', async () => { + test('should update the name on an existing entry', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) await rolodex.add('JaneSmith', NANO_TEST_VECTORS.ADDRESS_0) @@ -50,14 +50,14 @@ describe('rolodex valid contact management', async () => { assert.equal(rolodex.getAddresses('JaneSmith')[0], NANO_TEST_VECTORS.ADDRESS_0) }) - it('should return empty address array for an unknown contact', async () => { + test('should return empty address array for an unknown contact', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) assert.equal(Array.isArray(rolodex.getAddresses('JaneSmith')), true) assert.equal(rolodex.getAddresses('JaneSmith').length, 0) }) - it('should return empty address array for blank contact names', () => { + test('should return empty address array for blank contact names', () => { const rolodex = new Rolodex() //@ts-expect-error assert.equal(Array.isArray(rolodex.getAddresses(undefined)), true) @@ -71,14 +71,14 @@ describe('rolodex valid contact management', async () => { assert.equal(rolodex.getAddresses('').length, 0) }) - it('should return null for an unknown address', async () => { + test('should return null for an unknown address', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) assert.equal(rolodex.getName(NANO_TEST_VECTORS.ADDRESS_1), null) assert.notEqual(rolodex.getName(NANO_TEST_VECTORS.ADDRESS_1), undefined) }) - it('should return null for a blank address', async () => { + test('should return null for a blank address', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) //@ts-expect-error @@ -95,13 +95,13 @@ describe('rolodex valid contact management', async () => { }) describe('rolodex exceptions', async () => { - it('should throw if adding no data', async () => { + test('should throw if adding no data', async () => { const rolodex = new Rolodex() //@ts-expect-error await assert.rejects(rolodex.add()) }) - it('should throw if passed no address', async () => { + test('should throw if passed no address', async () => { const rolodex = new Rolodex() //@ts-expect-error await assert.rejects(rolodex.add('JohnDoe')) @@ -112,7 +112,7 @@ describe('rolodex exceptions', async () => { await assert.rejects(rolodex.add('JohnDoe', '')) }) - it('should throw if name is blank', async () => { + test('should throw if name is blank', async () => { const rolodex = new Rolodex() //@ts-expect-error await assert.rejects(rolodex.add(undefined, NANO_TEST_VECTORS.ADDRESS_0)) @@ -127,13 +127,13 @@ describe('rolodex data signature verification', async () => { const signature = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0, data) const rolodex = new Rolodex() - it('should verify valid data and signature', async () => { + test('should verify valid data and signature', async () => { await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) const result = await rolodex.verify('JohnDoe', signature, data) assert.equal(result, true) }) - it('should reject incorrect contact for signature', async () => { + test('should reject incorrect contact for signature', async () => { await rolodex.add('JaneSmith', NANO_TEST_VECTORS.ADDRESS_1) const result = await rolodex.verify('JaneSmith', signature, data) assert.equal(result, false) diff --git a/test/refresh-accounts.test.js b/test/refresh-accounts.test.js index 9803a94..0bec0eb 100644 --- a/test/refresh-accounts.test.js +++ b/test/refresh-accounts.test.js @@ -15,7 +15,7 @@ const node = new Rpc(process.env.NODE_URL ?? '', process.env.API_KEY_NAME) const skip = true describe('refreshing account info', { skip }, async () => { - it('should fetch balance, frontier, and representative', async () => { + test('should fetch balance, frontier, and representative', async () => { const accounts = await wallet.accounts() const account = accounts[0] await account.refresh(node) @@ -41,19 +41,19 @@ describe('refreshing account info', { skip }, async () => { assert.notEqual(account.representative?.address, '') }) - it('should throw when refreshing unopened account', async () => { + test('should throw when refreshing unopened account', async () => { const accounts = await wallet.accounts(0x7fffffff) const account = accounts[0] await assert.rejects(account.refresh(node), { message: 'Account not found' }) }) - it('should throw when referencing invalid account index', async () => { + test('should throw when referencing invalid account index', async () => { await assert.rejects(wallet.accounts(0x80000000), { message: 'Invalid child key index 0x80000000' }) }) - it('should throw with invalid node', async () => { + test('should throw with invalid node', async () => { const invalidNode = new Rpc('http://invalid.com') const accounts = await wallet.accounts() const account = accounts[0] @@ -63,28 +63,28 @@ describe('refreshing account info', { skip }, async () => { }) describe('finding next unopened account', { skip }, async () => { - it('should return correct account from test vector', async () => { + test('should return correct account from test vector', async () => { const account = await wallet.getNextNewAccount(node) assert.ok(account) assert.equal(account.address, NANO_TEST_VECTORS.ADDRESS_1) assert.equal(account.publicKey, NANO_TEST_VECTORS.PUBLIC_1) }) - it('should return successfully for small batch size', async () => { + test('should return successfully for small batch size', async () => { const account = await wallet.getNextNewAccount(node, 1) assert.ok(account) assert.equal(account.address, NANO_TEST_VECTORS.ADDRESS_1) assert.equal(account.publicKey, NANO_TEST_VECTORS.PUBLIC_1) }) - it('should return successfully for large batch size', async () => { + test('should return successfully for large batch size', async () => { const account = await wallet.getNextNewAccount(node, 100) assert.ok(account) assert.equal(account.address, NANO_TEST_VECTORS.ADDRESS_1) assert.equal(account.publicKey, NANO_TEST_VECTORS.PUBLIC_1) }) - it('should throw on invalid node URL', async () => { + test('should throw on invalid node URL', async () => { //@ts-expect-error await assert.rejects(wallet.getNextNewAccount()) //@ts-expect-error @@ -97,7 +97,7 @@ describe('finding next unopened account', { skip }, async () => { await assert.rejects(wallet.getNextNewAccount('foo')) }) - it('should throw on invalid batch size', async () => { + test('should throw on invalid batch size', async () => { //@ts-expect-error await assert.rejects(wallet.getNextNewAccount(node, null)) await assert.rejects(wallet.getNextNewAccount(node, -1)) @@ -111,7 +111,7 @@ describe('finding next unopened account', { skip }, async () => { }) describe('refreshing wallet accounts', { skip }, async () => { - it('should get balance, frontier, and representative for one account', async () => { + test('should get balance, frontier, and representative for one account', async () => { const accounts = await wallet.refresh(node) const account = accounts[0] assert.ok(account instanceof Account) @@ -121,13 +121,13 @@ describe('refreshing wallet accounts', { skip }, async () => { assert.equal(typeof account.frontier, 'string') }) - it('should get balance, frontier, and representative for multiple accounts', async () => { + test('should get balance, frontier, and representative for multiple accounts', async () => { const accounts = await wallet.refresh(node, 0, 2) assert.equal(accounts.length, 1) assert.ok(accounts[0] instanceof Account) }) - it('should handle failure gracefully', async () => { + test('should handle failure gracefully', async () => { await assert.doesNotReject(wallet.refresh(node, 0, 20)) }) }) diff --git a/test/sign-blocks.test.js b/test/sign-blocks.test.js index bdc60b8..d37439c 100644 --- a/test/sign-blocks.test.js +++ b/test/sign-blocks.test.js @@ -9,7 +9,7 @@ import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { SendBlock, ReceiveBlock, ChangeBlock } from '#dist/main.js' describe('valid blocks', async () => { - it('should not allow negative balances', async () => { + test('should not allow negative balances', async () => { assert.throws(() => { const block = new SendBlock( NANO_TEST_VECTORS.ADDRESS_0, @@ -22,7 +22,7 @@ describe('valid blocks', async () => { }, { message: 'Negative balance' }) }) - it('should allow zero balances', async () => { + test('should allow zero balances', async () => { const block = new SendBlock( NANO_TEST_VECTORS.ADDRESS_0, '9007199254740991', @@ -35,7 +35,7 @@ describe('valid blocks', async () => { assert.equal(block.balance, BigInt(0)) }) - it('should subtract balance from SendBlock correctly', async () => { + test('should subtract balance from SendBlock correctly', async () => { const block = new SendBlock( NANO_TEST_VECTORS.ADDRESS_0, '3000000000000000000000000000000', @@ -47,7 +47,7 @@ describe('valid blocks', async () => { assert.equal(block.balance, 1000000000000000000000000000000n) }) - it('should add balance from ReceiveBlock correctly', async () => { + test('should add balance from ReceiveBlock correctly', async () => { const block = new ReceiveBlock( NANO_TEST_VECTORS.ADDRESS_0, '2000000000000000000000000000000', @@ -61,7 +61,7 @@ describe('valid blocks', async () => { }) describe('block signing tests using official test vectors', async () => { - it('should create a valid signature for an open block', async () => { + test('should create a valid signature for an open block', async () => { const block = new ReceiveBlock( NANO_TEST_VECTORS.OPEN_BLOCK.account, '0', @@ -76,7 +76,7 @@ describe('block signing tests using official test vectors', async () => { assert.equal(block.signature, NANO_TEST_VECTORS.OPEN_BLOCK.signature) }) - it('should create a valid signature for a receive block', async () => { + test('should create a valid signature for a receive block', async () => { const block = new ReceiveBlock( NANO_TEST_VECTORS.RECEIVE_BLOCK.account, NANO_TEST_VECTORS.RECEIVE_BLOCK.balance, @@ -91,7 +91,7 @@ describe('block signing tests using official test vectors', async () => { assert.equal(block.signature, NANO_TEST_VECTORS.RECEIVE_BLOCK.signature) }) - it('should create a valid signature for a receive block without work', async () => { + test('should create a valid signature for a receive block without work', async () => { const block = new ReceiveBlock( NANO_TEST_VECTORS.RECEIVE_BLOCK.account, NANO_TEST_VECTORS.RECEIVE_BLOCK.balance, @@ -106,7 +106,7 @@ describe('block signing tests using official test vectors', async () => { assert.equal(block.work, '') }) - it('should create a valid signature for a send block', async () => { + test('should create a valid signature for a send block', async () => { const block = new SendBlock( NANO_TEST_VECTORS.SEND_BLOCK.account, NANO_TEST_VECTORS.SEND_BLOCK.balance, @@ -121,7 +121,7 @@ describe('block signing tests using official test vectors', async () => { assert.equal(block.signature, NANO_TEST_VECTORS.SEND_BLOCK.signature) }) - it('should create a valid signature for a send block without work', async () => { + test('should create a valid signature for a send block without work', async () => { const block = new SendBlock( NANO_TEST_VECTORS.SEND_BLOCK.account, NANO_TEST_VECTORS.SEND_BLOCK.balance, @@ -136,7 +136,7 @@ describe('block signing tests using official test vectors', async () => { assert.equal(block.work, '') }) - it('should create a valid signature for a change rep block', async () => { + test('should create a valid signature for a change rep block', async () => { const work = '0000000000000000' const block = new ChangeBlock( 'nano_3igf8hd4sjshoibbbkeitmgkp1o6ug4xads43j6e4gqkj5xk5o83j8ja9php', @@ -150,7 +150,7 @@ describe('block signing tests using official test vectors', async () => { assert.equal(block.work, work) }) - it('should create a valid signature for a change rep block without work', async () => { + test('should create a valid signature for a change rep block without work', async () => { const block = new ChangeBlock( NANO_TEST_VECTORS.ADDRESS_0, '0', diff --git a/test/tools.test.js b/test/tools.test.js index 925753b..1997210 100644 --- a/test/tools.test.js +++ b/test/tools.test.js @@ -15,79 +15,79 @@ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const rpc = new Rpc(process.env.NODE_URL ?? '', process.env.API_KEY_NAME) describe('unit conversion tests', async () => { - it('should convert nano to raw', async () => { + test('should convert nano to raw', async () => { const result = await Tools.convert('1', 'NANO', 'RAW') assert.equal(result, '1000000000000000000000000000000') }) - it('should convert raw to nano', async () => { + test('should convert raw to nano', async () => { const result = await Tools.convert('1000000000000000000000000000000', 'RAW', 'NANO') assert.equal(result, '1') }) - it('should convert 1 raw to 10^-29 nano', async () => { + test('should convert 1 raw to 10^-29 nano', async () => { const result = await Tools.convert('1', 'RAW', 'NANO') assert.equal(result, '.000000000000000000000000000001') }) - it('should ignore leading and trailing zeros', async () => { + test('should ignore leading and trailing zeros', async () => { const result = await Tools.convert('0011002200.0033004400', 'nano', 'nano') assert.equal(result, '11002200.00330044') }) - it('should convert raw to nyano', async () => { + test('should convert raw to nyano', async () => { const result = await Tools.convert(RAW_MAX, 'RAW', 'NYANO') assert.equal(result, '340282366920938.463463374607431768211455') }) - it('should convert case-insensitive nyano to raw', async () => { + test('should convert case-insensitive nyano to raw', async () => { const result = await Tools.convert('0.000000000000000123456789', 'nYaNo', 'rAw') assert.equal(result, '123456789') }) - it('should convert nano to pico', async () => { + test('should convert nano to pico', async () => { const result = await Tools.convert('123.456', 'nano', 'pico') assert.equal(result, '123456') }) - it('should convert knano to pico', async () => { + test('should convert knano to pico', async () => { const result = await Tools.convert('123.456', 'nano', 'pico') assert.equal(result, '123456') }) - it('should throw if amount exceeds raw max', async () => { + test('should throw if amount exceeds raw max', async () => { await assert.rejects(Tools.convert(RAW_MAX, 'NANO', 'RAW'), { message: 'Amount exceeds Nano limits' }) }) - it('should throw if amount exceeds raw min', async () => { + test('should throw if amount exceeds raw min', async () => { await assert.rejects(Tools.convert('0.1', 'RAW', 'NANO'), { message: 'Amount must be at least 1 raw' }) }) - it('should throw if amount is blank', async () => { + test('should throw if amount is blank', async () => { await assert.rejects(Tools.convert('', 'RAW', 'NANO'), { message: 'Invalid amount' }) }) - it('should throw if amount has non-digit characters', async () => { + test('should throw if amount has non-digit characters', async () => { await assert.rejects(Tools.convert('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'RAW', 'NANO'), { message: 'Invalid amount' }) }) }) describe('signature tests', async () => { - it('should sign data with a single parameter', async () => { + test('should sign data with a single parameter', async () => { const result = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0, 'miro@metsanheimo.fi') assert.equal(result, 'FECB9B084065ADC969904B55A0099C63746B68DF41FECB713244D387EED83A80B9D4907278C5EBC0998A5FC8BA597FBAAABBFCE0ABD2CA2212ACFE788637040C') }) - it('should sign data with multiple parameters', async () => { + test('should sign data with multiple parameters', async () => { const result = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0, 'miro@metsanheimo.fi', 'somePassword') assert.equal(result, 'BB534F9B469AF451B1941FFEF8EE461FC5D284B5D393140900C6E13A65EF08D0AE2BC77131EE182922F66C250C7237A83878160457D5C39A70E55F7FCE925804') }) - it('should verify a signature using the public key', async () => { + test('should verify a signature using the public key', async () => { const result = await Tools.verify(NANO_TEST_VECTORS.PUBLIC_0, 'FECB9B084065ADC969904B55A0099C63746B68DF41FECB713244D387EED83A80B9D4907278C5EBC0998A5FC8BA597FBAAABBFCE0ABD2CA2212ACFE788637040C', 'miro@metsanheimo.fi') assert.equal(result, true) @@ -98,7 +98,7 @@ describe('signature tests', async () => { assert.equal(result3, false) }) - it('should verify a block using the public key', async () => { + test('should verify a block using the public key', async () => { const accounts = await wallet.accounts() const account = accounts[0] const sendBlock = new SendBlock( @@ -114,7 +114,7 @@ describe('signature tests', async () => { assert.equal(valid, true) }) - it('should reject a block using the wrong public key', async () => { + test('should reject a block using the wrong public key', async () => { const accounts = await wallet.accounts() const account = accounts[0] const sendBlock = new SendBlock( @@ -134,13 +134,13 @@ describe('signature tests', async () => { }) describe('sweeper', async () => { - it('throws without required parameters', async () => { + test('throws without required parameters', async () => { //@ts-expect-error await assert.rejects(Tools.sweep(), { message: 'Missing required sweep arguments' }) }) - it('fails gracefully for ineligible accounts', { skip }, async () => { + test('fails gracefully for ineligible accounts', { skip }, async () => { const results = await Tools.sweep(rpc, wallet, NANO_TEST_VECTORS.ADDRESS_1) assert.ok(results) assert.equal(results.length, 1)