github.com/decred/dcrlnd@v0.7.6/lnwire/mat_test.go (about)

     1  package lnwire
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/decred/dcrd/dcrutil/v4"
     7  )
     8  
     9  func TestMilliAtomConversion(t *testing.T) {
    10  	t.Parallel()
    11  
    12  	testCases := []struct {
    13  		mAtAmount MilliAtom
    14  		atAmount  dcrutil.Amount
    15  		dcrAmount float64
    16  	}{
    17  		{
    18  			mAtAmount: 0,
    19  			atAmount:  0,
    20  			dcrAmount: 0,
    21  		},
    22  		{
    23  			mAtAmount: 10,
    24  			atAmount:  0,
    25  			dcrAmount: 0,
    26  		},
    27  		{
    28  			mAtAmount: 999,
    29  			atAmount:  0,
    30  			dcrAmount: 0,
    31  		},
    32  		{
    33  			mAtAmount: 1000,
    34  			atAmount:  1,
    35  			dcrAmount: 1e-8,
    36  		},
    37  		{
    38  			mAtAmount: 10000,
    39  			atAmount:  10,
    40  			dcrAmount: 0.00000010,
    41  		},
    42  		{
    43  			mAtAmount: 100000000000,
    44  			atAmount:  100000000,
    45  			dcrAmount: 1,
    46  		},
    47  		{
    48  			mAtAmount: 2500000000000,
    49  			atAmount:  2500000000,
    50  			dcrAmount: 25,
    51  		},
    52  		{
    53  			mAtAmount: 5000000000000,
    54  			atAmount:  5000000000,
    55  			dcrAmount: 50,
    56  		},
    57  		{
    58  			mAtAmount: 21 * 1e6 * 1e8 * 1e3,
    59  			atAmount:  21 * 1e6 * 1e8,
    60  			dcrAmount: 21 * 1e6,
    61  		},
    62  	}
    63  
    64  	for i, test := range testCases {
    65  		if test.mAtAmount.ToAtoms() != test.atAmount {
    66  			t.Fatalf("test #%v: wrong atom amount, expected %v "+
    67  				"got %v", i, int64(test.atAmount),
    68  				int64(test.mAtAmount.ToAtoms()))
    69  		}
    70  		if test.mAtAmount.ToCoin() != test.dcrAmount {
    71  			t.Fatalf("test #%v: wrong dcr amount, expected %v "+
    72  				"got %v", i, test.dcrAmount,
    73  				test.mAtAmount.ToCoin())
    74  		}
    75  	}
    76  }