示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
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);
        }
        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);
        }