Skip to content

Commit 731e74b

Browse files
authored
Creating a method to auto generate the test wallet db (#264)
* Creating a method to auto generate the test wallet db * make sure IStakeChain can be null for POW networks * Change LiteDB.FileMode for mac os
1 parent 7c32b4a commit 731e74b

12 files changed

Lines changed: 737 additions & 12 deletions

File tree

src/Features/Blockcore.Features.BlockStore/Api/Controllers/BlockStoreController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public BlockStoreController(
5959
ChainIndexer chainIndexer,
6060
IAddressIndexer addressIndexer,
6161
IUtxoIndexer utxoIndexer,
62-
IStakeChain stakeChain)
62+
IStakeChain stakeChain = null)
6363
{
6464
Guard.NotNull(network, nameof(network));
6565
Guard.NotNull(loggerFactory, nameof(loggerFactory));

src/Features/Blockcore.Features.BlockStore/Api/Models/BlockStoreRouteEndPoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public static class BlockStoreRouteEndPoint
66
public const string GetVerboseAddressesBalances = "getverboseaddressesbalances";
77
public const string GetAddressIndexerTip = "addressindexertip";
88
public const string GetBlock = "block";
9-
public const string GetBlockCount = "GetBlockCount";
9+
public const string GetBlockCount = "getblockcount";
1010
public const string GetUtxoSet = "getutxoset";
1111
}
12-
}
12+
}

src/Features/Blockcore.Features.Wallet/Database/WalletStore.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Runtime.InteropServices;
56
using Blockcore.Configuration;
67
using Blockcore.Consensus.ScriptInfo;
78
using Blockcore.Consensus.TransactionInfo;
@@ -45,15 +46,16 @@ public WalletStore(Network network, DataFolder dataFolder, Types.Wallet wallet)
4546
}
4647

4748
BsonMapper mapper = this.Create();
48-
49+
LiteDB.FileMode fileMode = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? LiteDB.FileMode.Exclusive : LiteDB.FileMode.Shared;
50+
4951
if (!File.Exists(dbPath))
5052
{
51-
this.db = new LiteDatabase(new ConnectionString() { Filename = dbPath }, mapper: mapper);
53+
this.db = new LiteDatabase(new ConnectionString() { Filename = dbPath, Mode = fileMode }, mapper: mapper);
5254
}
5355
else
5456
{
5557
// Only perform this check if the database file already exists.
56-
this.db = new LiteDatabase(new ConnectionString() { Filename = dbPath }, mapper: mapper);
58+
this.db = new LiteDatabase(new ConnectionString() { Filename = dbPath, Mode = fileMode }, mapper: mapper);
5759

5860
// Attempt to access the user version, this will crash if the loaded database is V5 and we use V4 packages.
5961
try
@@ -68,7 +70,7 @@ public WalletStore(Network network, DataFolder dataFolder, Types.Wallet wallet)
6870
File.Move(dbPath, dbBackupPath);
6971

7072
// Re-create the database object after we renamed the file.
71-
this.db = new LiteDatabase(new ConnectionString() { Filename = dbPath }, mapper: mapper);
73+
this.db = new LiteDatabase(new ConnectionString() { Filename = dbPath, Mode = fileMode }, mapper: mapper);
7274
}
7375
}
7476

@@ -166,7 +168,6 @@ public IEnumerable<WalletHistoryData> GetAccountHistory(int accountIndex, bool e
166168
.OrderByDescending(x => x.SpendingDetails.CreationTime)
167169
.ToList();
168170

169-
170171
Query historyUnSpentQuery = Query.EQ("AccountIndex", new BsonValue(accountIndex));
171172
if (excludeColdStake)
172173
{
@@ -387,4 +388,4 @@ public void Dispose()
387388
this.db?.Dispose();
388389
}
389390
}
390-
}
391+
}

src/Tests/Blockcore.IntegrationTests.Common/Blockcore.IntegrationTests.Common.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
<None Update="ReadyData\StratisXOver15K.zip">
8383
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8484
</None>
85+
<None Update="ReadyData\wallet-data-table.json">
86+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
87+
</None>
88+
<None Update="ReadyData\wallet-transactions-table.json">
89+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
90+
</None>
8591
</ItemGroup>
8692

