Skip to content

Commit 68ded29

Browse files
committed
Fix build break
1 parent 77a49c0 commit 68ded29

2 files changed

Lines changed: 47 additions & 45 deletions

File tree

src/Tests/Blockcore.Features.BlockStore.Tests/BlockRepositoryTests.cs

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using Blockcore.Consensus.BlockInfo;
55
using Blockcore.Consensus.TransactionInfo;
6+
using Blockcore.Features.BlockStore.Persistence.LevelDb;
67
using Blockcore.Features.BlockStore.Persistence.RocksDb;
78
using Blockcore.Features.BlockStore.Repository;
89
using Blockcore.Networks;
@@ -26,8 +27,8 @@ public void InitializesGenesisBlockAndTxIndexOnFirstLoad()
2627

2728
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
2829
{
29-
byte[] blockRow = engine.Get(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]));
30-
bool txIndexRow = BitConverter.ToBoolean(engine.Get(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1])));
30+
byte[] blockRow = engine.Get(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]));
31+
bool txIndexRow = BitConverter.ToBoolean(engine.Get(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1])));
3132

3233
Assert.Equal(this.Network.GetGenesis().GetHash(), this.DataStoreSerializer.Deserialize<HashHeightPair>(blockRow).Hash);
3334
Assert.False(txIndexRow);
@@ -41,8 +42,8 @@ public void DoesNotOverwriteExistingBlockAndTxIndexOnFirstLoad()
4142

4243
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
4344
{
44-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(new uint256(56), 1)));
45-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
45+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(new uint256(56), 1)));
46+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
4647
}
4748

4849
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -51,8 +52,8 @@ public void DoesNotOverwriteExistingBlockAndTxIndexOnFirstLoad()
5152

5253
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
5354
{
54-
byte[] blockRow = engine.Get(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]));
55-
bool txIndexRow = BitConverter.ToBoolean(engine.Get(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1])));
55+
byte[] blockRow = engine.Get(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]));
56+
bool txIndexRow = BitConverter.ToBoolean(engine.Get(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1])));
5657

5758
Assert.Equal(new HashHeightPair(new uint256(56), 1), this.DataStoreSerializer.Deserialize<HashHeightPair>(blockRow));
5859
Assert.True(txIndexRow);
@@ -66,8 +67,8 @@ public void GetTrxAsyncWithoutTransactionIndexReturnsNewTransaction()
6667

6768
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
6869
{
69-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
70-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(false));
70+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
71+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(false));
7172
}
7273

7374
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -84,8 +85,8 @@ public void GetTrxAsyncWithoutTransactionInIndexReturnsNull()
8485
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
8586
{
8687
var blockId = new uint256(8920);
87-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
88-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
88+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
89+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
8990
}
9091

9192
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -107,10 +108,10 @@ public void GetTrxAsyncWithTransactionReturnsExistingTransaction()
107108
block.Header.GetHash();
108109
block.Transactions.Add(trans);
109110

110-
engine.Put(DBH.Key(LeveldbBlockRepository.BlockTableName, block.Header.GetHash().ToBytes()), block.ToBytes());
111-
engine.Put(DBH.Key(LeveldbBlockRepository.TransactionTableName, trans.GetHash().ToBytes()), block.Header.GetHash().ToBytes());
112-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
113-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
111+
engine.Put(DBH.Key(LevelDbBlockRepository.BlockTableName, block.Header.GetHash().ToBytes()), block.ToBytes());
112+
engine.Put(DBH.Key(LevelDbBlockRepository.TransactionTableName, trans.GetHash().ToBytes()), block.Header.GetHash().ToBytes());
113+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
114+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
114115
}
115116

116117
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -126,8 +127,8 @@ public void GetTrxBlockIdAsyncWithoutTxIndexReturnsDefaultId()
126127

127128
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
128129
{
129-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
130-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(false));
130+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
131+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(false));
131132
}
132133

133134
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -143,8 +144,8 @@ public void GetTrxBlockIdAsyncWithoutExistingTransactionReturnsNull()
143144

144145
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
145146
{
146-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
147-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
147+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
148+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
148149
}
149150

150151
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -160,9 +161,9 @@ public void GetTrxBlockIdAsyncWithTransactionReturnsBlockId()
160161

