mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-19 05:33:31 +01:00
Fix tests
This commit is contained in:
parent
2b6bd3d751
commit
ba9928831e
@ -1461,53 +1461,60 @@ namespace BTCPayServer.Tests
|
|||||||
{
|
{
|
||||||
var testnetNetworkProvider = new BTCPayNetworkProvider(NetworkType.Testnet);
|
var testnetNetworkProvider = new BTCPayNetworkProvider(NetworkType.Testnet);
|
||||||
var regtestNetworkProvider = new BTCPayNetworkProvider(NetworkType.Regtest);
|
var regtestNetworkProvider = new BTCPayNetworkProvider(NetworkType.Regtest);
|
||||||
var parser = new DerivationSchemeParser(testnetNetworkProvider.GetNetwork("BTC"));
|
var mainnetNetworkProvider = new BTCPayNetworkProvider(NetworkType.Mainnet);
|
||||||
|
var testnetParser = new DerivationSchemeParser(testnetNetworkProvider.GetNetwork("BTC"));
|
||||||
|
var mainnetParser = new DerivationSchemeParser(mainnetNetworkProvider.GetNetwork("BTC"));
|
||||||
NBXplorer.DerivationStrategy.DerivationStrategyBase result;
|
NBXplorer.DerivationStrategy.DerivationStrategyBase result;
|
||||||
// Passing electrum stuff
|
// Passing electrum stuff
|
||||||
// Native
|
// Native
|
||||||
result = parser.Parse("zpub6nL6PUGurpU3DfPDSZaRS6WshpbNc9ctCFFzrCn54cssnheM31SZJZUcFHKtjJJNhAueMbh6ptFMfy1aeiMQJr3RJ4DDt1hAPx7sMTKV48t");
|
result = testnetParser.Parse("zpub6nL6PUGurpU3DfPDSZaRS6WshpbNc9ctCFFzrCn54cssnheM31SZJZUcFHKtjJJNhAueMbh6ptFMfy1aeiMQJr3RJ4DDt1hAPx7sMTKV48t");
|
||||||
Assert.Equal("tpubD93CJNkmGjLXnsBqE2zGDqfEh1Q8iJ8wueordy3SeWt1RngbbuxXCsqASuVWFywmfoCwUE1rSfNJbaH4cBNcbp8WcyZgPiiRSTazLGL8U9w", result.ToString());
|
Assert.Equal("tpubD93CJNkmGjLXnsBqE2zGDqfEh1Q8iJ8wueordy3SeWt1RngbbuxXCsqASuVWFywmfoCwUE1rSfNJbaH4cBNcbp8WcyZgPiiRSTazLGL8U9w", result.ToString());
|
||||||
// P2SH
|
// P2SH
|
||||||
result = parser.Parse("ypub6QqdH2c5z79681jUgdxjGJzGW9zpL4ryPCuhtZE4GpvrJoZqM823XQN6iSQeVbbbp2uCRQ9UgpeMcwiyV6qjvxTWVcxDn2XEAnioMUwsrQ5");
|
result = testnetParser.Parse("upub57Wa4MvRPNyAipy1MCpERxcFpHR2ZatyikppkyeWkoRL6QJvLVMo39jYdcaJVxyvBURyRVmErBEA5oGicKBgk1j72GAXSPFH5tUDoGZ8nEu");
|
||||||
Assert.Equal("tpubD6NzVbkrYhZ4YWjDJUACG9E8fJx2NqNY1iynTiPKEjJrzzRKAgha3nNnwGXr2BtvCJKJHW4nmG7rRqc2AGGy2AECgt16seMyV2FZivUmaJg-[p2sh]", result.ToString());
|
Assert.Equal("tpubD6NzVbkrYhZ4YWjDJUACG9E8fJx2NqNY1iynTiPKEjJrzzRKAgha3nNnwGXr2BtvCJKJHW4nmG7rRqc2AGGy2AECgt16seMyV2FZivUmaJg-[p2sh]", result.ToString());
|
||||||
result = parser.Parse("xpub661MyMwAqRbcGeVGU5e5KBcau1HHEUGf9Wr7k4FyLa8yRPNQrrVa7Ndrgg8Afbe2UYXMSL6tJBFd2JewwWASsePPLjkcJFL1tTVEs3UQ23X");
|
|
||||||
Assert.Equal("tpubD6NzVbkrYhZ4YSg7vGdAX6wxE8NwDrmih9SR6cK7gUtsAg37w5LfFpJgviCxC6bGGT4G3uckqH5fiV9ZLN1gm5qgQLVuymzFUR5ed7U7ksu-[legacy]", result.ToString());
|
result = mainnetParser.Parse("ypub6QqdH2c5z79681jUgdxjGJzGW9zpL4ryPCuhtZE4GpvrJoZqM823XQN6iSQeVbbbp2uCRQ9UgpeMcwiyV6qjvxTWVcxDn2XEAnioMUwsrQ5");
|
||||||
|
Assert.Equal("xpub661MyMwAqRbcGiYMrHB74DtmLBrNPSsUU6PV7ALAtpYyFhkc6TrUuLhxhET4VgwgQPnPfvYvEAHojf7QmQRj8imudHFoC7hju4f9xxri8wR-[p2sh]", result.ToString());
|
||||||
|
|
||||||
|
// if prefix not recognize, assume it is segwit
|
||||||
|
result = testnetParser.Parse("xpub661MyMwAqRbcGeVGU5e5KBcau1HHEUGf9Wr7k4FyLa8yRPNQrrVa7Ndrgg8Afbe2UYXMSL6tJBFd2JewwWASsePPLjkcJFL1tTVEs3UQ23X");
|
||||||
|
Assert.Equal("tpubD6NzVbkrYhZ4YSg7vGdAX6wxE8NwDrmih9SR6cK7gUtsAg37w5LfFpJgviCxC6bGGT4G3uckqH5fiV9ZLN1gm5qgQLVuymzFUR5ed7U7ksu", result.ToString());
|
||||||
////////////////
|
////////////////
|
||||||
|
|
||||||
var tpub = "tpubD6NzVbkrYhZ4Wc65tjhmcKdWFauAo7bGLRTxvggygkNyp6SMGutJp7iociwsinU33jyNBp1J9j2hJH5yQsayfiS3LEU2ZqXodAcnaygra8o";
|
var tpub = "tpubD6NzVbkrYhZ4Wc65tjhmcKdWFauAo7bGLRTxvggygkNyp6SMGutJp7iociwsinU33jyNBp1J9j2hJH5yQsayfiS3LEU2ZqXodAcnaygra8o";
|
||||||
|
|
||||||
result = parser.Parse(tpub);
|
result = testnetParser.Parse(tpub);
|
||||||
Assert.Equal(tpub, result.ToString());
|
Assert.Equal(tpub, result.ToString());
|
||||||
parser.HintScriptPubKey = BitcoinAddress.Create("tb1q4s33amqm8l7a07zdxcunqnn3gcsjcfz3xc573l", parser.Network).ScriptPubKey;
|
testnetParser.HintScriptPubKey = BitcoinAddress.Create("tb1q4s33amqm8l7a07zdxcunqnn3gcsjcfz3xc573l", testnetParser.Network).ScriptPubKey;
|
||||||
result = parser.Parse(tpub);
|
result = testnetParser.Parse(tpub);
|
||||||
Assert.Equal(tpub, result.ToString());
|
Assert.Equal(tpub, result.ToString());
|
||||||
|
|
||||||
parser.HintScriptPubKey = BitcoinAddress.Create("2N2humNio3YTApSfY6VztQ9hQwDnhDvaqFQ", parser.Network).ScriptPubKey;
|
testnetParser.HintScriptPubKey = BitcoinAddress.Create("2N2humNio3YTApSfY6VztQ9hQwDnhDvaqFQ", testnetParser.Network).ScriptPubKey;
|
||||||
result = parser.Parse(tpub);
|
result = testnetParser.Parse(tpub);
|
||||||
Assert.Equal($"{tpub}-[p2sh]", result.ToString());
|
Assert.Equal($"{tpub}-[p2sh]", result.ToString());
|
||||||
|
|
||||||
parser.HintScriptPubKey = BitcoinAddress.Create("mwD8bHS65cdgUf6rZUUSoVhi3wNQFu1Nfi", parser.Network).ScriptPubKey;
|
testnetParser.HintScriptPubKey = BitcoinAddress.Create("mwD8bHS65cdgUf6rZUUSoVhi3wNQFu1Nfi", testnetParser.Network).ScriptPubKey;
|
||||||
result = parser.Parse(tpub);
|
result = testnetParser.Parse(tpub);
|
||||||
Assert.Equal($"{tpub}-[legacy]", result.ToString());
|
Assert.Equal($"{tpub}-[legacy]", result.ToString());
|
||||||
|
|
||||||
parser.HintScriptPubKey = BitcoinAddress.Create("2N2humNio3YTApSfY6VztQ9hQwDnhDvaqFQ", parser.Network).ScriptPubKey;
|
testnetParser.HintScriptPubKey = BitcoinAddress.Create("2N2humNio3YTApSfY6VztQ9hQwDnhDvaqFQ", testnetParser.Network).ScriptPubKey;
|
||||||
result = parser.Parse($"{tpub}-[legacy]");
|
result = testnetParser.Parse($"{tpub}-[legacy]");
|
||||||
Assert.Equal($"{tpub}-[p2sh]", result.ToString());
|
Assert.Equal($"{tpub}-[p2sh]", result.ToString());
|
||||||
|
|
||||||
result = parser.Parse(tpub);
|
result = testnetParser.Parse(tpub);
|
||||||
Assert.Equal($"{tpub}-[p2sh]", result.ToString());
|
Assert.Equal($"{tpub}-[p2sh]", result.ToString());
|
||||||
|
|
||||||
parser = new DerivationSchemeParser(regtestNetworkProvider.GetNetwork("BTC"));
|
var regtestParser = new DerivationSchemeParser(regtestNetworkProvider.GetNetwork("BTC"));
|
||||||
var parsed = parser.Parse("xpub6DG1rMYXiQtCc6CfdLFD9CtxqhzzRh7j6Sq6EdE9abgYy3cfDRrniLLv2AdwqHL1exiLnnKR5XXcaoiiexf3Y9R6J6rxkJtqJHzNzMW9QMZ-[p2sh]");
|
var parsed = regtestParser.Parse("xpub6DG1rMYXiQtCc6CfdLFD9CtxqhzzRh7j6Sq6EdE9abgYy3cfDRrniLLv2AdwqHL1exiLnnKR5XXcaoiiexf3Y9R6J6rxkJtqJHzNzMW9QMZ-[p2sh]");
|
||||||
Assert.Equal("tpubDDdeNbNDRgqestPX5XEJM8ELAq6eR5cne5RPbBHHvWSSiLHNHehsrn1kGCijMnHFSsFFQMqHcdMfGzDL3pWHRasPMhcGRqZ4tFankQ3i4ok-[p2sh]", parsed.ToString());
|
Assert.Equal("tpubDDdeNbNDRgqestPX5XEJM8ELAq6eR5cne5RPbBHHvWSSiLHNHehsrn1kGCijMnHFSsFFQMqHcdMfGzDL3pWHRasPMhcGRqZ4tFankQ3i4ok-[p2sh]", parsed.ToString());
|
||||||
|
|
||||||
// Let's make sure we can't generate segwit with dogecoin
|
// Let's make sure we can't generate segwit with dogecoin
|
||||||
parser = new DerivationSchemeParser(regtestNetworkProvider.GetNetwork("DOGE"));
|
regtestParser = new DerivationSchemeParser(regtestNetworkProvider.GetNetwork("DOGE"));
|
||||||
parsed = parser.Parse("xpub6DG1rMYXiQtCc6CfdLFD9CtxqhzzRh7j6Sq6EdE9abgYy3cfDRrniLLv2AdwqHL1exiLnnKR5XXcaoiiexf3Y9R6J6rxkJtqJHzNzMW9QMZ-[p2sh]");
|
parsed = regtestParser.Parse("xpub6DG1rMYXiQtCc6CfdLFD9CtxqhzzRh7j6Sq6EdE9abgYy3cfDRrniLLv2AdwqHL1exiLnnKR5XXcaoiiexf3Y9R6J6rxkJtqJHzNzMW9QMZ-[p2sh]");
|
||||||
Assert.Equal("tpubDDdeNbNDRgqestPX5XEJM8ELAq6eR5cne5RPbBHHvWSSiLHNHehsrn1kGCijMnHFSsFFQMqHcdMfGzDL3pWHRasPMhcGRqZ4tFankQ3i4ok-[legacy]", parsed.ToString());
|
Assert.Equal("tpubDDdeNbNDRgqestPX5XEJM8ELAq6eR5cne5RPbBHHvWSSiLHNHehsrn1kGCijMnHFSsFFQMqHcdMfGzDL3pWHRasPMhcGRqZ4tFankQ3i4ok-[legacy]", parsed.ToString());
|
||||||
|
|
||||||
parser = new DerivationSchemeParser(regtestNetworkProvider.GetNetwork("DOGE"));
|
regtestParser = new DerivationSchemeParser(regtestNetworkProvider.GetNetwork("DOGE"));
|
||||||
parsed = parser.Parse("tpubDDdeNbNDRgqestPX5XEJM8ELAq6eR5cne5RPbBHHvWSSiLHNHehsrn1kGCijMnHFSsFFQMqHcdMfGzDL3pWHRasPMhcGRqZ4tFankQ3i4ok-[p2sh]");
|
parsed = regtestParser.Parse("tpubDDdeNbNDRgqestPX5XEJM8ELAq6eR5cne5RPbBHHvWSSiLHNHehsrn1kGCijMnHFSsFFQMqHcdMfGzDL3pWHRasPMhcGRqZ4tFankQ3i4ok-[p2sh]");
|
||||||
Assert.Equal("tpubDDdeNbNDRgqestPX5XEJM8ELAq6eR5cne5RPbBHHvWSSiLHNHehsrn1kGCijMnHFSsFFQMqHcdMfGzDL3pWHRasPMhcGRqZ4tFankQ3i4ok-[legacy]", parsed.ToString());
|
Assert.Equal("tpubDDdeNbNDRgqestPX5XEJM8ELAq6eR5cne5RPbBHHvWSSiLHNHehsrn1kGCijMnHFSsFFQMqHcdMfGzDL3pWHRasPMhcGRqZ4tFankQ3i4ok-[legacy]", parsed.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ namespace BTCPayServer
|
|||||||
ElectrumMapping = NetworkType == NetworkType.Mainnet
|
ElectrumMapping = NetworkType == NetworkType.Mainnet
|
||||||
? new Dictionary<uint, string[]>()
|
? new Dictionary<uint, string[]>()
|
||||||
{
|
{
|
||||||
{0x0488b21eU, new[] {"legacy"}},
|
{0x0488b21eU, new[] {"legacy"}}, // xpub
|
||||||
{0x049d7cb2U, new[] {"p2sh"}},
|
{0x049d7cb2U, new[] {"p2sh"}}, // ypub
|
||||||
{0x4b24746U, Array.Empty<string>()},
|
{0x4b24746U, Array.Empty<string>()}, //zpub
|
||||||
}
|
}
|
||||||
: new Dictionary<uint, string[]>()
|
: new Dictionary<uint, string[]>()
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ namespace BTCPayServer
|
|||||||
{
|
{
|
||||||
public class DerivationSchemeParser
|
public class DerivationSchemeParser
|
||||||
{
|
{
|
||||||
private BTCPayNetwork BtcPayNetwork { get; }
|
public BTCPayNetwork BtcPayNetwork { get; }
|
||||||
|
|
||||||
public Network Network => BtcPayNetwork.NBitcoinNetwork;
|
public Network Network => BtcPayNetwork.NBitcoinNetwork;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user