func TestMerkleBlock3(t *testing.T) { blockStr := "0100000073cf056852529ffadc50b49589218795adc4d3f24170950d49f201000000000033fd46dda0acfa5c0651c58bee00362b04186c5b4d1045d37751b25779148649000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000ffff011b00c2eb0b00000000000100007e0100006614b956bee4fc44442bf144050552b3010000000000000000000000000000000000000000000000000000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff03fa1a981200000000000017a914f5916158e3e2c4551c1796708db8367207ed13bb8700000000000000000000266a24000100000000000000000000000000000000000000000000000000004dfb774daa8f3a76dea1906f0000000000001976a914b74b7476bdbcf03d18f12cca1766b0ddfd030cdd88ac000000000000000001d8bc28820000000000000000ffffffff0800002f646372642f00" blockBytes, err := hex.DecodeString(blockStr) if err != nil { t.Errorf("TestMerkleBlock3 DecodeString failed: %v", err) return } blk, err := dcrutil.NewBlockFromBytes(blockBytes) if err != nil { t.Errorf("TestMerkleBlock3 NewBlockFromBytes failed: %v", err) return } f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr := "4986147957b25177d345104d5b6c18042b3600ee8bc551065cfaaca0dd46fd33" hash, err := chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestMerkleBlock3 NewHashFromStr failed: %v", err) return } f.AddHash(hash) mBlock, _ := bloom.NewMerkleBlock(blk, f) wantStr := "0100000073cf056852529ffadc50b49589218795adc4d3f24170950d49f201000000000033fd46dda0acfa5c0651c58bee00362b04186c5b4d1045d37751b25779148649000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000ffff011b00c2eb0b00000000000100007e0100006614b956bee4fc44442bf144050552b3010000000000000000000000000000000000000000000000000000000100000001d0f51e5a4978d736eb3d4a8d615bee74943756b4745d29b27ab2943bc1307cc800000000000100" want, err := hex.DecodeString(wantStr) if err != nil { t.Errorf("TestMerkleBlock3 DecodeString failed: %v", err) return } got := bytes.NewBuffer(nil) err = mBlock.BtcEncode(got, wire.ProtocolVersion) if err != nil { t.Errorf("TestMerkleBlock3 BtcEncode failed: %v", err) return } if !bytes.Equal(want, got.Bytes()) { t.Errorf("TestMerkleBlock3 failed merkle block comparison: "+ "got %v want %v", got.Bytes(), want) return } }
func TestFilterInsertP2PubKeyOnly(t *testing.T) { blockStr := "000000003ffad804971ce6b8a13c8162287222d91395fa77b6bea6b4" + "626b4827000000004259bd8a4d5d5f8469f390903d27b9cab2ea03822fbe" + "616478756ada751a283be8e4aa58eeb75810e22031cc2756442b7f68c77b" + "3735522fc5490be1676253c301005f031703bb61050000005c1300006fb2" + "381c30dd35680000000091940000fc0900000cadf15600d9781d3a5f237b" + "083799410f00000000000000000000000000000000000000000000000000" + "000002010000000100000000000000000000000000000000000000000000" + "00000000000000000000ffffffff00ffffffff032727750c000000000000" + "17a9144fa6cbd0dbe5ec407fe4c8ad374e667771fa0d4487000000000000" + "00000000266a249194000000000000000000000000000000000000000000" + "0000000000b90c53023ee736e6d7eebe4a0000000000001976a914bfe0f6" + "3eda5d7db3ee05661051c026f5296ffc7888ac0000000000000000011512" + "34570000000000000000ffffffff0800002f646372642f01000000020c57" + "441e66eaa72bc76ab54faaa0ec87941f4423a463c5e34d7f23f247d65e9d" + "0200000001ffffffff31b7ffaec935e787dc03670d4d13ee0066717cb750" + "2cb4d925b09b7f692a73580400000001ffffffff0200ca9a3b0000000000" + "0023210351b64c01163b9184637671e27d6d29b3a205203710f6fbc5a6e1" + "b646a11984d6ac81001f060000000000001976a9144feba3e04d91d9dc90" + "ebb13ce91bf9bcfe32ff9288ac000000000000000002c29f493300000000" + "8f9400000a0000006a4730440220186741de60d6fe75d2206b62780edabe" + "8a0a13f823aaeca58f0d5a8dedfa99f202201dc84a1bd26d14723ddf2fe4" + "216d4a24d788597fa22255d144ce119d7544ce39012103879a3b3666bf03" + "88ab33e6e24e77c3c219044f7c5d778b71ac1837817095830da72e700e00" + "000000909400000e0000006b4830450221008cc441f58be0eedc713b867d" + "c8dfff21e2f6c2e38a906a0af5aa0625b2683f6b0220308bcaf6628b3c68" + "19da76ebb2ca5e5d1ddde6e5035193d75e3e667731deadc4012102a871fe" + "4e4f77121f1cbaf2db62190539687092b465e252a3bd732791ca442d5405" + "010000000200000000000000000000000000000000000000000000000000" + "00000000000000ffffffff00ffffffff91ed802c4a23cca0517dbc2d89f7" + "b6f8a2d1491a27ed25e3d3f621bac03316da0000000001ffffffff030000" + "0000000000000000266a243ffad804971ce6b8a13c8162287222d91395fa" + "77b6bea6b4626b4827000000009094000000000000000000000000046a02" + "010003d0db190100000000001abb76a914339f1f6a41d7ef65ffd80bbb8c" + "daaa215a16472d88ac000000000000000002e47d79070000000000000000" + "ffffffff04deadbeef1f52621201000000938b0000090000006a47304402" + "207184b4d7a95a559b1142f50cfde3e40bf460572aea4d5eeabad062e45c" + "9a8f5102202304acbcc9cc55e58770e51d4fc9ac81af9c790a65d251ea4d" + "556bc7ee96fb47012103c46bdbf6b24be97eac230ca9b23e928e2e76750d" + "3d3c8b29e15cebb64ba01f86010000000200000000000000000000000000" + "00000000000000000000000000000000000000ffffffff00ffffffff17be" + "9d003549030c20c018a71745af6f6a02d96637f49f5a548ee7fe0ac84420" + "0000000001ffffffff0300000000000000000000266a243ffad804971ce6" + "b8a13c8162287222d91395fa77b6bea6b4626b4827000000009094000000" + "000000000000000000046a02010071c339cf0000000000001abb76a9147f" + "1aaac9f04febbf9dadd262b1c710729970445988ac000000000000000002" + "e47d79070000000000000000ffffffff04deadbeef8d45c0c70000000099" + "8f0000070000006a473044022054a09af013f1a74960686bf5c36f3eb822" + "5ffc96e76a54dc1aac9fdea65cff2b022010359dfcd16ac77f3a6ab47309" + "e106a885fa2d031d5bac0824f4432a77ccdae001210389e445603d66ce44" + "92ec74d9b1974268a2e83413c84df87895184bc6f46ae1d7010000000200" + "000000000000000000000000000000000000000000000000000000000000" + "00ffffffff00ffffffff49a883465f82c0483b3ff7da057cab44a42ecbc8" + "27c344a960a2a33c95263f760000000001ffffffff030000000000000000" + "0000266a243ffad804971ce6b8a13c8162287222d91395fa77b6bea6b462" + "6b4827000000009094000000000000000000000000046a0201002c9d63bf" + "0000000000001abb76a91449d402e31fc08414f565febaa1b69eccc2fb8d" + "2688ac000000000000000002e47d79070000000000000000ffffffff04de" + "adbeef481feab70000000064870000120000006a473044022008daa49081" + "d7dc6c466a4d3fd4184927e8b77fd1f5721f206bf0d13a2c00b07802202d" + "89841ad5346de14db95c3e5b15a0d82e0df1f50a235f67aeec08b98f4b36" + "7a012102907261a4670a9d0ff918724af50f2ecb7947831dad30ac285afa" + "1b90549aa282010000000200000000000000000000000000000000000000" + "00000000000000000000000000ffffffff00ffffffffb6df4ea74c958f39" + "65ecc90b9226cfdc2d7986b1df30998cf3e827d7e9fbf4b80000000001ff" + "ffffff0300000000000000000000266a243ffad804971ce6b8a13c816228" + "7222d91395fa77b6bea6b4626b4827000000009094000000000000000000" + "000000046a020100f3a613b90000000000001abb76a9147f9321c65ee805" + "d87f67b0b0e9dac4f0779c1d3a88ac000000000000000002e47d79070000" + "000000000000ffffffff04deadbeef0f299ab100000000408d0000130000" + "006b4830450221008c5759dd9f0c40c61f61f5b67c0b3f860d4d59859fb2" + "451dbeab9956b3ceb05602203e81d5b88b83e279dc7feca13c8e5eb58676" + "158243058ec43d6366933397be4a0121031e6757ee86e94a02e567db7d4e" + "c4ba5088f6b5fdbfe9b2794b70b42b52b879200100000002000000000000" + "0000000000000000000000000000000000000000000000000000ffffffff" + "00ffffffff9e74ead771c313f0c0bb739860eba39d04a8cce201cda626dc" + "6a7dd4e83b3f770000000001ffffffff0400000000000000000000266a24" + "3ffad804971ce6b8a13c8162287222d91395fa77b6bea6b4626b48270000" + "00009094000000000000000000000000046a0201000793a0e00000000000" + "001abb76a914c8c5a2cbd183871718dcb14b5f198561450d157e88ac596e" + "8f250000000000001abb76a9147112f7d015baeb129e732b9c4805e492ef" + "d0a2fb88ac000000000000000002e47d79070000000000000000ffffffff" + "04deadbeef7d83b6fe0000000022920000070000006a4730440220160ff7" + "bd84190d8d837ac6bd782be475d23d50832872626453bd70ea63d9a6a002" + "20603afdd51fc8e3fead1fd9dbae410b8d0617969ad5119e6dc2b0855d7b" + "48e73501210297ab850cae270e9438693353e40444c7e714e179505e8b12" + "1c042f4869e42072" blockBytes, err := hex.DecodeString(blockStr) if err != nil { t.Errorf("TestFilterInsertP2PubKeyOnly DecodeString failed: %v", err) return } block, err := dcrutil.NewBlockFromBytes(blockBytes) if err != nil { t.Errorf("TestFilterInsertP2PubKeyOnly NewBlockFromBytes failed: %v", err) return } f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateP2PubkeyOnly) // Generation pubkey inputStr := "0351b64c01163b9184637671e27d6d29b3a205203710f6fbc5a6e1b646a11984d6" inputBytes, err := hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterInsertP2PubKeyOnly DecodeString failed: %v", err) return } f.Add(inputBytes) // Output address of 2nd transaction inputStr = "4feba3e04d91d9dc90ebb13ce91bf9bcfe32ff92" inputBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterInsertP2PubKeyOnly DecodeString failed: %v", err) return } f.Add(inputBytes) // Ignore return value -- this is just used to update the filter. _, _ = bloom.NewMerkleBlock(block, f) // We should match the generation pubkey inputStr = "8199f30ccc006056ed79cf0a3cd0b67a195ffd46903d42adc7babe2ed2f2e371" hash, err := chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestMerkleBlockP2PubKeyOnly NewHashFromStr failed: %v", err) return } outpoint := wire.NewOutPoint(hash, 0, wire.TxTreeRegular) if !f.MatchesOutPoint(outpoint) { t.Errorf("TestMerkleBlockP2PubKeyOnly didn't match the generation "+ "outpoint %s", inputStr) return } // We should not match the 4th transaction, which is not p2pk inputStr = "d7314aaf54253c651e8258c7d22c574af8804611f0dcea79fd9a47f4565d85ad" hash, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestMerkleBlockP2PubKeyOnly NewHashFromStr failed: %v", err) return } outpoint = wire.NewOutPoint(hash, 0, wire.TxTreeRegular) if f.MatchesOutPoint(outpoint) { t.Errorf("TestMerkleBlockP2PubKeyOnly matched outpoint %s", inputStr) return } }
func TestFilterInsertP2PubKeyOnly(t *testing.T) { blockStr := "000000004ad131bae9cb9f74b8bcd928" + "a60dfe4dadabeb31b1e79403385f9ac4" + "ccc28b7400429e56f7df2872aaaa0c16" + "221cb09059bd3ea897de156ff51202ff" + "72b2cd8d000000000000000000000000" + "00000000000000000000000000000000" + "00000000010000000000000000000000" + "22000000ffff7f20002d310100000000" + "640000007601000063a0815601000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000010100000001000000000000" + "00000000000000000000000000000000" + "00000000000000000000ffffffff00ff" + "ffffff0380b2e60e00000000000017a9" + "144fa6cbd0dbe5ec407fe4c8ad374e66" + "7771fa0d448700000000000000000000" + "226a2000000000000000000000000000" + "0000009e0453a6ab10610e17a7a5fadc" + "f6c34f002f68590000000000001976a9" + "141b79e6496226f89ad4e049667c1344" + "c16a75815188ac000000000000000001" + "000000000000000000000000ffffffff" + "04deadbeef00" blockBytes, err := hex.DecodeString(blockStr) if err != nil { t.Errorf("TestFilterInsertP2PubKeyOnly DecodeString failed: %v", err) return } block, err := dcrutil.NewBlockFromBytes(blockBytes) if err != nil { t.Errorf("TestFilterInsertP2PubKeyOnly NewBlockFromBytes failed: %v", err) return } f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateP2PubkeyOnly) // Generation pubkey inputStr := "04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c" + "876f2c01ec0f0dd5b2e86e7168cefe0d81113c3807420ce13ad1357231a" + "2252247d97a46a91" inputBytes, err := hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterInsertP2PubKeyOnly DecodeString failed: %v", err) return } f.Add(inputBytes) // Output address of 4th transaction inputStr = "b6efd80d99179f4f4ff6f4dd0a007d018c385d21" inputBytes, err = hex.DecodeString(inputStr) if err != nil { t.Errorf("TestFilterInsertP2PubKeyOnly DecodeString failed: %v", err) return } f.Add(inputBytes) // Ignore return value -- this is just used to update the filter. _, _ = bloom.NewMerkleBlock(block, f) // We should match the generation pubkey inputStr = "147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b" sha, err := chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestMerkleBlockP2PubKeyOnly NewShaHashFromStr failed: %v", err) return } outpoint := wire.NewOutPoint(sha, 0, dcrutil.TxTreeRegular) if !f.MatchesOutPoint(outpoint) { t.Errorf("TestMerkleBlockP2PubKeyOnly didn't match the generation "+ "outpoint %s", inputStr) return } // We should not match the 4th transaction, which is not p2pk inputStr = "02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041" sha, err = chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestMerkleBlockP2PubKeyOnly NewShaHashFromStr failed: %v", err) return } outpoint = wire.NewOutPoint(sha, 0, dcrutil.TxTreeRegular) if f.MatchesOutPoint(outpoint) { t.Errorf("TestMerkleBlockP2PubKeyOnly matched outpoint %s", inputStr) return } }
func TestMerkleBlock3(t *testing.T) { blockStr := "000000004ad131bae9cb9f74b8bcd928" + "a60dfe4dadabeb31b1e79403385f9ac4" + "ccc28b7400429e56f7df2872aaaa0c16" + "221cb09059bd3ea897de156ff51202ff" + "72b2cd8d000000000000000000000000" + "00000000000000000000000000000000" + "00000000010000000000000000000000" + "22000000ffff7f20002d310100000000" + "640000007601000063a0815601000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000010100000001000000000000" + "00000000000000000000000000000000" + "00000000000000000000ffffffff00ff" + "ffffff0380b2e60e00000000000017a9" + "144fa6cbd0dbe5ec407fe4c8ad374e66" + "7771fa0d448700000000000000000000" + "226a2000000000000000000000000000" + "0000009e0453a6ab10610e17a7a5fadc" + "f6c34f002f68590000000000001976a9" + "141b79e6496226f89ad4e049667c1344" + "c16a75815188ac000000000000000001" + "000000000000000000000000ffffffff" + "04deadbeef00" blockBytes, err := hex.DecodeString(blockStr) if err != nil { t.Errorf("TestMerkleBlock3 DecodeString failed: %v", err) return } blk, err := dcrutil.NewBlockFromBytes(blockBytes) if err != nil { t.Errorf("TestMerkleBlock3 NewBlockFromBytes failed: %v", err) return } f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr := "4797be83be7b4c4f833739c3542c2c1c403ffb01f0b721b5bc5dee3ff655a856" sha, err := chainhash.NewHashFromStr(inputStr) if err != nil { t.Errorf("TestMerkleBlock3 NewShaHashFromStr failed: %v", err) return } f.AddShaHash(sha) mBlock, _ := bloom.NewMerkleBlock(blk, f) wantStr := "0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4" + "b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc" + "96b2c3ff60abe184f196367291b4d4c86041b8fa45d630100000001b50c" + "c069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196" + "30101" want, err := hex.DecodeString(wantStr) if err != nil { t.Errorf("TestMerkleBlock3 DecodeString failed: %v", err) return } got := bytes.NewBuffer(nil) err = mBlock.BtcEncode(got, wire.ProtocolVersion) if err != nil { t.Errorf("TestMerkleBlock3 BtcEncode failed: %v", err) return } if !bytes.Equal(want, got.Bytes()) { t.Errorf("TestMerkleBlock3 failed merkle block comparison: "+ "got %v want %v", got.Bytes, want) return } }