Fix Safe DateTimeOffset bug
MODIFY
HiddenWallet.Tests/SafeTests.cs
HiddenWallet.Tests/SafeTests.cs
@@ -5,6 +5,7 @@ using NBitcoin;
using Xunit;
using HiddenWallet.Models;
using System.Threading.Tasks;
+using System.IO;
namespace HiddenWallet.Tests
{
@@ -19,14 +20,18 @@ namespace HiddenWallet.Tests
const string path = "Wallets/TestWallet.json";
const string password = "password";
+ const string recoveredPath = "Wallets/RecoveredTestWallet.json";
+
+ if (File.Exists(path)) File.Delete(path);
+ if (File.Exists(recoveredPath)) File.Delete(recoveredPath);
var result = await Safe.CreateAsync(password, path, network);
var safe = result.Safe;
var mnemonic = result.Mnemonic;
var loadedSafe = await Safe.LoadAsync(password, path);
- var wantedCreation = DateTimeOffset.ParseExact("1998-01-01", "yyyy-MM-dd", CultureInfo.InvariantCulture);
- var recoverdSafe = await Safe.RecoverAsync(mnemonic, password, "Wallets/RecoveredTestWallet.json", network, wantedCreation);
+ var wantedCreation = DateTimeOffset.ParseExact("1998-01-01", "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
+ var recoverdSafe = await Safe.RecoverAsync(mnemonic, password, recoveredPath, network, wantedCreation);
var alice = new SafeAccount(3);
var bob = new SafeAccount(4);

MODIFY
HiddenWallet/KeyManagement/Safe.cs
HiddenWallet/KeyManagement/Safe.cs
@@ -15,7 +15,7 @@ namespace HiddenWallet.KeyManagement
{
public Network Network { get; }
- public static DateTimeOffset EarliestPossibleCreationTime { get; set; } = DateTimeOffset.ParseExact("2017-02-19", "yyyy-MM-dd", CultureInfo.InvariantCulture);
+ public static DateTimeOffset EarliestPossibleCreationTime { get; set; } = DateTimeOffset.ParseExact("2017-02-19", "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
public DateTimeOffset CreationTime { get; }
@@ -109,7 +109,7 @@ namespace HiddenWallet.KeyManagement
/// <returns>Safe</returns>
public static async Task<(Safe Safe, Mnemonic Mnemonic)> CreateAsync(string password, string walletFilePath, Network network)
{
- var creationTime = new DateTimeOffset(DateTimeOffset.UtcNow.Date);
+ var creationTime = new DateTimeOffset(DateTimeOffset.UtcNow.Date, TimeSpan.Zero);
var safe = new Safe(password, walletFilePath, network, creationTime);
@@ -192,7 +192,7 @@ namespace HiddenWallet.KeyManagement
var networkString = walletFileRawContent.Network;
network = networkString == Network.Main.ToString() ? Network.Main : Network.TestNet;
- DateTimeOffset creationTime = DateTimeOffset.ParseExact(walletFileRawContent.CreationTime, "yyyy-MM-dd", CultureInfo.InvariantCulture);
+ DateTimeOffset creationTime = DateTimeOffset.ParseExact(walletFileRawContent.CreationTime, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
var safe = new Safe(password, walletFilePath, network, creationTime);

Fix Safe DateTimeOffset bug