示例#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_more_detailed()
        {
            BeaconBlockBody body = new BeaconBlockBody();

            AttestationData data = new AttestationData();

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

            Attestation attestation = new Attestation();

            attestation.Data            = data;
            attestation.Signature       = BlsSignature.TestSig1;
            attestation.AggregationBits = new byte[5];

            DepositData depositData = new DepositData();

            depositData.Amount                = new Gwei(7);
            depositData.Signature             = BlsSignature.TestSig1;
            depositData.PublicKey             = BlsPublicKey.TestKey1;
            depositData.WithdrawalCredentials = Sha256.OfAnEmptyString;

            Deposit deposit = new Deposit();

            deposit.Data  = depositData;
            deposit.Proof = new Hash32[Deposit.ContractTreeDepth + 1];

            IndexedAttestation indexedAttestation1 = new IndexedAttestation();

            indexedAttestation1.Data             = data;
            indexedAttestation1.Signature        = BlsSignature.TestSig1;
            indexedAttestation1.AttestingIndices = new ValidatorIndex[8];

            IndexedAttestation indexedAttestation2 = new IndexedAttestation();

            indexedAttestation2.Data             = data;
            indexedAttestation2.Signature        = BlsSignature.TestSig1;
            indexedAttestation2.AttestingIndices = new ValidatorIndex[8];

            AttesterSlashing slashing = new AttesterSlashing();

            slashing.Attestation1 = indexedAttestation1;
            slashing.Attestation2 = indexedAttestation2;

            Eth1Data eth1Data = new Eth1Data();

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

            body.Attestations    = new Attestation[3];
            body.Attestations[1] = attestation;

            body.Deposits    = new Deposit[3];
            body.Deposits[2] = deposit;

            body.Graffiti             = new byte[32];
            body.AttesterSlashings    = new AttesterSlashing[3];
            body.AttesterSlashings[0] = slashing;
            body.Eth1Data             = eth1Data;
            body.ProposerSlashings    = new ProposerSlashing[10];
            body.RandaoReversal       = BlsSignature.TestSig1;
            body.VoluntaryExits       = new VoluntaryExit[11];

            byte[] encoded = new byte[BeaconBlockBody.SszLength(body)];
            Ssz.Encode(encoded, body);
        }