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); }
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 Attestation_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)); Attestation container = new Attestation( new BitArray(new byte[] { 1, 2, 3 }), data, TestSig1); Span <byte> encoded = new byte[Ssz.AttestationLength(container)]; Ssz.Encode(encoded, container); Attestation decoded = Ssz.DecodeAttestation(encoded); Assert.AreEqual(container, decoded); Merkle.Ize(out UInt256 root, container); }