SmartContractsUtils { static String checkCoinNameExist(String coinName, Map<String, String> coins) { if(coins.containsKey(coinName)) { String nameWithBrace = coinName + "("; int number = 0; for (String existingName : coins.keySet()){ if(existingName.contains(nameWithBrace)){ int parsedNumber = parseNumberOfDuplicateName(nameWithBrace.length(), existingName); if(parsedNumber > number) number = parsedNumber; } } return coinName + "(" + ++number + ")"; } return coinName; }  static List<ByteBuffer> getSmartsListFromField(String field); static byte[] generateSmartContractAddress(byte[] deployerAddress, long transactionId, List<ByteCodeObjectData> byteCodeObjects); static void saveSmartInTokenList(ObjectKeeper<ConcurrentHashMap<String, String>> coinsKeeper, String coinName, BigDecimal balance, String smartContractAddress); static int parseNumberOfDuplicateName(int identityPieceIndex, String coinName); static String generateSmartContractHashState(byte[] byteCode);  }
@Test public void checkCoinNameExistTest() { HashMap<String, String> coins = new HashMap<>(); assertEquals("Contract", checkCoinNameExist("Contract", coins)); }
@Test public void checkCoinNameExistOneContract() { HashMap<String, String> coins = new HashMap<>(); coins.put("Contract", ""); assertEquals("Contract(1)", checkCoinNameExist("Contract", coins)); }
@Test public void checkCoinNameExistMultipleNames() { ConcurrentHashMap<String, String> coins = new ConcurrentHashMap<>(); coins.put("Contract", ""); coins.put("Contract(3)", ""); coins.put("Contract(1)", ""); coins.put("Contract(2)", ""); assertEquals("Contract(4)", checkCoinNameExist("Contract", coins)); }