github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/lnutil/litadr_test.go (about) 1 package lnutil 2 3 import ( 4 "crypto/rand" 5 "testing" 6 7 "github.com/mit-dci/lit/btcutil/chaincfg/chainhash" 8 ) 9 10 func TestAdr(t *testing.T) { 11 12 for i := 0; i < 10; i++ { 13 data := make([]byte, 16) 14 _, _ = rand.Read(data) 15 16 h := chainhash.DoubleHashH(data) 17 pub := PubFromHash(h) 18 adr := LitFullKeyAdrEncode(pub) 19 t.Logf("%d\tadr %s\n", i, adr) 20 rePub, err := LitFullAdrDecode(adr) 21 if err != nil { 22 t.Fatal(err) 23 } 24 if pub != rePub { 25 t.Fatalf("pubkey mismatch:\n%x\n%x\n", pub, rePub) 26 } 27 t.Logf("restore %x\n", rePub[:]) 28 29 } 30 }