// TestFilterInsertKey ensures inserting public keys and addresses works as // expected. func TestFilterInsertKey(t *testing.T) { secret := "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C" wif, err := coinutil.DecodeWIF(secret) if err != nil { t.Errorf("TestFilterInsertKey DecodeWIF failed: %v", err) return } f := bloom.NewFilter(2, 0, 0.001, wire.BloomUpdateAll) f.Add(wif.SerializePubKey()) f.Add(coinutil.Hash160(wif.SerializePubKey())) want, err := hex.DecodeString("038fc16b080000000000000001") if err != nil { t.Errorf("TestFilterInsertWithTweak DecodeString failed: %v\n", err) return } got := bytes.NewBuffer(nil) err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion) if err != nil { t.Errorf("TestFilterInsertWithTweak BtcDecode failed: %v\n", err) return } if !bytes.Equal(got.Bytes(), want) { t.Errorf("TestFilterInsertWithTweak failure: got %v want %v\n", got.Bytes(), want) return } }
// newManager creates a new waddrmgr and imports the given privKey into it. func newManager(t *testing.T, privKeys []string, bs *waddrmgr.BlockStamp) *waddrmgr.Manager { dbPath := filepath.Join(os.TempDir(), "wallet.bin") os.Remove(dbPath) db, err := walletdb.Create("bdb", dbPath) if err != nil { t.Fatal(err) } namespace, err := db.Namespace(waddrmgrNamespaceKey) if err != nil { t.Fatal(err) } seed, err := hdkeychain.GenerateSeed(hdkeychain.RecommendedSeedLen) if err != nil { t.Fatal(err) } pubPassphrase := []byte("pub") privPassphrase := []byte("priv") mgr, err := waddrmgr.Create(namespace, seed, pubPassphrase, privPassphrase, &chaincfg.TestNet3Params, fastScrypt) if err != nil { t.Fatal(err) } for _, key := range privKeys { wif, err := coinutil.DecodeWIF(key) if err != nil { t.Fatal(err) } if err = mgr.Unlock(privPassphrase); err != nil { t.Fatal(err) } _, err = mgr.ImportPrivateKey(wif, bs) if err != nil { t.Fatal(err) } } return mgr }