Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kth-bch/kth-bch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>0.2.201</Version>
<Version>0.23.0</Version>
<Authors>Knuth</Authors>
<Company>Knuth</Company>
<Description>Bitcoin full node as a C# library</Description>
Expand Down
35 changes: 27 additions & 8 deletions tests/bch/PaymentAddressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
using Xunit;

namespace Knuth.Tests {
public class PaymentAddressTest
public class PaymentAddressTests
{
[Fact]
public void EmptyAddressShouldFail() {
Assert.False(PaymentAddress.TryParse("", out PaymentAddress addr));
Assert.Null(addr);
}


[Fact]
public void WhitespaceAddressShouldFail() {
Assert.False(PaymentAddress.TryParse(" ", out PaymentAddress addr));
Expand All @@ -27,30 +26,50 @@ public void InvalidAddressShouldFail() {
}

[Fact]
public void MainnetCashAddrAddressOK() {
public void ValidMainnetCashAddrAddressShouldParseCorrectly() {
Assert.True(PaymentAddress.TryParse("bitcoincash:qrcuqadqrzp2uztjl9wn5sthepkg22majyxw4gmv6p", out PaymentAddress addr));
Assert.NotNull(addr);
Assert.True(addr.IsValid);
Assert.Equal("bitcoincash:qrcuqadqrzp2uztjl9wn5sthepkg22majyxw4gmv6p", addr.EncodeCashAddr(false));
Assert.Equal("bitcoincash:zrcuqadqrzp2uztjl9wn5sthepkg22majypyxk429j", addr.EncodeCashAddr(true));
Assert.Equal("1P3GQYtcWgZHrrJhUa4ctoQ3QoCU2F65nz", addr.EncodeLegacy());
addr.Dispose();
}

[Fact]
public void MainnetCashAddrNoPrefixAddressOK() {
public void ValidMainnetCashAddrNoPrefixAddressShouldParseCorrectly() {
Assert.True(PaymentAddress.TryParse("qrcuqadqrzp2uztjl9wn5sthepkg22majyxw4gmv6p", out PaymentAddress addr));
Assert.NotNull(addr);
Assert.True(addr.IsValid);
Assert.Equal("bitcoincash:qrcuqadqrzp2uztjl9wn5sthepkg22majyxw4gmv6p", addr.EncodeCashAddr(false));
Assert.Equal("bitcoincash:zrcuqadqrzp2uztjl9wn5sthepkg22majypyxk429j", addr.EncodeCashAddr(true));
Assert.Equal("1P3GQYtcWgZHrrJhUa4ctoQ3QoCU2F65nz", addr.EncodeLegacy());
addr.Dispose();
}

[Fact]
public void MainnetLegacyAddressOK() {
public void ValidMainnetLegacyAddressShouldParseCorrectly() {
Assert.True(PaymentAddress.TryParse("1P3GQYtcWgZHrrJhUa4ctoQ3QoCU2F65nz", out PaymentAddress addr));
Assert.NotNull(addr);
Assert.True(addr.IsValid);
Assert.Equal("bitcoincash:qrcuqadqrzp2uztjl9wn5sthepkg22majyxw4gmv6p", addr.EncodeCashAddr(false));
Assert.Equal("bitcoincash:zrcuqadqrzp2uztjl9wn5sthepkg22majypyxk429j", addr.EncodeCashAddr(true));
Assert.Equal("1P3GQYtcWgZHrrJhUa4ctoQ3QoCU2F65nz", addr.EncodeLegacy());
addr.Dispose();
}

[Fact]
public void Valid32ByteCashAddrAddressShouldParseCorrectly() {
Assert.True(PaymentAddress.TryParse("bitcoincash:pvstqkm54dtvnpyqxt5m5n7sjsn4enrlxc526xyxlnjkaycdzfeu69reyzmqx", out PaymentAddress addr));
Assert.NotNull(addr);
Assert.True(addr.IsValid);
Assert.Equal("bitcoincash:pvstqkm54dtvnpyqxt5m5n7sjsn4enrlxc526xyxlnjkaycdzfeu69reyzmqx", addr.EncodeCashAddr(false));
Assert.Equal("bitcoincash:rvstqkm54dtvnpyqxt5m5n7sjsn4enrlxc526xyxlnjkaycdzfeu6hs99m6ed", addr.EncodeCashAddr(true));
Assert.Equal("34frpCV2v6wtzig9xx4Z9XJ6s4jU3zqwR7", addr.EncodeLegacy()); // In fact a 32-byte address is not representable in legacy encoding.
addr.Dispose();
}

// TODO A standalone testnet address is not considered valid by default; the node needs to be in testnet mode
// Analyze removing this hidden dependency
// TODO: A standalone testnet address is not considered valid by default; the node needs to be in testnet mode.
// Analyze removing this hidden dependency.
}
}
}
Loading