|
22 | 22 |
|
23 | 23 | import com.google.common.collect.Lists; |
24 | 24 | import java.io.IOException; |
| 25 | +import java.security.SecureRandom; |
25 | 26 | import org.junit.Assert; |
26 | 27 | import org.junit.Before; |
27 | 28 | import org.junit.Rule; |
28 | 29 | import org.junit.Test; |
29 | 30 | import org.junit.rules.TemporaryFolder; |
| 31 | +import org.tron.common.utils.ByteArray; |
30 | 32 | import org.tron.common.utils.LocalWitnesses; |
31 | 33 | import org.tron.common.utils.PublicMethod; |
32 | 34 | import org.tron.common.utils.StringUtil; |
@@ -115,9 +117,12 @@ public void testInvalidPrivateKey() { |
115 | 117 | assertTronError(localWitnesses, " ", expectedMessage); |
116 | 118 | assertTronError(localWitnesses, "11111", expectedMessage); |
117 | 119 | String expectedMessage2 = "private key must be hex string"; |
118 | | - final String privateKey = "11111111111111111111111111111111111111111111111111111111111111 "; |
| 120 | + SecureRandom secureRandom = new SecureRandom(); |
| 121 | + byte[] keyBytes = new byte[31]; |
| 122 | + secureRandom.nextBytes(keyBytes); |
| 123 | + final String privateKey = ByteArray.toHexString(keyBytes) + " "; |
119 | 124 | assertTronError(localWitnesses, privateKey, expectedMessage2); |
120 | | - final String privateKey2 = "xy11111111111111111111111111111111111111111111111111111111111111"; |
| 125 | + final String privateKey2 = "xy" + ByteArray.toHexString(keyBytes); |
121 | 126 | assertTronError(localWitnesses, privateKey2, expectedMessage2); |
122 | 127 | } |
123 | 128 |
|
|
0 commit comments