コード例 #1
0
    @Test
    public void nemesisBlockCannotBeLoadedFromInvalidBlob() {
      // Arrange:
      final byte[] buffer = loadNemesisBlockBlobObject();
      final byte[] badBuffer1 =
          ByteBuffer.allocate(3 + buffer.length).put("bad".getBytes()).put(buffer).array();
      final byte[] badBuffer2 =
          ByteBuffer.allocate(3 + buffer.length)
              .put(Arrays.copyOfRange(buffer, 0, 100))
              .put("bad".getBytes())
              .put(Arrays.copyOfRange(buffer, 100, buffer.length))
              .array();

      // Act:
      ExceptionAssert.assertThrows(
          v ->
              NemesisBlock.fromBlobObject(
                  NEMESIS_BLOCK_INFO,
                  badBuffer1,
                  new DeserializationContext(new MockAccountLookup())),
          IllegalArgumentException.class);
      ExceptionAssert.assertThrows(
          v ->
              NemesisBlock.fromBlobObject(
                  NEMESIS_BLOCK_INFO,
                  badBuffer2,
                  new DeserializationContext(new MockAccountLookup())),
          SerializationException.class);
    }
コード例 #2
0
    @Test
    public void nemesisBlockCannotBeLoadedFromBlobWithIncorrectType() {
      // Arrange (set type to 1):
      final byte[] buffer = loadNemesisBlockBlobObject();
      buffer[0] = 1;
      buffer[1] = 0;
      buffer[2] = 0;
      buffer[3] = 0;

      // Act:
      ExceptionAssert.assertThrows(
          v ->
              NemesisBlock.fromBlobObject(
                  NEMESIS_BLOCK_INFO, buffer, new DeserializationContext(new MockAccountLookup())),
          IllegalArgumentException.class);
    }
コード例 #3
0
 @Override
 protected Block loadNemesisBlock(final MockAccountLookup accountLookup) {
   final byte[] blob = loadNemesisBlockBlobObject();
   return NemesisBlock.fromBlobObject(
       NEMESIS_BLOCK_INFO, blob, new DeserializationContext(accountLookup));
 }
コード例 #4
0
 @Override
 protected Block loadNemesisBlock(final MockAccountLookup accountLookup) {
   return NemesisBlock.fromResource(
       NEMESIS_BLOCK_INFO, new DeserializationContext(accountLookup));
 }