public void Test_Returns_False_When_Address_Not_Null_Topics_Not_Null()
        {
            var address = new uint160(1);

            var topics = new List <byte[]>
            {
                new byte[] { 0xAA, 0xAA, 0xAA },
                new byte[] { 0xBB, 0xBB, 0xBB },
                new byte[] { 0xCC, 0xCC, 0xCC }
            };

            var bloom = new Bloom();

            bloom.Add(address.ToBytes());

            foreach (var topic in topics)
            {
                bloom.Add(topic);
            }

            var address2 = new uint160(2);

            Assert.False(bloom.Test(address2));
            Assert.False(bloom.Test(address2, new[] { topics[0] }));
            Assert.False(bloom.Test(address2, new[] { topics[1] }));
            Assert.False(bloom.Test(address2, new[] { topics[2] }));
        }
Ejemplo n.º 2
0
        public void Test_Bloom_Contains_Another_Bloom_Success()
        {
            var topics =
                new List <byte[]>
            {
                Encoding.UTF8.GetBytes("Topic1"),
                Encoding.UTF8.GetBytes("Topic2"),
                Encoding.UTF8.GetBytes("Topic3"),
                Encoding.UTF8.GetBytes("Topic4")
            };

            var bloom = new Bloom();

            foreach (var topic in topics)
            {
                bloom.Add(topic);
            }

            // Test all combos of topics.
            for (var i = 0; i < topics.Count; i++)
            {
                var bloom2 = new Bloom();
                bloom2.Add(topics[i]);

                Assert.True(bloom.Test(bloom2));

                for (var j = i + 1; j < topics.Count; j++)
                {
                    bloom2.Add(topics[j]);

                    Assert.True(bloom.Test(bloom2));
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Return a bloom filter for the address of the contract logging and the topics to be logged.
        /// </summary>
        public Bloom GetBloom()
        {
            var bloom = new Bloom();

            bloom.Add(this.Address.ToBytes());
            foreach (byte[] topic in this.Topics)
            {
                bloom.Add(topic);
            }
            return(bloom);
        }
Ejemplo n.º 4
0
        private Bloom GetBloom(params LogEntry[] logEntries)
        {
            var bloom = new Bloom();

            bloom.Add(logEntries);
            return(bloom);
        }
Ejemplo n.º 5
0
        public KeyValuePair <string, int> GetUrl()
        {
            var newURL = newURLQueue.Dequeue();

            Bloom.Add(newURL.Key);
            return(newURL);
        }
Ejemplo n.º 6
0
        public void Add_Items_To_Bloom_And_Test()
        {
            const string testValue1    = "095e7baea6a6c7c4c2dfeb977efac326af552d87";
            const string testValue2    = "0000000000000000000000000000000000000000000000000000000000000000";
            string       expectedBloom = "00000000000000000000000000000000000000000000000000000040000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000";

            var bloom = new Bloom();

            bloom.Add(testValue1.HexToByteArray());
            bloom.Add(testValue2.HexToByteArray());
            Assert.Equal(expectedBloom, bloom.ToString());

            Assert.True(bloom.Test(testValue1.HexToByteArray()));
            Assert.True(bloom.Test(testValue2.HexToByteArray()));
            Assert.False(bloom.Test("1001".HexToByteArray()));
            Assert.True(bloom.Test(testValue1.HexToByteArray()));
        }
        public void Test_Returns_True_When_Address_Not_Null_Topics_Null()
        {
            var address = new uint160(1);

            var bloom = new Bloom();

            bloom.Add(address.ToBytes());

            Assert.True(bloom.Test(address, null));
        }
        public void Test_Returns_True_When_Address_Null_Topics_Null()
        {
            var data = new byte[] { 0xAA, 0xBB, 0xCC };

            var bloom = new Bloom();

            bloom.Add(data);

            Assert.True(bloom.Test((uint160)null, (IEnumerable <byte[]>)null));
        }
Ejemplo n.º 9
0
        private Bloom BuildBloom(TransactionReceipt[] transactionReceipts)
        {
            Bloom bloom = new Bloom();

            for (int i = 0; i < transactionReceipts.Length; i++)
            {
                bloom.Add(transactionReceipts[i].Logs);
            }

            return(bloom);
        }
Ejemplo n.º 10
0
        public Bloom BuildBloom(TransactionReceipt[] receipts)
        {
            Bloom bloom = new Bloom();

            for (int i = 0; i < receipts.Length; i++)
            {
                bloom.Add(receipts[i].Logs);
            }

            return(bloom);
        }
Ejemplo n.º 11
0
        public void MatchingTest(Func <LogEntry[]> addedEntries, Func <LogEntry[], LogEntry[]> testedEntries, bool isMatchExpectation)
        {
            Bloom bloom   = new Bloom();
            var   entries = addedEntries();

            bloom.Add(entries);

            var testEntries = testedEntries(entries);
            var results     = testEntries.Select(e => bloom.Matches(e));

            results.Should().AllBeEquivalentTo(isMatchExpectation);
        }
Ejemplo n.º 12
0
        static void Main()
        {
            var bloom = new Bloom(102400) {Hashes = 10};

            for (char a = 'a'; a < 'z'; a++)
                for (char b = 'a'; b < 'z'; b++)
                    for (var l = 1; l < 10; l++)
                    {
                        var str = new string(a, l) + new string(b, l);
                        bloom.Add(str);
                    }

            var x1 = bloom.MayContains("aaabbb");
            var x2 = bloom.MayContains("ccdd");
            var x3 = bloom.MayContains("aaabbc");
        }
Ejemplo n.º 13
0
        public void Test_Many_Bloom_Values()
        {
            // Hey friend! There's a miniscule chance that this test will fail purely due to chance.
            // If it happens to you, congratulations! You're one in a million.

            const int numberToGen = 25;
            const int byteLength  = 32;

            var           bloom               = new Bloom();
            var           random              = new Random();
            List <byte[]> containedInBloom    = new List <byte[]>();
            List <byte[]> notContainedInBloom = new List <byte[]>();

            // Fill bloom up with some random numbers.
            for (int i = 0; i < numberToGen; i++)
            {
                byte[] buffer = new byte[byteLength];
                random.NextBytes(buffer);
                containedInBloom.Add(buffer);
                bloom.Add(buffer);
            }

            // Create some random numbers that aren't in the bloom.
            for (int i = 0; i < numberToGen; i++)
            {
                byte[] buffer = new byte[byteLength];
                random.NextBytes(buffer);
                notContainedInBloom.Add(buffer);
            }

            // Check that all in bloom match, and all not in bloom don't match.
            for (int i = 0; i < numberToGen; i++)
            {
                Assert.False(bloom.Test(notContainedInBloom[i]));
                Assert.True(bloom.Test(containedInBloom[i]));
            }
        }
Ejemplo n.º 14
0
        public void Test_Many_Bloom_Values()
        {
            // Use a seed so we get the same values every time and avoid non-deterministic tests.
            const int seed        = 123456;
            const int numberToGen = 25;
            const int byteLength  = 32;

            var           bloom               = new Bloom();
            var           random              = new Random(seed);
            List <byte[]> containedInBloom    = new List <byte[]>();
            List <byte[]> notContainedInBloom = new List <byte[]>();

            // Fill bloom up with some random numbers.
            for (int i = 0; i < numberToGen; i++)
            {
                byte[] buffer = new byte[byteLength];
                random.NextBytes(buffer);
                containedInBloom.Add(buffer);
                bloom.Add(buffer);
            }

            // Create some random numbers that aren't in the bloom.
            for (int i = 0; i < numberToGen; i++)
            {
                byte[] buffer = new byte[byteLength];
                random.NextBytes(buffer);
                notContainedInBloom.Add(buffer);
            }

            // Check that all in bloom match, and all not in bloom don't match.
            for (int i = 0; i < numberToGen; i++)
            {
                Assert.False((bool)bloom.Test(notContainedInBloom[i]));
                Assert.True((bool)bloom.Test(containedInBloom[i]));
            }
        }