Exemple #1
0
        public void OutPointCacheCanRetrieveExisting()
        {
            const string CollectionName = "DummyCollection";
            var          dataFolder     = new DataFolder(TestBase.CreateTestDir(this));
            string       dbPath         = Path.Combine(dataFolder.RootPath, CollectionName);
            FileMode     fileMode       = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? FileMode.Exclusive : FileMode.Shared;

            var database = new LiteDatabase(new ConnectionString()
            {
                Filename = dbPath, Mode = fileMode
            });
            var cache = new AddressIndexerOutpointsRepository(database, new ExtendedLoggerFactory());

            var outPoint = new OutPoint(uint256.Parse("0000af9ab2c8660481328d0444cf167dfd31f24ca2dbba8e5e963a2434cffa93"), 0);

            var data = new OutPointData()
            {
                Outpoint = outPoint.ToString(), ScriptPubKeyBytes = new byte[] { 0, 0, 0, 0 }, Money = Money.Coins(1)
            };

            cache.AddOutPointData(data);

            Assert.True(cache.TryGetOutPointData(outPoint, out OutPointData retrieved));

            Assert.NotNull(retrieved);
            Assert.Equal(outPoint.ToString(), retrieved.Outpoint);
        }
Exemple #2
0
        public void OutPointCacheEvicts()
        {
            const string CollectionName = "OutputsData";
            var          dataFolder     = new DataFolder(TestBase.CreateTestDir(this));
            string       dbPath         = Path.Combine(dataFolder.RootPath, CollectionName);

            var database = new LiteDatabase(new ConnectionString()
            {
                Filename = dbPath, Upgrade = true
            });
            var cache = new AddressIndexerOutpointsRepository(database, new ExtendedLoggerFactory(), 2);

            Assert.Equal(0, cache.Count);
            Assert.Equal(0, database.GetCollection <OutPointData>(CollectionName).Count());

            var outPoint1 = new OutPoint(uint256.Parse("0000af9ab2c8660481328d0444cf167dfd31f24ca2dbba8e5e963a2434cffa93"), 1);;
            var pair1     = new OutPointData()
            {
                Outpoint = outPoint1.ToString(), ScriptPubKeyBytes = new byte[] { 0, 0, 0, 0 }, Money = Money.Coins(1)
            };

            cache.AddOutPointData(pair1);

            Assert.Equal(1, cache.Count);
            Assert.Equal(0, database.GetCollection <OutPointData>(CollectionName).Count());

            var outPoint2 = new OutPoint(uint256.Parse("cf8ce1419bbc4870b7d4f1c084534d91126dd3283b51ec379e0a20e27bd23633"), 2);;
            var pair2     = new OutPointData()
            {
                Outpoint = outPoint2.ToString(), ScriptPubKeyBytes = new byte[] { 1, 1, 1, 1 }, Money = Money.Coins(2)
            };

            cache.AddOutPointData(pair2);

            Assert.Equal(2, cache.Count);
            Assert.Equal(0, database.GetCollection <OutPointData>(CollectionName).Count());

            var outPoint3 = new OutPoint(uint256.Parse("126dd3283b51ec379e0a20e27bd23633cf8ce1419bbc4870b7d4f1c084534d91"), 3);;
            var pair3     = new OutPointData()
            {
                Outpoint = outPoint3.ToString(), ScriptPubKeyBytes = new byte[] { 2, 2, 2, 2 }, Money = Money.Coins(3)
            };

            cache.AddOutPointData(pair3);

            Assert.Equal(2, cache.Count);

            // One of the cache items should have been evicted, and will therefore be persisted on disk.
            Assert.Equal(1, database.GetCollection <OutPointData>(CollectionName).Count());

            // The evicted item should be pair1.
            Assert.Equal(pair1.ScriptPubKeyBytes, database.GetCollection <OutPointData>(CollectionName).FindAll().First().ScriptPubKeyBytes);

            // It should still be possible to retrieve pair1 from the cache (it will pull it from disk).
            Assert.True(cache.TryGetOutPointData(outPoint1, out OutPointData pair1AfterEviction));

            Assert.NotNull(pair1AfterEviction);
            Assert.Equal(pair1.ScriptPubKeyBytes, pair1AfterEviction.ScriptPubKeyBytes);
            Assert.Equal(pair1.Money, pair1AfterEviction.Money);
        }
Exemple #3
0
        public AddressIndexerOutpointsRepositoryTests()
        {
            var db = new LiteDatabase(new ConnectionString()
            {
                Filename = this.RandomString(20) + ".litedb", Upgrade = true
            });

            this.repository = new AddressIndexerOutpointsRepository(db, new ExtendedLoggerFactory(), this.maxItems);
        }
        public AddressIndexerOutpointsRepositoryTests()
        {
            FileMode fileMode = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? FileMode.Exclusive : FileMode.Shared;
            var      db       = new LiteDatabase(new ConnectionString()
            {
                Filename = this.RandomString(20) + ".litedb", Mode = fileMode
            });

            this.repository = new AddressIndexerOutpointsRepository(db, new ExtendedLoggerFactory(), this.maxItems);
        }
Exemple #5
0
        public void OutPointCacheCannotRetrieveNonexistent()
        {
            const string CollectionName = "DummyCollection";
            var          dataFolder     = new DataFolder(TestBase.CreateTestDir(this));
            string       dbPath         = Path.Combine(dataFolder.RootPath, CollectionName);

            var database = new LiteDatabase(new ConnectionString()
            {
                Filename = dbPath, Upgrade = true
            });
            var cache = new AddressIndexerOutpointsRepository(database, new ExtendedLoggerFactory());

            Assert.False(cache.TryGetOutPointData(new OutPoint(uint256.Parse("0000af9ab2c8660481328d0444cf167dfd31f24ca2dbba8e5e963a2434cffa93"), 1), out OutPointData retrieved));
            Assert.Null(retrieved);
        }
        public void OutPointCacheCannotRetrieveNonexistent()
        {
            const string CollectionName = "DummyCollection";
            var          dataFolder     = new DataFolder(TestBase.CreateTestDir(this));
            string       dbPath         = Path.Combine(dataFolder.RootPath, CollectionName);
            FileMode     fileMode       = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? FileMode.Exclusive : FileMode.Shared;

            var database = new LiteDatabase(new ConnectionString()
            {
                Filename = dbPath, Mode = fileMode
            });
            var cache = new AddressIndexerOutpointsRepository(database);

            Assert.False(cache.TryGetOutPointData(new OutPoint(uint256.Parse("0000af9ab2c8660481328d0444cf167dfd31f24ca2dbba8e5e963a2434cffa93"), 1), out OutPointData retrieved));
            Assert.Null(retrieved);
        }