mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 17:26:28 +01:00
Base58Test: Independent methods for tests that expect an exception.
This commit is contained in:
parent
3ca4bd3792
commit
eabc206b89
1 changed files with 20 additions and 26 deletions
|
@ -19,7 +19,6 @@ package org.bitcoinj.core;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -53,40 +52,35 @@ public class Base58Test {
|
||||||
|
|
||||||
assertTrue("1", Arrays.equals(Base58.decode("1"), new byte[1]));
|
assertTrue("1", Arrays.equals(Base58.decode("1"), new byte[1]));
|
||||||
assertTrue("1111", Arrays.equals(Base58.decode("1111"), new byte[4]));
|
assertTrue("1111", Arrays.equals(Base58.decode("1111"), new byte[4]));
|
||||||
|
|
||||||
try {
|
|
||||||
Base58.decode("This isn't valid base58");
|
|
||||||
fail();
|
|
||||||
} catch (AddressFormatException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
Base58.decodeChecked("4stwEBjT6FYyVV");
|
|
||||||
|
|
||||||
// Checksum should fail.
|
|
||||||
try {
|
|
||||||
Base58.decodeChecked("4stwEBjT6FYyVW");
|
|
||||||
fail();
|
|
||||||
} catch (AddressFormatException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
// Input is too short.
|
|
||||||
try {
|
|
||||||
Base58.decodeChecked("4s");
|
|
||||||
fail();
|
|
||||||
} catch (AddressFormatException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test decode of empty String.
|
// Test decode of empty String.
|
||||||
assertEquals(0, Base58.decode("").length);
|
assertEquals(0, Base58.decode("").length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = AddressFormatException.class)
|
||||||
|
public void testDecode_invalidBase58() {
|
||||||
|
Base58.decode("This isn't valid base58");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecodeChecked() {
|
||||||
|
Base58.decodeChecked("4stwEBjT6FYyVV");
|
||||||
|
|
||||||
// Now check we can correctly decode the case where the high bit of the first byte is not zero, so BigInteger
|
// Now check we can correctly decode the case where the high bit of the first byte is not zero, so BigInteger
|
||||||
// sign extends. Fix for a bug that stopped us parsing keys exported using sipas patch.
|
// sign extends. Fix for a bug that stopped us parsing keys exported using sipas patch.
|
||||||
Base58.decodeChecked("93VYUMzRG9DdbRP72uQXjaWibbQwygnvaCu9DumcqDjGybD864T");
|
Base58.decodeChecked("93VYUMzRG9DdbRP72uQXjaWibbQwygnvaCu9DumcqDjGybD864T");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = AddressFormatException.class)
|
||||||
|
public void testDecodeChecked_badChecksum() {
|
||||||
|
Base58.decodeChecked("4stwEBjT6FYyVW");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = AddressFormatException.class)
|
||||||
|
public void testDecodeChecked_shortInput() {
|
||||||
|
Base58.decodeChecked("4s");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecodeToBigInteger() {
|
public void testDecodeToBigInteger() {
|
||||||
byte[] input = Base58.decode("129");
|
byte[] input = Base58.decode("129");
|
||||||
|
|
Loading…
Add table
Reference in a new issue