161162
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
162163
{
163-
engine.Put(DBH.Key(LeveldbBlockRepository.TransactionTableName, new uint256(26).ToBytes()), new uint256(42).ToBytes());
164-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
165-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
164+
engine.Put(DBH.Key(LevelDbBlockRepository.TransactionTableName, new uint256(26).ToBytes()), new uint256(42).ToBytes());
165+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
166+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
166167
}
167168

168169
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -198,8 +199,8 @@ public void PutAsyncWritesBlocksAndTransactionsToDbAndSavesNextBlockHash()
198199

199200
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
200201
{
201-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
202-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
202+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
203+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
203204
}
204205

205206
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -209,10 +210,10 @@ public void PutAsyncWritesBlocksAndTransactionsToDbAndSavesNextBlockHash()
209210

210211
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
211212
{
212-
byte[] blockHashKeyRow = engine.Get(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]));
213+
byte[] blockHashKeyRow = engine.Get(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]));
213214

214-
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(LeveldbBlockRepository.BlockTableName);
215-
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(LeveldbBlockRepository.TransactionTableName);
215+
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(LevelDbBlockRepository.BlockTableName);
216+
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(LevelDbBlockRepository.TransactionTableName);
216217

217218
Assert.Equal(new HashHeightPair(nextBlockHash, 100), this.DataStoreSerializer.Deserialize<HashHeightPair>(blockHashKeyRow));
218219
Assert.Equal(2, blockDict.Count);
@@ -238,7 +239,7 @@ public void SetTxIndexUpdatesTxIndex()
238239
string dir = CreateTestDir(this);
239240
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
240241
{
241-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
242+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
242243
}
243244

244245
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -248,7 +249,7 @@ public void SetTxIndexUpdatesTxIndex()
248249

249250
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
250251
{
251-
bool txIndexRow = BitConverter.ToBoolean(engine.Get(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1])));
252+
bool txIndexRow = BitConverter.ToBoolean(engine.Get(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1])));
252253
Assert.False(txIndexRow);
253254
}
254255
}
@@ -261,7 +262,7 @@ public void GetAsyncWithExistingBlockReturnsBlock()
261262

