import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '#dist/main.js'\r
\r
describe('creating a new wallet', async () => {\r
- it('BIP-44 wallet with random entropy', async () => {\r
+ test('BIP-44 wallet with random entropy', async () => {\r
const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
assert.ok(/[A-Fa-f0-9]{32,64}/.test(wallet.seed))\r
})\r
\r
- it('BLAKE2b wallet with random entropy', async () => {\r
+ test('BLAKE2b wallet with random entropy', async () => {\r
const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
assert.ok(/[A-Fa-f0-9]{32,64}/.test(wallet.seed))\r
})\r
\r
- it('BIP-44 replace invalid salt with empty string', async () => {\r
+ test('BIP-44 replace invalid salt with empty string', async () => {\r
const invalidArgs = [null, true, false, 0, 1, 2, { "foo": "bar" }]\r
for (const arg of invalidArgs) {\r
//@ts-expect-error\r
}\r
})\r
\r
- it('fail when using new', async () => {\r
+ test('fail when using new', async () => {\r
//@ts-expect-error\r
assert.throws(() => new Bip44Wallet())\r
//@ts-expect-error\r
assert.throws(() => new LedgerWallet())\r
})\r
\r
- it('fail without a password', async () => {\r
+ test('fail without a password', async () => {\r
//@ts-expect-error\r
await assert.rejects(Bip44Wallet.create())\r
//@ts-expect-error\r
await assert.rejects(Blake2bWallet.create())\r
})\r
\r
- it('connect to ledger', { skip: true }, async () => {\r
+ test('connect to ledger', { skip: true }, async () => {\r
const wallet = await LedgerWallet.create()\r
assert.ok(wallet)\r
})\r
const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
- it('should derive the first account from the given BIP-44 seed', async () => {\r
+ test('should derive the first account from the given BIP-44 seed', async () => {\r
const accounts = await wallet.accounts()\r
\r
assert.equal(accounts.length, 1)\r
assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
})\r
\r
- it('should derive low indexed accounts from the given BIP-44 seed', async () => {\r
+ test('should derive low indexed accounts from the given BIP-44 seed', async () => {\r
const accounts = await wallet.accounts(1, 2)\r
\r
assert.equal(accounts.length, 2)\r
assert.equal(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_2)\r
})\r
\r
- it('should derive high indexed accounts from the given seed', async () => {\r
+ test('should derive high indexed accounts from the given seed', async () => {\r
const accounts = await wallet.accounts(0x70000000, 0x700000ff)\r
\r
assert.equal(accounts.length, 0x100)\r
}\r
})\r
\r
- it('should derive accounts for a BLAKE2b wallet', async () => {\r
+ test('should derive accounts for a BLAKE2b wallet', async () => {\r
const bwallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)\r
await bwallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const lowAccounts = await bwallet.accounts(0, 2)\r
describe('Ledger device accounts', { skip: true }, async () => {\r
const wallet = await LedgerWallet.create()\r
\r
- it('should fetch the first account from a Ledger device', async () => {\r
+ test('should fetch the first account from a Ledger device', async () => {\r
const accounts = await wallet.accounts()\r
\r
assert.equal(accounts.length, 1)\r
import { Account, Bip44Wallet, Blake2bWallet } from '#dist/main.js'\r
\r
describe('import wallet with test vectors test', () => {\r
- it('should successfully import a wallet with the official Nano test vectors mnemonic', async () => {\r
+ test('should successfully import a wallet with the official Nano test vectors mnemonic', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts()\r
assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
})\r
\r
- it('should successfully import a wallet with the checksum starting with a zero', async () => {\r
+ test('should successfully import a wallet with the checksum starting with a zero', async () => {\r
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')\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
assert.equal(wallet.seed, 'F665F804E5907985455D1E5A7AD344843A2ED4179A7E06EEF263DE925FF6F4C0991B0A9344FCEE939FE0F1B1841B8C9B20FEACF6B954B74B2D26A01906B758E2')\r
})\r
\r
- it('should successfully import a wallet with a 12-word phrase', async () => {\r
+ test('should successfully import a wallet with a 12-word phrase', async () => {\r
const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_0)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts()\r
assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_0)\r
})\r
\r
- it('should successfully import a wallet with a 15-word phrase', async () => {\r
+ test('should successfully import a wallet with a 15-word phrase', async () => {\r
const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts()\r
assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_1)\r
})\r
\r
- it('should successfully import a wallet with a 18-word phrase', async () => {\r
+ test('should successfully import a wallet with a 18-word phrase', async () => {\r
const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_2)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts()\r
assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_2)\r
})\r
\r
- it('should successfully import a wallet with a 21-word phrase', async () => {\r
+ test('should successfully import a wallet with a 21-word phrase', async () => {\r
const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_3)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts()\r
assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_3)\r
})\r
\r
- it('should successfully import a wallet with the official Nano test vectors seed', async () => {\r
+ test('should successfully import a wallet with the official Nano test vectors seed', async () => {\r
const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts()\r
assert.equal(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
})\r
\r
- it('should successfully import a BIP-44 wallet with the zero seed', async () => {\r
+ test('should successfully import a BIP-44 wallet with the zero seed', async () => {\r
const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0, TREZOR_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(0, 3)\r
}\r
})\r
\r
- it('should successfully import a BLAKE2b wallet with the zero seed', async () => {\r
+ test('should successfully import a BLAKE2b wallet with the zero seed', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(0, 3)\r
}\r
})\r
\r
- it('should successfully import a BLAKE2b wallet with Trezor test vectors', async () => {\r
+ test('should successfully import a BLAKE2b wallet with Trezor test vectors', async () => {\r
const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(0, 1)\r
assert.equal(accounts[1].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1)\r
})\r
\r
- it('should get identical BLAKE2b wallets when created with a seed versus with its derived mnemonic', async () => {\r
+ test('should get identical BLAKE2b wallets when created with a seed versus with its derived mnemonic', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_2)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const walletAccounts = await wallet.accounts()\r
assert.equal(importedAccount.publicKey, walletAccount.publicKey)\r
})\r
\r
- it('should get identical BLAKE2b wallets when created with max entropy value', async () => {\r
+ test('should get identical BLAKE2b wallets when created with max entropy value', async () => {\r
const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_3)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts()\r
})\r
\r
describe('invalid wallet', async () => {\r
- it('throw when given invalid entropy', async () => {\r
+ test('throw when given invalid entropy', async () => {\r
assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C797'))\r
assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C79701'))\r
assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0.replaceAll(/./g, 'x')))\r
})\r
\r
- it('should throw when given a seed with an invalid length', async () => {\r
+ test('should throw when given a seed with an invalid length', async () => {\r
await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED + 'f'),\r
{ message: `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length + 1}-character string.` })\r
await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED.slice(0, -1)),\r
{ message: `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length - 1}-character string.` })\r
})\r
\r
- it('should throw when given a seed containing non-hex characters', async () => {\r
+ test('should throw when given a seed containing non-hex characters', async () => {\r
await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.SEED_0.replace(/./, 'g')),\r
{ message: 'Seed contains invalid hexadecimal characters.' })\r
await assert.rejects(Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1.replace(/./, 'g')),\r
})\r
\r
describe('import from storage', async () => {\r
- it('should retrieve a Bip44Wallet from storage using an ID', async () => {\r
+ test('should retrieve a Bip44Wallet from storage using an ID', async () => {\r
const id = (await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)).id\r
const wallet = await Bip44Wallet.restore(id)\r
\r
assert.equal(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
})\r
\r
- it('should retrieve a Blake2bWallet from storage using an ID', async () => {\r
+ test('should retrieve a Blake2bWallet from storage using an ID', async () => {\r
const id = (await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)).id\r
const wallet = await Blake2bWallet.restore(id)\r
\r
import { Bip44Wallet, Blake2bWallet } from '#dist/main.js'\r
\r
describe('locking and unlocking a Bip44Wallet', async () => {\r
- it('should succeed with a password', async () => {\r
+ test('should succeed with a password', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
\r
assert.ok('mnemonic' in wallet)\r
assert.equal(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
})\r
\r
- it('should succeed with a random CryptoKey', async () => {\r
+ test('should succeed with a random CryptoKey', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
assert.equal(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
})\r
\r
- it('should fail to unlock with different passwords', async () => {\r
+ test('should fail to unlock with different passwords', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const lockResult = await wallet.lock(TREZOR_TEST_VECTORS.PASSWORD)\r
assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
})\r
\r
- it('should fail to unlock with different keys', async () => {\r
+ test('should fail to unlock with different keys', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const rightKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
})\r
\r
- it('should fail to unlock with different valid inputs', async () => {\r
+ test('should fail to unlock with different valid inputs', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
\r
assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
})\r
\r
- it('should fail with no input', async () => {\r
+ test('should fail with no input', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
})\r
\r
- it('should fail with invalid input', async () => {\r
+ test('should fail with invalid input', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
})\r
\r
describe('locking and unlocking a Blake2bWallet', async () => {\r
- it('should succeed with a password', async () => {\r
+ test('should succeed with a password', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
\r
assert.ok('mnemonic' in wallet)\r
assert.equal(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_0)\r
})\r
\r
- it('should succeed with a random CryptoKey', async () => {\r
+ test('should succeed with a random CryptoKey', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
assert.equal(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1)\r
})\r
\r
- it('should fail to unlock with different passwords', async () => {\r
+ test('should fail to unlock with different passwords', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
\r
await assert.rejects(wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' })\r
assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1)\r
})\r
\r
- it('should fail to unlock with different keys', async () => {\r
+ test('should fail to unlock with different keys', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const rightKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1)\r
})\r
\r
- it('should fail to unlock with different valid inputs', async () => {\r
+ test('should fail to unlock with different valid inputs', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
\r
assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1)\r
})\r
\r
- it('should fail with no input', async () => {\r
+ test('should fail with no input', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1)\r
})\r
\r
- it('should fail with invalid input', async () => {\r
+ test('should fail with invalid input', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
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)
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)
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)
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)
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
})
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'))
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))
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)
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)
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]
})
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
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))
})
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)
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))
})
})
import { SendBlock, ReceiveBlock, ChangeBlock } from '#dist/main.js'\r
\r
describe('valid blocks', async () => {\r
- it('should not allow negative balances', async () => {\r
+ test('should not allow negative balances', async () => {\r
assert.throws(() => {\r
const block = new SendBlock(\r
NANO_TEST_VECTORS.ADDRESS_0,\r
}, { message: 'Negative balance' })\r
})\r
\r
- it('should allow zero balances', async () => {\r
+ test('should allow zero balances', async () => {\r
const block = new SendBlock(\r
NANO_TEST_VECTORS.ADDRESS_0,\r
'9007199254740991',\r
assert.equal(block.balance, BigInt(0))\r
})\r
\r
- it('should subtract balance from SendBlock correctly', async () => {\r
+ test('should subtract balance from SendBlock correctly', async () => {\r
const block = new SendBlock(\r
NANO_TEST_VECTORS.ADDRESS_0,\r
'3000000000000000000000000000000',\r
assert.equal(block.balance, 1000000000000000000000000000000n)\r
})\r
\r
- it('should add balance from ReceiveBlock correctly', async () => {\r
+ test('should add balance from ReceiveBlock correctly', async () => {\r
const block = new ReceiveBlock(\r
NANO_TEST_VECTORS.ADDRESS_0,\r
'2000000000000000000000000000000',\r
})\r
\r
describe('block signing tests using official test vectors', async () => {\r
- it('should create a valid signature for an open block', async () => {\r
+ test('should create a valid signature for an open block', async () => {\r
const block = new ReceiveBlock(\r
NANO_TEST_VECTORS.OPEN_BLOCK.account,\r
'0',\r
assert.equal(block.signature, NANO_TEST_VECTORS.OPEN_BLOCK.signature)\r
})\r
\r
- it('should create a valid signature for a receive block', async () => {\r
+ test('should create a valid signature for a receive block', async () => {\r
const block = new ReceiveBlock(\r
NANO_TEST_VECTORS.RECEIVE_BLOCK.account,\r
NANO_TEST_VECTORS.RECEIVE_BLOCK.balance,\r
assert.equal(block.signature, NANO_TEST_VECTORS.RECEIVE_BLOCK.signature)\r
})\r
\r
- it('should create a valid signature for a receive block without work', async () => {\r
+ test('should create a valid signature for a receive block without work', async () => {\r
const block = new ReceiveBlock(\r
NANO_TEST_VECTORS.RECEIVE_BLOCK.account,\r
NANO_TEST_VECTORS.RECEIVE_BLOCK.balance,\r
assert.equal(block.work, '')\r
})\r
\r
- it('should create a valid signature for a send block', async () => {\r
+ test('should create a valid signature for a send block', async () => {\r
const block = new SendBlock(\r
NANO_TEST_VECTORS.SEND_BLOCK.account,\r
NANO_TEST_VECTORS.SEND_BLOCK.balance,\r
assert.equal(block.signature, NANO_TEST_VECTORS.SEND_BLOCK.signature)\r
})\r
\r
- it('should create a valid signature for a send block without work', async () => {\r
+ test('should create a valid signature for a send block without work', async () => {\r
const block = new SendBlock(\r
NANO_TEST_VECTORS.SEND_BLOCK.account,\r
NANO_TEST_VECTORS.SEND_BLOCK.balance,\r
assert.equal(block.work, '')\r
})\r
\r
- it('should create a valid signature for a change rep block', async () => {\r
+ test('should create a valid signature for a change rep block', async () => {\r
const work = '0000000000000000'\r
const block = new ChangeBlock(\r
'nano_3igf8hd4sjshoibbbkeitmgkp1o6ug4xads43j6e4gqkj5xk5o83j8ja9php',\r
assert.equal(block.work, work)\r
})\r
\r
- it('should create a valid signature for a change rep block without work', async () => {\r
+ test('should create a valid signature for a change rep block without work', async () => {\r
const block = new ChangeBlock(\r
NANO_TEST_VECTORS.ADDRESS_0,\r
'0',\r
const rpc = new Rpc(process.env.NODE_URL ?? '', process.env.API_KEY_NAME)\r
\r
describe('unit conversion tests', async () => {\r
- it('should convert nano to raw', async () => {\r
+ test('should convert nano to raw', async () => {\r
const result = await Tools.convert('1', 'NANO', 'RAW')\r
assert.equal(result, '1000000000000000000000000000000')\r
})\r
\r
- it('should convert raw to nano', async () => {\r
+ test('should convert raw to nano', async () => {\r
const result = await Tools.convert('1000000000000000000000000000000', 'RAW', 'NANO')\r
assert.equal(result, '1')\r
})\r
\r
- it('should convert 1 raw to 10^-29 nano', async () => {\r
+ test('should convert 1 raw to 10^-29 nano', async () => {\r
const result = await Tools.convert('1', 'RAW', 'NANO')\r
assert.equal(result, '.000000000000000000000000000001')\r
})\r
\r
- it('should ignore leading and trailing zeros', async () => {\r
+ test('should ignore leading and trailing zeros', async () => {\r
const result = await Tools.convert('0011002200.0033004400', 'nano', 'nano')\r
assert.equal(result, '11002200.00330044')\r
})\r
\r
- it('should convert raw to nyano', async () => {\r
+ test('should convert raw to nyano', async () => {\r
const result = await Tools.convert(RAW_MAX, 'RAW', 'NYANO')\r
assert.equal(result, '340282366920938.463463374607431768211455')\r
})\r
\r
- it('should convert case-insensitive nyano to raw', async () => {\r
+ test('should convert case-insensitive nyano to raw', async () => {\r
const result = await Tools.convert('0.000000000000000123456789', 'nYaNo', 'rAw')\r
assert.equal(result, '123456789')\r
})\r
\r
- it('should convert nano to pico', async () => {\r
+ test('should convert nano to pico', async () => {\r
const result = await Tools.convert('123.456', 'nano', 'pico')\r
assert.equal(result, '123456')\r
})\r
\r
- it('should convert knano to pico', async () => {\r
+ test('should convert knano to pico', async () => {\r
const result = await Tools.convert('123.456', 'nano', 'pico')\r
assert.equal(result, '123456')\r
})\r
\r
- it('should throw if amount exceeds raw max', async () => {\r
+ test('should throw if amount exceeds raw max', async () => {\r
await assert.rejects(Tools.convert(RAW_MAX, 'NANO', 'RAW'),\r
{ message: 'Amount exceeds Nano limits' })\r
})\r
\r
- it('should throw if amount exceeds raw min', async () => {\r
+ test('should throw if amount exceeds raw min', async () => {\r
await assert.rejects(Tools.convert('0.1', 'RAW', 'NANO'),\r
{ message: 'Amount must be at least 1 raw' })\r
})\r
\r
- it('should throw if amount is blank', async () => {\r
+ test('should throw if amount is blank', async () => {\r
await assert.rejects(Tools.convert('', 'RAW', 'NANO'),\r
{ message: 'Invalid amount' })\r
})\r
\r
- it('should throw if amount has non-digit characters', async () => {\r
+ test('should throw if amount has non-digit characters', async () => {\r
await assert.rejects(Tools.convert('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'RAW', 'NANO'),\r
{ message: 'Invalid amount' })\r
})\r
})\r
\r
describe('signature tests', async () => {\r
- it('should sign data with a single parameter', async () => {\r
+ test('should sign data with a single parameter', async () => {\r
const result = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0, 'miro@metsanheimo.fi')\r
assert.equal(result, 'FECB9B084065ADC969904B55A0099C63746B68DF41FECB713244D387EED83A80B9D4907278C5EBC0998A5FC8BA597FBAAABBFCE0ABD2CA2212ACFE788637040C')\r
})\r
\r
- it('should sign data with multiple parameters', async () => {\r
+ test('should sign data with multiple parameters', async () => {\r
const result = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0, 'miro@metsanheimo.fi', 'somePassword')\r
assert.equal(result, 'BB534F9B469AF451B1941FFEF8EE461FC5D284B5D393140900C6E13A65EF08D0AE2BC77131EE182922F66C250C7237A83878160457D5C39A70E55F7FCE925804')\r
})\r
\r
- it('should verify a signature using the public key', async () => {\r
+ test('should verify a signature using the public key', async () => {\r
const result = await Tools.verify(NANO_TEST_VECTORS.PUBLIC_0, 'FECB9B084065ADC969904B55A0099C63746B68DF41FECB713244D387EED83A80B9D4907278C5EBC0998A5FC8BA597FBAAABBFCE0ABD2CA2212ACFE788637040C', 'miro@metsanheimo.fi')\r
assert.equal(result, true)\r
\r
assert.equal(result3, false)\r
})\r
\r
- it('should verify a block using the public key', async () => {\r
+ test('should verify a block using the public key', async () => {\r
const accounts = await wallet.accounts()\r
const account = accounts[0]\r
const sendBlock = new SendBlock(\r
assert.equal(valid, true)\r
})\r
\r
- it('should reject a block using the wrong public key', async () => {\r
+ test('should reject a block using the wrong public key', async () => {\r
const accounts = await wallet.accounts()\r
const account = accounts[0]\r
const sendBlock = new SendBlock(\r
})\r
\r
describe('sweeper', async () => {\r
- it('throws without required parameters', async () => {\r
+ test('throws without required parameters', async () => {\r
//@ts-expect-error\r
await assert.rejects(Tools.sweep(),\r
{ message: 'Missing required sweep arguments' })\r
})\r
\r
- it('fails gracefully for ineligible accounts', { skip }, async () => {\r
+ test('fails gracefully for ineligible accounts', { skip }, async () => {\r
const results = await Tools.sweep(rpc, wallet, NANO_TEST_VECTORS.ADDRESS_1)\r
assert.ok(results)\r
assert.equal(results.length, 1)\r