public void Beacon_block_body_there_and_back()
        {
            Eth1Data eth1Data = new Eth1Data(
                Sha256.OfAnEmptyString,
                1,
                Sha256.OfAnEmptyString);

            BeaconBlockBody container = new BeaconBlockBody(
                SszTest.TestSig1,
                eth1Data,
                new Bytes32(new byte[32]),
                new ProposerSlashing[2],
                new AttesterSlashing[3],
                new Attestation[4],
                new Deposit[5],
                new VoluntaryExit[6]
                );

            Span <byte> encoded = new byte[Ssz.BeaconBlockBodyLength(container)];

            Ssz.Encode(encoded, container);
            BeaconBlockBody decoded = Ssz.DecodeBeaconBlockBody(encoded);

            AssertBeaconBlockBodyEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
        public void EmptyBeaconBlockBodyDecode()
        {
            // Arrange
            string hex =
                // static
                "565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656" +
                "1212121212121212121212121212121212121212121212121212121212121212" +
                "4000000000000000" +
                "3434343434343434343434343434343434343434343434343434343434343434" +
                "7878787878787878787878787878787878787878787878787878787878787878" +
                "dc000000" + // proposer dynamic offset 96+(32+8+32)+32 + 5*4 = 220 = 0xdc
                "dc000000" + // attester slashings & all remaining offsets are the same, as they are empty
                "dc000000" +
                "dc000000" +
                "dc000000"; // dynamic part is empty

            byte[] bytes = Bytes.FromHexString(hex);

            // Act
            BeaconBlockBody beaconBlockBody = Ssz.DecodeBeaconBlockBody(bytes);

            // Assert
            beaconBlockBody.RandaoReveal.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x56, 96).ToArray());
            beaconBlockBody.Eth1Data.DepositRoot.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x12, 32).ToArray());
            beaconBlockBody.Eth1Data.DepositCount.ShouldBe(64uL);
            beaconBlockBody.Eth1Data.BlockHash.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x34, 32).ToArray());
            beaconBlockBody.Graffiti.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x78, 32).ToArray());
            beaconBlockBody.ProposerSlashings.Count.ShouldBe(0);
            beaconBlockBody.AttesterSlashings.Count.ShouldBe(0);
            beaconBlockBody.Attestations.Count.ShouldBe(0);
            beaconBlockBody.Deposits.Count.ShouldBe(0);
            beaconBlockBody.VoluntaryExits.Count.ShouldBe(0);
        }
