Exemplo n.º 1
0
        public void TestFromPublicKey(string publicKey, string expected)
        {
            var bytes = new byte[33];

            Base16.DecodeFromUtf8(System.Text.Encoding.UTF8.GetBytes(publicKey), bytes, out var _, out var _);
            var account = AccountId.FromPublicKey(bytes);

            Assert.Equal(expected, account.ToString());
        }
Exemplo n.º 2
0
        public void TestDestinationTooSmall(string data)
        {
            var utf8 = System.Text.Encoding.UTF8.GetBytes(data);

            var bytes  = new byte[Base16.GetDecodedFromUtf8Length(utf8.Length) - 1];
            var status = Base16.DecodeFromUtf8(utf8, bytes, out var bytesConsumed, out var bytesWritten);

            Assert.Equal(OperationStatus.DestinationTooSmall, status);
        }
Exemplo n.º 3
0
        public void TestExample()
        {
            var utf8 = System.Text.Encoding.UTF8.GetBytes("005B67A60163457208228EB931635D1A225FF646885BFA8A33A2A3424BFE3290E493C6C6CEB9A51D84D5457BD96702F77340ED9C5294B88A13A0F42BE487D7921F18A2916E6BCA9AC3F9D3F1EEBDADA11F85DA6AB50E29754BEBF4276C327BA05E48004AE574C8F04B4493FD261A7568261A75690A00");
            var data = new byte[Base16.GetDecodedFromUtf8Length(utf8.Length)];

            Assert.Equal(System.Buffers.OperationStatus.Done, Base16.DecodeFromUtf8(utf8, data, out var _, out var _));

            var reader = new St.StReader(data);
            var header = new LedgerHeader(reader);

            Assert.Equal(5990310u, header.Sequence);
            Assert.Equal(99999972797353657ul, header.TotalCoins);
            Assert.Equal(new Hash256("31635D1A225FF646885BFA8A33A2A3424BFE3290E493C6C6CEB9A51D84D5457B"), header.ParentHash);
            Assert.Equal(new Hash256("D96702F77340ED9C5294B88A13A0F42BE487D7921F18A2916E6BCA9AC3F9D3F1"), header.TransactionHash);
            Assert.Equal(new Hash256("EEBDADA11F85DA6AB50E29754BEBF4276C327BA05E48004AE574C8F04B4493FD"), header.AccountHash);
            Assert.Equal(Epoch.ToDateTimeOffset(639268200), header.ParentCloseTime);
            Assert.Equal(Epoch.ToDateTimeOffset(639268201), header.CloseTime);
            Assert.Equal(10, header.CloseTimeResolution);
            Assert.Equal(0, header.CloseFlags);
        }
Exemplo n.º 4
0
        public void TestRoundTrip(string data)
        {
            var utf8 = System.Text.Encoding.UTF8.GetBytes(data);

            var bytes  = new byte[Base16.GetDecodedFromUtf8Length(utf8.Length)];
            var status = Base16.DecodeFromUtf8(utf8, bytes, out var bytesConsumed, out var bytesWritten);

            Assert.Equal(OperationStatus.Done, status);
            Assert.Equal(utf8.Length, bytesConsumed);
            Assert.Equal(bytes.Length, bytesWritten);

            utf8   = new byte[Base16.GetEncodedToUtf8Length(bytes.Length)];
            status = Base16.EncodeToUtf8(bytes, utf8, out bytesConsumed, out bytesWritten);

            Assert.Equal(OperationStatus.Done, status);
            Assert.Equal(bytes.Length, bytesConsumed);
            Assert.Equal(utf8.Length, bytesWritten);

            Assert.Equal(data.ToUpper(), System.Text.Encoding.UTF8.GetString(utf8));
        }
Exemplo n.º 5
0
        public void TestExample()
        {
            var         utf8 = System.Text.Encoding.UTF8.GetBytes("11006122000000002400000001250062FEA42D0000000055C204A65CF2542946289A3358C67D991B5E135FABFA89F271DBA7A150C08CA0466240000000354540208114C909F42250CFE8F12A7A1A0DFBD3CBD20F32CD79");
            Span <byte> data = new byte[Base16.GetDecodedFromUtf8Length(utf8.Length)];

            Assert.Equal(System.Buffers.OperationStatus.Done, Base16.DecodeFromUtf8(utf8, data, out var _, out var _));

            var reader = new StReader(data);

            Assert.Equal(StFieldId.UInt16_LedgerEntryType, reader.ReadFieldId());
            Assert.Equal(StLedgerEntryType.AccountRoot, (StLedgerEntryType)reader.ReadUInt16());

            var accountRoot = new AccountRootLedgerEntry(ref reader);

            Assert.Equal(new AccountId("rKKzk9ghA2iuy3imqMXUHJqdRPMtNDGf4c"), accountRoot.Account);
            Assert.Equal(XrpAmount.FromDrops(893730848), accountRoot.Balance);
            Assert.Equal(AccountRootFlags.None, accountRoot.Flags);
            Assert.Equal(0u, accountRoot.OwnerCount);
            Assert.Equal(new Hash256("C204A65CF2542946289A3358C67D991B5E135FABFA89F271DBA7A150C08CA046"), accountRoot.PreviousTxnID);
            Assert.Equal(6487716u, accountRoot.PreviousTxnLgrSeq);
            Assert.Equal(1u, accountRoot.Sequence);
            Assert.Equal(new Hash256("00001A2969BE1FC85F1D7A55282FA2E6D95C71D2E4B9C0FDD3D9994F3C00FF8F"), accountRoot.ID);
            Assert.Equal(data.Length, reader.ConsumedBytes);
        }