@Test
public void serializeWithWitness()
        throws InvalidAlgorithmParameterException, NoSuchAlgorithmException,
        NoSuchProviderException {

    byte[] message = new byte[10];
    Arrays.fill(message, (byte) 10);
    ECKeyPair keyPair = ECKeyPair.createEcKeyPair();
    Witness witness = Witness.createWitness(message, keyPair);
    byte[] invScript = InvocationScript.fromMessageAndKeyPair(message, keyPair).getScript();
    byte[] invScriptLen = BigInteger.valueOf(invScript.length).toByteArray();
    byte[] veriScript = new VerificationScript(keyPair.getPublicKey()).getScript();
    byte[] veriScriptLen = BigInteger.valueOf(veriScript.length).toByteArray();
    byte[] expectedWitness = concatenate(invScriptLen, invScript, veriScriptLen, veriScript);
    assertArrayEquals(expectedWitness, witness.toArray());
}