From: Chris Duncan Date: Mon, 8 Sep 2025 04:38:03 +0000 (-0700) Subject: Update account tests to use Map methods. X-Git-Tag: v0.10.5~24^2~6 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=f50ff67865bec57d1fc8b730b1ec8eab5273fbbf;p=libnemo.git Update account tests to use Map methods. --- diff --git a/test/test.derive-accounts.mjs b/test/test.derive-accounts.mjs index bc0cde7..e90d28d 100644 --- a/test/test.derive-accounts.mjs +++ b/test/test.derive-accounts.mjs @@ -29,8 +29,8 @@ await Promise.all([ assert.equal(account.index, 0) const accounts = await wallet.accounts() - assert.exists(accounts[0]) - assert.equal(account, accounts[0]) + assert.exists(accounts.get(0)) + assert.equal(account, accounts.get(0)) await assert.resolves(wallet.destroy()) }) @@ -41,12 +41,18 @@ await Promise.all([ const accounts = await wallet.accounts(1, 2) assert.equal(accounts.size, 2) - assert.equal(accounts[1].publicKey, NANO_TEST_VECTORS.PUBLIC_1) - assert.equal(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_1) - assert.equal(accounts[1].index, 1) - assert.equal(accounts[2].publicKey, NANO_TEST_VECTORS.PUBLIC_2) - assert.equal(accounts[2].address, NANO_TEST_VECTORS.ADDRESS_2) - assert.equal(accounts[2].index, 2) + + const account1 = accounts.get(1) + assert.exists(account1) + assert.equal(account1.publicKey, NANO_TEST_VECTORS.PUBLIC_1) + assert.equal(account1.address, NANO_TEST_VECTORS.ADDRESS_1) + assert.equal(account1.index, 1) + + const account2 = accounts.get(2) + assert.exists(account2) + assert.equal(account2.publicKey, NANO_TEST_VECTORS.PUBLIC_2) + assert.equal(account2.address, NANO_TEST_VECTORS.ADDRESS_2) + assert.equal(account2.index, 2) await assert.resolves(wallet.destroy()) }) @@ -58,7 +64,7 @@ await Promise.all([ assert.equal(accounts.size, 0x10) for (let i = 0x70000000; i < 0x7000000f; i++) { - const a = accounts[i] + const a = accounts.get(i) assert.exists(a) assert.equal(a.index, i) assert.exists(a.address) @@ -81,10 +87,11 @@ await Promise.all([ assert.equal(account.index, 1) const accounts = await wallet.accounts(1) - assert.exists(accounts[1]) - assert.exists(accounts[1].publicKey) - assert.exists(accounts[1].address) - assert.equal(account, accounts[1]) + const account1 = accounts.get(1) + assert.exists(account1) + assert.exists(account1.publicKey) + assert.exists(account1.address) + assert.equal(account, account1) await assert.resolves(wallet.destroy()) }) @@ -95,12 +102,18 @@ await Promise.all([ const accounts = await wallet.accounts(2, 3) assert.equal(accounts.size, 2) - assert.exists(accounts[2].publicKey) - assert.exists(accounts[2].address) - assert.equal(accounts[2].index, 2) - assert.exists(accounts[3].publicKey) - assert.exists(accounts[3].address) - assert.equal(accounts[3].index, 3) + + const account2 = accounts.get(2) + assert.exists(account2) + assert.exists(account2.publicKey) + assert.exists(account2.address) + assert.equal(account2.index, 2) + + const account3 = accounts.get(3) + assert.exists(account3) + assert.exists(account3.publicKey) + assert.exists(account3.address) + assert.equal(account3.index, 3) await assert.resolves(wallet.destroy()) }) @@ -112,7 +125,7 @@ await Promise.all([ assert.equal(accounts.size, 0x10) for (let i = 0x70000000; i < 0x7000000f; i++) { - const a = accounts[i] + const a = accounts.get(i) assert.exists(a) assert.equal(a.index, i) assert.exists(a.address) diff --git a/test/test.import-wallet.mjs b/test/test.import-wallet.mjs index b5fdf77..3fd9f57 100644 --- a/test/test.import-wallet.mjs +++ b/test/test.import-wallet.mjs @@ -117,9 +117,10 @@ await Promise.all([ assert.equal(accounts.size, 4) for (let i = 0; i < accounts.size; i++) { - assert.exists(accounts[i]) - assert.exists(accounts[i].address) - assert.exists(accounts[i].publicKey) + const account = accounts.get(i) + assert.exists(account) + assert.exists(account.address) + assert.exists(account.publicKey) } await assert.resolves(wallet.destroy()) @@ -139,9 +140,10 @@ await Promise.all([ assert.equal(accounts.size, 4) for (let i = 0; i < accounts.size; i++) { - assert.exists(accounts[i]) - assert.exists(accounts[i].address) - assert.exists(accounts[i].publicKey) + const account = accounts.get(i) + assert.exists(account) + assert.exists(account.address) + assert.exists(account.publicKey) } await assert.resolves(wallet.destroy()) @@ -155,13 +157,17 @@ await Promise.all([ assert.ok(await wallet.verify(TREZOR_TEST_VECTORS.MNEMONIC_1)) assert.ok(await wallet.verify(TREZOR_TEST_VECTORS.ENTROPY_1)) - assert.ok(accounts[0] instanceof Account) - assert.equal(accounts[0].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_0) - assert.equal(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_0) - - assert.ok(accounts[1] instanceof Account) - assert.equal(accounts[1].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_1) - assert.equal(accounts[1].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1) + const account0 = accounts.get(0) + assert.exists(account0) + assert.ok(account0 instanceof Account) + assert.equal(account0.publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_0) + assert.equal(account0.address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_0) + + const account1 = accounts.get(1) + assert.exists(account1) + assert.ok(account1 instanceof Account) + assert.equal(account1.publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_1) + assert.equal(account1.address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1) await assert.resolves(wallet.destroy()) }) diff --git a/test/test.refresh-accounts.mjs b/test/test.refresh-accounts.mjs index 6544340..56d3f4e 100644 --- a/test/test.refresh-accounts.mjs +++ b/test/test.refresh-accounts.mjs @@ -168,7 +168,7 @@ await Promise.all([ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.refresh(rpc) - const account = accounts[0] + const account = accounts.get(0) assert.ok(account instanceof Account) assert.equal(typeof account.balance, 'bigint') @@ -192,9 +192,9 @@ await Promise.all([ assert.equal(account.balance, 0n) assert.equal(account.receivable, 0n) } - assert.equal(accounts[0].address, 'nano_1pu7p5n3ghq1i1p4rhmek41f5add1uh34xpb94nkbxe8g4a6x1p69emk8y1d') - assert.equal(accounts[1].address, 'nano_3phqgrqbso99xojkb1bijmfryo7dy1k38ep1o3k3yrhb7rqu1h1k47yu78gz') - assert.equal(accounts[2].address, 'nano_3b5fnnerfrkt4me4wepqeqggwtfsxu8fai4n473iu6gxprfq4xd8pk9gh1dg') + assert.equal(accounts.get(0)?.address, 'nano_1pu7p5n3ghq1i1p4rhmek41f5add1uh34xpb94nkbxe8g4a6x1p69emk8y1d') + assert.equal(accounts.get(1)?.address, 'nano_3phqgrqbso99xojkb1bijmfryo7dy1k38ep1o3k3yrhb7rqu1h1k47yu78gz') + assert.equal(accounts.get(2)?.address, 'nano_3b5fnnerfrkt4me4wepqeqggwtfsxu8fai4n473iu6gxprfq4xd8pk9gh1dg') await assert.resolves(wallet.destroy()) })