github.com/bchainhub/blockbook@v0.3.2/bchain/coins/flo/floparser_test.go (about) 1 // +build unittest 2 3 package flo 4 5 import ( 6 "blockbook/bchain/coins/btc" 7 "encoding/hex" 8 "os" 9 "reflect" 10 "testing" 11 12 "github.com/martinboehm/btcutil/chaincfg" 13 ) 14 15 func TestMain(m *testing.M) { 16 c := m.Run() 17 chaincfg.ResetParams() 18 os.Exit(c) 19 } 20 21 func Test_GetAddrDescFromAddress_Testnet(t *testing.T) { 22 type args struct { 23 address string 24 } 25 tests := []struct { 26 name string 27 args args 28 want string 29 wantErr bool 30 }{ 31 { 32 name: "P2PKH1", 33 args: args{address: "oX8YUMFwRhQdqGvuVGpLJz8BcYmM87e9ee"}, 34 want: "76a9149c708c27ce34ead174a7a9b4f47afafb3d906d0d88ac", 35 wantErr: false, 36 }, 37 } 38 parser := NewFloParser(GetChainParams("test"), &btc.Configuration{}) 39 40 for _, tt := range tests { 41 t.Run(tt.name, func(t *testing.T) { 42 got, err := parser.GetAddrDescFromAddress(tt.args.address) 43 if (err != nil) != tt.wantErr { 44 t.Errorf("GetAddrDescFromAddress() error = %v, wantErr %v", err, tt.wantErr) 45 return 46 } 47 h := hex.EncodeToString(got) 48 if !reflect.DeepEqual(h, tt.want) { 49 t.Errorf("GetAddrDescFromAddress() = %v, want %v", h, tt.want) 50 } 51 }) 52 } 53 } 54 55 func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) { 56 type args struct { 57 address string 58 } 59 tests := []struct { 60 name string 61 args args 62 want string 63 wantErr bool 64 }{ 65 { 66 name: "P2PKH1", 67 args: args{address: "FAPiw7EFMYmYK1mUuQQekyLsmimUBQT9zd"}, 68 want: "76a914320b6c674c8bc353942046981ff7ac73f5ceae4688ac", 69 wantErr: false, 70 }, 71 { 72 name: "P2PKH2", 73 args: args{address: "FMg9M7GPuUAGKvhWmgWjoqYtMqmckD4tRF"}, 74 want: "76a914adcfd792793fb204ec4e8cf2d0215fea6963b97388ac", 75 wantErr: false, 76 }, 77 } 78 parser := NewFloParser(GetChainParams("main"), &btc.Configuration{}) 79 80 for _, tt := range tests { 81 t.Run(tt.name, func(t *testing.T) { 82 got, err := parser.GetAddrDescFromAddress(tt.args.address) 83 if (err != nil) != tt.wantErr { 84 t.Errorf("GetAddrDescFromAddress() error = %v, wantErr %v", err, tt.wantErr) 85 return 86 } 87 h := hex.EncodeToString(got) 88 if !reflect.DeepEqual(h, tt.want) { 89 t.Errorf("GetAddrDescFromAddress() = %v, want %v", h, tt.want) 90 } 91 }) 92 } 93 }