[FIX] Fixed a problem with a flaky test, related to upper/lower case encoded keys.
@@ -131,8 +131,10 @@ public class NKeyTests {
assertFalse(true);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test
public void testBadCRC() throws Exception {
+ for (int i=0;i<1000;i++) {
+ try {
byte[] bytes = new byte[32];
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
random.nextBytes(bytes);
@@ -141,17 +143,21 @@ public class NKeyTests {
StringBuilder builder = new StringBuilder();
- builder.append(encoded.substring(0, 3));
+ builder.append(encoded.substring(0, 6));
- if (encoded.charAt(3) == 'x') {
- builder.append('z');
+ if (encoded.charAt(6) == 'x' || encoded.charAt(6) == 'X') {
+ builder.append('Z');
} else {
- builder.append('x');
+ builder.append('X');
}
- builder.append(encoded.substring(4));
+ builder.append(encoded.substring(7));
NKey.decode(NKey.Type.ACCOUNT, builder.toString());
assertFalse(true);
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+ }
}
@Test
