// test/lib/wallet-context.test.js - Wallet Context Tests
import test from 'brittle'
import WalletContext from '../../lib/wallet-context.js'
import os from 'os'
import path from 'path'
import testTmp from 'test-tmp'
const { tmpdir } = testTmp
test('wallet context - initialization', async t => {
const tmp = await tmpdir(t)
const config = {
storagePath: tmp,
protocols: ['wdk']
}
const context = new WalletContext(config)
t.ok(context, 'context created')
t.is(context.config, config, 'config stored')
t.ok(typeof context.protocols === 'object', 'protocols object exists')
t.is(context.identity, null, 'identity null before init')
t.is(context.store, null, 'store null before init')
t.is(context.db, null, 'db null before init')
t.is(context.txHistory, null, 'txHistory null before init')
await context.close()
})
test('wallet context - resolveStoragePath', async t => {
const config = { storagePath: '~/.hyper-wallet/storage' }
const context = new WalletContext(config)
const resolved = context.resolveStoragePath('~/.hyper-wallet/storage')
const expected = path.join(os.homedir(), '.hyper-wallet/storage')
t.is(resolved, expected, 'expands ~ correctly')
const absolute = context.resolveStoragePath('/absolute/path')
t.is(absolute, '/absolute/path', 'keeps absolute paths')
await context.close()
})
test('wallet context - init with mnemonic', async t => {
const tmp = await tmpdir(t)
const config = {
storagePath: tmp,
protocols: ['wdk']
}
const context = new WalletContext(config)
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
await context.init(mnemonic)
t.ok(context.identity, 'identity initialized')
t.ok(context.store, 'store initialized')
t.ok(context.db, 'db initialized')
t.ok(context.txHistory, 'txHistory initialized')
await context.close()
})