public void Beacon_block_there_and_back() { Eth1Data eth1Data = new Eth1Data(); eth1Data.BlockHash = Sha256.OfAnEmptyString; eth1Data.DepositCount = 1; eth1Data.DepositRoot = Sha256.OfAnEmptyString; BeaconBlockBody beaconBlockBody = new BeaconBlockBody(); beaconBlockBody.RandaoReversal = BlsSignature.TestSig1; beaconBlockBody.Eth1Data = eth1Data; beaconBlockBody.Graffiti = new byte[32]; beaconBlockBody.ProposerSlashings = new ProposerSlashing[2]; beaconBlockBody.AttesterSlashings = new AttesterSlashing[3]; beaconBlockBody.Attestations = new Attestation[4]; beaconBlockBody.Deposits = new Deposit[5]; beaconBlockBody.VoluntaryExits = new VoluntaryExit[6]; BeaconBlock container = new BeaconBlock(); container.Body = beaconBlockBody; container.Signature = BlsSignature.TestSig1; container.Slot = new Slot(1); container.ParentRoot = Sha256.OfAnEmptyString; container.StateRoot = Sha256.OfAnEmptyString; Span <byte> encoded = new byte[BeaconBlock.SszLength(container)]; Ssz.Encode(encoded, container); BeaconBlock decoded = Ssz.DecodeBeaconBlock(encoded); Assert.AreEqual(container, decoded); Span <byte> encodedAgain = new byte[BeaconBlock.SszLength(container)]; Ssz.Encode(encodedAgain, decoded); Assert.True(Bytes.AreEqual(encodedAgain, encoded)); Merkle.Ize(out UInt256 root, container); }
public void Beacon_block_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 beaconBlockBody = 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() ); BeaconBlock container = new BeaconBlock( new Slot(1), Sha256.RootOfAnEmptyString, Sha256.RootOfAnEmptyString, beaconBlockBody); Span <byte> encoded = new byte[Ssz.BeaconBlockLength(container)]; Ssz.Encode(encoded, container); BeaconBlock decoded = Ssz.DecodeBeaconBlock(encoded); AssertBeaconBlockEqual(container, decoded); Span <byte> encodedAgain = new byte[Ssz.BeaconBlockLength(container)]; Ssz.Encode(encodedAgain, decoded); Assert.True(Bytes.AreEqual(encodedAgain, encoded)); Merkle.Ize(out UInt256 root, container); }
public void Beacon_block_there_and_back() { Eth1Data eth1Data = new Eth1Data( Sha256.OfAnEmptyString, 1, Sha256.OfAnEmptyString); BeaconBlockBody beaconBlockBody = 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] ); BeaconBlock container = new BeaconBlock( new Slot(1), Sha256.OfAnEmptyString, Sha256.OfAnEmptyString, beaconBlockBody, SszTest.TestSig1); Span <byte> encoded = new byte[Ssz.BeaconBlockLength(container)]; Ssz.Encode(encoded, container); BeaconBlock decoded = Ssz.DecodeBeaconBlock(encoded); AssertBeaconBlockEqual(container, decoded); Span <byte> encodedAgain = new byte[Ssz.BeaconBlockLength(container)]; Ssz.Encode(encodedAgain, decoded); Assert.True(Bytes.AreEqual(encodedAgain, encoded)); Merkle.Ize(out UInt256 root, container); }
public void Attestation_data_there_and_back() { AttestationData container = new AttestationData( new Slot(1), new CommitteeIndex(2), Sha256.RootOfAnEmptyString, new Checkpoint(new Epoch(1), Sha256.RootOfAnEmptyString), new Checkpoint(new Epoch(2), Sha256.RootOfAnEmptyString)); Span <byte> encoded = new byte[Ssz.AttestationDataLength]; Ssz.Encode(encoded, container); AttestationData decoded = Ssz.DecodeAttestationData(encoded); Assert.AreEqual(container, decoded); Span <byte> encodedAgain = new byte[Ssz.AttestationDataLength]; Ssz.Encode(encodedAgain, decoded); Assert.True(Bytes.AreEqual(encodedAgain, encoded)); Merkle.Ize(out UInt256 root, container); }
public void Attestation_data_there_and_back() { AttestationData container = new AttestationData(); container.Slot = new Slot(1); container.CommitteeIndex = new CommitteeIndex(2); container.BeaconBlockRoot = Sha256.OfAnEmptyString; container.Source = new Checkpoint(new Epoch(1), Sha256.OfAnEmptyString); container.Target = new Checkpoint(new Epoch(2), Sha256.OfAnEmptyString); Span <byte> encoded = new byte[AttestationData.SszLength]; Ssz.Encode(encoded, container); AttestationData decoded = Ssz.DecodeAttestationData(encoded); Assert.AreEqual(container, decoded); Span <byte> encodedAgain = new byte[AttestationData.SszLength]; Ssz.Encode(encodedAgain, decoded); Assert.True(Bytes.AreEqual(encodedAgain, encoded)); Merkle.Ize(out UInt256 root, container); }
public void Beacon_state_there_and_back() { Eth1Data eth1Data = new Eth1Data(); eth1Data.BlockHash = Sha256.OfAnEmptyString; eth1Data.DepositCount = 1; eth1Data.DepositRoot = Sha256.OfAnEmptyString; BeaconBlockHeader beaconBlockHeader = new BeaconBlockHeader(); beaconBlockHeader.Signature = BlsSignature.TestSig1; beaconBlockHeader.Slot = new Slot(14); beaconBlockHeader.BodyRoot = Sha256.OfAnEmptyString; beaconBlockHeader.ParentRoot = Sha256.OfAnEmptyString; beaconBlockHeader.StateRoot = Sha256.OfAnEmptyString; BeaconBlockBody beaconBlockBody = new BeaconBlockBody(); beaconBlockBody.RandaoReversal = BlsSignature.TestSig1; beaconBlockBody.Eth1Data = eth1Data; beaconBlockBody.Graffiti = new byte[32]; beaconBlockBody.ProposerSlashings = new ProposerSlashing[2]; beaconBlockBody.AttesterSlashings = new AttesterSlashing[3]; beaconBlockBody.Attestations = new Attestation[4]; beaconBlockBody.Deposits = new Deposit[5]; beaconBlockBody.VoluntaryExits = new VoluntaryExit[6]; BeaconBlock beaconBlock = new BeaconBlock(); beaconBlock.Body = beaconBlockBody; beaconBlock.Signature = BlsSignature.TestSig1; beaconBlock.Slot = new Slot(1); beaconBlock.ParentRoot = Sha256.OfAnEmptyString; beaconBlock.StateRoot = Sha256.OfAnEmptyString; BeaconState container = new BeaconState(); container.Balances = new Gwei[3]; container.Fork = new Fork(new ForkVersion(new byte[] { 0x05, 0x00, 0x00, 0x00 }), new ForkVersion(new byte[] { 0x07, 0x00, 0x00, 0x00 }), new Epoch(3)); container.Slashings = new Gwei[Time.EpochsPerSlashingsVector]; container.Slot = new Slot(1); container.Validators = new Validator[7]; container.BlockRoots = new Hash32[Time.SlotsPerHistoricalRoot]; container.StateRoots = new Hash32[Time.SlotsPerHistoricalRoot]; container.Eth1Data = eth1Data; container.Eth1DataVotes = new Eth1Data[2]; container.PreviousJustifiedCheckpoint = new Checkpoint(new Epoch(3), Sha256.OfAnEmptyString); container.CurrentJustifiedCheckpoint = new Checkpoint(new Epoch(5), Sha256.OfAnEmptyString); container.FinalizedCheckpoint = new Checkpoint(new Epoch(7), Sha256.OfAnEmptyString); container.GenesisTime = 123; container.HistoricalRoots = new Hash32[13]; container.JustificationBits = 9; container.RandaoMixes = new Hash32[Time.EpochsPerHistoricalVector]; container.PreviousEpochAttestations = new PendingAttestation[1]; container.CurrentEpochAttestations = new PendingAttestation[11]; container.Eth1DepositIndex = 1234; container.LatestBlockHeader = beaconBlockHeader; Span <byte> encoded = new byte[BeaconState.SszLength(container)]; Ssz.Encode(encoded, container); BeaconState decoded = Ssz.DecodeBeaconState(encoded); Assert.AreEqual(container, decoded); Span <byte> encodedAgain = new byte[BeaconState.SszLength(decoded)]; Ssz.Encode(encodedAgain, decoded); Assert.True(Bytes.AreEqual(encodedAgain, encoded)); Merkle.Ize(out UInt256 root, container); }