diff --git a/kth-bch/kth-bch.csproj b/kth-bch/kth-bch.csproj index 049659f..9e52e38 100644 --- a/kth-bch/kth-bch.csproj +++ b/kth-bch/kth-bch.csproj @@ -2,7 +2,7 @@ net8.0 - 0.2.201 + 0.23.0 Knuth Knuth Bitcoin full node as a C# library diff --git a/tests/bch/PaymentAddressTest.cs b/tests/bch/PaymentAddressTest.cs index b69d468..16e8380 100644 --- a/tests/bch/PaymentAddressTest.cs +++ b/tests/bch/PaymentAddressTest.cs @@ -5,7 +5,7 @@ using Xunit; namespace Knuth.Tests { - public class PaymentAddressTest + public class PaymentAddressTests { [Fact] public void EmptyAddressShouldFail() { @@ -13,7 +13,6 @@ public void EmptyAddressShouldFail() { Assert.Null(addr); } - [Fact] public void WhitespaceAddressShouldFail() { Assert.False(PaymentAddress.TryParse(" ", out PaymentAddress addr)); @@ -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. } -} \ No newline at end of file +}