use of tech.pegasys.teku.infrastructure.ssz.schema.impl.AbstractSszCollectionSchema in project teku by ConsenSys.
the class SszSchemaTestBase method sszDeserialize_tooLongSszShouldFailFastWithoutReadingWholeInput.
@MethodSource("testSchemaArguments")
@ParameterizedTest
void sszDeserialize_tooLongSszShouldFailFastWithoutReadingWholeInput(SszSchema<SszData> schema) {
long maxSszLength = schema.getSszLengthBounds().getMaxBytes();
// ignore too large and degenerative structs
assumeThat(maxSszLength).isLessThan(32 * 1024 * 1024).isGreaterThan(0);
// ignore lists using SszSuperNode as many validations are skipped
if (schema instanceof AbstractSszCollectionSchema) {
assumeThat(((AbstractSszCollectionSchema<?, ?>) schema).getHints().getHint(SszSuperNodeHint.class)).describedAs("uses SszSuperNode").isEmpty();
}
SszData data = randomSsz.randomData(schema);
Bytes ssz = data.sszSerialize();
Bytes sszWithExtraData = Bytes.wrap(ssz, Bytes.random((int) (maxSszLength - ssz.size() + 1)));
AtomicInteger bytesCounter = new AtomicInteger();
SimpleSszReader countingReader = new SimpleSszReader(sszWithExtraData) {
@Override
public Bytes read(int length) {
bytesCounter.addAndGet(length);
return super.read(length);
}
};
assertThatThrownBy(() -> schema.sszDeserialize(countingReader)).isInstanceOf(SszDeserializeException.class);
assertThat(bytesCounter.get()).isLessThanOrEqualTo(ssz.size());
}
Aggregations