lnd/lnwire/msat_test.go
Oli 8047149c6a
multi: upgrade to btcd v2 modules
Migrate all btcd dependencies to the new per-package v2 modules (wire/v2,
txscript/v2, chaincfg/v2, chainhash/v2, btcutil/v2, psbt/v2, btcec/v2)
introduced by btcd v0.26.0, and pin the tagged ecosystem versions:
btcwallet v0.17.0, neutrino v0.18.0 and lightning-onion v1.4.0.

The bulk of the import rewrite was produced by the scripted diff from
https://github.com/btcsuite/btcd/pull/2547 (followed by 'make rpc'). The
address symbols that moved out of btcutil into the new address package
are imported as btcaddr where a local "address" variable would otherwise
shadow them. The go.mod/go.sum updates and the remaining manual
compilation fixes are folded into this single commit so it builds on its
own (the migration was previously split into a reproducible scripted-diff
plus follow-ups, intended to be squashed on merge).
2026-06-24 10:58:36 -07:00

77 lines
1.3 KiB
Go

package lnwire
import (
"testing"
"github.com/btcsuite/btcd/btcutil/v2"
)
func TestMilliSatoshiConversion(t *testing.T) {
t.Parallel()
testCases := []struct {
mSatAmount MilliSatoshi
satAmount btcutil.Amount
btcAmount float64
}{
{
mSatAmount: 0,
satAmount: 0,
btcAmount: 0,
},
{
mSatAmount: 10,
satAmount: 0,
btcAmount: 0,
},
{
mSatAmount: 999,
satAmount: 0,
btcAmount: 0,
},
{
mSatAmount: 1000,
satAmount: 1,
btcAmount: 1e-8,
},
{
mSatAmount: 10000,
satAmount: 10,
btcAmount: 0.00000010,
},
{
mSatAmount: 100000000000,
satAmount: 100000000,
btcAmount: 1,
},
{
mSatAmount: 2500000000000,
satAmount: 2500000000,
btcAmount: 25,
},
{
mSatAmount: 5000000000000,
satAmount: 5000000000,
btcAmount: 50,
},
{
mSatAmount: 21 * 1e6 * 1e8 * 1e3,
satAmount: 21 * 1e6 * 1e8,
btcAmount: 21 * 1e6,
},
}
for i, test := range testCases {
if test.mSatAmount.ToSatoshis() != test.satAmount {
t.Fatalf("test #%v: wrong sat amount, expected %v "+
"got %v", i, int64(test.satAmount),
int64(test.mSatAmount.ToSatoshis()))
}
if test.mSatAmount.ToBTC() != test.btcAmount {
t.Fatalf("test #%v: wrong btc amount, expected %v "+
"got %v", i, test.btcAmount,
test.mSatAmount.ToBTC())
}
}
}