8793
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"Id": "Key",
4+
"EncryptedSeed": "6PYVfbtgR2vvkEtjCGFSq6v2nRoZMc2X1yPo5jG9TmGfCdQaoP8cR3iVLf",
5+
"WalletName": "wallet-with-funds",
6+
"WalletTip": "612591-d79c85e49d4024adb6f5d0a4e84aabac7a12f5964d41d3f16af3dedef22a2ad7",
7+
"BlockLocator": [ "d79c85e49d4024adb6f5d0a4e84aabac7a12f5964d41d3f16af3dedef22a2ad7", "4b879668ea35a9dc1d0dee41263b8016cefb1ad61675a81a196f105a605f6253", "bba5ab001f7062f83b03d80879be19cdaa986830dc8dec8a4a1e562ab147e70b", "2e1a140297f7eaa1bed438c212a96b21c7d9c04769453a2c9cc268df98aa8ed9", "493bd83839f93cbcc889815262a3f3e54103dccb260051048e23b5604afcdcb0", "f11e1a27ca52006fd47d51a706648ea7b5a9f192a61710d0e82c835828abef5f", "580f36fa1c57bf64f11df5fbe239c022097f637e64ac5bbc3c3899435d0071a0", "f62357b1d4672f4eb6b1f963adb0ead2b307102cae5387732b642e8564400c6d", "9870ae47fcc2738ca011cb74d61f67f9da07b7438ff3d09dc6fa02917e13a48d", "63b4aba410a3b3c527eabe38412166d89f0e098d19a3bd052c70b155ebd0d0f5", "7b2d2fe5d7c4c4dd01c7d456bb288a684f3a901b0d12453cb77d199d609f710f", "feec721ef1f80e5e012eed5afe9ca78cde43f3494b08aca7f49ec15cf1737171", "d7345f76239eaaa5323d6e1fe7900e26909d4007a06a09b7f8a5010c9e318326", "a1afdab1e03cda7055678ca3cef5fc7a0f9d06bc0fcafc6700ffae77bceea452", "b7911ba105301945ccf59ae3b78921a8e7198ee82d6ec25e9b7a754a7ac1002e", "e9c38e323f466535b8bc6835c90bf260f360d5736ddd42e9cf64b0ac221f679b", "b2f5ee550f209aa5f7ce6f4422763e7ef79f3386f745b70939bda2da5a76bf6b", "5a90d268ba726930203c9adc2537e7f962b22452edc97146d0e6d8d179c84e54", "eafd04ba3a794d9a1c12269796e9b8c4ac7449bb7ea7cf9e206b14a3fc279ef9", "a9c671439827cb12a5295949bbfe601eab867c0370c91044dd385f64275ac84f", "a43d26bb6f835a520af7dd45a6c526557b9b5885faeabe64c932a5a7bca9769f", "0e15cd950c3b11c9f2a9c202a604b767fc7831da0dd1ea92c327a5406fac7040", "8af05078c9ec117b47406ab37c78ff770df562cdd605455e0f0718f8b9d0e5c0", "3c5292dd49bd3a004c355583c418c23793a713fac520cf14d29dfc598325186b", "33cc2264bf832b1eb27684bb9b64e83e7356a8b1571feae9f520dbb6deb3c6be", "180c94c93bd809a7d485114f5836e838902cd46ce0f613284c90be7a5846e816", "a2ec04f0f3544be538f483b8ae30043154d4e84a6cc63fd3aa3b12b749afbf27", "462091fa4e345b8d3b8985a363a555abdd5826a94d5ef201fadddeeadef2e9aa", "70d26875349c222a1c8b48c85ac382d8c10cdd594df773550ef45f551a68f901", "86f4b8458194221f5a94f00b5b396a24a9c12e97a42e92e29879c17a64941888", "00000e246d7b73b88c9ab55f2e5e94d9e22d471def3df5ea448f5576b1d156b9" ]
8+
}
9+
]

0 commit comments

Comments
 (0)