コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void BasicEth1DataDecode()
        {
            // Arrange
            string hex =
                "1212121212121212121212121212121212121212121212121212121212121212" +
                "4000000000000000" +
                "3434343434343434343434343434343434343434343434343434343434343434";

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

            // Act
            Eth1Data eth1Data = Ssz.DecodeEth1Data(bytes);

            // Assert
            eth1Data.DepositRoot.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x12, 32).ToArray());
            eth1Data.DepositCount.ShouldBe(64uL);
            eth1Data.BlockHash.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x34, 32).ToArray());
        }