diff --git a/BTCPayServer.Tests/PSBTTests.cs b/BTCPayServer.Tests/PSBTTests.cs index 0b6588d76..1c41890e2 100644 --- a/BTCPayServer.Tests/PSBTTests.cs +++ b/BTCPayServer.Tests/PSBTTests.cs @@ -11,6 +11,7 @@ using NBitcoin; using NBitpayClient; using Xunit; using Xunit.Abstractions; +using BTCPayServer.Models; namespace BTCPayServer.Tests { @@ -70,7 +71,7 @@ namespace BTCPayServer.Tests BitcoinAddress.Create(vmLedger.HintChange, user.SupportedNetwork.NBitcoinNetwork); Assert.NotNull(vmLedger.WebsocketPath); - var redirectedPSBT = (string)Assert.IsType(await walletController.WalletSend(walletId, sendModel, command: "analyze-psbt")).RouteValues["psbt"]; + string redirectedPSBT = AssertRedirectedPSBT(await walletController.WalletSend(walletId, sendModel, command: "analyze-psbt")); var vmPSBT = await walletController.WalletPSBT(walletId, new WalletPSBTViewModel() { PSBT = redirectedPSBT }).AssertViewModelAsync(); var unsignedPSBT = PSBT.Parse(vmPSBT.PSBT, user.SupportedNetwork.NBitcoinNetwork); Assert.NotNull(vmPSBT.Decoded); @@ -97,9 +98,9 @@ namespace BTCPayServer.Tests var combineVM = await walletController.WalletPSBT(walletId, vmPSBT, "combine").AssertViewModelAsync(); Assert.Equal(vmPSBT.PSBT, combineVM.OtherPSBT); combineVM.PSBT = signedPSBT.ToBase64(); - vmPSBT = await walletController.WalletPSBTCombine(walletId, combineVM).AssertViewModelAsync(); + var psbt = AssertRedirectedPSBT(await walletController.WalletPSBTCombine(walletId, combineVM)); - var signedPSBT2 = PSBT.Parse(vmPSBT.PSBT, user.SupportedNetwork.NBitcoinNetwork); + var signedPSBT2 = PSBT.Parse(psbt, user.SupportedNetwork.NBitcoinNetwork); Assert.True(signedPSBT.TryFinalize(out _)); Assert.True(signedPSBT2.TryFinalize(out _)); Assert.Equal(signedPSBT, signedPSBT2); @@ -107,19 +108,27 @@ namespace BTCPayServer.Tests // Can use uploaded file? combineVM.PSBT = null; combineVM.UploadedPSBTFile = TestUtils.GetFormFile("signedPSBT", signedPSBT.ToBytes()); - vmPSBT = await walletController.WalletPSBTCombine(walletId, combineVM).AssertViewModelAsync(); - signedPSBT2 = PSBT.Parse(vmPSBT.PSBT, user.SupportedNetwork.NBitcoinNetwork); + psbt = AssertRedirectedPSBT(await walletController.WalletPSBTCombine(walletId, combineVM)); + signedPSBT2 = PSBT.Parse(psbt, user.SupportedNetwork.NBitcoinNetwork); Assert.True(signedPSBT.TryFinalize(out _)); Assert.True(signedPSBT2.TryFinalize(out _)); Assert.Equal(signedPSBT, signedPSBT2); var ready = (await walletController.WalletPSBTReady(walletId, signedPSBT.ToBase64())).AssertViewModel(); Assert.Equal(signedPSBT.ToBase64(), ready.PSBT); - redirect = Assert.IsType(await walletController.WalletPSBTReady(walletId, ready, command: "analyze-psbt")); - Assert.Equal(signedPSBT.ToBase64(), (string)redirect.RouteValues["psbt"]); + psbt = AssertRedirectedPSBT(await walletController.WalletPSBTReady(walletId, ready, command: "analyze-psbt")); + Assert.Equal(signedPSBT.ToBase64(), psbt); redirect = Assert.IsType(await walletController.WalletPSBTReady(walletId, ready, command: "broadcast")); Assert.Equal(nameof(walletController.WalletTransactions), redirect.ActionName); } } + + private static string AssertRedirectedPSBT(IActionResult view) + { + var postRedirectView = Assert.IsType(view); + var postRedirectViewModel = Assert.IsType(postRedirectView.Model); + var redirectedPSBT = postRedirectViewModel.Parameters.Single(p => p.Key == "psbt").Value; + return redirectedPSBT; + } } } diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index e8565db1a..dc9387ace 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -465,7 +465,7 @@ namespace BTCPayServer.Controllers private IActionResult RedirectToWalletPSBT(WalletId walletId, PSBT psbt, string fileName = null) { - var vm = new PostRedictViewModel() + var vm = new PostRedirectViewModel() { AspController = "Wallets", AspAction = nameof(WalletPSBT), diff --git a/BTCPayServer/Models/PostRedictViewModel.cs b/BTCPayServer/Models/PostRedictViewModel.cs index 0895f1199..53b8ef206 100644 --- a/BTCPayServer/Models/PostRedictViewModel.cs +++ b/BTCPayServer/Models/PostRedictViewModel.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; namespace BTCPayServer.Models { - public class PostRedictViewModel + public class PostRedirectViewModel { public string AspAction { get; set; } public string AspController { get; set; } diff --git a/BTCPayServer/Views/Shared/PostRedirect.cshtml b/BTCPayServer/Views/Shared/PostRedirect.cshtml index 3492aec88..50a946f7e 100644 --- a/BTCPayServer/Views/Shared/PostRedirect.cshtml +++ b/BTCPayServer/Views/Shared/PostRedirect.cshtml @@ -1,4 +1,4 @@ -@model PostRedictViewModel +@model PostRedirectViewModel @{ Layout = null; }