Fix missing master fingerprint/account key path on wallet import (#2727)

* Fix missing master fingerprint/account key path on wallet import

Re-adds the view model properties that got removed in 8a1d5bbc57 and passes them through the confirm addresses form.

* Add test

This test fails on current master
This commit is contained in:
d11n 2021-08-03 07:27:04 +02:00 committed by GitHub
parent 1b85ab8b54
commit 63d4ccc058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 17 deletions

View File

@ -128,6 +128,7 @@ namespace BTCPayServer.Tests
public Mnemonic GenerateWallet(string cryptoCode = "BTC", string seed = "", bool importkeys = false, bool privkeys = false, ScriptPubKeyType format = ScriptPubKeyType.Segwit) public Mnemonic GenerateWallet(string cryptoCode = "BTC", string seed = "", bool importkeys = false, bool privkeys = false, ScriptPubKeyType format = ScriptPubKeyType.Segwit)
{ {
var isImport = !string.IsNullOrEmpty(seed);
Driver.FindElement(By.Id($"Modify{cryptoCode}")).Click(); Driver.FindElement(By.Id($"Modify{cryptoCode}")).Click();
// Replace previous wallet case // Replace previous wallet case
@ -137,14 +138,7 @@ namespace BTCPayServer.Tests
Driver.FindElement(By.Id("continue")).Click(); Driver.FindElement(By.Id("continue")).Click();
} }
if (string.IsNullOrEmpty(seed)) if (isImport)
{
var option = privkeys ? "Hotwallet" : "Watchonly";
Logs.Tester.LogInformation($"Generating new seed ({option})");
Driver.FindElement(By.Id("GenerateWalletLink")).Click();
Driver.FindElement(By.Id($"Generate{option}Link")).Click();
}
else
{ {
Logs.Tester.LogInformation("Progressing with existing seed"); Logs.Tester.LogInformation("Progressing with existing seed");
Driver.FindElement(By.Id("ImportWalletOptionsLink")).Click(); Driver.FindElement(By.Id("ImportWalletOptionsLink")).Click();
@ -152,6 +146,13 @@ namespace BTCPayServer.Tests
Driver.FindElement(By.Id("ExistingMnemonic")).SendKeys(seed); Driver.FindElement(By.Id("ExistingMnemonic")).SendKeys(seed);
Driver.SetCheckbox(By.Id("SavePrivateKeys"), privkeys); Driver.SetCheckbox(By.Id("SavePrivateKeys"), privkeys);
} }
else
{
var option = privkeys ? "Hotwallet" : "Watchonly";
Logs.Tester.LogInformation($"Generating new seed ({option})");
Driver.FindElement(By.Id("GenerateWalletLink")).Click();
Driver.FindElement(By.Id($"Generate{option}Link")).Click();
}
Driver.FindElement(By.Id("ScriptPubKeyType")).Click(); Driver.FindElement(By.Id("ScriptPubKeyType")).Click();
Driver.FindElement(By.CssSelector($"#ScriptPubKeyType option[value={format}]")).Click(); Driver.FindElement(By.CssSelector($"#ScriptPubKeyType option[value={format}]")).Click();
@ -160,17 +161,25 @@ namespace BTCPayServer.Tests
Driver.SetCheckbox(By.Id("ImportKeysToRPC"), importkeys); Driver.SetCheckbox(By.Id("ImportKeysToRPC"), importkeys);
Driver.FindElement(By.Id("Continue")).Click(); Driver.FindElement(By.Id("Continue")).Click();
// Seed backup page if (isImport)
FindAlertMessage();
if (string.IsNullOrEmpty(seed))
{ {
seed = Driver.FindElements(By.Id("RecoveryPhrase")).First().GetAttribute("data-mnemonic"); // Confirm addresses
Driver.FindElement(By.Id("Confirm")).Click();
} }
else
{
// Seed backup
FindAlertMessage();
if (string.IsNullOrEmpty(seed))
{
seed = Driver.FindElements(By.Id("RecoveryPhrase")).First().GetAttribute("data-mnemonic");
}
// Confirm seed backup // Confirm seed backup
Driver.FindElement(By.Id("confirm")).Click(); Driver.FindElement(By.Id("confirm")).Click();
Driver.FindElement(By.Id("submit")).Click(); Driver.FindElement(By.Id("submit")).Click();
}
WalletId = new WalletId(StoreId, cryptoCode); WalletId = new WalletId(StoreId, cryptoCode);
return new Mnemonic(seed); return new Mnemonic(seed);
} }

