// test/protocols/wdk.test.js - WDK Protocol Interface Tests
import test from 'brittle'
import wdk from '../../protocols/wdk.js'
test('wdk protocol - has required interface', t => {
t.is(wdk.name, 'wdk', 'protocol has name')
t.ok(wdk.info, 'protocol has info')
t.is(typeof wdk.init, 'function', 'protocol has init function')
t.is(typeof wdk.getBalance, 'function', 'protocol has getBalance function')
t.is(typeof wdk.send, 'function', 'protocol has send function')
t.is(typeof wdk.receive, 'function', 'protocol has receive function')
t.is(typeof wdk.history, 'function', 'protocol has history function')
})
test('wdk protocol - info metadata', t => {
t.is(wdk.info.displayName, 'Tether WDK', 'has display name')
t.ok(Array.isArray(wdk.info.chains), 'has chains array')
t.ok(wdk.info.chains.includes('bitcoin'), 'supports bitcoin')
t.ok(wdk.info.chains.includes('ethereum'), 'supports ethereum')
t.is(wdk.info.stablecoin, true, 'marked as stablecoin')
})
test('wdk protocol - chain selection', t => {
// Auto-detect chain from address format
t.is(wdk.selectChain('0x1234...'), 'ethereum', 'detects ethereum address')
t.is(wdk.selectChain('bc1q...'), 'bitcoin', 'detects bitcoin bech32')
t.is(wdk.selectChain('tb1q...'), 'bitcoin', 'detects testnet bech32')
t.is(wdk.selectChain('1A1zP1...'), 'bitcoin', 'detects legacy bitcoin')
t.is(wdk.selectChain('unknown'), 'ethereum', 'defaults to ethereum')
})
test('wdk protocol - currency mapping', t => {
t.is(wdk.getCurrency('bitcoin'), 'BTC', 'maps bitcoin to BTC')
t.is(wdk.getCurrency('ethereum'), 'ETH', 'maps ethereum to ETH')
})
test('wdk protocol - balance formatting', t => {
// Bitcoin (satoshis to BTC)
const btcBalance = wdk.formatBalance(100000000n, 'bitcoin')
t.is(btcBalance, '1.00000000', 'formats 1 BTC correctly')
const smallBtc = wdk.formatBalance(1000n, 'bitcoin')
t.is(smallBtc, '0.00001000', 'formats small BTC correctly')
// Ethereum (wei to ETH)
const ethBalance = wdk.formatBalance(1000000000000000000n, 'ethereum')
t.is(ethBalance, '1.000000000000000000', 'formats 1 ETH correctly')
const smallEth = wdk.formatBalance(1000000000000000n, 'ethereum')
t.is(smallEth, '0.001000000000000000', 'formats small ETH correctly')
})