// mockCredits decodes the given txHex and returns the outputs with // the given indices as eligible inputs. func mockCredits(t *testing.T, txHex string, indices []uint32) []wtxmgr.Credit { serialized, err := hex.DecodeString(txHex) if err != nil { t.Fatal(err) } utx, err := dcrutil.NewTxFromBytes(serialized) if err != nil { t.Fatal(err) } tx := utx.MsgTx() isCB := blockchain.IsCoinBaseTx(tx) now := time.Now() eligible := make([]wtxmgr.Credit, len(indices)) c := wtxmgr.Credit{ OutPoint: wire.OutPoint{Hash: *utx.Sha()}, BlockMeta: wtxmgr.BlockMeta{ Block: wtxmgr.Block{Height: -1}, }, } for i, idx := range indices { c.OutPoint.Index = idx c.Amount = dcrutil.Amount(tx.TxOut[idx].Value) c.PkScript = tx.TxOut[idx].PkScript c.Received = now c.FromCoinBase = isCB eligible[i] = c } return eligible }
// TestTxErrors tests the error paths for the Tx API. func TestTxErrors(t *testing.T) { // Serialize the test transaction. testTx := Block100000.Transactions[0] var testTxBuf bytes.Buffer err := testTx.Serialize(&testTxBuf) if err != nil { t.Errorf("Serialize: %v", err) } testTxBytes := testTxBuf.Bytes() // Truncate the transaction byte buffer to force errors. shortBytes := testTxBytes[:4] _, err = dcrutil.NewTxFromBytes(shortBytes) if err != io.EOF { t.Errorf("NewTxFromBytes: did not get expected error - "+ "got %v, want %v", err, io.EOF) } }
// TestNewTxFromBytes tests creation of a Tx from serialized bytes. func TestNewTxFromBytes(t *testing.T) { // Serialize the test transaction. testTx := Block100000.Transactions[0] var testTxBuf bytes.Buffer err := testTx.Serialize(&testTxBuf) if err != nil { t.Errorf("Serialize: %v", err) } testTxBytes := testTxBuf.Bytes() // Create a new transaction from the serialized bytes. tx, err := dcrutil.NewTxFromBytes(testTxBytes) if err != nil { t.Errorf("NewTxFromBytes: %v", err) return } // Ensure the generated MsgTx is correct. if msgTx := tx.MsgTx(); !reflect.DeepEqual(msgTx, testTx) { t.Errorf("MsgTx: mismatched MsgTx - got %v, want %v", spew.Sdump(msgTx), spew.Sdump(testTx)) } }
func TestMinPrioritySelector(t *testing.T) { testCoinSelector(minPriorityTests, t) } var ( // should be two outpoints, with 1st one having 1.29994545DCR value. testSimpleCoinNumConfs = int64(1) testSimpleCoinTxHash = "fdc5aa15e3c9fdef4e6436f79ad334842b1596edae13e8b2450ab576dc5494f5" testSimpleCoinTxHex = "010000000101e4d1fdb04871f69d198701e8c8c410da20507a74c3ffc4dea00b4d7444491c0600000001ffffffff02318fbf070000000000001976a9148485ee5dba5ac084f12450f8ebac97e2114fc90088ace06735000000000000001976a914784ebee20805af80a526f8d7603bffd6355d6d1988ac000000000000000001f9faf40700000000c92a0000090000006b483045022100ae3188239dc0983de2cfd2ed47ce5996888ef3512ee0b88c6cd6e1996781277f022021d849fc851df171bd9b4b1304bd24aee4050c7bda111fddbd9ebf83faa8640c0121026eea31de604e54e9027e1913d82e3d7f072b9553fde5792d2ac2317b9babda31" testSimpleCoinTxValue0 = dcrutil.Amount(129994545) testSimpleCoinTxValueAge0 = int64(testSimpleCoinTxValue0) * testSimpleCoinNumConfs testSimpleCoinTxPkScript0Hex = "76a9148485ee5dba5ac084f12450f8ebac97e2114fc90088ac" testSimpleCoinTxPkScript0Bytes, _ = hex.DecodeString(testSimpleCoinTxPkScript0Hex) testSimpleCoinTxBytes, _ = hex.DecodeString(testSimpleCoinTxHex) testSimpleCoinTx, _ = dcrutil.NewTxFromBytes(testSimpleCoinTxBytes) testSimpleCoin = &coinset.SimpleCoin{ Tx: testSimpleCoinTx, TxIndex: 0, TxNumConfs: testSimpleCoinNumConfs, } ) func TestSimpleCoin(t *testing.T) { if testSimpleCoin.Hash().String() != testSimpleCoinTxHash { t.Error("Different value for tx hash than expected") } if testSimpleCoin.Index() != 0 { t.Error("Different value for index of outpoint than expected") } if testSimpleCoin.Value() != testSimpleCoinTxValue0 {
"github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" "github.com/decred/dcrd/wire" "github.com/decred/dcrutil" "github.com/decred/dcrwallet/walletdb" _ "github.com/decred/dcrwallet/walletdb/bdb" "github.com/decred/dcrwallet/wtxmgr" . "github.com/decred/dcrwallet/wtxmgr" ) // Received transaction output for mainnet outpoint // 61d3696de4c888730cbe06b0ad8ecb6d72d6108e893895aa9bc067bd7eba3fad:0 var ( TstRecvSerializedTx, _ = hex.DecodeString("01000000020000000000000000000000000000000000000000000000000000000000000000ffffffff0000ffffffff04a2b971f28a2068ca54c6ba47507be802b3204264c67a8d8ce1fa7b34980908000000000100ffffffff0300000000000000002a6a28147ecac1bb4fe2db0246bebf91ea469c7ae53bd764c8f97edb7e9d637d8100035c0c0000000000000000000000000000046a02ffffb8101d1e000000001abb76a91414ab317ede91b40545f2e3b32678f9b6cc21b69e88ac000000000204deadbeef6a47304402200d590d4da7cea182fe9f2f812f1f42ac2ab8217018a5f423774f8f9c9f665c8f02200128fc6222d7daa44f5492aae5f60345e4a78935fafa6c73d2e531f4a297405f012103ca49eba5fb8d6c881e8a7385cc3c027971257d938de9e0ea6fa8426268703501") TstRecvTx, _ = dcrutil.NewTxFromBytes(TstRecvSerializedTx) TstRecvTxSpendingTxBlockHash, _ = chainhash.NewHashFromStr("60be28d1fa9721a22a4346245fa9694bde31ea2c8f29e49fdcd5d0a00e59bf4e") TstRecvAmt = int64(100) TstRecvTxBlockDetails = &BlockMeta{ Block: Block{Hash: *TstRecvTxSpendingTxBlockHash, Height: 762}, Time: time.Unix(1387737310, 0), } TstRecvCurrentHeight = int32(284498) // mainnet blockchain height at time of writing TstRecvTxOutConfirms = 8074 // hardcoded number of confirmations given the above block height TstSpendingSerializedTx, _ = hex.DecodeString("01000000042238516e1d48beb5b0c90dfcbaff751088237efc09c13cf66178969fe0d880cb0a000000016a47304402205ae23e9fb4ab4b4b23a7c762df8541b3313197d2f408337da91973ef97eac66202204734fbabed53405febfe64f4cebad29b8434f4f69c56879f1a703d997ea395a90121036b392a1272ca0fbe04de90e48ef872ef470839887842ad5520fd3d79b42ed223ffffffff308c17f850f1b18034da3446a8dc0d69406ed1f37683b6f43071f0070de27d6003000000016b483045022100eac9a62e4499dd80b20c16c6a65c9ecab1e1e4bf00c85f8fb1691cd5c8e9628d02202b79b30b6fc4cbee8cca548093040b5bb05c15a79f4d0664a2ef0f909150f1cf0121031f9913f6db4884a463e77c050fae18626376c0cf8e20232c9de40aeebcd7c457ffffffff3241e3b556db727f6003613fbbb38d7c409f6ac0971c200d6052cc7dde68dd5904000000016a47304402207d08ebb2f70856624e5ac1054c3c6ae289c280e6ed47877f05395f6f7a1ef7880220264b011099af48d548b12ac5e69f6a2abadded6ad68dbbe3f716bec9c806edab0121023ccb059324229c1149701380468b4b656f043ea75bf785b9ed83a0700650a08dffffffff2c4e4360883e113cde3c6857d71e65e822289ef13e4b2a3229b42a65f9b7b93b03000000006a473044022020d50f153f5a0dadbbaedd2e76a7f12fb4c06c09e57fe9927187739da5695a350220648cc08901fa238007525b4cfd0e0014b5e8f5546200bf56797456dd6d95f73c0121032501f9806b6e00949f91105b4363b10507352ca42ecc4260842259bb45f3fcd0ffffffff0200e40b54020000001976a914de6d4ab876fd17638a0f651dda6b9e5f84637acb88ac34849525000000001976a9140bf5130cf9c0e8a10a7da6f6d90961335783fd7b88ac00000000") TstSpendingTx, _ = dcrutil.NewTxFromBytes(TstSpendingSerializedTx) TstSpendingTxBlockHeight = int32(279143) TstSignedTxBlockHash, _ = chainhash.NewHashFromStr("00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4") TstSignedTxBlockDetails = &BlockMeta{
func TestFilterBloomMatch(t *testing.T) { // tx 2 from blk 10000 str := "0100000001a4fbbbca2416ba4c10c94be9f4a650d37fc4f9a1a4ecded9cc2" + "714aa0a529a750000000000ffffffff02c2d0b32f0000000000001976a91" + "499678d10a90c8df40e4c9af742aa6ebc7764a60e88acbe01611c0000000" + "000001976a9147701528df10cf0c14f9e53925031bd398796c1f988ac000" + "000000000000001e0b52b4c0000000003270000020000006b48304502210" + "08003ce072e4b67f9a98129ac2f58e3de6e06f47a15e248d4375d19dfb52" + "7a02d02204ab0a0dfe7c69024ae8e524e01d1c45183efda945a0d411e4e9" + "4b69be21efbe601210270c906c3ba64ba5eb3943cc012a3b142ef169f066" + "002515bf9ec1bd9b7e27f0d" strBytes, err := hex.DecodeString(str) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failure: %v", err) return } tx, err := dcrutil.NewTxFromBytes(strBytes) if err != nil { t.Errorf("TestFilterBloomMatch NewTxFromBytes failure: %v", err) return } spendingStr := "01000000018c5e1f62f83d750a0ee228c228731eae241e6b483e5b63be199" + "12846eb2d11500000000000ffffffff02ed44871d0000000000001976a91" + "461788151a27fad1a9c609fa29a2bd43886e2dd4088ac75a815120000000" + "000001976a91483419547ee3db5c0ee29f347740ff7f448e8ab2c88ac000" + "000000000000001c2d0b32f0000000010270000010000006b48304502210" + "0aca38b780893b6be3287efa908ace8bb8b91af0477ab433f101889b86bb" + "d9c2d0220789a177956f91c75141ea527573294a20f6fc0ea8bd5cc33550" + "4a0654ae197e30121025516815b900e10e51824ea1f451fd197fb11209af" + "60c5c52f9a8cf3edad5dc09" spendingTxBytes, err := hex.DecodeString(spendingStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failure: %v", err) return } spendingTx, err := dcrutil.NewTxFromBytes(spendingTxBytes) if err != nil { t.Errorf("TestFilterBloomMatch NewTxFromBytes failure: %v", err) return } f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr := "50112deb46289119be635b3e486b1e24ae1e7328c228e20e0a753df8621f5e8c" hash, err := chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewHashFromStr failed: %v\n", err) return } f.AddHash(hash) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match hash %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "8c5e1f62f83d750a0ee228c228731eae241e6b483e5b63be19912846eb2d1150" hashBytes, err := hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(hashBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match hash %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "30450221008003ce072e4b67f9a98129ac2f58e3de6e06f47a15e248d43" + "75d19dfb527a02d02204ab0a0dfe7c69024ae8e524e01d1c45183efda945a0" + "d411e4e94b69be21efbe601" hashBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(hashBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match input signature %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "0270c906c3ba64ba5eb3943cc012a3b142ef169f066002515bf9ec1bd9b7e27f0d" hashBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(hashBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match input pubkey %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "99678d10a90c8df40e4c9af742aa6ebc7764a60e" hashBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(hashBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match output address %s", inputStr) } if !f.MatchTxAndUpdate(spendingTx) { t.Errorf("TestFilterBloomMatch spendingTx didn't match output address %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "7701528df10cf0c14f9e53925031bd398796c1f9" hashBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(hashBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match output address %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "759a520aaa1427ccd9deeca4a1f9c47fd350a6f4e94bc9104cba1624cabbfba4" hash, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewHashFromStr failed: %v\n", err) return } outpoint := wire.NewOutPoint(hash, 0, wire.TxTreeRegular) f.AddOutPoint(outpoint) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match outpoint %s", inputStr) } // XXX unchanged from btcd f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "00000009e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436" hash, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewHashFromStr failed: %v\n", err) return } f.AddHash(hash) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched hash %s", inputStr) } // XXX unchanged from btcd f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "0000006d2965547608b9e15d9032a7b9d64fa431" hashBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(hashBytes) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched address %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "759a520aaa1427ccd9deeca4a1f9c47fd350a6f4e94bc9104cba1624cabbfba4" hash, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewHashFromStr failed: %v\n", err) return } outpoint = wire.NewOutPoint(hash, 1, wire.TxTreeRegular) f.AddOutPoint(outpoint) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) } // XXX unchanged from btcd f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "000000d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b" hash, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewHashFromStr failed: %v\n", err) return } outpoint = wire.NewOutPoint(hash, 0, wire.TxTreeRegular) f.AddOutPoint(outpoint) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) } }
func TestFilterBloomMatch(t *testing.T) { str := "0100000001cd24a3a215761757d2b565994b5f544be8cc7996e7835a0b326" + "feed9f8a3072802000000016a47304402200d1f455ff952f3fae2f9b3d5c" + "471371ba9d09789abb5cd80f01c6576c6d760e70220283aaa6e18a043a3b" + "5d105d6fccaca8edf31b705b75d82488414366ca48bdda60121030e233e9" + "6e98d98336bd2b3f4ec23aaa3c9b5c9b57de6d408490a9ce36c9d4326fff" + "fffff0600ca9a3b000000001976a914e6719fd3749c5ed40f193928e8b2a" + "d0dd163efe588acf82f357a0a0000001976a91468447782004ae8718618f" + "d752f1d02e285f897d488ac00ca9a3b000000001976a9148d2b19f048851" + "857afd872acde7ccf93bf16f5d488ac00ca9a3b000000001976a914e5aaf" + "268a042555daabf1e33030f12f61d663ea088ac00ca9a3b000000001976a" + "914f02e3cb22c39d3e6e0179241e52f21df097b17ae88ac00ca9a3b00000" + "0001976a9142ea99ce64965bf8cfb40e8e1b7bf4d2cea89db1988ac00000" + "000" strBytes, err := hex.DecodeString(str) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failure: %v", err) return } tx, err := dcrutil.NewTxFromBytes(strBytes) if err != nil { t.Errorf("TestFilterBloomMatch NewTxFromBytes failure: %v", err) return } spendingTxBytes := []byte{0x01, 0x00, 0x00, 0x00, 0x01, 0x6b, 0xff, 0x7f, 0xcd, 0x4f, 0x85, 0x65, 0xef, 0x40, 0x6d, 0xd5, 0xd6, 0x3d, 0x4f, 0xf9, 0x4f, 0x31, 0x8f, 0xe8, 0x20, 0x27, 0xfd, 0x4d, 0xc4, 0x51, 0xb0, 0x44, 0x74, 0x01, 0x9f, 0x74, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x49, 0x30, 0x46, 0x02, 0x21, 0x00, 0xda, 0x0d, 0xc6, 0xae, 0xce, 0xfe, 0x1e, 0x06, 0xef, 0xdf, 0x05, 0x77, 0x37, 0x57, 0xde, 0xb1, 0x68, 0x82, 0x09, 0x30, 0xe3, 0xb0, 0xd0, 0x3f, 0x46, 0xf5, 0xfc, 0xf1, 0x50, 0xbf, 0x99, 0x0c, 0x02, 0x21, 0x00, 0xd2, 0x5b, 0x5c, 0x87, 0x04, 0x00, 0x76, 0xe4, 0xf2, 0x53, 0xf8, 0x26, 0x2e, 0x76, 0x3e, 0x2d, 0xd5, 0x1e, 0x7f, 0xf0, 0xbe, 0x15, 0x77, 0x27, 0xc4, 0xbc, 0x42, 0x80, 0x7f, 0x17, 0xbd, 0x39, 0x01, 0x41, 0x04, 0xe6, 0xc2, 0x6e, 0xf6, 0x7d, 0xc6, 0x10, 0xd2, 0xcd, 0x19, 0x24, 0x84, 0x78, 0x9a, 0x6c, 0xf9, 0xae, 0xa9, 0x93, 0x0b, 0x94, 0x4b, 0x7e, 0x2d, 0xb5, 0x34, 0x2b, 0x9d, 0x9e, 0x5b, 0x9f, 0xf7, 0x9a, 0xff, 0x9a, 0x2e, 0xe1, 0x97, 0x8d, 0xd7, 0xfd, 0x01, 0xdf, 0xc5, 0x22, 0xee, 0x02, 0x28, 0x3d, 0x3b, 0x06, 0xa9, 0xd0, 0x3a, 0xcf, 0x80, 0x96, 0x96, 0x8d, 0x7d, 0xbb, 0x0f, 0x91, 0x78, 0xff, 0xff, 0xff, 0xff, 0x02, 0x8b, 0xa7, 0x94, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xba, 0xde, 0xec, 0xfd, 0xef, 0x05, 0x07, 0x24, 0x7f, 0xc8, 0xf7, 0x42, 0x41, 0xd7, 0x3b, 0xc0, 0x39, 0x97, 0x2d, 0x7b, 0x88, 0xac, 0x40, 0x94, 0xa8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xc1, 0x09, 0x32, 0x48, 0x3f, 0xec, 0x93, 0xed, 0x51, 0xf5, 0xfe, 0x95, 0xe7, 0x25, 0x59, 0xf2, 0xcc, 0x70, 0x43, 0xf9, 0x88, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00} spendingTx, err := dcrutil.NewTxFromBytes(spendingTxBytes) if err != nil { t.Errorf("TestFilterBloomMatch NewTxFromBytes failure: %v", err) return } f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr := "b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b" sha, err := chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return } f.AddShaHash(sha) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match sha %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "6bff7fcd4f8565ef406dd5d63d4ff94f318fe82027fd4dc451b04474019f74b4" shaBytes, err := hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(shaBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match sha %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "30450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065" + "f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643" + "ac4cb7cb3c462aced7f14711a01" shaBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(shaBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match input signature %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95" + "c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe" + "76036c339" shaBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(shaBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match input pubkey %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "04943fdd508053c75000106d3bc6e2754dbcff19" shaBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(shaBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match output address %s", inputStr) } if !f.MatchTxAndUpdate(spendingTx) { t.Errorf("TestFilterBloomMatch spendingTx didn't match output address %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "a266436d2965547608b9e15d9032a7b9d64fa431" shaBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(shaBytes) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match output address %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b" sha, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return } outpoint := wire.NewOutPoint(sha, 0, dcrutil.TxTreeRegular) f.AddOutPoint(outpoint) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match outpoint %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "00000009e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436" sha, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return } f.AddShaHash(sha) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched sha %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "0000006d2965547608b9e15d9032a7b9d64fa431" shaBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch DecodeString failed: %v\n", err) return } f.Add(shaBytes) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched address %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b" sha, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return } outpoint = wire.NewOutPoint(sha, 1, dcrutil.TxTreeRegular) f.AddOutPoint(outpoint) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) } f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "000000d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b" sha, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return } outpoint = wire.NewOutPoint(sha, 0, dcrutil.TxTreeRegular) f.AddOutPoint(outpoint) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) } }