use of tech.pegasys.teku.infrastructure.ssz.collections.SszMutableBytes32Vector in project teku by ConsenSys.
the class HistoricalBatchTest method roundTripViaSsz.
@Test
void roundTripViaSsz() {
SszMutableBytes32Vector block_roots = schema.getBlockRootsSchema().getDefault().createWritableCopy();
SszMutableBytes32Vector state_roots = schema.getStateRootsSchema().getDefault().createWritableCopy();
IntStream.range(0, spec.getGenesisSpecConfig().getSlotsPerHistoricalRoot()).forEach(i -> {
block_roots.setElement(i, dataStructureUtil.randomBytes32());
state_roots.setElement(i, dataStructureUtil.randomBytes32());
});
HistoricalBatch batch = schema.create(block_roots, state_roots);
Bytes serialized = batch.sszSerialize();
HistoricalBatch result = schema.sszDeserialize(serialized);
assertEquals(batch, result);
}
use of tech.pegasys.teku.infrastructure.ssz.collections.SszMutableBytes32Vector in project teku by ConsenSys.
the class AbstractSszMutableCompositeTest method setChildAfterAcquiringItByRefShouldWork.
@Test
@SuppressWarnings("unchecked")
void setChildAfterAcquiringItByRefShouldWork() {
SszBytes32VectorSchema<SszBytes32Vector> childSchema = SszBytes32VectorSchema.create(3);
SszVectorSchema<SszBytes32Vector, ?> compositeSchema = SszVectorSchema.create(childSchema, 2);
SszMutableRefVector<SszBytes32Vector, SszMutableBytes32Vector> mutableComposite = (SszMutableRefVector<SszBytes32Vector, SszMutableBytes32Vector>) compositeSchema.getDefault().createWritableCopy();
SszMutableBytes32Vector mutableChild = mutableComposite.getByRef(0);
mutableChild.setElement(0, Bytes32.fromHexStringLenient("0x1111"));
SszBytes32Vector newChild = childSchema.of(Bytes32.fromHexStringLenient("0x2222"), Bytes32.fromHexStringLenient("0x3333"), Bytes32.fromHexStringLenient("0x4444"));
mutableComposite.set(0, newChild);
SszVector<SszBytes32Vector> changedComposite = mutableComposite.commitChanges();
assertThat(changedComposite.get(0).getElement(0)).isEqualTo(Bytes32.fromHexStringLenient("0x2222"));
assertThat(changedComposite.get(0).getElement(1)).isEqualTo(Bytes32.fromHexStringLenient("0x3333"));
assertThat(changedComposite.get(0).getElement(2)).isEqualTo(Bytes32.fromHexStringLenient("0x4444"));
assertThat(changedComposite.get(1).getElement(0)).isEqualTo(Bytes32.ZERO);
assertThat(changedComposite.get(1).getElement(1)).isEqualTo(Bytes32.ZERO);
assertThat(changedComposite.get(1).getElement(2)).isEqualTo(Bytes32.ZERO);
}
Aggregations