public void BasicAttestationEncode() { // Arrange Attestation attestation = new Attestation( new BitArray(new[] { true, false, false, false, false, true, false, false, true, true, false }), new AttestationData( new Slot(2 * 8 + 5), new CommitteeIndex(2), new Root(Enumerable.Repeat((byte)0x12, 32).ToArray()), new Checkpoint( new Epoch(1), new Root(Enumerable.Repeat((byte)0x34, 32).ToArray()) ), new Checkpoint( new Epoch(2), new Root(Enumerable.Repeat((byte)0x56, 32).ToArray()) ) ), new BlsSignature(Enumerable.Repeat((byte)0xef, 96).ToArray())); // Act Span <byte> encoded = new byte[Ssz.AttestationLength(attestation)]; Ssz.Encode(encoded, attestation); // Assert // Bitlist is little endian // true, false, false, false, false, true, false, false, = 0b 0010 0001 = 0x 21 // true, true, false}), = 0b 0000 0011, add sentinel bit (so we know only 3 bits used) -> 0b 0000 1011 = 0x 0b string expectedHex = // static "e4000000" + // aggregation dynamic offset 4 + 8+8+32+(8+32)+(8+32) + 96 = 228 = 0xe4 "1500000000000000" + "0200000000000000" + "1212121212121212121212121212121212121212121212121212121212121212" + "0100000000000000" + "3434343434343434343434343434343434343434343434343434343434343434" + "0200000000000000" + "5656565656565656565656565656565656565656565656565656565656565656" + "efefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefef" + // dynamic part "210b"; encoded.ToHexString().ShouldBe(expectedHex); }
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); }