public void ProcessRecoverWallet_ShouldRecoverAWalletWhenGivenValidArguments() { // Arrange const string walletFileName = "wallet_recover_test.json"; const string mnemonic = "dash destroy twelve twice labor patch embrace embody chronic inch install term"; var args = new[] { $"wallet-file={walletFileName}", $"mnemonic={mnemonic}", }; var password = new SecureString(); password.AppendChar('p'); password.AppendChar('a'); password.AppendChar('s'); password.AppendChar('s'); password.AppendChar('w'); password.AppendChar('o'); password.AppendChar('r'); password.AppendChar('d'); const string expectedEncryptedSeed = "6PYM714zxNRpmx7WRaCLNJyAreYx2BU5GkbCx5jF5QQNKeZExYqrNHzK8L"; const string expectedChainCode = "CarQU+owbi2iML7Fy5vf+6O0Lpc/V//NFkk7WLVkh70="; IBitcoinLibrary bitcoinLibrary = new BitcoinLibrary(); // Act var recoveredWalletLocation = string.Empty; try { recoveredWalletLocation = bitcoinLibrary.ProcessRecoverWallet(args, password); } catch (Exception ex) { ex.Should().BeNull(); } // Assert File.Exists(recoveredWalletLocation).Should().BeTrue(); var fileContents = File.ReadAllText(recoveredWalletLocation); // Check our Encrypted Seed exists fileContents.Should().Contain(expectedEncryptedSeed); // Check our Chain Code exists fileContents.Should().Contain(expectedChainCode); // Cleanup Directory.Delete("Wallets", true); File.Delete(walletFileName); }
public void ProcessRecoverWallet_ShouldThrowCustomExceptionIfWalletExists() { // Arrange const string walletDirectoryName = "Wallets"; const string walletFileName = "wallet_recover_exists_test.json"; Directory.CreateDirectory(walletDirectoryName); using (File.Create(Path.Combine(walletDirectoryName, walletFileName))) { } const string mnemonic = "dash,destroy,twelve,twice,labor,patch,embrace,embody,chronic,inch,install,term"; var args = new[] { $"wallet-file={walletFileName}", $"mnemonic={mnemonic}", }; var password = new SecureString(); password.AppendChar('p'); password.AppendChar('a'); password.AppendChar('s'); password.AppendChar('s'); password.AppendChar('w'); password.AppendChar('o'); password.AppendChar('r'); password.AppendChar('d'); IBitcoinLibrary bitcoinLibrary = new BitcoinLibrary(); try { // Act bitcoinLibrary.ProcessRecoverWallet(args, password); // Should not get here - force a fail if we do bitcoinLibrary.Should().BeNull(); } catch (WalletAlreadyExistsException ex) { // Assert ex.Message.Should().Be("The request to generate a wallet failed because the wallet already exists."); } // Cleanup Directory.Delete(walletDirectoryName, true); File.Delete(walletFileName); }
public void ProcessRecoverWallet_ShouldThrowCustomExceptionOnInvalidMnemonic() { // Arrange const string walletFileName = "wallet_recover_invalid_mnemonic_test.json"; var args = new[] { $"wallet-file={walletFileName}", "mnemonic=InvalidMnemonic", }; var password = new SecureString(); password.AppendChar('p'); password.AppendChar('a'); password.AppendChar('s'); password.AppendChar('s'); password.AppendChar('w'); password.AppendChar('o'); password.AppendChar('r'); password.AppendChar('d'); IBitcoinLibrary bitcoinLibrary = new BitcoinLibrary(); try { // Act bitcoinLibrary.ProcessRecoverWallet(args, password); // Should not get here - force a fail if we do bitcoinLibrary.Should().BeNull(); } catch (InvalidMnemonicException ex) { // Assert ex.Message.Should().Be("Mnemonic is invalid."); } }