2626import org .junit .rules .TemporaryFolder ;
2727import org .tron .common .utils .LocalWitnesses ;
2828import org .tron .common .utils .PublicMethod ;
29+ import org .tron .common .utils .StringUtil ;
2930import org .tron .core .Constant ;
3031
3132public class LocalWitnessTest {
@@ -108,7 +109,7 @@ public void testInvalidPrivateKey() {
108109 localWitnesses .addPrivateKeys (null );
109110 fail ("should throw IllegalArgumentException" );
110111 } catch (IllegalArgumentException e ) {
111- Assert .assertTrue (e .getMessage ().contains ("private key must be" ));
112+ Assert .assertTrue (e .getMessage ().contains ("private key must be 64 hex string " ));
112113 } catch (Exception e ) {
113114 fail ("should IllegalArgumentException,actual exception: " + e .getClass ().getSimpleName ());
114115 }
@@ -117,7 +118,7 @@ public void testInvalidPrivateKey() {
117118 localWitnesses .addPrivateKeys ("" );
118119 fail ("should throw IllegalArgumentException" );
119120 } catch (IllegalArgumentException e ) {
120- Assert .assertTrue (e .getMessage ().contains ("private key must be" ));
121+ Assert .assertTrue (e .getMessage ().contains ("private key must be 64 hex string " ));
121122 } catch (Exception e ) {
122123 fail ("should IllegalArgumentException,actual exception: " + e .getClass ().getSimpleName ());
123124 }
@@ -126,7 +127,16 @@ public void testInvalidPrivateKey() {
126127 localWitnesses .addPrivateKeys (" " );
127128 fail ("should throw IllegalArgumentException" );
128129 } catch (IllegalArgumentException e ) {
129- Assert .assertTrue (e .getMessage ().contains ("private key must be" ));
130+ Assert .assertTrue (e .getMessage ().contains ("private key must be 64 hex string" ));
131+ } catch (Exception e ) {
132+ fail ("should IllegalArgumentException,actual exception: " + e .getClass ().getSimpleName ());
133+ }
134+
135+ try {
136+ localWitnesses .addPrivateKeys ("11111" );
137+ fail ("should throw IllegalArgumentException" );
138+ } catch (IllegalArgumentException e ) {
139+ Assert .assertTrue (e .getMessage ().contains ("private key must be 64 hex string" ));
130140 } catch (Exception e ) {
131141 fail ("should IllegalArgumentException,actual exception: " + e .getClass ().getSimpleName ());
132142 }
@@ -152,6 +162,16 @@ public void testInvalidPrivateKey() {
152162 }
153163 }
154164
165+ @ Test
166+ public void testHexStringFormat () {
167+ Assert .assertTrue (StringUtil .isHexadecimal ("0123456789abcdefABCDEF" ));
168+ Assert .assertFalse (StringUtil .isHexadecimal (null ));
169+ Assert .assertFalse (StringUtil .isHexadecimal ("" ));
170+ Assert .assertFalse (StringUtil .isHexadecimal ("abc" ));
171+ Assert .assertFalse (StringUtil .isHexadecimal (" " ));
172+ Assert .assertFalse (StringUtil .isHexadecimal ("123xyz" ));
173+ }
174+
155175 @ Test
156176 public void getPrivateKey () {
157177 Assert .assertEquals (Lists
0 commit comments