Exemple #1
0
 public void InvalidAddress()
 {
     foreach (var test in INVALID_ADDRESS)
     {
         var encoder = Bech32Encoder.ExtractEncoderFromString(test);
         Assert.ThrowsAny <FormatException>(() => encoder.Decode(test, out var v));
     }
 }
 public void ValidateValidChecksum()
 {
     foreach (string test in VALID_CHECKSUM)
     {
         Bech32Encoder bech  = Bech32Encoder.ExtractEncoderFromString(test);
         int           pos   = test.LastIndexOf('1');
         string        test2 = test.Substring(0, pos + 1) + ((test[pos + 1]) ^ 1) + test.Substring(pos + 2);
         Assert.Throws <FormatException>(() => bech.DecodeData(test2));
     }
 }
Exemple #3
0
        public void ValidAddress()
        {
            foreach (var address in VALID_ADDRESS)
            {
                Bech32Encoder encoder      = Bech32Encoder.ExtractEncoderFromString(address[0]);
                var           witProg      = encoder.Decode(address[0], out var witVer);
                var           scriptPubkey = Scriptpubkey(witVer, witProg);
                var           hex          = string.Join("", scriptPubkey.Select(x => x.ToString("x2")));
                Assert.Equal(hex, address[1]);

                var addr = encoder.Encode(witVer, witProg);
                Assert.Equal(address[0].ToLowerInvariant(), addr);
            }
        }
Exemple #4
0
 public void DetectInvalidChecksum()
 {
     foreach (var test in INVALID_CHECKSUM)
     {
         try
         {
             var bech  = Bech32Encoder.ExtractEncoderFromString(test);
             var pos   = test.LastIndexOf('1');
             var test2 = test.Substring(0, pos + 1) + ((test[pos + 1]) ^ 1) + test.Substring(pos + 2);
             bech.Decode(test2, out var wit);
             throw new Exception($"The \"{test}\" string was recognized as a valid bech32 encoded string. FormatException was expected.");
         }
         catch (FormatException)
         { }
     }
 }
Exemple #5
0
 public void bech32m_testvectors_valid()
 {
     foreach (var address in new[]
     {
         "A1LQFN3A",
         "a1lqfn3a",
         "an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6",
         "abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx",
         "11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8",
         "split1checkupstagehandshakeupstreamerranterredcaperredlc445v",
         "?1v759aa"
     })
     {
         var encoder = Bech32Encoder.ExtractEncoderFromString(address);
         var bytes   = encoder.DecodeDataRaw(address, out var encodingType);
         Assert.Equal(Bech32EncodingType.BECH32M, encodingType);
         var reencoded = encoder.EncodeRaw(bytes, encodingType);
         Assert.Equal(address, reencoded, true);
     }
 }