### Question:
ColuTransferInstructionsParser { public List<Integer> retrieveOutputIndexesFromScript(byte []scriptBytes) throws ParseException { List<Integer> indexes = new ArrayList<>(); if (!isValidColuScript(scriptBytes)) { return indexes; } int offset = OPCODE_OFFSET; int issueByteLen = 0; if (scriptBytes[offset] >= OPCODE_ISSUANCE_TORRENT_METADATA && scriptBytes[offset] <= 0x0F) issueByteLen = 1; switch(scriptBytes[offset]) { case OPCODE_ISSUANCE_TORRENT_METADATA: offset += (TORRENT_HASH_LEN + SHA2_LEN + 1); offset += getAmountTotalBytesSFFC(scriptBytes[offset]); break; case OPCODE_TRANSFER_TORRENT_METADATA: case OPCODE_BURN_TRANSFER_METADATA: offset += (TORRENT_HASH_LEN + SHA2_LEN + 1); break; case OPCODE_ISSUANCE_TORRENT_HASH_MS: case OPCODE_ISSUANCE_TORRENT_HASH: case OPCODE_TRANSFER_TORRENT_HASH: case OPCODE_TRANSFER_TORRENT_HASH_NO_RULES: case OPCODE_BURN_TORRENT_HASH: case OPCODE_BURN_TORRENT_HASH_NO_RULES: offset += (TORRENT_HASH_LEN + 1); break; default: offset += 1; } try { while (offset < (scriptBytes.length - issueByteLen)) { byte curByte = scriptBytes[offset]; if ((curByte & RANGE_FLAG) == RANGE_FLAG) { int outputIndex = new BigInteger(new byte[]{(byte) (curByte & (~FLAG_MASK)), scriptBytes[offset + 1]}).intValue(); indexes.add(outputIndex); offset += 2; } else { indexes.add(curByte & (~FLAG_MASK)); offset += 1; } if ((curByte & PERCENT_FLAG) == PERCENT_FLAG) { offset += 1; } else { int amountTotalBytes = getAmountTotalBytesSFFC(scriptBytes[offset]); offset += amountTotalBytes; } } } catch(IndexOutOfBoundsException ex) { logger.logError("retrieveOutputIndexesFromScript(" + HexUtils.toHex(scriptBytes) + ") script could not be parsed. Assuming invalid script."); throw new ParseException("Can't parse the script", offset); } return indexes; } ColuTransferInstructionsParser(WapiLogger logger); boolean isValidColuScript(byte []scriptBytes); List<Integer> retrieveOutputIndexesFromScript(byte []scriptBytes); static final int SCRIPTBYTES_MIN_SIZE; }### Answer:
@Test public void retrieveOutputIndexesFromScript() throws Exception { byte[] script = Hex.decode("00 00 43 43" + "02 15 " + "40 01 20 73" + "25 0a" + "00 03"); List<Integer> outputIndexes = coluTransferInstructionsParser.retrieveOutputIndexesFromScript(script); assertEquals(3, outputIndexes.size()); assertEquals(1, (int)outputIndexes.get(0)); assertEquals(5, (int)outputIndexes.get(1)); assertEquals(0, (int)outputIndexes.get(2)); }
@Test public void retrieveOutputIndexesFromTooSmallScript() throws Exception { byte[] script = Hex.decode("00 00 43 43 02"); List<Integer> outputIndexes = coluTransferInstructionsParser.retrieveOutputIndexesFromScript(script); assertEquals(0, outputIndexes.size()); }
@Test(expected = ParseException.class) public void retrieveOutputFromCrashingScript() throws Exception { byte[] script = Hex.decode("6a 07 43 43 02 15 00 21 64"); List<Integer> outputIndexes = coluTransferInstructionsParser.retrieveOutputIndexesFromScript(script); assertEquals(0, outputIndexes.size()); }