Beispiel #3
0
        public void Can_serialize_uin128_1()
        {
            Span <byte> output = stackalloc byte[16];

            Ssz.Encode(output, UInt128.One);
            Assert.AreEqual("01000000000000000000000000000000", output.ToHexString());
        }
        public void Current()
        {
            Span <byte> output = stackalloc byte[32];

            Ssz.Encode(output, 0);
            Ssz.Encode(output, 0);
            Ssz.Encode(output, 0);
            Ssz.Encode(output, 0);
            Ssz.Encode(output, UInt128.Zero);
            Ssz.Encode(output, UInt256.Zero);

            Ssz.Encode(output, 1);
            Ssz.Encode(output, 1);
            Ssz.Encode(output, 1);
            Ssz.Encode(output, 1UL);
            Ssz.Encode(output, UInt128.One);
            Ssz.Encode(output, UInt256.One);

            Ssz.Encode(output, byte.MaxValue);
            Ssz.Encode(output, ushort.MaxValue);
            Ssz.Encode(output, uint.MaxValue);
            Ssz.Encode(output, ulong.MaxValue);
            Ssz.Encode(output, UInt128.MaxValue);
            Ssz.Encode(output, UInt256.MaxValue);
        }
        public void Attestation_there_and_back()
        {
            AttestationData data = new AttestationData();

            data.Slot            = new Slot(1);
            data.CommitteeIndex  = new CommitteeIndex(2);
            data.BeaconBlockRoot = Sha256.OfAnEmptyString;
            data.Source          = new Checkpoint(new Epoch(1), Sha256.OfAnEmptyString);
            data.Target          = new Checkpoint(new Epoch(2), Sha256.OfAnEmptyString);

            Attestation container = new Attestation();

            container.AggregationBits = new byte[] { 1, 2, 3 };
            container.Data            = data;
            container.Signature       = BlsSignature.TestSig1;

            Span <byte> encoded = new byte[Attestation.SszLength(container)];

            Ssz.Encode(encoded, container);
            Attestation?decoded = Ssz.DecodeAttestation(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
        public void Pending_attestation_there_and_back()
        {
            AttestationData data = new AttestationData();

            data.Slot            = new Slot(1);
            data.CommitteeIndex  = new CommitteeIndex(2);
            data.BeaconBlockRoot = Sha256.OfAnEmptyString;
            data.Source          = new Checkpoint(new Epoch(1), Sha256.OfAnEmptyString);
            data.Target          = new Checkpoint(new Epoch(2), Sha256.OfAnEmptyString);

            PendingAttestation container = new PendingAttestation();

            container.AggregationBits = new byte[3];
            container.Data            = data;
            container.InclusionDelay  = new Slot(7);
            container.ProposerIndex   = new ValidatorIndex(13);

            Span <byte> encoded = new byte[PendingAttestation.SszLength(container)];

            Ssz.Encode(encoded, container);
            PendingAttestation?decoded = Ssz.DecodePendingAttestation(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
Beispiel #7
0
        public void Can_serialize_uin32(uint uint32, string expectedOutput)
        {
            Span <byte> output = stackalloc byte[4];

            Ssz.Encode(output, uint32);
            Assert.AreEqual(Bytes.FromHexString(expectedOutput), output.ToArray());
        }
Beispiel #8
0
        public void Can_serialize_uin128_max()
        {
            Span <byte> output = stackalloc byte[16];

            Ssz.Encode(output, UInt128.MaxValue);
            Assert.AreEqual("ffffffffffffffffffffffffffffffff", output.ToHexString());
        }
Beispiel #9
0
        public void Can_serialize_uin64(ulong uint64, string expectedOutput)
        {
            Span <byte> output = stackalloc byte[8];

            Ssz.Encode(output, uint64);
            Assert.AreEqual(Bytes.FromHexString(expectedOutput), output.ToArray());
        }
        public void Beacon_block_body_there_and_back()
        {
            Eth1Data eth1Data = new Eth1Data();

            eth1Data.BlockHash    = Sha256.OfAnEmptyString;
            eth1Data.DepositCount = 1;
            eth1Data.DepositRoot  = Sha256.OfAnEmptyString;

            BeaconBlockBody container = new BeaconBlockBody();

            container.RandaoReversal    = BlsSignature.TestSig1;
            container.Eth1Data          = eth1Data;
            container.Graffiti          = new byte[32];
            container.ProposerSlashings = new ProposerSlashing[2];
            container.AttesterSlashings = new AttesterSlashing[3];
            container.Attestations      = new Attestation[4];
            container.Deposits          = new Deposit[5];
            container.VoluntaryExits    = new VoluntaryExit[6];

            Span <byte> encoded = new byte[BeaconBlockBody.SszLength(container)];

            Ssz.Encode(encoded, container);
            BeaconBlockBody decoded = Ssz.DecodeBeaconBlockBody(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
        public void BasicEth1DataDecode()
        {
            // Arrange
            string hex =
                // static
                "e4000000" + // aggregation dynamic offset 4 + 8+8+32+(8+32)+(8+32) + 96 = 228 = 0xe5
                "1500000000000000" +
                "0200000000000000" +
                "1212121212121212121212121212121212121212121212121212121212121212" +
                "0100000000000000" +
                "3434343434343434343434343434343434343434343434343434343434343434" +
                "0200000000000000" +
                "5656565656565656565656565656565656565656565656565656565656565656" +
                "efefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefef" +
                // dynamic part
                "210b";

            byte[] bytes = Bytes.FromHexString(hex);

            // Act
            Attestation attestation = Ssz.DecodeAttestation(bytes);

            // Assert
            attestation.Data.Slot.ShouldBe(new Slot(21));
            attestation.Data.Target.Epoch.ShouldBe(new Epoch(2));
            attestation.Data.Target.Root.AsSpan()[31].ShouldBe((byte)0x56);
            attestation.Signature.Bytes[95].ShouldBe((byte)0xef);

            attestation.AggregationBits[0].ShouldBeTrue();
            attestation.AggregationBits[5].ShouldBeTrue();
            attestation.AggregationBits.Length.ShouldBe(11);
        }
Beispiel #12
0
        public void Attester_slashing_there_and_back()
        {
            AttestationData data = new AttestationData(
                new Slot(1),
                new CommitteeIndex(2),
                Sha256.RootOfAnEmptyString,
                new Checkpoint(new Epoch(1), Sha256.RootOfAnEmptyString),
                new Checkpoint(new Epoch(2), Sha256.RootOfAnEmptyString));

            IndexedAttestation indexedAttestation1 = new IndexedAttestation(
                new ValidatorIndex[3],
                data,
                TestSig1);

            IndexedAttestation indexedAttestation2 = new IndexedAttestation(
                new ValidatorIndex[5],
                data,
                TestSig1);

            AttesterSlashing container = new AttesterSlashing(indexedAttestation1, indexedAttestation2);

            Span <byte> encoded = new byte[Ssz.AttesterSlashingLength(container)];

            Ssz.Encode(encoded, container);
            AttesterSlashing?decoded = Ssz.DecodeAttesterSlashing(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
Beispiel #13
0
        public void Beacon_block_body_there_and_back()
        {
            Eth1Data eth1Data = new Eth1Data(
                Sha256.RootOfAnEmptyString,
                1,
                Sha256.Bytes32OfAnEmptyString);

            Deposit         zeroDeposit = new Deposit(Enumerable.Repeat(Bytes32.Zero, Ssz.DepositContractTreeDepth + 1), DepositData.Zero);
            BeaconBlockBody container   = new BeaconBlockBody(
                TestSig1,
                eth1Data,
                new Bytes32(new byte[32]),
                Enumerable.Repeat(ProposerSlashing.Zero, 2).ToArray(),
                Enumerable.Repeat(AttesterSlashing.Zero, 3).ToArray(),
                Enumerable.Repeat(Attestation.Zero, 4).ToArray(),
                Enumerable.Repeat(zeroDeposit, 5).ToArray(),
                Enumerable.Repeat(SignedVoluntaryExit.Zero, 6).ToArray()
                );

            Span <byte> encoded = new byte[Ssz.BeaconBlockBodyLength(container)];

            Ssz.Encode(encoded, container);
            BeaconBlockBody decoded = Ssz.DecodeBeaconBlockBody(encoded);

            AssertBeaconBlockBodyEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
Beispiel #14
0
        public void Proposer_slashing_there_and_back()
        {
            BeaconBlockHeader header1 = new BeaconBlockHeader(
                new Slot(1),
                Sha256.RootOfAnEmptyString,
                Sha256.RootOfAnEmptyString,
                Sha256.RootOfAnEmptyString);

            BeaconBlockHeader header2 = new BeaconBlockHeader(
                new Slot(2),
                Sha256.RootOfAnEmptyString,
                Sha256.RootOfAnEmptyString,
                Sha256.RootOfAnEmptyString);

            ProposerSlashing container = new ProposerSlashing(
                new ValidatorIndex(1),
                new SignedBeaconBlockHeader(header1, TestSig1),
                new SignedBeaconBlockHeader(header2, TestSig1));

            Span <byte> encoded = new byte[Ssz.ProposerSlashingLength];

            Ssz.Encode(encoded, container);
            ProposerSlashing?decoded = Ssz.DecodeProposerSlashing(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
        public void Proposer_slashing_there_and_back()
        {
            BeaconBlockHeader header1 = new BeaconBlockHeader();

            header1.Slot       = new Slot(1);
            header1.ParentRoot = Sha256.OfAnEmptyString;
            header1.BodyRoot   = Sha256.OfAnEmptyString;
            header1.StateRoot  = Sha256.OfAnEmptyString;
            header1.Signature  = BlsSignature.TestSig1;

            BeaconBlockHeader header2 = new BeaconBlockHeader();

            header2.Slot       = new Slot(2);
            header2.ParentRoot = Sha256.OfAnEmptyString;
            header2.BodyRoot   = Sha256.OfAnEmptyString;
            header2.StateRoot  = Sha256.OfAnEmptyString;
            header2.Signature  = BlsSignature.TestSig1;

            ProposerSlashing container = new ProposerSlashing();

            container.ProposerIndex = new ValidatorIndex(1);
            container.Header1       = header1;
            container.Header2       = header2;

            Span <byte> encoded = new byte[ProposerSlashing.SszLength];

            Ssz.Encode(encoded, container);
            ProposerSlashing?decoded = Ssz.DecodeProposerSlashing(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
Beispiel #16
0
        public void Can_serialize_uin256_0()
        {
            Span <byte> output = stackalloc byte[32];

            Ssz.Encode(output, UInt256.Zero);
            Assert.AreEqual("0000000000000000000000000000000000000000000000000000000000000000", output.ToHexString());
        }
        public void Fork_there_and_back()
        {
            Fork        container = new Fork(new ForkVersion(new byte[] { 0x01, 0x00, 0x00, 0x00 }), new ForkVersion(new byte[] { 0x02, 0x00, 0x00, 0x00 }), new Epoch(3));
            Span <byte> encoded   = new byte[Fork.SszLength];

            Ssz.Encode(encoded, container);
            Fork decoded = Ssz.DecodeFork(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
        public void Checkpoint_there_and_back()
        {
            Checkpoint  container = new Checkpoint(new Epoch(1), Sha256.OfAnEmptyString);
            Span <byte> encoded   = new byte[Checkpoint.SszLength];

            Ssz.Encode(encoded, container);
            Checkpoint decoded = Ssz.DecodeCheckpoint(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
        public void CheckEmptyBlockRootAfterDeserializing()
        {
            // Arrange

            Eth1Data eth1Data = new Eth1Data(
                new Root(Enumerable.Repeat((byte)0x12, 32).ToArray()),
                64,
                new Bytes32(Enumerable.Repeat((byte)0x34, 32).ToArray()));

            BlsSignature randaoReveal = new BlsSignature(Enumerable.Repeat((byte)0xfe, 96).ToArray());

            BeaconBlockBody beaconBlockBody = new BeaconBlockBody(
                randaoReveal,
                eth1Data,
                new Bytes32(new byte[32]),
                new ProposerSlashing[0],
                new AttesterSlashing [0],
                new Attestation[0],
                new Deposit[0],
                new SignedVoluntaryExit[0]
                );

            BeaconBlock beaconBlock = new BeaconBlock(
                new Slot(1),
                new Root(Enumerable.Repeat((byte)0x78, 32).ToArray()),
                new Root(Enumerable.Repeat((byte)0x9a, 32).ToArray()),
                beaconBlockBody);

            Merkle.Ize(out UInt256 blockRoot256, beaconBlock);
            Span <byte> blockRootSpan = MemoryMarshal.Cast <UInt256, byte>(MemoryMarshal.CreateSpan(ref blockRoot256, 1));
            Root        blockRoot     = new Root(blockRootSpan);

            SignedBeaconBlock signedBeaconBlock = new SignedBeaconBlock(
                beaconBlock,
                new BlsSignature(Enumerable.Repeat((byte)0x0e, 96).ToArray())
                );

            // Act

            Span <byte> encoded = new byte[Ssz.SignedBeaconBlockLength(signedBeaconBlock)];

            Ssz.Encode(encoded, signedBeaconBlock);

            SignedBeaconBlock decoded = Ssz.DecodeSignedBeaconBlock(encoded);

            // Assert

            Merkle.Ize(out UInt256 decodedBlockRoot256, decoded.Message);
            Span <byte> decodedBlockRootSpan = MemoryMarshal.Cast <UInt256, byte>(MemoryMarshal.CreateSpan(ref decodedBlockRoot256, 1));
            Root        decodedBlockRoot     = new Root(decodedBlockRootSpan);

            decodedBlockRoot.ShouldBe(blockRoot);
        }
Beispiel #20
0
        public void Can_deserialize_bitarray_bitlist(bool[] value, ulong limit, string expectedByteString, byte[] expectedHashTreeRoot)
        {
            // Arrange
            var encoded = Bytes.FromHexString(expectedByteString);

            // Act
            BitArray decoded = Ssz.DecodeBitlist(encoded);

            // Assert
            BitArray expected = new BitArray(value);

            decoded.ShouldBe(expected);
        }
Beispiel #21
0
        public void EmptyBeaconBlockEncode()
        {
            // Arrange
            Eth1Data eth1Data = new Eth1Data(
                new Root(Enumerable.Repeat((byte)0x12, 32).ToArray()),
                64,
                new Bytes32(Enumerable.Repeat((byte)0x34, 32).ToArray()));
            BeaconBlockBody beaconBlockBody = new BeaconBlockBody(
                new BlsSignature(Enumerable.Repeat((byte)0x56, 96).ToArray()),
                eth1Data,
                new Bytes32(Enumerable.Repeat((byte)0x78, 32).ToArray()),
                new ProposerSlashing[0],
                new AttesterSlashing [0],
                new Attestation[0],
                new Deposit[0],
                new SignedVoluntaryExit[0]
                );
            BeaconBlock beaconBlock = new BeaconBlock(
                Slot.One,
                new Root(Enumerable.Repeat((byte)0x9a, 32).ToArray()),
                new Root(Enumerable.Repeat((byte)0xbc, 32).ToArray()),
                beaconBlockBody
                );

            // Act
            Span <byte> encoded = new byte[Ssz.BeaconBlockLength(beaconBlock)];

            Ssz.Encode(encoded, beaconBlock);

            // Assert
            string expectedHex =
                // static
                "0100000000000000" +
                "9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a" +
                "bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc" +
                "4c000000" + // body dynamic offset 8+32+32+4 = 76 = 0x4c
                // dynamic
                // - body - static
                "565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656" +
                "1212121212121212121212121212121212121212121212121212121212121212" +
                "4000000000000000" +
                "3434343434343434343434343434343434343434343434343434343434343434" +
                "7878787878787878787878787878787878787878787878787878787878787878" +
                "dc000000" + // proposer dynamic offset 96+(32+8+32)+32 + 5*4 = 220 = 0xdc
                "dc000000" + // attester slashings & all remaining offsets are the same, as they are empty
                "dc000000" +
                "dc000000" +
                "dc000000"; // body - dynamic part is empty

            encoded.ToHexString().ShouldBe(expectedHex);
        }
Beispiel #22
0
        public void Can_deserialize_bitarray_bitvector(bool[] value, string expectedByteString, byte[] expectedHashTreeRoot)
        {
            // Arrange
            var encoded      = Bytes.FromHexString(expectedByteString);
            var vectorLength = value.Length;

            // Act
            BitArray decoded = Ssz.DecodeBitvector(encoded, vectorLength);

            // Assert
            BitArray expected = new BitArray(value);

            decoded.ShouldBe(expected);
        }
        public void BasicAttestationEncode()
        {
            // Arrange
            Attestation attestation = new Attestation(
                new BitArray(new[] {
                true, false, false, false, false, true, false, false,
                true, true, false
            }),
                new AttestationData(
                    new Slot(2 * 8 + 5),
                    new CommitteeIndex(2),
                    new Root(Enumerable.Repeat((byte)0x12, 32).ToArray()),
                    new Checkpoint(
                        new Epoch(1),
                        new Root(Enumerable.Repeat((byte)0x34, 32).ToArray())
                        ),
                    new Checkpoint(
                        new Epoch(2),
                        new Root(Enumerable.Repeat((byte)0x56, 32).ToArray())
                        )
                    ),
                new BlsSignature(Enumerable.Repeat((byte)0xef, 96).ToArray()));

            // Act
            Span <byte> encoded = new byte[Ssz.AttestationLength(attestation)];

            Ssz.Encode(encoded, attestation);

            // Assert

            // Bitlist is little endian
            // true, false, false, false, false, true, false, false, = 0b 0010 0001 = 0x 21
            // true, true, false}), = 0b 0000 0011, add sentinel bit (so we know only 3 bits used) -> 0b 0000 1011 = 0x 0b

            string expectedHex =
                // static
                "e4000000" + // aggregation dynamic offset 4 + 8+8+32+(8+32)+(8+32) + 96 = 228 = 0xe4
                "1500000000000000" +
                "0200000000000000" +
                "1212121212121212121212121212121212121212121212121212121212121212" +
                "0100000000000000" +
                "3434343434343434343434343434343434343434343434343434343434343434" +
                "0200000000000000" +
                "5656565656565656565656565656565656565656565656565656565656565656" +
                "efefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefef" +
                // dynamic part
                "210b";

            encoded.ToHexString().ShouldBe(expectedHex);
        }
Beispiel #24
0
        public void Eth1_data_there_and_back()
        {
            Eth1Data container = new Eth1Data(
                Sha256.RootOfAnEmptyString,
                1,
                Sha256.Bytes32OfAnEmptyString);
            Span <byte> encoded = new byte[Ssz.Eth1DataLength];

            Ssz.Encode(encoded, container);
            Eth1Data decoded = Ssz.DecodeEth1Data(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
Beispiel #25
0
        public void Can_serialize_bitarray_bitlist(bool[] value, ulong limit, string expectedByteString, byte[] expectedHashTreeRoot)
        {
            // Arrange
            var input = new BitArray(value);

            // Act
            var encoded = new byte[(input.Length + 8) / 8];

            Ssz.EncodeList(encoded, input);

            // Assert
            var byteString = Bytes.ToHexString(encoded);

            byteString.ShouldBe(expectedByteString);
        }
Beispiel #26
0
        public void Voluntary_exit_there_and_back()
        {
            VoluntaryExit container = new VoluntaryExit(
                new Epoch(1),
                new ValidatorIndex(2));

            Span <byte> encoded = new byte[Ssz.VoluntaryExitLength];

            Ssz.Encode(encoded, container);
            VoluntaryExit?decoded = Ssz.DecodeVoluntaryExit(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
        public void Historical_batch_there_and_back()
        {
            HistoricalBatch container = new HistoricalBatch();

            container.BlockRoots[3] = Sha256.OfAnEmptyString;
            container.StateRoots[7] = Sha256.OfAnEmptyString;
            Span <byte> encoded = new byte[HistoricalBatch.SszLength];

            Ssz.Encode(encoded, container);
            HistoricalBatch?decoded = Ssz.DecodeHistoricalBatch(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
Beispiel #28
0
        public void Beacon_block_header_there_and_back()
        {
            BeaconBlockHeader container = new BeaconBlockHeader(
                new Slot(1),
                Sha256.RootOfAnEmptyString,
                Sha256.RootOfAnEmptyString,
                Sha256.RootOfAnEmptyString);
            Span <byte> encoded = new byte[Ssz.BeaconBlockHeaderLength];

            Ssz.Encode(encoded, container);
            BeaconBlockHeader decoded = Ssz.DecodeBeaconBlockHeader(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
Beispiel #29
0
        public void Deposit_data_there_and_back()
        {
            DepositData container = new DepositData(
                TestKey1,
                Sha256.Bytes32OfAnEmptyString,
                Gwei.One,
                TestSig1);
            Span <byte> encoded = new byte[Ssz.DepositDataLength];

            Ssz.Encode(encoded, container);
            DepositData decoded = Ssz.DecodeDepositData(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
        public void Eth1_data_there_and_back()
        {
            Eth1Data container = new Eth1Data();

            container.BlockHash    = Sha256.OfAnEmptyString;
            container.DepositCount = 1;
            container.DepositRoot  = Sha256.OfAnEmptyString;
            Span <byte> encoded = new byte[Eth1Data.SszLength];

            Ssz.Encode(encoded, container);
            Eth1Data decoded = Ssz.DecodeEth1Data(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }