去掉依赖
This commit is contained in:
1 parent
79183ee0d9
commit
7cb16bc84d
12 files changed
+183
-75
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package com.ruoyi.system.chain;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.SecureRandom;
|
||||
import org.junit.Test;
|
||||
import org.tron.trident.utils.Base58Check;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/** 固定公开测试密钥验证地址格式,所有测试均离线执行。 */
|
||||
public class TronKeyTest {
|
||||
@Test
|
||||
public void privateKeyOneKeepsKnownAddressAndLeadingZeros() {
|
||||
TronKey key = TronKey.fromPrivate(BigInteger.ONE);
|
||||
byte[] bytes = key.getPrivKeyBytes();
|
||||
assertEquals(32, bytes.length);
|
||||
assertEquals(1, bytes[31]);
|
||||
for (int i = 0; i < 31; i++) {
|
||||
assertEquals(0, bytes[i]);
|
||||
}
|
||||
assertEquals("TMVQGm1qAQYVdetCeGRRkTWYYrLXuHK2HC",
|
||||
Base58Check.bytesToBase58(key.getAddress()));
|
||||
assertEquals(21, key.getAddress().length);
|
||||
assertEquals(0x41, key.getAddress()[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatedKeyCanBeRestored() {
|
||||
TronKey key = new TronKey(new SecureRandom());
|
||||
assertArrayEquals(key.getAddress(),
|
||||
TronKey.fromPrivate(new BigInteger(1, key.getPrivKeyBytes())).getAddress());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void zeroPrivateKeyIsRejected() {
|
||||
TronKey.fromPrivate(BigInteger.ZERO);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void truncatedSignatureIsRejected() {
|
||||
TronKey.signatureToAddress(new byte[32], "AA==");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user