target stringlengths 20 113k | src_fm stringlengths 11 86.3k | src_fm_fc stringlengths 21 86.4k | src_fm_fc_co stringlengths 30 86.4k | src_fm_fc_ms stringlengths 42 86.8k | src_fm_fc_ms_ff stringlengths 43 86.8k |
|---|---|---|---|---|---|
@Test public void testFindValidLogs() { Map<String[], Long> mapIO = new HashMap<String[], Long>() {{ put(new String[]{}, -1L); put(new String[]{"o 1"}, 1L); put(new String[]{"?", "o 1"}, -1L); put(new String[]{"I 1", "?", "O 1"}, -1L); put(new String[]{"i 2", "o 1"}, 2L); put(new String[]{"?", "O 1", "?", "O 2"}, -1L);... | public static long findValidLogs(List<String> logs) { if (logs == null || logs.size() <= 0) { return -1; } long index = 0; long freeErrors = 0; HashMap<Long, String> map = new HashMap<Long, String>(); for (String log : logs) { index++; if (log == null || log.length() <= 0) { break; } String[] values = log.split(" "); i... | Coupon { public static long findValidLogs(List<String> logs) { if (logs == null || logs.size() <= 0) { return -1; } long index = 0; long freeErrors = 0; HashMap<Long, String> map = new HashMap<Long, String>(); for (String log : logs) { index++; if (log == null || log.length() <= 0) { break; } String[] values = log.spli... | Coupon { public static long findValidLogs(List<String> logs) { if (logs == null || logs.size() <= 0) { return -1; } long index = 0; long freeErrors = 0; HashMap<Long, String> map = new HashMap<Long, String>(); for (String log : logs) { index++; if (log == null || log.length() <= 0) { break; } String[] values = log.spli... | Coupon { public static long findValidLogs(List<String> logs) { if (logs == null || logs.size() <= 0) { return -1; } long index = 0; long freeErrors = 0; HashMap<Long, String> map = new HashMap<Long, String>(); for (String log : logs) { index++; if (log == null || log.length() <= 0) { break; } String[] values = log.spli... | Coupon { public static long findValidLogs(List<String> logs) { if (logs == null || logs.size() <= 0) { return -1; } long index = 0; long freeErrors = 0; HashMap<Long, String> map = new HashMap<Long, String>(); for (String log : logs) { index++; if (log == null || log.length() <= 0) { break; } String[] values = log.spli... |
@Test public void testElectionWinner() { String ret = ElectionWinner.electionWinner(new String[] {"Alex", "Michael", "harry", "Dave", "Michael", "Victor", "Harry", "Alex", "Mary", "Mary"}); Assert.assertEquals("Michael", ret); } | public static String electionWinner(String[] votes) { if (votes == null || votes.length <= 0) { return null; } Map<String, Integer> voteCountMap = new HashMap<String, Integer>(); int maxCount = 0; for (String vote : votes) { String tmp = vote.trim(); int count = 1 + (voteCountMap.containsKey(tmp) ? voteCountMap.get(tmp... | ElectionWinner { public static String electionWinner(String[] votes) { if (votes == null || votes.length <= 0) { return null; } Map<String, Integer> voteCountMap = new HashMap<String, Integer>(); int maxCount = 0; for (String vote : votes) { String tmp = vote.trim(); int count = 1 + (voteCountMap.containsKey(tmp) ? vot... | ElectionWinner { public static String electionWinner(String[] votes) { if (votes == null || votes.length <= 0) { return null; } Map<String, Integer> voteCountMap = new HashMap<String, Integer>(); int maxCount = 0; for (String vote : votes) { String tmp = vote.trim(); int count = 1 + (voteCountMap.containsKey(tmp) ? vot... | ElectionWinner { public static String electionWinner(String[] votes) { if (votes == null || votes.length <= 0) { return null; } Map<String, Integer> voteCountMap = new HashMap<String, Integer>(); int maxCount = 0; for (String vote : votes) { String tmp = vote.trim(); int count = 1 + (voteCountMap.containsKey(tmp) ? vot... | ElectionWinner { public static String electionWinner(String[] votes) { if (votes == null || votes.length <= 0) { return null; } Map<String, Integer> voteCountMap = new HashMap<String, Integer>(); int maxCount = 0; for (String vote : votes) { String tmp = vote.trim(); int count = 1 + (voteCountMap.containsKey(tmp) ? vot... |
@Test public void testDeltaEncode() { Map<int[], int[]> mapIO = new HashMap<int[], int[]>(){{ put(new int[]{25626, 25757, 24367, 24267, 16, 100, 2, 7277}, new int[]{25626, -128, 131, -128, -1390, -100, -128, -24251, 84, -98, -128, 7275}); }}; for (Map.Entry<int[], int[]> io : mapIO.entrySet()) { int[] ret = DeltaEncode... | public static int[] delta_encode(final int[] array) { if (array == null || array.length <= 1) { return array; } List<Integer> encode = new ArrayList<Integer>(){{ add(array[0]); }}; for (int i = 1; i < array.length; i++) { int diff = array[i] - array[i - 1]; if (diff < -127 || diff > 127) { encode.add(-128); } encode.ad... | DeltaEncode { public static int[] delta_encode(final int[] array) { if (array == null || array.length <= 1) { return array; } List<Integer> encode = new ArrayList<Integer>(){{ add(array[0]); }}; for (int i = 1; i < array.length; i++) { int diff = array[i] - array[i - 1]; if (diff < -127 || diff > 127) { encode.add(-128... | DeltaEncode { public static int[] delta_encode(final int[] array) { if (array == null || array.length <= 1) { return array; } List<Integer> encode = new ArrayList<Integer>(){{ add(array[0]); }}; for (int i = 1; i < array.length; i++) { int diff = array[i] - array[i - 1]; if (diff < -127 || diff > 127) { encode.add(-128... | DeltaEncode { public static int[] delta_encode(final int[] array) { if (array == null || array.length <= 1) { return array; } List<Integer> encode = new ArrayList<Integer>(){{ add(array[0]); }}; for (int i = 1; i < array.length; i++) { int diff = array[i] - array[i - 1]; if (diff < -127 || diff > 127) { encode.add(-128... | DeltaEncode { public static int[] delta_encode(final int[] array) { if (array == null || array.length <= 1) { return array; } List<Integer> encode = new ArrayList<Integer>(){{ add(array[0]); }}; for (int i = 1; i < array.length; i++) { int diff = array[i] - array[i - 1]; if (diff < -127 || diff > 127) { encode.add(-128... |
@Test public void testZombieCluster() { Map<String[], Integer> mapIO = new HashMap<String[], Integer>() {{ put(new String[]{"10000", "01000", "00100", "00010", "00001"}, 5); put(new String[]{"1100", "1110", "0110", "0001"}, 2); }}; for (Map.Entry<String[], Integer> io : mapIO.entrySet()) { int ret = ZombieCluster.zombi... | static int zombieCluster(String[] zombieArr) { if (zombieArr == null || zombieArr.length <= 0) { return 0; } int len = zombieArr.length; boolean[][] zombieMatric = new boolean[len][len]; for (int i = 0; i < len; i++) { int j = 0; for (char c : zombieArr[i].toCharArray()) { zombieMatric[i][j++] = (c == '1'); } } markClu... | ZombieCluster { static int zombieCluster(String[] zombieArr) { if (zombieArr == null || zombieArr.length <= 0) { return 0; } int len = zombieArr.length; boolean[][] zombieMatric = new boolean[len][len]; for (int i = 0; i < len; i++) { int j = 0; for (char c : zombieArr[i].toCharArray()) { zombieMatric[i][j++] = (c == '... | ZombieCluster { static int zombieCluster(String[] zombieArr) { if (zombieArr == null || zombieArr.length <= 0) { return 0; } int len = zombieArr.length; boolean[][] zombieMatric = new boolean[len][len]; for (int i = 0; i < len; i++) { int j = 0; for (char c : zombieArr[i].toCharArray()) { zombieMatric[i][j++] = (c == '... | ZombieCluster { static int zombieCluster(String[] zombieArr) { if (zombieArr == null || zombieArr.length <= 0) { return 0; } int len = zombieArr.length; boolean[][] zombieMatric = new boolean[len][len]; for (int i = 0; i < len; i++) { int j = 0; for (char c : zombieArr[i].toCharArray()) { zombieMatric[i][j++] = (c == '... | ZombieCluster { static int zombieCluster(String[] zombieArr) { if (zombieArr == null || zombieArr.length <= 0) { return 0; } int len = zombieArr.length; boolean[][] zombieMatric = new boolean[len][len]; for (int i = 0; i < len; i++) { int j = 0; for (char c : zombieArr[i].toCharArray()) { zombieMatric[i][j++] = (c == '... |
@Test public void testGetDay() { Map<String[], String> mapIO = new HashMap<String[], String>() {{ put(new String[]{"05", "08", "2015"}, "WEDNESDAY"); put(new String[]{"04", "06", "2018"}, "MONDAY"); put(new String[]{"06", "06", "2018"}, "WEDNESDAY"); }}; for (Map.Entry<String[], String> io : mapIO.entrySet()) { String[... | public static String getDay(String day, String month, String year) { if (day == null || day.length() <= 0 || month == null || month.length() <= 0 || year == null || year.length() <= 0) { return ""; } String dateStr = String.format("%s-%s-%s", year, month, day); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date d... | GetDay { public static String getDay(String day, String month, String year) { if (day == null || day.length() <= 0 || month == null || month.length() <= 0 || year == null || year.length() <= 0) { return ""; } String dateStr = String.format("%s-%s-%s", year, month, day); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"... | GetDay { public static String getDay(String day, String month, String year) { if (day == null || day.length() <= 0 || month == null || month.length() <= 0 || year == null || year.length() <= 0) { return ""; } String dateStr = String.format("%s-%s-%s", year, month, day); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"... | GetDay { public static String getDay(String day, String month, String year) { if (day == null || day.length() <= 0 || month == null || month.length() <= 0 || year == null || year.length() <= 0) { return ""; } String dateStr = String.format("%s-%s-%s", year, month, day); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"... | GetDay { public static String getDay(String day, String month, String year) { if (day == null || day.length() <= 0 || month == null || month.length() <= 0 || year == null || year.length() <= 0) { return ""; } String dateStr = String.format("%s-%s-%s", year, month, day); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"... |
@Test public void testGetRanks() { Map<List<int[]>, int[]> ioMap = new HashMap<List<int[]>, int[]>() {{ put(new ArrayList() {{ add(new int[] {100, 100, 50, 40, 40, 20, 10}); add(new int[] {5, 25, 50, 120}); }}, new int[] {6, 4, 2, 1}); }}; for (Map.Entry<List<int[]>, int[]> io : ioMap.entrySet()) { int[] ranks = Leader... | public static int[] getRanks(int[] scores, int[] alice) { Player[] players = new Player[scores.length]; for (int i = 0; i < scores.length; i++) { players[i] = new Player(scores[i], 0); } Arrays.sort(players); for (int i = 0; i < scores.length; i++) { if (i == 0) { players[i].setRank(1); } else if (players[i].getScore()... | LeaderBoard { public static int[] getRanks(int[] scores, int[] alice) { Player[] players = new Player[scores.length]; for (int i = 0; i < scores.length; i++) { players[i] = new Player(scores[i], 0); } Arrays.sort(players); for (int i = 0; i < scores.length; i++) { if (i == 0) { players[i].setRank(1); } else if (players... | LeaderBoard { public static int[] getRanks(int[] scores, int[] alice) { Player[] players = new Player[scores.length]; for (int i = 0; i < scores.length; i++) { players[i] = new Player(scores[i], 0); } Arrays.sort(players); for (int i = 0; i < scores.length; i++) { if (i == 0) { players[i].setRank(1); } else if (players... | LeaderBoard { public static int[] getRanks(int[] scores, int[] alice) { Player[] players = new Player[scores.length]; for (int i = 0; i < scores.length; i++) { players[i] = new Player(scores[i], 0); } Arrays.sort(players); for (int i = 0; i < scores.length; i++) { if (i == 0) { players[i].setRank(1); } else if (players... | LeaderBoard { public static int[] getRanks(int[] scores, int[] alice) { Player[] players = new Player[scores.length]; for (int i = 0; i < scores.length; i++) { players[i] = new Player(scores[i], 0); } Arrays.sort(players); for (int i = 0; i < scores.length; i++) { if (i == 0) { players[i].setRank(1); } else if (players... |
@Test public void testWaitingTime() { Map<int[], long[]> mapIO = new HashMap<int[], long[]>(){{ put(new int[]{2, 6, 3, 4, 5}, new long[]{2, 12}); put(new int[]{1, 1, 1, 1}, new long[]{0, 1}); put(new int[]{5, 5, 2, 3}, new long[]{3, 11}); }}; for(Map.Entry<int[], long[]> io : mapIO.entrySet()) { long ret = WaitingTime.... | public static long waitingTime(int[] tickets, int p) { if (tickets == null || tickets.length <= 0 || p < 0 || p >= tickets.length) { return -1; } int count = 0; int ticket = tickets[p]; for (int i = 0; i < tickets.length; i++) { int tmp = tickets[i]; if (tmp < ticket) { count += tmp; } else { count += ticket; if (i > p... | WaitingTime { public static long waitingTime(int[] tickets, int p) { if (tickets == null || tickets.length <= 0 || p < 0 || p >= tickets.length) { return -1; } int count = 0; int ticket = tickets[p]; for (int i = 0; i < tickets.length; i++) { int tmp = tickets[i]; if (tmp < ticket) { count += tmp; } else { count += tic... | WaitingTime { public static long waitingTime(int[] tickets, int p) { if (tickets == null || tickets.length <= 0 || p < 0 || p >= tickets.length) { return -1; } int count = 0; int ticket = tickets[p]; for (int i = 0; i < tickets.length; i++) { int tmp = tickets[i]; if (tmp < ticket) { count += tmp; } else { count += tic... | WaitingTime { public static long waitingTime(int[] tickets, int p) { if (tickets == null || tickets.length <= 0 || p < 0 || p >= tickets.length) { return -1; } int count = 0; int ticket = tickets[p]; for (int i = 0; i < tickets.length; i++) { int tmp = tickets[i]; if (tmp < ticket) { count += tmp; } else { count += tic... | WaitingTime { public static long waitingTime(int[] tickets, int p) { if (tickets == null || tickets.length <= 0 || p < 0 || p >= tickets.length) { return -1; } int count = 0; int ticket = tickets[p]; for (int i = 0; i < tickets.length; i++) { int tmp = tickets[i]; if (tmp < ticket) { count += tmp; } else { count += tic... |
@Test public void testMain() { Hello.main(null); } | public static void main(String[] args) { Map<String, Integer> map = new HashMap<String, Integer>() {{ put("a", 1); put("b", 2); }}; System.out.println(map.toString()); System.out.println(map.keySet().toString()); } | Hello { public static void main(String[] args) { Map<String, Integer> map = new HashMap<String, Integer>() {{ put("a", 1); put("b", 2); }}; System.out.println(map.toString()); System.out.println(map.keySet().toString()); } } | Hello { public static void main(String[] args) { Map<String, Integer> map = new HashMap<String, Integer>() {{ put("a", 1); put("b", 2); }}; System.out.println(map.toString()); System.out.println(map.keySet().toString()); } } | Hello { public static void main(String[] args) { Map<String, Integer> map = new HashMap<String, Integer>() {{ put("a", 1); put("b", 2); }}; System.out.println(map.toString()); System.out.println(map.keySet().toString()); } static void main(String[] args); } | Hello { public static void main(String[] args) { Map<String, Integer> map = new HashMap<String, Integer>() {{ put("a", 1); put("b", 2); }}; System.out.println(map.toString()); System.out.println(map.keySet().toString()); } static void main(String[] args); } |
@Test public void testIsValid() { Map<String, Boolean> mapIO = new HashMap<String, Boolean>() {{ put("000.12.12.034", true); put("121.234.12.12", true); put("23.45.12.56", true); put("000.12.234.23.23", false); put("666.666.23.23", false); put(".213.123.23.32", false); put("23.45.22.32.", false); put("I.Am.not.an.ip", ... | public static boolean isValid(String ip) { if (ip == null || ip.length() <= 0) { return false; } return ip.trim().matches(new MyRegex().pattern); } | IP { public static boolean isValid(String ip) { if (ip == null || ip.length() <= 0) { return false; } return ip.trim().matches(new MyRegex().pattern); } } | IP { public static boolean isValid(String ip) { if (ip == null || ip.length() <= 0) { return false; } return ip.trim().matches(new MyRegex().pattern); } } | IP { public static boolean isValid(String ip) { if (ip == null || ip.length() <= 0) { return false; } return ip.trim().matches(new MyRegex().pattern); } static boolean isValid(String ip); } | IP { public static boolean isValid(String ip) { if (ip == null || ip.length() <= 0) { return false; } return ip.trim().matches(new MyRegex().pattern); } static boolean isValid(String ip); } |
@Test public void testPermutationEquation() { Map<int[], int[]> mapIO = new HashMap<int[], int[]>(){{ put(new int[]{2, 3, 1}, new int[] {2, 3, 1}); }}; for (Map.Entry<int[], int[]> io : mapIO.entrySet()) { int[] ret = PermutationEquation.permutationEquation(io.getKey()); Assert.assertArrayEquals(io.getValue(), ret); } ... | public static int[] permutationEquation(final int[] p) { if (p == null || p.length <= 0) { return null; } Map<Integer, Integer> equationMap = new HashMap<Integer, Integer>(){{ for (int i = 0; i < p.length; i++) { put(p[i], i + 1); } }}; int[] arr = new int[p.length]; for (int i = 0; i < arr.length; i++) { arr[i] = equa... | PermutationEquation { public static int[] permutationEquation(final int[] p) { if (p == null || p.length <= 0) { return null; } Map<Integer, Integer> equationMap = new HashMap<Integer, Integer>(){{ for (int i = 0; i < p.length; i++) { put(p[i], i + 1); } }}; int[] arr = new int[p.length]; for (int i = 0; i < arr.length... | PermutationEquation { public static int[] permutationEquation(final int[] p) { if (p == null || p.length <= 0) { return null; } Map<Integer, Integer> equationMap = new HashMap<Integer, Integer>(){{ for (int i = 0; i < p.length; i++) { put(p[i], i + 1); } }}; int[] arr = new int[p.length]; for (int i = 0; i < arr.length... | PermutationEquation { public static int[] permutationEquation(final int[] p) { if (p == null || p.length <= 0) { return null; } Map<Integer, Integer> equationMap = new HashMap<Integer, Integer>(){{ for (int i = 0; i < p.length; i++) { put(p[i], i + 1); } }}; int[] arr = new int[p.length]; for (int i = 0; i < arr.length... | PermutationEquation { public static int[] permutationEquation(final int[] p) { if (p == null || p.length <= 0) { return null; } Map<Integer, Integer> equationMap = new HashMap<Integer, Integer>(){{ for (int i = 0; i < p.length; i++) { put(p[i], i + 1); } }}; int[] arr = new int[p.length]; for (int i = 0; i < arr.length... |
@Test public void testMaxMin() { Map<Object[], long[]> pairIO = new HashMap<Object[], long[]>() {{ put(new Object[] {new String[]{"push", "push", "push", "pop"}, new int[]{1, 2, 3, 1}}, new long[]{1, 2, 3, 6}); put(new Object[] {new String[]{"push", "push"}, new int[] {3, 2}}, new long[]{9, 6}); }}; for (Map.Entry<Obje... | public static long[] maxMin(String[] operations, int[] values) { if (operations == null || values == null || operations.length > values.length) { return null; } long[] products = new long[operations.length]; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; int[] arr = new int[operations.length]; int index = 0;... | MaxMin { public static long[] maxMin(String[] operations, int[] values) { if (operations == null || values == null || operations.length > values.length) { return null; } long[] products = new long[operations.length]; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; int[] arr = new int[operations.length]; int i... | MaxMin { public static long[] maxMin(String[] operations, int[] values) { if (operations == null || values == null || operations.length > values.length) { return null; } long[] products = new long[operations.length]; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; int[] arr = new int[operations.length]; int i... | MaxMin { public static long[] maxMin(String[] operations, int[] values) { if (operations == null || values == null || operations.length > values.length) { return null; } long[] products = new long[operations.length]; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; int[] arr = new int[operations.length]; int i... | MaxMin { public static long[] maxMin(String[] operations, int[] values) { if (operations == null || values == null || operations.length > values.length) { return null; } long[] products = new long[operations.length]; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; int[] arr = new int[operations.length]; int i... |
@Test public void testWinOrLose() { Map<Integer, int[]> mapIO = new HashMap<Integer, int[]>() {{ put(0, new int[] {2, 3}); put(1, new int[] {5, 3}); }}; for (Map.Entry<Integer, int[]> io : mapIO.entrySet()) { Assert.assertEquals( io.getKey().intValue(), WinOrLose2.winOrLose(io.getValue()[0], io.getValue()[1]) ); } } | public static int winOrLose(long first, long second) { if (first > second) return 1; else if (first < second) return 0; return random.nextBoolean() ? 1 : 0; } | WinOrLose2 { public static int winOrLose(long first, long second) { if (first > second) return 1; else if (first < second) return 0; return random.nextBoolean() ? 1 : 0; } } | WinOrLose2 { public static int winOrLose(long first, long second) { if (first > second) return 1; else if (first < second) return 0; return random.nextBoolean() ? 1 : 0; } } | WinOrLose2 { public static int winOrLose(long first, long second) { if (first > second) return 1; else if (first < second) return 0; return random.nextBoolean() ? 1 : 0; } static void main(String[] args); static int calculateLoop(List<Long> ar); static int winOrLose(long first, long second); } | WinOrLose2 { public static int winOrLose(long first, long second) { if (first > second) return 1; else if (first < second) return 0; return random.nextBoolean() ? 1 : 0; } static void main(String[] args); static int calculateLoop(List<Long> ar); static int winOrLose(long first, long second); } |
@Test public void testCutSticks() { Map<int[], int[]> mapIO = new HashMap<int[], int[]>() {{ put(new int[]{1, 1, 2, 3}, new int[]{4, 2, 1}); put(new int[]{5, 4, 4, 2, 2, 8}, new int[]{6, 4, 2, 1}); }}; for (Map.Entry<int[], int[]> io : mapIO.entrySet()) { int[] ret = CutSticks.cutSticks(io.getKey()); Assert.assertArray... | public static int[] cutSticks(int[] lengths) { if (lengths == null || lengths.length <= 0) { return null; } Arrays.sort(lengths); int index = 0, count = lengths.length; List<Integer> countList = new ArrayList<Integer>(); while (index < count) { countList.add(count - index); if (index == count - 1) { break; } int value ... | CutSticks { public static int[] cutSticks(int[] lengths) { if (lengths == null || lengths.length <= 0) { return null; } Arrays.sort(lengths); int index = 0, count = lengths.length; List<Integer> countList = new ArrayList<Integer>(); while (index < count) { countList.add(count - index); if (index == count - 1) { break; ... | CutSticks { public static int[] cutSticks(int[] lengths) { if (lengths == null || lengths.length <= 0) { return null; } Arrays.sort(lengths); int index = 0, count = lengths.length; List<Integer> countList = new ArrayList<Integer>(); while (index < count) { countList.add(count - index); if (index == count - 1) { break; ... | CutSticks { public static int[] cutSticks(int[] lengths) { if (lengths == null || lengths.length <= 0) { return null; } Arrays.sort(lengths); int index = 0, count = lengths.length; List<Integer> countList = new ArrayList<Integer>(); while (index < count) { countList.add(count - index); if (index == count - 1) { break; ... | CutSticks { public static int[] cutSticks(int[] lengths) { if (lengths == null || lengths.length <= 0) { return null; } Arrays.sort(lengths); int index = 0, count = lengths.length; List<Integer> countList = new ArrayList<Integer>(); while (index < count) { countList.add(count - index); if (index == count - 1) { break; ... |
@Test public void testCounting() { Map<String, Integer> mapIO = new HashMap<String, Integer>(){{ put("10001", 2); put("10101", 4); put("00110", 3); }}; for (Map.Entry<String, Integer> io : mapIO.entrySet()) { int ret = BinarySubString.counting(io.getKey()); Assert.assertEquals(io.getValue().intValue(), ret); } } | public static int counting(String s) { if (s == null || s.trim().length() <= 1) { return 0; } char[] arr = s.trim().toCharArray(); int len = arr.length; int count = 0; for (int i = 0; i < len - 1; i++) { if (arr[i] != arr[i + 1]) { count++; int m = i - 1; int n = i + 1 + 1; while (m >= 0 && n < len && arr[i] == arr[m] ... | BinarySubString { public static int counting(String s) { if (s == null || s.trim().length() <= 1) { return 0; } char[] arr = s.trim().toCharArray(); int len = arr.length; int count = 0; for (int i = 0; i < len - 1; i++) { if (arr[i] != arr[i + 1]) { count++; int m = i - 1; int n = i + 1 + 1; while (m >= 0 && n < len &&... | BinarySubString { public static int counting(String s) { if (s == null || s.trim().length() <= 1) { return 0; } char[] arr = s.trim().toCharArray(); int len = arr.length; int count = 0; for (int i = 0; i < len - 1; i++) { if (arr[i] != arr[i + 1]) { count++; int m = i - 1; int n = i + 1 + 1; while (m >= 0 && n < len &&... | BinarySubString { public static int counting(String s) { if (s == null || s.trim().length() <= 1) { return 0; } char[] arr = s.trim().toCharArray(); int len = arr.length; int count = 0; for (int i = 0; i < len - 1; i++) { if (arr[i] != arr[i + 1]) { count++; int m = i - 1; int n = i + 1 + 1; while (m >= 0 && n < len &&... | BinarySubString { public static int counting(String s) { if (s == null || s.trim().length() <= 1) { return 0; } char[] arr = s.trim().toCharArray(); int len = arr.length; int count = 0; for (int i = 0; i < len - 1; i++) { if (arr[i] != arr[i + 1]) { count++; int m = i - 1; int n = i + 1 + 1; while (m >= 0 && n < len &&... |
@Test public void testFindMax() { Map<String, int[]> mapIO = new HashMap<String, int[]>() {{ put("3 4 5 1 3 # 1", new int[]{6, 9}); put("3 2 3 # 3 # 1", new int[]{5, 7}); }}; for (Map.Entry<String, int[]> io : mapIO.entrySet()) { long ret = Portfolio.findMax(io.getValue()[0], io.getKey()); Assert.assertEquals((long)(io... | public static long findMax(int n, String tree) { if (n <= 0 || tree == null || tree.trim().length() <= 0) { return 0; } String[] nodes = tree.trim().split(" "); if (nodes.length < n) { return 0; } List<Long> sumList = new ArrayList<Long>(); int countExpected = 1; int count = 0; int index = 0; long sum = 0; for (int i =... | Portfolio { public static long findMax(int n, String tree) { if (n <= 0 || tree == null || tree.trim().length() <= 0) { return 0; } String[] nodes = tree.trim().split(" "); if (nodes.length < n) { return 0; } List<Long> sumList = new ArrayList<Long>(); int countExpected = 1; int count = 0; int index = 0; long sum = 0; ... | Portfolio { public static long findMax(int n, String tree) { if (n <= 0 || tree == null || tree.trim().length() <= 0) { return 0; } String[] nodes = tree.trim().split(" "); if (nodes.length < n) { return 0; } List<Long> sumList = new ArrayList<Long>(); int countExpected = 1; int count = 0; int index = 0; long sum = 0; ... | Portfolio { public static long findMax(int n, String tree) { if (n <= 0 || tree == null || tree.trim().length() <= 0) { return 0; } String[] nodes = tree.trim().split(" "); if (nodes.length < n) { return 0; } List<Long> sumList = new ArrayList<Long>(); int countExpected = 1; int count = 0; int index = 0; long sum = 0; ... | Portfolio { public static long findMax(int n, String tree) { if (n <= 0 || tree == null || tree.trim().length() <= 0) { return 0; } String[] nodes = tree.trim().split(" "); if (nodes.length < n) { return 0; } List<Long> sumList = new ArrayList<Long>(); int countExpected = 1; int count = 0; int index = 0; long sum = 0; ... |
@Test public void testBestTrio() { Map<Object[], Integer> mapIO = new HashMap<Object[], Integer>() {{ put(new Object[]{5, new int[]{1, 1, 2, 2, 3, 4}, new int[]{2, 3, 3, 4, 4, 5}}, 2); put(new Object[]{7, new int[]{2, 3, 5, 1}, new int[]{1, 6, 1, 7}}, -1); }}; for (Map.Entry<Object[], Integer> io : mapIO.entrySet()) { ... | static int bestTrio(int friends_nodes, int[] friends_from, int[] friends_to) { if (friends_nodes < 0 || friends_from == null || friends_to == null || friends_from.length > friends_to.length) { return -1; } List<HashSet<Integer>> friends = new ArrayList<HashSet<Integer>>(friends_nodes); for (int i = 0; i < friends_nodes... | BestTrio { static int bestTrio(int friends_nodes, int[] friends_from, int[] friends_to) { if (friends_nodes < 0 || friends_from == null || friends_to == null || friends_from.length > friends_to.length) { return -1; } List<HashSet<Integer>> friends = new ArrayList<HashSet<Integer>>(friends_nodes); for (int i = 0; i < fr... | BestTrio { static int bestTrio(int friends_nodes, int[] friends_from, int[] friends_to) { if (friends_nodes < 0 || friends_from == null || friends_to == null || friends_from.length > friends_to.length) { return -1; } List<HashSet<Integer>> friends = new ArrayList<HashSet<Integer>>(friends_nodes); for (int i = 0; i < fr... | BestTrio { static int bestTrio(int friends_nodes, int[] friends_from, int[] friends_to) { if (friends_nodes < 0 || friends_from == null || friends_to == null || friends_from.length > friends_to.length) { return -1; } List<HashSet<Integer>> friends = new ArrayList<HashSet<Integer>>(friends_nodes); for (int i = 0; i < fr... | BestTrio { static int bestTrio(int friends_nodes, int[] friends_from, int[] friends_to) { if (friends_nodes < 0 || friends_from == null || friends_to == null || friends_from.length > friends_to.length) { return -1; } List<HashSet<Integer>> friends = new ArrayList<HashSet<Integer>>(friends_nodes); for (int i = 0; i < fr... |
@Test public void testMovieTitles() { final String[] ret = MovieTitles.getMovieTitles("spiderman"); System.out.println(Arrays.asList(ret).toString()); Assert.assertArrayEquals(new String[]{ "Amazing Spiderman Syndrome", "Fighting, Flying and Driving: The Stunts of Spiderman 3", "Hollywood's Master Storytellers: Spiderm... | public static String[] getMovieTitles(String substr) { if (substr == null || substr.trim().length() <= 0) { return null; } int page = 1; final String url = "https: Gson gson = new Gson(); List<String> movies = new ArrayList<String>(); while (true) { String response = null; try { response = httpGet(String.format(url, su... | MovieTitles { public static String[] getMovieTitles(String substr) { if (substr == null || substr.trim().length() <= 0) { return null; } int page = 1; final String url = "https: Gson gson = new Gson(); List<String> movies = new ArrayList<String>(); while (true) { String response = null; try { response = httpGet(String.... | MovieTitles { public static String[] getMovieTitles(String substr) { if (substr == null || substr.trim().length() <= 0) { return null; } int page = 1; final String url = "https: Gson gson = new Gson(); List<String> movies = new ArrayList<String>(); while (true) { String response = null; try { response = httpGet(String.... | MovieTitles { public static String[] getMovieTitles(String substr) { if (substr == null || substr.trim().length() <= 0) { return null; } int page = 1; final String url = "https: Gson gson = new Gson(); List<String> movies = new ArrayList<String>(); while (true) { String response = null; try { response = httpGet(String.... | MovieTitles { public static String[] getMovieTitles(String substr) { if (substr == null || substr.trim().length() <= 0) { return null; } int page = 1; final String url = "https: Gson gson = new Gson(); List<String> movies = new ArrayList<String>(); while (true) { String response = null; try { response = httpGet(String.... |
@Test public void testReductionCost() { Map<int[], Integer> mapIO = new HashMap<int[], Integer>() {{ put(new int[] {1, 2, 3}, 9); put(new int[] {1, 2, 3, 4}, 19); }}; for (Map.Entry<int[], Integer> io : mapIO.entrySet()) { int ret = ReductionCost.reductionCost(io.getKey()); Assert.assertEquals(io.getValue().intValue(),... | public static int reductionCost(int[] numArr) { if (numArr == null || numArr.length <= 0) { return 0; } int cost = 0; for (int i = 0; i < numArr.length - 1; i++) { Arrays.sort(numArr); int sum = numArr[i] + numArr[i + 1]; numArr[i] = 0; numArr[i + 1] = sum; cost += sum; } return cost; } | ReductionCost { public static int reductionCost(int[] numArr) { if (numArr == null || numArr.length <= 0) { return 0; } int cost = 0; for (int i = 0; i < numArr.length - 1; i++) { Arrays.sort(numArr); int sum = numArr[i] + numArr[i + 1]; numArr[i] = 0; numArr[i + 1] = sum; cost += sum; } return cost; } } | ReductionCost { public static int reductionCost(int[] numArr) { if (numArr == null || numArr.length <= 0) { return 0; } int cost = 0; for (int i = 0; i < numArr.length - 1; i++) { Arrays.sort(numArr); int sum = numArr[i] + numArr[i + 1]; numArr[i] = 0; numArr[i + 1] = sum; cost += sum; } return cost; } } | ReductionCost { public static int reductionCost(int[] numArr) { if (numArr == null || numArr.length <= 0) { return 0; } int cost = 0; for (int i = 0; i < numArr.length - 1; i++) { Arrays.sort(numArr); int sum = numArr[i] + numArr[i + 1]; numArr[i] = 0; numArr[i + 1] = sum; cost += sum; } return cost; } static int redu... | ReductionCost { public static int reductionCost(int[] numArr) { if (numArr == null || numArr.length <= 0) { return 0; } int cost = 0; for (int i = 0; i < numArr.length - 1; i++) { Arrays.sort(numArr); int sum = numArr[i] + numArr[i + 1]; numArr[i] = 0; numArr[i + 1] = sum; cost += sum; } return cost; } static int redu... |
@Test public void testArbitrage() { int[] ret = Arbitrage.arbitrage(new String[]{"1.1837 1.3829 0.6102", "1.1234 1.2134 1.2311"}); Assert.assertArrayEquals(new int[]{114, 0}, ret); } | public static int[] arbitrage(String[] quotes) { if (quotes == null || quotes.length <= 0) { return null; } int[] profits = new int[quotes.length]; for (int i = 0; i < quotes.length; i++) { double[] prices = parseQuote(quotes[i]); int profit = 0; if (prices != null) { double dollar = 100000; for (int j = 0; j < prices.... | Arbitrage { public static int[] arbitrage(String[] quotes) { if (quotes == null || quotes.length <= 0) { return null; } int[] profits = new int[quotes.length]; for (int i = 0; i < quotes.length; i++) { double[] prices = parseQuote(quotes[i]); int profit = 0; if (prices != null) { double dollar = 100000; for (int j = 0;... | Arbitrage { public static int[] arbitrage(String[] quotes) { if (quotes == null || quotes.length <= 0) { return null; } int[] profits = new int[quotes.length]; for (int i = 0; i < quotes.length; i++) { double[] prices = parseQuote(quotes[i]); int profit = 0; if (prices != null) { double dollar = 100000; for (int j = 0;... | Arbitrage { public static int[] arbitrage(String[] quotes) { if (quotes == null || quotes.length <= 0) { return null; } int[] profits = new int[quotes.length]; for (int i = 0; i < quotes.length; i++) { double[] prices = parseQuote(quotes[i]); int profit = 0; if (prices != null) { double dollar = 100000; for (int j = 0;... | Arbitrage { public static int[] arbitrage(String[] quotes) { if (quotes == null || quotes.length <= 0) { return null; } int[] profits = new int[quotes.length]; for (int i = 0; i < quotes.length; i++) { double[] prices = parseQuote(quotes[i]); int profit = 0; if (prices != null) { double dollar = 100000; for (int j = 0;... |
@Test public void testSplitTokens() { Map<String, Integer> mapIO = new HashMap<String, Integer>() {{ put("He is a very very good boy, isn't he?", 10); put(" YES leading spaces are valid, problemsetters are evillllll", 8); put("", 0); put(null, 0); }}; for (Map.Entry<String, Integer> io : mapIO.entrySet()) { String[] re... | public static String[] splitTokens(String str) { if (str == null || str.trim().length() <= 0) { return null; } String[] strArr = str.trim().split("[ !,?._'@]+"); return strArr; } | SubStr { public static String[] splitTokens(String str) { if (str == null || str.trim().length() <= 0) { return null; } String[] strArr = str.trim().split("[ !,?._'@]+"); return strArr; } } | SubStr { public static String[] splitTokens(String str) { if (str == null || str.trim().length() <= 0) { return null; } String[] strArr = str.trim().split("[ !,?._'@]+"); return strArr; } } | SubStr { public static String[] splitTokens(String str) { if (str == null || str.trim().length() <= 0) { return null; } String[] strArr = str.trim().split("[ !,?._'@]+"); return strArr; } static String[] splitTokens(String str); static String getSmallestAndLargest(String str, int k); } | SubStr { public static String[] splitTokens(String str) { if (str == null || str.trim().length() <= 0) { return null; } String[] strArr = str.trim().split("[ !,?._'@]+"); return strArr; } static String[] splitTokens(String str); static String getSmallestAndLargest(String str, int k); } |
@Test public void testGetSmallestAndLargest() { Map<String, String> mapIO = new HashMap<String, String>() {{ put("welcometojava", "ava\nwel"); }}; for (Map.Entry<String, String> io : mapIO.entrySet()) { String ret = SubStr.getSmallestAndLargest(io.getKey(), 3); Assert.assertEquals(io.getValue(), ret); } } | public static String getSmallestAndLargest(String str, int k) { if (str == null || str.length() < k || k <= 0) { return "\n"; } String smallest = str.substring(0, k); String largest = smallest; for (int i = 1; i < str.length() - k + 1; i++) { String sub = str.substring(i, i + k); if (smallest.compareTo(sub) > 0) { smal... | SubStr { public static String getSmallestAndLargest(String str, int k) { if (str == null || str.length() < k || k <= 0) { return "\n"; } String smallest = str.substring(0, k); String largest = smallest; for (int i = 1; i < str.length() - k + 1; i++) { String sub = str.substring(i, i + k); if (smallest.compareTo(sub) > ... | SubStr { public static String getSmallestAndLargest(String str, int k) { if (str == null || str.length() < k || k <= 0) { return "\n"; } String smallest = str.substring(0, k); String largest = smallest; for (int i = 1; i < str.length() - k + 1; i++) { String sub = str.substring(i, i + k); if (smallest.compareTo(sub) > ... | SubStr { public static String getSmallestAndLargest(String str, int k) { if (str == null || str.length() < k || k <= 0) { return "\n"; } String smallest = str.substring(0, k); String largest = smallest; for (int i = 1; i < str.length() - k + 1; i++) { String sub = str.substring(i, i + k); if (smallest.compareTo(sub) > ... | SubStr { public static String getSmallestAndLargest(String str, int k) { if (str == null || str.length() < k || k <= 0) { return "\n"; } String smallest = str.substring(0, k); String largest = smallest; for (int i = 1; i < str.length() - k + 1; i++) { String sub = str.substring(i, i + k); if (smallest.compareTo(sub) > ... |
@Test public void testBraces() { Map<int[], Integer[]> mapIO = new HashMap<int[], Integer[]>() {{ put(new int[] {6, 6, 3, 9, 3, 5, 1}, new Integer[]{12, 2}); }}; for (Map.Entry<int[], Integer[]> io : mapIO.entrySet()) { Integer ret = NumberOfPairs.numberOfPairs(io.getKey(), io.getValue()[0]); Assert.assertEquals(io.get... | static int numberOfPairs(int[] a, long k) { if (a == null || a.length <= 1) { return 0; } Arrays.sort(a); Map<Integer, Integer> pairMap = new HashMap<Integer, Integer>(); for (int i = 0; i < a.length; i++) { int m = a[i]; for (int j = a.length - 1; j > i; j--) { int n = a[j]; if (m + n < k) { break; } else if (m + n ==... | NumberOfPairs { static int numberOfPairs(int[] a, long k) { if (a == null || a.length <= 1) { return 0; } Arrays.sort(a); Map<Integer, Integer> pairMap = new HashMap<Integer, Integer>(); for (int i = 0; i < a.length; i++) { int m = a[i]; for (int j = a.length - 1; j > i; j--) { int n = a[j]; if (m + n < k) { break; } e... | NumberOfPairs { static int numberOfPairs(int[] a, long k) { if (a == null || a.length <= 1) { return 0; } Arrays.sort(a); Map<Integer, Integer> pairMap = new HashMap<Integer, Integer>(); for (int i = 0; i < a.length; i++) { int m = a[i]; for (int j = a.length - 1; j > i; j--) { int n = a[j]; if (m + n < k) { break; } e... | NumberOfPairs { static int numberOfPairs(int[] a, long k) { if (a == null || a.length <= 1) { return 0; } Arrays.sort(a); Map<Integer, Integer> pairMap = new HashMap<Integer, Integer>(); for (int i = 0; i < a.length; i++) { int m = a[i]; for (int j = a.length - 1; j > i; j--) { int n = a[j]; if (m + n < k) { break; } e... | NumberOfPairs { static int numberOfPairs(int[] a, long k) { if (a == null || a.length <= 1) { return 0; } Arrays.sort(a); Map<Integer, Integer> pairMap = new HashMap<Integer, Integer>(); for (int i = 0; i < a.length; i++) { int m = a[i]; for (int j = a.length - 1; j > i; j--) { int n = a[j]; if (m + n < k) { break; } e... |
@Test public void testCalculateLoop() { Map<long[], Integer> mapIO = new HashMap<long[], Integer>() {{ put(new long[] {7, 1, 2, 3, 1, 3, 1, 2, 5, 6, 1, 6, 2, 5}, 0); put(new long[] {4, 1}, 1); put(new long[] {1000000, 1, 2, -1000000}, 2); put(new long[] {4, 1, 2, 3, 1, 3, 1, 2}, 3); put(new long[] {7, 1, 2, 3, 1, 3, 1,... | public static int calculateLoop(List<Long> ar) { int n = ar.size(); if (n <= 1 || (n & (n - 1)) != 0) { return 0; } Iterator<Long> iterator = ar.iterator(); long score = iterator.next(); long index = 0; long mark = 1; int loop = 0; while (iterator.hasNext()) { if (winOrLose(score, iterator.next()) == 1) { index++; if (... | WinOrLose2 { public static int calculateLoop(List<Long> ar) { int n = ar.size(); if (n <= 1 || (n & (n - 1)) != 0) { return 0; } Iterator<Long> iterator = ar.iterator(); long score = iterator.next(); long index = 0; long mark = 1; int loop = 0; while (iterator.hasNext()) { if (winOrLose(score, iterator.next()) == 1) { ... | WinOrLose2 { public static int calculateLoop(List<Long> ar) { int n = ar.size(); if (n <= 1 || (n & (n - 1)) != 0) { return 0; } Iterator<Long> iterator = ar.iterator(); long score = iterator.next(); long index = 0; long mark = 1; int loop = 0; while (iterator.hasNext()) { if (winOrLose(score, iterator.next()) == 1) { ... | WinOrLose2 { public static int calculateLoop(List<Long> ar) { int n = ar.size(); if (n <= 1 || (n & (n - 1)) != 0) { return 0; } Iterator<Long> iterator = ar.iterator(); long score = iterator.next(); long index = 0; long mark = 1; int loop = 0; while (iterator.hasNext()) { if (winOrLose(score, iterator.next()) == 1) { ... | WinOrLose2 { public static int calculateLoop(List<Long> ar) { int n = ar.size(); if (n <= 1 || (n & (n - 1)) != 0) { return 0; } Iterator<Long> iterator = ar.iterator(); long score = iterator.next(); long index = 0; long mark = 1; int loop = 0; while (iterator.hasNext()) { if (winOrLose(score, iterator.next()) == 1) { ... |
@Test public void testGetScore() { Map<String, Integer> mapIO = new HashMap<String, Integer>(){{ put("acdapmpomp", 15); put("axbawbaseksqke", 25); put("aa", 1); put("ab", 1); put("abb", 2); put("aab", 2); }}; for (Map.Entry<String, Integer> io : mapIO.entrySet()) { int ret = Palindrome.getScore(io.getKey()); Assert.ass... | static int getScore(String s) { if (s == null || s.trim().length() <= 1) { return 0; } if (s.length() == 2) { return 1; } int score = 0; for (int i = 1; i < s.length(); i++) { String p1 = getMaxPalindrome(s.substring(0, i)); String p2 = getMaxPalindrome(s.substring(i, s.length())); int tmp = (p1 == null ? 0 : p1.length... | Palindrome { static int getScore(String s) { if (s == null || s.trim().length() <= 1) { return 0; } if (s.length() == 2) { return 1; } int score = 0; for (int i = 1; i < s.length(); i++) { String p1 = getMaxPalindrome(s.substring(0, i)); String p2 = getMaxPalindrome(s.substring(i, s.length())); int tmp = (p1 == null ? ... | Palindrome { static int getScore(String s) { if (s == null || s.trim().length() <= 1) { return 0; } if (s.length() == 2) { return 1; } int score = 0; for (int i = 1; i < s.length(); i++) { String p1 = getMaxPalindrome(s.substring(0, i)); String p2 = getMaxPalindrome(s.substring(i, s.length())); int tmp = (p1 == null ? ... | Palindrome { static int getScore(String s) { if (s == null || s.trim().length() <= 1) { return 0; } if (s.length() == 2) { return 1; } int score = 0; for (int i = 1; i < s.length(); i++) { String p1 = getMaxPalindrome(s.substring(0, i)); String p2 = getMaxPalindrome(s.substring(i, s.length())); int tmp = (p1 == null ? ... | Palindrome { static int getScore(String s) { if (s == null || s.trim().length() <= 1) { return 0; } if (s.length() == 2) { return 1; } int score = 0; for (int i = 1; i < s.length(); i++) { String p1 = getMaxPalindrome(s.substring(0, i)); String p2 = getMaxPalindrome(s.substring(i, s.length())); int tmp = (p1 == null ? ... |
@Test public void testPickNumbers() { Map<int[], Integer> mapIO = new HashMap<int[], Integer>() {{ put(null, 0); put(new int[]{4, 6, 5, 3, 3, 1}, 3); put(new int[]{1, 2, 2, 3, 1, 2}, 5); put(new int[]{ 4, 2, 3, 4, 4, 9, 98, 98, 3, 3, 3, 4, 2, 98, 1, 98, 98, 1, 1, 4, 98, 2, 98, 3, 9, 9, 3, 1, 4, 1, 98, 9, 9, 2, 9, 4, 2,... | public static int pickNumbers(int[] ar) { if (ar == null || ar.length <= 0) { return 0; } Arrays.sort(ar); int n = ar.length; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { int count = 0; int diff = 0; for (int j = i - 1; j >= 0; j--) { int tmp = Math.abs(ar[i] - ar[j]); if (tmp <= 1) { count++; if (diff < ... | PickNumbers { public static int pickNumbers(int[] ar) { if (ar == null || ar.length <= 0) { return 0; } Arrays.sort(ar); int n = ar.length; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { int count = 0; int diff = 0; for (int j = i - 1; j >= 0; j--) { int tmp = Math.abs(ar[i] - ar[j]); if (tmp <= 1) { count+... | PickNumbers { public static int pickNumbers(int[] ar) { if (ar == null || ar.length <= 0) { return 0; } Arrays.sort(ar); int n = ar.length; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { int count = 0; int diff = 0; for (int j = i - 1; j >= 0; j--) { int tmp = Math.abs(ar[i] - ar[j]); if (tmp <= 1) { count+... | PickNumbers { public static int pickNumbers(int[] ar) { if (ar == null || ar.length <= 0) { return 0; } Arrays.sort(ar); int n = ar.length; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { int count = 0; int diff = 0; for (int j = i - 1; j >= 0; j--) { int tmp = Math.abs(ar[i] - ar[j]); if (tmp <= 1) { count+... | PickNumbers { public static int pickNumbers(int[] ar) { if (ar == null || ar.length <= 0) { return 0; } Arrays.sort(ar); int n = ar.length; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { int count = 0; int diff = 0; for (int j = i - 1; j >= 0; j--) { int tmp = Math.abs(ar[i] - ar[j]); if (tmp <= 1) { count+... |
@Test public void testBraces() { Map<String[], String[]> mapIO = new HashMap<String[], String[]>() {{ put(new String[] {"{}[]()", "{[}]}"}, new String[] {"YES", "NO"}); put(new String[] {"}][}}(}][))]"}, new String[] {"NO"}); }}; for (Map.Entry<String[], String[]> io : mapIO.entrySet()) { String[] ret = Braces.braces(i... | static String[] braces(String[] values) { if (values == null || values.length <= 0) { return null; } Map<Integer, Integer> braceMap = new HashMap<Integer, Integer>() {{ put((int)')', (int)'('); put((int)']', (int)'['); put((int)'}', (int)'{'); }}; String[] ret = new String[values.length]; for (int i = 0; i < values.len... | Braces { static String[] braces(String[] values) { if (values == null || values.length <= 0) { return null; } Map<Integer, Integer> braceMap = new HashMap<Integer, Integer>() {{ put((int)')', (int)'('); put((int)']', (int)'['); put((int)'}', (int)'{'); }}; String[] ret = new String[values.length]; for (int i = 0; i < v... | Braces { static String[] braces(String[] values) { if (values == null || values.length <= 0) { return null; } Map<Integer, Integer> braceMap = new HashMap<Integer, Integer>() {{ put((int)')', (int)'('); put((int)']', (int)'['); put((int)'}', (int)'{'); }}; String[] ret = new String[values.length]; for (int i = 0; i < v... | Braces { static String[] braces(String[] values) { if (values == null || values.length <= 0) { return null; } Map<Integer, Integer> braceMap = new HashMap<Integer, Integer>() {{ put((int)')', (int)'('); put((int)']', (int)'['); put((int)'}', (int)'{'); }}; String[] ret = new String[values.length]; for (int i = 0; i < v... | Braces { static String[] braces(String[] values) { if (values == null || values.length <= 0) { return null; } Map<Integer, Integer> braceMap = new HashMap<Integer, Integer>() {{ put((int)')', (int)'('); put((int)']', (int)'['); put((int)'}', (int)'{'); }}; String[] ret = new String[values.length]; for (int i = 0; i < v... |
@Test public void testGetInstrumentedObject() { AopInstrumenter instrumenter = new AopInstrumenter(); AopService service = (AopService) instrumenter.getInstrumentedClass(AopServiceImpl.class); service.findInfo("Instrumenter from test"); } | public Object getInstrumentedClass(Class clz) { enhancer.setSuperclass(clz); enhancer.setCallback(this); return enhancer.create(); } | AopInstrumenter implements MethodInterceptor { public Object getInstrumentedClass(Class clz) { enhancer.setSuperclass(clz); enhancer.setCallback(this); return enhancer.create(); } } | AopInstrumenter implements MethodInterceptor { public Object getInstrumentedClass(Class clz) { enhancer.setSuperclass(clz); enhancer.setCallback(this); return enhancer.create(); } } | AopInstrumenter implements MethodInterceptor { public Object getInstrumentedClass(Class clz) { enhancer.setSuperclass(clz); enhancer.setCallback(this); return enhancer.create(); } Object getInstrumentedClass(Class clz); Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy); } | AopInstrumenter implements MethodInterceptor { public Object getInstrumentedClass(Class clz) { enhancer.setSuperclass(clz); enhancer.setCallback(this); return enhancer.create(); } Object getInstrumentedClass(Class clz); Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy); } |
@Test public void testApp() { App.main(null); } | public static void main(String[] args) { AopService service = (AopService) AopFactory.getAopProxyedObject(AopServiceImpl.class.getName()); service.findInfo("Jonn from app.main"); AopInstrumenter instrumenter = new AopInstrumenter(); service = (AopService) instrumenter.getInstrumentedClass(AopServiceImpl.class); service... | App { public static void main(String[] args) { AopService service = (AopService) AopFactory.getAopProxyedObject(AopServiceImpl.class.getName()); service.findInfo("Jonn from app.main"); AopInstrumenter instrumenter = new AopInstrumenter(); service = (AopService) instrumenter.getInstrumentedClass(AopServiceImpl.class); s... | App { public static void main(String[] args) { AopService service = (AopService) AopFactory.getAopProxyedObject(AopServiceImpl.class.getName()); service.findInfo("Jonn from app.main"); AopInstrumenter instrumenter = new AopInstrumenter(); service = (AopService) instrumenter.getInstrumentedClass(AopServiceImpl.class); s... | App { public static void main(String[] args) { AopService service = (AopService) AopFactory.getAopProxyedObject(AopServiceImpl.class.getName()); service.findInfo("Jonn from app.main"); AopInstrumenter instrumenter = new AopInstrumenter(); service = (AopService) instrumenter.getInstrumentedClass(AopServiceImpl.class); s... | App { public static void main(String[] args) { AopService service = (AopService) AopFactory.getAopProxyedObject(AopServiceImpl.class.getName()); service.findInfo("Jonn from app.main"); AopInstrumenter instrumenter = new AopInstrumenter(); service = (AopService) instrumenter.getInstrumentedClass(AopServiceImpl.class); s... |
@Test public void testGetAopProxyedObject() { AopService service = (AopService) AopFactory.getAopProxyedObject(AopServiceImpl.class.getName()); service.findInfo("Jonn from test"); } | public static Object getAopProxyedObject(String clzName) { Object proxy = null; AopHandler handler = new AopHandler(); Object obj = getClassInst(clzName); if (obj != null) { proxy = handler.bind(obj); } else { System.out.println("Can't get the proxyObj"); } return proxy; } | AopFactory { public static Object getAopProxyedObject(String clzName) { Object proxy = null; AopHandler handler = new AopHandler(); Object obj = getClassInst(clzName); if (obj != null) { proxy = handler.bind(obj); } else { System.out.println("Can't get the proxyObj"); } return proxy; } } | AopFactory { public static Object getAopProxyedObject(String clzName) { Object proxy = null; AopHandler handler = new AopHandler(); Object obj = getClassInst(clzName); if (obj != null) { proxy = handler.bind(obj); } else { System.out.println("Can't get the proxyObj"); } return proxy; } } | AopFactory { public static Object getAopProxyedObject(String clzName) { Object proxy = null; AopHandler handler = new AopHandler(); Object obj = getClassInst(clzName); if (obj != null) { proxy = handler.bind(obj); } else { System.out.println("Can't get the proxyObj"); } return proxy; } static Object getAopProxyedObjec... | AopFactory { public static Object getAopProxyedObject(String clzName) { Object proxy = null; AopHandler handler = new AopHandler(); Object obj = getClassInst(clzName); if (obj != null) { proxy = handler.bind(obj); } else { System.out.println("Can't get the proxyObj"); } return proxy; } static Object getAopProxyedObjec... |
@Test public void testIncr() { String key = "RedisServiceTest.testStr"; long ret = redisService.incr(key); Assertions.assertTrue(ret > 0); System.out.println(ret); redisService.expire(key, 1); } | public long incr(String key) { Long ret = strValOps.increment(key, 1L); return ret == null ? 0 : ret; } | RedisService { public long incr(String key) { Long ret = strValOps.increment(key, 1L); return ret == null ? 0 : ret; } } | RedisService { public long incr(String key) { Long ret = strValOps.increment(key, 1L); return ret == null ? 0 : ret; } } | RedisService { public long incr(String key) { Long ret = strValOps.increment(key, 1L); return ret == null ? 0 : ret; } long incr(String key); boolean expire(String key, long seconds); } | RedisService { public long incr(String key) { Long ret = strValOps.increment(key, 1L); return ret == null ? 0 : ret; } long incr(String key); boolean expire(String key, long seconds); } |
@Test void testServletHook() throws ClassNotFoundException, IOException { String expected = ServletTestHook.class.getName() + " instruments [javax.servlet.Filter, javax.servlet.Servlet]:\n" + " * doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)\n" + " * service(javax.servlet.ServletRequest, javax.s... | SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); SortedSet<HookMetadata> parse(Predicate<String> classNameFilter); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); SortedSet<HookMetadata> parse(Predicate<String> classNameFilter); } |
@Test void testPrimitiveTypes() throws ClassNotFoundException, IOException { String expected = PrimitiveTypesTestHook.class.getName() + " instruments [com.example.Some]:\n" + " * arrayArgs(java.lang.Object[], int[], java.lang.String[])\n" + " * boxedArgs(java.lang.Boolean, java.lang.Character, java.lang.Byte, java.lang... | SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); SortedSet<HookMetadata> parse(Predicate<String> classNameFilter); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); SortedSet<HookMetadata> parse(Predicate<String> classNameFilter); } |
@Test void testReturnedAndThrown() throws IOException, ClassNotFoundException { String expected = ReturnedAndThrownTestHook.class.getName() + " instruments [com.example.ReturnThrown]:\n" + " * div(int, int)"; SortedSet<HookMetadata> result = parser.parse(className -> className.equals(ReturnedAndThrownTestHook.class.get... | SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); SortedSet<HookMetadata> parse(Predicate<String> classNameFilter); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); SortedSet<HookMetadata> parse(Predicate<String> classNameFilter); } |
@Test void testNoHook() throws ClassNotFoundException, IOException { SortedSet<HookMetadata> result = parser.parse(className -> className.equals(HookMetadataParserTest.class.getName())); Assertions.assertTrue(result.isEmpty()); } | SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); SortedSet<HookMetadata> parse(Predicate<String> classNameFilter); } | HookMetadataParser { SortedSet<HookMetadata> parse() throws IOException, ClassNotFoundException { return parse(className -> true); } HookMetadataParser(Collection<Path> hookJars); SortedSet<HookMetadata> parse(Predicate<String> classNameFilter); } |
@Test void testCmdlineParserWildfly() { String[] cmdlineArgs = new String[]{ "-D[Standalone]", "-Xbootclasspath/p:/tmp/wildfly-10.1.0.Final/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-2.0.4.Final.jar", "-Djboss.modules.system.pkgs=org.jboss.logmanager,io.promagent.agent", "-Djava.util.logging.... | static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.jar file.")... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... |
@Test void testCmdlineParserVersioned() { String[] cmdlineArgs = new String[] { "-javaagent:promagent-1.0-SNAPSHOT.jar" }; assertEquals("promagent-1.0-SNAPSHOT.jar", findAgentJarFromCmdline(asList(cmdlineArgs)).toString()); } | static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.jar file.")... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... |
@Test() void testCmdlineParserFailed() { String[] cmdlineArgs = new String[] { "-javaagent:/some/other/agent.jar", "-jar", "promagent.jar" }; Exception e = assertThrows(Exception.class, () -> findAgentJarFromCmdline(asList(cmdlineArgs))); assertTrue(e.getMessage().contains("promagent.jar")); } | static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.jar file.")... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... | JarFiles { static Path findAgentJarFromCmdline(List<String> cmdlineArgs) { Pattern p = Pattern.compile("^-javaagent:(.*promagent([^/]*).jar)(=.*)?$"); for (String arg : cmdlineArgs) { Matcher m = p.matcher(arg); if (m.matches()) { return Paths.get(m.group(1)); } } throw new RuntimeException("Failed to locate promagent.... |
@Test public void getAttributes() throws Exception { long peerId = 100500L; String hostAddress = "testAddress.com"; String app = "testApp"; String version = "testVersion"; ExecutionContext ctx = mock(ExecutionContext.class); ExecutionContext.Host host = mock(ExecutionContext.Host.class); fork = mock(IFork.class); when(... | @Override public SalientAttributes getAttributes() throws RemotePeerException, IOException { SalientAttributes originAttributes = new SalientAttributes(); originAttributes.setApplication(context.getApplication()); originAttributes.setVersion(context.getVersion()); originAttributes.setPeerId(context.getHost().getPeerID(... | SyncMetadataService extends BaseService implements IMetadataService { @Override public SalientAttributes getAttributes() throws RemotePeerException, IOException { SalientAttributes originAttributes = new SalientAttributes(); originAttributes.setApplication(context.getApplication()); originAttributes.setVersion(context.... | SyncMetadataService extends BaseService implements IMetadataService { @Override public SalientAttributes getAttributes() throws RemotePeerException, IOException { SalientAttributes originAttributes = new SalientAttributes(); originAttributes.setApplication(context.getApplication()); originAttributes.setVersion(context.... | SyncMetadataService extends BaseService implements IMetadataService { @Override public SalientAttributes getAttributes() throws RemotePeerException, IOException { SalientAttributes originAttributes = new SalientAttributes(); originAttributes.setApplication(context.getApplication()); originAttributes.setVersion(context.... | SyncMetadataService extends BaseService implements IMetadataService { @Override public SalientAttributes getAttributes() throws RemotePeerException, IOException { SalientAttributes originAttributes = new SalientAttributes(); originAttributes.setApplication(context.getApplication()); originAttributes.setVersion(context.... |
@Test public void success_without_note() throws Exception { Transaction tx = Builder.newTransaction(timeProvider).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.matches()) { return ValidationResult.success; } } ... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... |
@Test public void empty_note() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("Invalid note"); Transaction tx = Builder.newTransaction(timeProvider).note("").build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.matches()) { return ValidationResult.success; } } ... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... |
@Test public void invalid_note_length() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("Invalid note"); Random random = new Random(); char[] symbols = alphabet.toCharArray(); char[] buffer = new char[Constant.TRANSACTION_NOTE_MAX_LENGTH_V2 + 1]; for (int i = 0; i <... | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.matches()) { return ValidationResult.success; } } ... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... |
@Test public void illegal_symbol() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("Invalid note"); Transaction tx = Builder.newTransaction(timeProvider).note("|note|").build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.matches()) { return ValidationResult.success; } } ... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... |
@Test public void check_alphabet() throws Exception { Transaction tx = Builder.newTransaction(timeProvider).note(alphabet).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.matches()) { return ValidationResult.success; } } ... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... | NoteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getNote() == null) { return ValidationResult.success; } int length = tx.getNote().length(); if (length > 0 && length <= maxLength) { Matcher m = notePattern.matcher(tx.getNote()); if (m.ma... |
@Test public void success() throws Exception { Transaction tx = Builder.newTransaction(timeProvider).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } | LengthValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } } | LengthValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } } | LengthValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } @Overrid... | LengthValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } @Overrid... |
@Test public void length_exceeds_limit() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("Invalid transaction length."); Transaction tx = spy(Builder.newTransaction(timeProvider).build(networkID, sender)); when(tx.getLength()).thenReturn(Constant.TRANSACTION_MAX_PAY... | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } | LengthValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } } | LengthValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } } | LengthValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } @Overrid... | LengthValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); if (length > Constant.TRANSACTION_MAX_PAYLOAD_LENGTH) { return ValidationResult.error("Invalid transaction length."); } return ValidationResult.success; } @Overrid... |
@Test public void getTransactions_shouldnt_return_ignore_trs() throws Exception { Transaction[] trs = sts.getTransactions(lastBlockIdStr, new String[] {ignoreTrIdStr}); assertEquals(2, trs.length); assertEquals(unconfTr1, trs[0]); assertEquals(unconfTr2, trs[1]); } | @Override public Transaction[] getTransactions(String lastBlockId, String[] ignoreList) throws RemotePeerException, IOException { List<TransactionID> ignoreIDs = new ArrayList<>(); try { if (!blockchain.getLastBlock().getID().equals(new BlockID(lastBlockId)) && !fork.isPassed(timeProvider.get())) { return new Transacti... | SyncTransactionService extends BaseService implements ITransactionSynchronizationService { @Override public Transaction[] getTransactions(String lastBlockId, String[] ignoreList) throws RemotePeerException, IOException { List<TransactionID> ignoreIDs = new ArrayList<>(); try { if (!blockchain.getLastBlock().getID().equ... | SyncTransactionService extends BaseService implements ITransactionSynchronizationService { @Override public Transaction[] getTransactions(String lastBlockId, String[] ignoreList) throws RemotePeerException, IOException { List<TransactionID> ignoreIDs = new ArrayList<>(); try { if (!blockchain.getLastBlock().getID().equ... | SyncTransactionService extends BaseService implements ITransactionSynchronizationService { @Override public Transaction[] getTransactions(String lastBlockId, String[] ignoreList) throws RemotePeerException, IOException { List<TransactionID> ignoreIDs = new ArrayList<>(); try { if (!blockchain.getLastBlock().getID().equ... | SyncTransactionService extends BaseService implements ITransactionSynchronizationService { @Override public Transaction[] getTransactions(String lastBlockId, String[] ignoreList) throws RemotePeerException, IOException { List<TransactionID> ignoreIDs = new ArrayList<>(); try { if (!blockchain.getLastBlock().getID().equ... |
@Test public void getState_for_existing_account_should_return_OK() throws Exception { AccountID id = new AccountID(12345L); ledger = ledger.putAccount(new Account(id)); assertEquals(AccountBotService.State.OK, service.getState(id.toString())); } | public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transaction.getType() == Tr... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... |
@Test public void getState_for_processing_account() throws Exception { ISigner sender = new TestSigner("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"); ISigner newAccount = new TestSigner("112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"); Transaction tx = RegistrationBuilder.create... | public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transaction.getType() == Tr... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... |
@Test public void getState_for_notexisting_account() throws Exception { assertEquals(AccountBotService.State.NotFound, service.getState(new AccountID(12345L).toString())); } | public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transaction.getType() == Tr... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... | AccountBotService { public State getState(String id) throws RemotePeerException, IOException { Account account = getAccount(id); if (account != null) { return State.OK; } IBacklog backlog = this.backlog; for (TransactionID item : backlog) { Transaction transaction = backlog.get(item); if (transaction != null && transac... |
@Test public void getBalance_for_existing_account() throws Exception { AccountID id = new AccountID(12345L); Account account = new Account(id); account = AccountProperties.setProperty(account, new BalanceProperty(100L)); ledger = ledger.putAccount(account); AccountBotService.EONBalance balance = service.getBalance(id.t... | public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(account); balance.amou... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... |
@Test public void getBalance_for_notexisting_account() throws Exception { AccountBotService.EONBalance balance = service.getBalance(new AccountID(12345L).toString()); assertEquals(AccountBotService.State.Unauthorized, balance.state); assertEquals(0, balance.amount); assertNull(balance.coloredCoins); } | public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(account); balance.amou... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... |
@Test public void getBalance_for_existing_account_with_colored_coins() throws Exception { AccountID id = new AccountID(12345L); Account account = new Account(id); account = AccountProperties.setProperty(account, new BalanceProperty(100L)); ColoredBalanceProperty coloredBalance = new ColoredBalanceProperty(); coloredBal... | public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(account); balance.amou... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... | AccountBotService { public EONBalance getBalance(String id) throws RemotePeerException, IOException { Account account = getAccount(id); EONBalance balance = new EONBalance(); if (account == null) { balance.state = State.Unauthorized; } else { balance.state = State.OK; BalanceProperty b = AccountProperties.getBalance(ac... |
@Test public void getInformation_for_existing_account() throws Exception { ISigner signer = new TestSigner("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"); AccountID id = new AccountID(signer.getPublicKey()); Account account = new Account(id); account = AccountProperties.setProperty(account, new Reg... | public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account).getPublicKey()); Va... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... |
@Test public void getInformation_for_existing_colored_coin() throws Exception { ISigner signer = new TestSigner("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"); AccountID id = new AccountID(signer.getPublicKey()); Account account = new Account(id); account = AccountProperties.setProperty(account, ne... | public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account).getPublicKey()); Va... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... |
@Test public void getInformation_for_public_account() throws Exception { String seed = "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"; ISigner signer = new TestSigner(seed); AccountID id = new AccountID(signer.getPublicKey()); Account account = new Account(id); account = AccountProperties.setPropert... | public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account).getPublicKey()); Va... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... |
@Test public void getWellKnownNodes_should_return_array() throws Exception { SyncMetadataService sms = new SyncMetadataService(fork, ctx, blockchain, storage); String[] wkn = sms.getWellKnownNodes(); assertEquals(2, wkn.length); assertEquals(peer1Addr, wkn[0]); assertEquals(peer2Addr, wkn[1]); } | @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = context.getPeers().getPeerByAddress(address); if (peer != null) { if (... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... |
@Test public void getInformation_for_mfa_account() throws Exception { ISigner signer = new TestSigner("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"); AccountID id = new AccountID(signer.getPublicKey()); Account account = new Account(id); account = AccountProperties.setProperty(account, new Registra... | public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account).getPublicKey()); Va... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... |
@Test public void getInformation_for_notexisting_account() throws Exception { AccountBotService.Info info = service.getInformation(new AccountID(12345L).toString()); assertEquals(AccountBotService.State.Unauthorized, info.state); assertNull(info.publicKey); assertEquals(0L, info.deposit); assertEquals(0L, info.amount);... | public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account).getPublicKey()); Va... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... | AccountBotService { public Info getInformation(String id) throws RemotePeerException, IOException { Account account = getAccount(id); Info info = new Info(); if (account == null) { info.state = State.Unauthorized; } else { info.state = State.OK; info.publicKey = Format.convert(AccountProperties.getRegistration(account)... |
@Test public void getInformation_OK() throws Exception { AccountID id = new AccountID(1L); targetAccount = new Account(id); ColoredCoinProperty coloredCoin = new ColoredCoinProperty(); coloredCoin.setEmitMode(ColoredCoinEmitMode.PRESET); coloredCoin.setMoneySupply(10000L); coloredCoin.setAttributes(new ColoredCoinPrope... | public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!coloredCoin.isIssued()) { ret... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... |
@Test public void getInformation_not_found() throws Exception { AccountID id = new AccountID(1L); ColoredCoinBotService.Info info = service.getInfo(id.toString()); assertEquals(info.state, ColoredCoinBotService.State.Unauthorized); assertNull(info.decimal); assertNull(info.supply); } | public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!coloredCoin.isIssued()) { ret... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... |
@Test public void getInformation_illegal_state() throws Exception { AccountID id = new AccountID(1L); targetAccount = new Account(id); ColoredCoinBotService.Info info = service.getInfo(id.toString()); assertEquals(info.state, ColoredCoinBotService.State.Unauthorized); assertNull(info.decimal); assertNull(info.supply); ... | public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!coloredCoin.isIssued()) { ret... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... | ColoredCoinBotService { public Info getInfo(String id) throws RemotePeerException, IOException { Account account = getColoredAccount(id); Info info = new Info(); info.state = State.Unauthorized; if (account == null) { return info; } ColoredCoinProperty coloredCoin = AccountProperties.getColoredCoin(account); if (!color... |
@Test public void isCome() { assertFalse("Before fork", forkState.isCome(50)); assertFalse("Fork started", forkState.isCome(100)); assertTrue("On fork", forkState.isCome(150)); assertTrue("Fork ended", forkState.isCome(200)); assertTrue("After fork", forkState.isCome(250)); } | @Override public boolean isCome(int timestamp) { return items.getFirst().isCome(timestamp); } | Fork implements IFork { @Override public boolean isCome(int timestamp) { return items.getFirst().isCome(timestamp); } } | Fork implements IFork { @Override public boolean isCome(int timestamp) { return items.getFirst().isCome(timestamp); } Fork(BlockID genesisBlockID, ForkItem[] items, String beginAll); Fork(BlockID genesisBlockID, ForkItem[] items); Fork(BlockID genesisBlockID, ForkItem[] items, long beginAll); } | Fork implements IFork { @Override public boolean isCome(int timestamp) { return items.getFirst().isCome(timestamp); } Fork(BlockID genesisBlockID, ForkItem[] items, String beginAll); Fork(BlockID genesisBlockID, ForkItem[] items); Fork(BlockID genesisBlockID, ForkItem[] items, long beginAll); @Override BlockID getGen... | Fork implements IFork { @Override public boolean isCome(int timestamp) { return items.getFirst().isCome(timestamp); } Fork(BlockID genesisBlockID, ForkItem[] items, String beginAll); Fork(BlockID genesisBlockID, ForkItem[] items); Fork(BlockID genesisBlockID, ForkItem[] items, long beginAll); @Override BlockID getGen... |
@Test public void isPassed() { assertFalse("Before fork", forkState.isPassed(50)); assertFalse("Fork started", forkState.isPassed(100)); assertFalse("On fork", forkState.isPassed(150)); assertFalse("Fork ended", forkState.isPassed(200)); assertTrue("After fork", forkState.isPassed(250)); } | @Override public boolean isPassed(int timestamp) { return items.getFirst().isPassed(timestamp); } | Fork implements IFork { @Override public boolean isPassed(int timestamp) { return items.getFirst().isPassed(timestamp); } } | Fork implements IFork { @Override public boolean isPassed(int timestamp) { return items.getFirst().isPassed(timestamp); } Fork(BlockID genesisBlockID, ForkItem[] items, String beginAll); Fork(BlockID genesisBlockID, ForkItem[] items); Fork(BlockID genesisBlockID, ForkItem[] items, long beginAll); } | Fork implements IFork { @Override public boolean isPassed(int timestamp) { return items.getFirst().isPassed(timestamp); } Fork(BlockID genesisBlockID, ForkItem[] items, String beginAll); Fork(BlockID genesisBlockID, ForkItem[] items); Fork(BlockID genesisBlockID, ForkItem[] items, long beginAll); @Override BlockID ge... | Fork implements IFork { @Override public boolean isPassed(int timestamp) { return items.getFirst().isPassed(timestamp); } Fork(BlockID genesisBlockID, ForkItem[] items, String beginAll); Fork(BlockID genesisBlockID, ForkItem[] items); Fork(BlockID genesisBlockID, ForkItem[] items, long beginAll); @Override BlockID ge... |
@Test public void getNumber() { assertEquals("Before fork", 1, forkState.getNumber(50)); assertEquals("Fork started", 1, forkState.getNumber(100)); assertEquals("On fork", 2, forkState.getNumber(150)); assertEquals("Fork ended", 2, forkState.getNumber(200)); assertEquals("After fork", 2, forkState.getNumber(250)); } | @Override public int getNumber(int timestamp) { Item item = getItem(timestamp); return (item == null) ? -1 : item.getNumber(); } | Fork implements IFork { @Override public int getNumber(int timestamp) { Item item = getItem(timestamp); return (item == null) ? -1 : item.getNumber(); } } | Fork implements IFork { @Override public int getNumber(int timestamp) { Item item = getItem(timestamp); return (item == null) ? -1 : item.getNumber(); } Fork(BlockID genesisBlockID, ForkItem[] items, String beginAll); Fork(BlockID genesisBlockID, ForkItem[] items); Fork(BlockID genesisBlockID, ForkItem[] items, long ... | Fork implements IFork { @Override public int getNumber(int timestamp) { Item item = getItem(timestamp); return (item == null) ? -1 : item.getNumber(); } Fork(BlockID genesisBlockID, ForkItem[] items, String beginAll); Fork(BlockID genesisBlockID, ForkItem[] items); Fork(BlockID genesisBlockID, ForkItem[] items, long ... | Fork implements IFork { @Override public int getNumber(int timestamp) { Item item = getItem(timestamp); return (item == null) ? -1 : item.getNumber(); } Fork(BlockID genesisBlockID, ForkItem[] items, String beginAll); Fork(BlockID genesisBlockID, ForkItem[] items); Fork(BlockID genesisBlockID, ForkItem[] items, long ... |
@Test public void testSyncSnapshotDisable() throws Exception { String connectURI = "jdbc:sqlite:file:memInitializerJsonTest2?mode=memory&cache=shared"; try { PeerStarter ps1 = create(connectURI, genesisJson, genesisForks, true); PeerStarter ps2 = create(connectURI, genesisJson, genesisForks, false); assertTrue("Snapsho... | public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } | PeerStarter { public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } } | PeerStarter { public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } PeerStarter(Config config); } | PeerStarter { public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } PeerStarter(Config config); static PeerStarter create(Config config); void initialize(); ExecutionCo... | PeerStarter { public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } PeerStarter(Config config); static PeerStarter create(Config config); void initialize(); ExecutionCo... |
@Test public void testSyncSnapshotEnable() throws Exception { String connectURI = "jdbc:sqlite:file:memInitializerJsonTest3?mode=memory&cache=shared"; try { PeerStarter ps1 = create(connectURI, genesisJson, genesisForks, false); PeerStarter ps2 = create(connectURI, genesisJson, genesisForks, true); assertTrue("Snapshot... | public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } | PeerStarter { public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } } | PeerStarter { public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } PeerStarter(Config config); } | PeerStarter { public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } PeerStarter(Config config); static PeerStarter create(Config config); void initialize(); ExecutionCo... | PeerStarter { public static PeerStarter create(Config config) throws SQLException, IOException, ClassNotFoundException { PeerStarter peerStarter = new PeerStarter(config); peerStarter.initialize(); return peerStarter; } PeerStarter(Config config); static PeerStarter create(Config config); void initialize(); ExecutionCo... |
@Test public void getWellKnownNodes_shouldnt_return_notconnected_peers() throws Exception { when(peer1.getState()).thenReturn(PeerInfo.STATE_AMBIGUOUS); when(peer2.getState()).thenReturn(PeerInfo.STATE_DISCONNECTED); SyncMetadataService sms = new SyncMetadataService(fork, ctx, blockchain, storage); String[] wkn = sms.g... | @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = context.getPeers().getPeerByAddress(address); if (peer != null) { if (... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... |
@Test public void test_reference() { tx.setReference(new TransactionID(132L)); byte[] bytes = formatter.getBytes(mapper.convert(tx)); Assert.assertEquals( "D10:ATTACHMENTDE8:DEADLINEI3600E3:FEEI10E7:NETWORK23:EON-B-22222-22222-2222J9:REFERENCE23:EON-T-66222-22222-2224L6:SENDER21:EON-65222-22222-222LK9:TIMESTAMPI1E4:TYP... | @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeStream.writeDictionary(map); } String str =... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... |
@Test public void test_attachment() { tx.setData(new HashMap<String, Object>() { { put("int", 123); put("str", "data"); } }); byte[] bytes = formatter.getBytes(mapper.convert(tx)); Assert.assertEquals( "D10:ATTACHMENTD3:INTI123E3:STR4:DATAE8:DEADLINEI3600E3:FEEI10E7:NETWORK23:EON-B-22222-22222-2222J6:SENDER21:EON-65222... | @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeStream.writeDictionary(map); } String str =... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... |
@Test public void test_note() { tx.setNote("test"); byte[] bytes = formatter.getBytes(mapper.convert(tx)); Assert.assertEquals( "D10:ATTACHMENTDE8:DEADLINEI3600E3:FEEI10E7:NETWORK23:EON-B-22222-22222-2222J4:NOTE4:TEST6:SENDER21:EON-65222-22222-222LK9:TIMESTAMPI1E4:TYPEI100E7:VERSIONI1EE", new String(bytes)); } | @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeStream.writeDictionary(map); } String str =... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... |
@Test public void test_nested() { Transaction tx2 = new Transaction(); tx2.setVersion(1); tx2.setFee(10); tx2.setTimestamp(1); tx2.setDeadline(3600); tx2.setType(100); tx2.setSenderID(new AccountID(100L)); tx2.setSignature(new byte[64]); tx.setNestedTransactions(new HashMap<String, Transaction>() { { put(tx2.getID().to... | @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeStream.writeDictionary(map); } String str =... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... |
@Test public void test_payer() { tx.setPayer(new AccountID(123L)); byte[] bytes = formatter.getBytes(mapper.convert(tx)); Assert.assertEquals( "D10:ATTACHMENTDE8:DEADLINEI3600E3:FEEI10E7:NETWORK23:EON-B-22222-22222-2222J5:PAYER21:EON-V5222-22222-22JXK6:SENDER21:EON-65222-22222-222LK9:TIMESTAMPI1E4:TYPEI100E7:VERSIONI1E... | @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeStream.writeDictionary(map); } String str =... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... | BencodeFormatter implements IFormatter { @Override public byte[] getBytes(Map<String, Object> map) { Objects.requireNonNull(map); try { try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { try (BencodeOutputStream bencodeStream = new BencodeOutputStream(outStream, Charset.forName("UTF-8"))) { bencodeSt... |
@Test public void transaction_base() throws Exception { Transaction a = Builder.newTransaction(timestamp).attach(null).build(networkID, signer); Transaction b = DTOConverter.convert(DTOConverter.convert(a)); assetEquals(a, b); } | public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID().getValue()); d... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... |
@Test public void transaction_contains_reference() throws Exception { Transaction a = Builder.newTransaction(timestamp).attach(null).refBy(referencedTx).build(networkID, signer); Transaction b = DTOConverter.convert(DTOConverter.convert(a)); assetEquals(a, b); } | public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID().getValue()); d... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... |
@Test public void transaction_contains_nested_transaction() throws Exception { Transaction a = Builder.newTransaction(timestamp) .attach(null) .addNested(Builder.newTransaction(timestamp).build(networkID, signer1)) .addNested(Builder.newTransaction(timestamp).build(networkID, signer2)) .build(networkID, signer); Transa... | public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID().getValue()); d... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... |
@Test public void transaction_contains_confirmations() throws Exception { Transaction a = Builder.newTransaction(timestamp) .attach(null) .build(networkID, signer, new ISigner[] {signer1, signer2}); Transaction b = DTOConverter.convert(DTOConverter.convert(a)); assetEquals(a, b); } | public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID().getValue()); d... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... |
@Test public void transaction_contains_payer() throws Exception { Transaction a = Builder.newTransaction(timestamp) .payedBy(new AccountID(signer2.getPublicKey())) .build(networkID, signer, new ISigner[] {signer1, signer2}); Transaction b = DTOConverter.convert(DTOConverter.convert(a)); assetEquals(a, b); } | public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID().getValue()); d... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... |
@Test public void getWellKnownNodes_shouldnt_return_blacklist_peers() throws Exception { when(peer1.getBlacklistingTime()).thenReturn(60L); when(peer2.getBlacklistingTime()).thenReturn(-60L); SyncMetadataService sms = new SyncMetadataService(fork, ctx, blockchain, storage); String[] wkn = sms.getWellKnownNodes(); asser... | @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = context.getPeers().getPeerByAddress(address); if (peer != null) { if (... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... |
@Test public void transaction_contains_nested_transaction_payed() throws Exception { Transaction a = Builder.newTransaction(timestamp) .attach(null) .addNested(Builder.newTransaction(timestamp) .payedBy(new AccountID(signer2.getPublicKey())) .build(networkID, signer1)) .addNested(Builder.newTransaction(timestamp) .paye... | public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID().getValue()); d... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... |
@Test public void db_transaction_format() throws Exception { Transaction tx1 = Builder.newTransaction(timestamp).build(networkID, signer1); Transaction tx2 = Builder.newTransaction(timestamp).build(networkID, signer2); Transaction tx = Builder.newTransaction(timestamp) .refBy(referencedTx) .attach(attachment) .note("no... | public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID().getValue()); d... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... | DTOConverter { public static DbBlock convert(Block block) { DbBlock dbBlock = new DbBlock(); dbBlock.setId(block.getID().getValue()); dbBlock.setVersion(block.getVersion()); dbBlock.setTimestamp(block.getTimestamp()); dbBlock.setPreviousBlock(block.getPreviousBlock().getValue()); dbBlock.setSenderID(block.getSenderID()... |
@Test public void success() throws Exception { Transaction tx = Builder.newTransaction(timeProvider).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } | VersionValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } } | VersionValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } } | VersionValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } @Override ValidationResult validate(Transaction tx, ILedger ledger... | VersionValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } @Override ValidationResult validate(Transaction tx, ILedger ledger... |
@Test public void unknown_version() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("Version is not supported."); Transaction tx = Builder.newTransaction(timeProvider).version(12345).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } | VersionValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } } | VersionValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } } | VersionValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } @Override ValidationResult validate(Transaction tx, ILedger ledger... | VersionValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getVersion() != 1) { return ValidationResult.error("Version is not supported."); } return ValidationResult.success; } @Override ValidationResult validate(Transaction tx, ILedger ledger... |
@Test public void success() throws Exception { Transaction tx = Builder.newTransaction(timeProvider).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.success; } | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... |
@Test public void fee_zero() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("Invalid fee."); Transaction tx = Builder.newTransaction(timeProvider).forFee(0L).build(networkID, sender); tx.setLength(1); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.success; } | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... |
@Test public void too_small_fee() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("Invalid fee."); Transaction tx = Builder.newTransaction(timeProvider).forFee(10L).build(networkID, sender); tx.setLength(1024 + 1); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.success; } | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... | FeePerByteValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { int length = tx.getLength(); long fee = tx.getFee(); if (fee < length * Constant.TRANSACTION_MIN_FEE_PER_BYTE) { return ValidationResult.error("Invalid fee."); } return ValidationResult.suc... |
@Test public void success() throws Exception { Transaction tx = Builder.newTransaction(timeProvider).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } | FutureTimestampValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } } | FutureTimestampValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } FutureTimestampValidationRule(ITimeProvider timePro... | FutureTimestampValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } FutureTimestampValidationRule(ITimeProvider timePro... | FutureTimestampValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } FutureTimestampValidationRule(ITimeProvider timePro... |
@Test public void future_timestamp() throws Exception { expectedException.expect(LifecycleException.class); Transaction tx = Builder.newTransaction(timeProvider).build(networkID, sender); int timestamp = tx.getTimestamp() - 1; Mockito.when(timeProvider.get()).thenReturn(timestamp); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } | FutureTimestampValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } } | FutureTimestampValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } FutureTimestampValidationRule(ITimeProvider timePro... | FutureTimestampValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } FutureTimestampValidationRule(ITimeProvider timePro... | FutureTimestampValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.isFuture(timeProvider.get())) { return ValidationResult.error(new LifecycleException()); } return ValidationResult.success; } FutureTimestampValidationRule(ITimeProvider timePro... |
@Test public void success() throws Exception { Transaction tx = Builder.newTransaction(timeProvider).type(10).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } | TypeValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } } | TypeValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } TypeValidationRule(Set<Integer> a... | TypeValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } TypeValidationRule(Set<Integer> a... | TypeValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } TypeValidationRule(Set<Integer> a... |
@Test public void getWellKnownNodes_shouldnt_return_noaddress_peers() throws Exception { when(peer1.getAddress()).thenReturn(null); when(peer2.getAddress()).thenReturn(""); SyncMetadataService sms = new SyncMetadataService(fork, ctx, blockchain, storage); String[] wkn = sms.getWellKnownNodes(); assertEquals(0, wkn.leng... | @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = context.getPeers().getPeerByAddress(address); if (peer != null) { if (... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... |
@Test public void unknown_type() throws Exception { int type = 12345; expectedException.expect(ValidateException.class); expectedException.expectMessage("Invalid transaction type. Type :" + type); Transaction tx = Builder.newTransaction(timeProvider).type(type).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } | TypeValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } } | TypeValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } TypeValidationRule(Set<Integer> a... | TypeValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } TypeValidationRule(Set<Integer> a... | TypeValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (allowedTypes.contains(tx.getType())) { return ValidationResult.success; } return ValidationResult.error("Invalid transaction type. Type :" + tx.getType()); } TypeValidationRule(Set<Integer> a... |
@Test public void unset_mfa() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("can not sign transaction."); Transaction tx = Builder.newTransaction(timeProvider).build(networkID, delegate1, new ISigner[] { sender, delegate2 }); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (sender == null) { return ValidationResult.error("Unknown sende... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... |
@Test public void unspecified_delegate() throws Exception { ISigner unknown = new Signer("33445566778899aabbccddeeff00112233445566778899aabbccddeeff001122"); AccountID id = new AccountID(unknown.getPublicKey()); expectedException.expect(ValidateException.class); expectedException.expectMessage("Account '" + id + "' can... | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (sender == null) { return ValidationResult.error("Unknown sende... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... |
@Test public void mfa_allow_payer() throws Exception { ISigner unknown = new Signer("33445566778899aabbccddeeff00112233445566778899aabbccddeeff001122"); AccountID id = new AccountID(unknown.getPublicKey()); Transaction tx = Builder.newTransaction(timeProvider).payedBy(id).build(networkID, sender, new ISigner[] {unknown... | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (sender == null) { return ValidationResult.error("Unknown sende... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... |
@Test public void unset_mfa_allow_payer() throws Exception { AccountID id = new AccountID(sender.getPublicKey()); Transaction tx = Builder.newTransaction(timeProvider).payedBy(id).build(networkID, delegate1, new ISigner[] { sender }); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (sender == null) { return ValidationResult.error("Unknown sende... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... | ConfirmationsSetValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Map<String, Object> confirmations = tx.getConfirmations(); if (confirmations == null) { return ValidationResult.success; } Account sender = ledger.getAccount(tx.getSenderID()); if (se... |
@Test public void payer_success() throws Exception { Transaction tx = Builder.newTransaction(timeProvider) .payedBy(payerAccount) .build(networkID, sender, new ISigner[] {payer}); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null || !tx.getConfirmations().containsKey(tx.getPayer... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... |
@Test public void no_payer_success() throws Exception { Transaction tx = Builder.newTransaction(timeProvider).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null || !tx.getConfirmations().containsKey(tx.getPayer... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... |
@Test public void illegal_payer() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("Invalid payer"); Transaction tx = Builder.newTransaction(timeProvider) .payedBy(new AccountID(sender.getPublicKey())) .build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null || !tx.getConfirmations().containsKey(tx.getPayer... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... |
@Test public void payer_not_confirm() throws Exception { expectedException.expect(ValidateException.class); expectedException.expectMessage("Payer not confirm"); Transaction tx = Builder.newTransaction(timeProvider).payedBy(payerAccount).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null || !tx.getConfirmations().containsKey(tx.getPayer... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... | PayerValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { if (tx.getPayer() == null) { return ValidationResult.success; } if (tx.getSenderID().equals(tx.getPayer())) { return ValidationResult.error("Invalid payer"); } if (tx.getConfirmations() == null ... |
@Test public void success() throws Exception { Transaction tx = Builder.newTransaction(timeProvider).build(networkID, sender); validate(tx); } | @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Account sender = ledger.getAccount(tx.getSenderID()); if (sender == null) { return ValidationResult.error("Unknown sender."); } if (!tx.isVerified()) { if (!accountHelper.verifySignature(tx, tx.getSignature(), sender, timeProvider.get())) { re... | SignatureValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Account sender = ledger.getAccount(tx.getSenderID()); if (sender == null) { return ValidationResult.error("Unknown sender."); } if (!tx.isVerified()) { if (!accountHelper.verifySignature(tx,... | SignatureValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Account sender = ledger.getAccount(tx.getSenderID()); if (sender == null) { return ValidationResult.error("Unknown sender."); } if (!tx.isVerified()) { if (!accountHelper.verifySignature(tx,... | SignatureValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Account sender = ledger.getAccount(tx.getSenderID()); if (sender == null) { return ValidationResult.error("Unknown sender."); } if (!tx.isVerified()) { if (!accountHelper.verifySignature(tx,... | SignatureValidationRule implements IValidationRule { @Override public ValidationResult validate(Transaction tx, ILedger ledger) { Account sender = ledger.getAccount(tx.getSenderID()); if (sender == null) { return ValidationResult.error("Unknown sender."); } if (!tx.isVerified()) { if (!accountHelper.verifySignature(tx,... |
@Test public void getWellKnownNodes_shouldnt_return_inner_peers() throws Exception { when(peer1.isInner()).thenReturn(true); when(peer2.isInner()).thenReturn(true); SyncMetadataService sms = new SyncMetadataService(fork, ctx, blockchain, storage); String[] wkn = sms.getWellKnownNodes(); assertEquals(0, wkn.length); } | @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = context.getPeers().getPeerByAddress(address); if (peer != null) { if (... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... | SyncMetadataService extends BaseService implements IMetadataService { @Override public String[] getWellKnownNodes() throws RemotePeerException, IOException { Collection<String> wellKnownPeers = new ArrayList<>(); String[] addresses = context.getPeers().getPeersList(); for (String address : addresses) { PeerInfo peer = ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.