github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/lib/btc/funcs_test.go (about) 1 package btc 2 3 import ( 4 "testing" 5 ) 6 7 func TestParseAmount(t *testing.T) { 8 var tv = []struct { 9 af string 10 ai uint64 11 } { 12 {"84.3449", 8434490000}, 13 {"84.3448", 8434480000}, 14 {"84.3447", 8434470000}, 15 {"84.3446", 8434460000}, 16 {"84.3445", 8434450000}, 17 {"84.3444", 8434440000}, 18 {"84.3443", 8434430000}, 19 {"84.3442", 8434420000}, 20 {"84.3441", 8434410000}, 21 {"84.3440", 8434400000}, 22 {"84.3439", 8434390000}, 23 {"0.99999990", 99999990}, 24 {"0.99999991", 99999991}, 25 {"0.99999992", 99999992}, 26 {"0.99999993", 99999993}, 27 {"0.99999994", 99999994}, 28 {"0.99999995", 99999995}, 29 {"0.99999996", 99999996}, 30 {"0.99999997", 99999997}, 31 {"0.99999998", 99999998}, 32 {"0.99999999", 99999999}, 33 {"1.00000001", 100000001}, 34 {"1.00000002", 100000002}, 35 {"1.00000003", 100000003}, 36 {"1.00000004", 100000004}, 37 {"1.00000005", 100000005}, 38 {"1.00000006", 100000006}, 39 {"1.00000007", 100000007}, 40 {"1000000.0", 100000000000000}, 41 {"100000.0", 10000000000000}, 42 {"10000.0", 1000000000000}, 43 {"1000.0", 100000000000}, 44 {"100.0", 10000000000}, 45 {"10.0", 1000000000}, 46 {"1.0", 100000000}, 47 {"0.1", 10000000}, 48 {"0.01", 1000000}, 49 {"0.001", 100000}, 50 {"0.00001", 1000}, 51 {"0.000001", 100}, 52 {"0.0000001", 10}, 53 {"0.00000001", 1}, 54 } 55 for i := range tv { 56 res, _ := StringToSatoshis(tv[i].af) 57 if res!=tv[i].ai { 58 t.Error("Mismatch at index", i, tv[i].af, res, tv[i].ai) 59 } 60 } 61 }