### Question:
ABICallSpec { public byte[] getEncoded() { byte[] functionBytes = function.getBytes(StandardCharsets.UTF_8); int totalLength = functionBytes.length; for (int i = 0; i < arguments.length; i++) { totalLength += arguments[i].length; } byte[] result = new byte[totalLength]; System.arraycopy(functionBytes, 0, result, 0, functionBytes.length); int offset = functionBytes.length; for (int i = 0; i < arguments.length; i++) { System.arraycopy(arguments[i], 0, result, offset, arguments[i].length); offset += arguments[i].length; } return result; } ABICallSpec(String function, byte[][] arguments); String getFunction(); byte[][] getArguments(); byte[] getEncoded(); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); static final Comparator<ABICallSpec> byBytesComparator; }### Answer:
@Test public void getEncoded() { ABICallSpec spec = new ABICallSpec("a-function", new byte[][]{ Hex.decode("1122"), Hex.decode("334455"), }); StringBuilder expectedBuilder = new StringBuilder(); expectedBuilder.append(Hex.toHexString("a-function".getBytes(StandardCharsets.UTF_8))); expectedBuilder.append("1122334455"); Assert.assertTrue(Arrays.equals(Hex.decode(expectedBuilder.toString()), spec.getEncoded())); }
@Test public void getEncoded() { ABICallSpec spec = new ABICallSpec("a-function", new byte[][]{ Hex.decode("1122"), Hex.decode("334455"), }); StringBuilder expectedBuilder = new StringBuilder(); expectedBuilder.append(ByteUtil.toHexString("a-function".getBytes(StandardCharsets.UTF_8))); expectedBuilder.append("1122334455"); Assert.assertTrue(Arrays.equals(Hex.decode(expectedBuilder.toString()), spec.getEncoded())); }