262263
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
263264
{
264-
engine.Put(DBH.Key(LeveldbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
265+
engine.Put(DBH.Key(LevelDbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
265266
}
266267

267268
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -286,7 +287,7 @@ public void GetAsyncWithExistingBlocksReturnsBlocks()
286287
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
287288
{
288289
for (int i = 0; i < blocks.Length; i++)
289-
engine.Put(DBH.Key(LeveldbBlockRepository.BlockTableName, blocks[i].GetHash().ToBytes()), blocks[i].ToBytes());
290+
engine.Put(DBH.Key(LevelDbBlockRepository.BlockTableName, blocks[i].GetHash().ToBytes()), blocks[i].ToBytes());
290291
}
291292

292293
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -318,7 +319,7 @@ public void ExistAsyncWithExistingBlockReturnsTrue()
318319

319320
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
320321
{
321-
engine.Put(DBH.Key(LeveldbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
322+
engine.Put(DBH.Key(LevelDbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
322323
}
323324

324325
using (IBlockRepository repository = this.SetupRepository(this.Network, dir))
@@ -347,9 +348,9 @@ public void DeleteAsyncRemovesBlocksAndTransactions()
347348

348349
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
349350
{
350-
engine.Put(DBH.Key(LeveldbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
351-
engine.Put(DBH.Key(LeveldbBlockRepository.TransactionTableName, block.Transactions[0].GetHash().ToBytes()), block.GetHash().ToBytes());
352-
engine.Put(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
351+
engine.Put(DBH.Key(LevelDbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
352+
engine.Put(DBH.Key(LevelDbBlockRepository.TransactionTableName, block.Transactions[0].GetHash().ToBytes()), block.GetHash().ToBytes());
353+
engine.Put(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
353354
}
354355

355356
var tip = new HashHeightPair(new uint256(45), 100);
@@ -361,9 +362,9 @@ public void DeleteAsyncRemovesBlocksAndTransactions()
361362

362363
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
363364
{
364-
byte[] blockHashKeyRow = engine.Get(DBH.Key(LeveldbBlockRepository.CommonTableName, new byte[0]));
365-
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(LeveldbBlockRepository.BlockTableName);
366-
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(LeveldbBlockRepository.TransactionTableName);
365+
byte[] blockHashKeyRow = engine.Get(DBH.Key(LevelDbBlockRepository.CommonTableName, new byte[0]));
366+
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(LevelDbBlockRepository.BlockTableName);
367+
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(LevelDbBlockRepository.TransactionTableName);
367368

368369
Assert.Equal(tip, this.DataStoreSerializer.Deserialize<HashHeightPair>(blockHashKeyRow));
369370
Assert.Empty(blockDict);
@@ -382,7 +383,7 @@ public void ReIndexAsync_TxIndex_OffToOn()
382383
// Set up database to mimic that created when TxIndex was off. No transactions stored.
383384
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
384385
{
385-
engine.Put(DBH.Key(LeveldbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
386+
engine.Put(DBH.Key(LevelDbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
386387
}
387388

388389
// Turn TxIndex on and then reindex database, as would happen on node startup if -txindex and -reindex are set.
@@ -395,8 +396,8 @@ public void ReIndexAsync_TxIndex_OffToOn()
395396
// Check that after indexing database, the transaction inside the block is now indexed.
396397
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
397398
{
398-
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(LeveldbBlockRepository.BlockTableName);
399-
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(LeveldbBlockRepository.TransactionTableName);
399+
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(LevelDbBlockRepository.BlockTableName);
400+
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(LevelDbBlockRepository.TransactionTableName);
400401

401402
// Block stored as expected.
402403
Assert.Single(blockDict);
@@ -421,8 +422,8 @@ public void ReIndexAsync_TxIndex_OnToOff()
421422
// Set up database to mimic that created when TxIndex was on. Transaction from block is stored.
422423
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
423424
{
424-
engine.Put(DBH.Key(LeveldbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
425-
engine.Put(DBH.Key(LeveldbBlockRepository.TransactionTableName, transaction.GetHash().ToBytes()), block.GetHash().ToBytes());
425+
engine.Put(DBH.Key(LevelDbBlockRepository.BlockTableName, block.GetHash().ToBytes()), block.ToBytes());
426+
engine.Put(DBH.Key(LevelDbBlockRepository.TransactionTableName, transaction.GetHash().ToBytes()), block.GetHash().ToBytes());
426427
}
427428

428429
// Turn TxIndex off and then reindex database, as would happen on node startup if -txindex=0 and -reindex are set.
@@ -435,8 +436,8 @@ public void ReIndexAsync_TxIndex_OnToOff()
435436
// Check that after indexing database, the transaction is no longer stored.
436437
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
437438
{
438-
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(LeveldbBlockRepository.BlockTableName);
439-
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(LeveldbBlockRepository.TransactionTableName);
439+
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(LevelDbBlockRepository.BlockTableName);
440+
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(LevelDbBlockRepository.TransactionTableName);
440441

441442
// Block still stored as expected.
442443
Assert.Single(blockDict);
@@ -541,7 +542,7 @@ private IBlockRepository SetupRepository(Network main, string dir)
541542
{
542543
var dBreezeSerializer = new DataStoreSerializer(main.Consensus.ConsensusFactory);
543544

544-
var repository = new LeveldbBlockRepository(main, dir, this.LoggerFactory.Object, dBreezeSerializer);
545+
var repository = new LevelDbBlockRepository(main, dir, this.LoggerFactory.Object, dBreezeSerializer);
545546
repository.Initialize();
546547

547548
return repository;

src/Tests/Blockcore.Features.BlockStore.Tests/Blockcore.Features.BlockStore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30+
<ProjectReference Include="..\..\Features\Persistence\Blockcore.Features.BlockStore.Persistence.LevelDb\Blockcore.Features.BlockStore.Persistence.LevelDb.csproj" />
3031
<ProjectReference Include="..\..\Features\Persistence\Blockcore.Features.BlockStore.Persistence.RocksDb\Blockcore.Features.BlockStore.Persistence.RocksDb.csproj" />
3132
<ProjectReference Include="..\..\Networks\Bitcoin\Blockcore.Networks.Bitcoin\Blockcore.Networks.Bitcoin.csproj" />
3233
<ProjectReference Include="..\..\Networks\Stratis\Blockcore.Networks.Stratis\Blockcore.Networks.Stratis.csproj" />

0 commit comments

Comments
 (0)