View File

@ -831,6 +831,11 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.LinkText("Manage")).Click(); s.Driver.FindElement(By.LinkText("Manage")).Click();
s.ClickOnAllSideMenus(); s.ClickOnAllSideMenus();
// Make sure wallet info is correct
s.Driver.FindElement(By.Id("WalletSettings")).Click();
Assert.Contains(mnemonic.DeriveExtKey().GetPublicKey().GetHDFingerPrint().ToString(), s.Driver.FindElement(By.Id("AccountKeys_0__MasterFingerprint")).GetAttribute("value"));
Assert.Contains("m/84'/1'/0'", s.Driver.FindElement(By.Id("AccountKeys_0__AccountKeyPath")).GetAttribute("value"));
// Make sure we can rescan, because we are admin! // Make sure we can rescan, because we are admin!
s.Driver.FindElement(By.Id("WalletRescan")).Click(); s.Driver.FindElement(By.Id("WalletRescan")).Click();
@ -908,6 +913,23 @@ namespace BTCPayServer.Tests
} }
} }
[Fact(Timeout = TestTimeout)]
public async Task CanImportWallet()
{
using (var s = SeleniumTester.Create())
{
await s.StartAsync();
s.RegisterNewUser(true);
var (_, storeId) = s.CreateNewStore();
var mnemonic = s.GenerateWallet("BTC", "click chunk owner kingdom faint steak safe evidence bicycle repeat bulb wheel");
// Make sure wallet info is correct
s.GoToWallet(new WalletId(storeId, "BTC"), WalletsNavPages.Settings);
Assert.Contains(mnemonic.DeriveExtKey().GetPublicKey().GetHDFingerPrint().ToString(), s.Driver.FindElement(By.Id("AccountKeys_0__MasterFingerprint")).GetAttribute("value"));
Assert.Contains( "m/84'/1'/0'", s.Driver.FindElement(By.Id("AccountKeys_0__AccountKeyPath")).GetAttribute("value"));
}
}
[Fact] [Fact]
[Trait("Selenium", "Selenium")] [Trait("Selenium", "Selenium")]
public async Task CanUsePullPaymentsViaUI() public async Task CanUsePullPaymentsViaUI()

View File

@ -305,9 +305,11 @@ namespace BTCPayServer.Controllers
derivationSchemeSettings.AccountOriginal = response.DerivationScheme.ToString(); derivationSchemeSettings.AccountOriginal = response.DerivationScheme.ToString();
// Set wallet properties from generate response // Set wallet properties from generate response
vm.RootFingerprint = response.AccountKeyPath.MasterFingerprint.ToString();
vm.AccountKey = response.AccountHDKey.Neuter().ToWif();
vm.KeyPath = response.AccountKeyPath.KeyPath.ToString();
vm.Config = ProtectString(derivationSchemeSettings.ToJson()); vm.Config = ProtectString(derivationSchemeSettings.ToJson());
var result = await UpdateWallet(vm); var result = await UpdateWallet(vm);
if (!ModelState.IsValid || !(result is RedirectToActionResult)) if (!ModelState.IsValid || !(result is RedirectToActionResult))

View File

@ -50,6 +50,9 @@
<input asp-for="Config" type="hidden"/> <input asp-for="Config" type="hidden"/>
<input asp-for="Confirmation" type="hidden"/> <input asp-for="Confirmation" type="hidden"/>
<input asp-for="DerivationScheme" type="hidden"/> <input asp-for="DerivationScheme" type="hidden"/>
<input asp-for="AccountKey" type="hidden" />
<input asp-for="RootFingerprint" type="hidden" />
<input asp-for="KeyPath" type="hidden" />
<div class="form-group"> <div class="form-group">
<table class="table table-sm table-responsive-md"> <table class="table table-sm table-responsive-md">