|
| 1 | +package org.tron.program; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertFalse; |
| 4 | +import static org.junit.Assert.assertNotNull; |
| 5 | +import static org.junit.Assert.assertTrue; |
| 6 | + |
| 7 | +import java.io.File; |
| 8 | +import java.math.BigInteger; |
| 9 | +import javax.annotation.Resource; |
| 10 | +import org.junit.BeforeClass; |
| 11 | +import org.junit.Rule; |
| 12 | +import org.junit.Test; |
| 13 | +import org.junit.rules.ExpectedException; |
| 14 | +import org.junit.runner.RunWith; |
| 15 | +import org.springframework.test.annotation.DirtiesContext; |
| 16 | +import org.springframework.test.context.ContextConfiguration; |
| 17 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 18 | +import org.tron.common.config.DbBackupConfig; |
| 19 | +import org.tron.common.entity.PeerInfo; |
| 20 | +import org.tron.common.utils.CompactEncoder; |
| 21 | +import org.tron.common.utils.JsonUtil; |
| 22 | +import org.tron.common.utils.Value; |
| 23 | +import org.tron.core.Constant; |
| 24 | +import org.tron.core.capsule.StorageRowCapsule; |
| 25 | +import org.tron.core.capsule.utils.RLP; |
| 26 | +import org.tron.core.config.DefaultConfig; |
| 27 | +import org.tron.core.config.args.Args; |
| 28 | +import org.tron.core.services.http.HttpSelfFormatFieldName; |
| 29 | +import org.tron.core.store.StorageRowStore; |
| 30 | +import org.tron.keystore.WalletUtils; |
| 31 | + |
| 32 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 33 | +@DirtiesContext |
| 34 | +@ContextConfiguration(classes = {DefaultConfig.class}) |
| 35 | +public class SupplementTest { |
| 36 | + |
| 37 | + private static final String dbPath = "output_coverage_test"; |
| 38 | + |
| 39 | + @Resource |
| 40 | + private StorageRowStore storageRowStore; |
| 41 | + |
| 42 | + @Rule |
| 43 | + public ExpectedException thrown = ExpectedException.none(); |
| 44 | + |
| 45 | + @BeforeClass |
| 46 | + public static void init() { |
| 47 | + Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testGet() throws Exception { |
| 52 | + StorageRowCapsule storageRowCapsule = storageRowStore.get(new byte[]{}); |
| 53 | + assertNotNull(storageRowCapsule); |
| 54 | + |
| 55 | + DbBackupConfig dbBackupConfig = new DbBackupConfig(); |
| 56 | + dbBackupConfig.initArgs(true, "propPath", "bak1path/", "bak2path/", 1); |
| 57 | + |
| 58 | + WalletUtils.generateFullNewWalletFile("123456", new File(dbPath)); |
| 59 | + WalletUtils.generateLightNewWalletFile("123456", new File(dbPath)); |
| 60 | + WalletUtils.getDefaultKeyDirectory(); |
| 61 | + WalletUtils.getTestnetKeyDirectory(); |
| 62 | + WalletUtils.getMainnetKeyDirectory(); |
| 63 | + |
| 64 | + Value value = new Value(new byte[]{1}); |
| 65 | + value.asBytes(); |
| 66 | + value = new Value(1); |
| 67 | + value.asInt(); |
| 68 | + value = new Value(100L); |
| 69 | + value.asLong(); |
| 70 | + value = new Value(new BigInteger("1000")); |
| 71 | + value.asBigInt(); |
| 72 | + value = new Value("1000"); |
| 73 | + value.asString(); |
| 74 | + value.isEmpty(); |
| 75 | + value = new Value(new byte[]{1, 2, 3}); |
| 76 | + value.isList(); |
| 77 | + value.isReadableString(); |
| 78 | + value.isHexString(); |
| 79 | + value.isHashCode(); |
| 80 | + value.isNull(); |
| 81 | + value.length(); |
| 82 | + assertNotNull(value.toString()); |
| 83 | + value.countBranchNodes(); |
| 84 | + |
| 85 | + PeerInfo peerInfo = new PeerInfo(); |
| 86 | + peerInfo.setAvgLatency(peerInfo.getAvgLatency()); |
| 87 | + peerInfo.setBlockInPorcSize(peerInfo.getBlockInPorcSize()); |
| 88 | + peerInfo.setConnectTime(peerInfo.getConnectTime()); |
| 89 | + peerInfo.setDisconnectTimes(peerInfo.getDisconnectTimes()); |
| 90 | + peerInfo.setHeadBlockTimeWeBothHave(peerInfo.getHeadBlockTimeWeBothHave()); |
| 91 | + peerInfo.setHeadBlockWeBothHave(peerInfo.getHeadBlockWeBothHave()); |
| 92 | + peerInfo.setHost(peerInfo.getHost()); |
| 93 | + peerInfo.setInFlow(peerInfo.getInFlow()); |
| 94 | + peerInfo.setLastBlockUpdateTime(peerInfo.getLastBlockUpdateTime()); |
| 95 | + peerInfo.setLastSyncBlock(peerInfo.getLastSyncBlock()); |
| 96 | + peerInfo.setLocalDisconnectReason(peerInfo.getLocalDisconnectReason()); |
| 97 | + peerInfo.setNodeCount(peerInfo.getNodeCount()); |
| 98 | + peerInfo.setNodeId(peerInfo.getNodeId()); |
| 99 | + peerInfo.setRemainNum(peerInfo.getRemainNum()); |
| 100 | + peerInfo.setRemoteDisconnectReason(peerInfo.getRemoteDisconnectReason()); |
| 101 | + peerInfo.setScore(peerInfo.getScore()); |
| 102 | + peerInfo.setPort(peerInfo.getPort()); |
| 103 | + peerInfo.setSyncFlag(peerInfo.isSyncFlag()); |
| 104 | + peerInfo.setNeedSyncFromPeer(peerInfo.isNeedSyncFromPeer()); |
| 105 | + peerInfo.setNeedSyncFromUs(peerInfo.isNeedSyncFromUs()); |
| 106 | + peerInfo.setSyncToFetchSize(peerInfo.getSyncToFetchSize()); |
| 107 | + peerInfo.setSyncToFetchSizePeekNum(peerInfo.getSyncToFetchSizePeekNum()); |
| 108 | + peerInfo.setSyncBlockRequestedSize(peerInfo.getSyncBlockRequestedSize()); |
| 109 | + peerInfo.setUnFetchSynNum(peerInfo.getUnFetchSynNum()); |
| 110 | + peerInfo.setActive(peerInfo.isActive()); |
| 111 | + |
| 112 | + assertNotNull(JsonUtil.json2Obj("{}", PeerInfo.class)); |
| 113 | + assertNotNull(JsonUtil.obj2Json(peerInfo)); |
| 114 | + |
| 115 | + assertTrue(HttpSelfFormatFieldName.isAddressFormat( |
| 116 | + "protocol.DelegatedResourceMessage.fromAddress")); |
| 117 | + assertTrue(HttpSelfFormatFieldName.isNameStringFormat( |
| 118 | + "protocol.MarketPriceList.buy_token_id")); |
| 119 | + |
| 120 | + CompactEncoder.packNibbles(new byte[] {1,2,3,4,5,6,7}); |
| 121 | + assertFalse(CompactEncoder.hasTerminator(new byte[] {1,2,3,4,5,6,7})); |
| 122 | + CompactEncoder.unpackToNibbles(new byte[] {1,2,3,4,5,6,7}); |
| 123 | + CompactEncoder.binToNibblesNoTerminator(new byte[] {1,2,3,4,5,6,7}); |
| 124 | + |
| 125 | + assertNotNull(RLP.decodeIP4Bytes(new byte[] {1,2,3,4,5,6,7}, 0)); |
| 126 | + RLP.decodeByteArray(new byte[] {1,2,3,4,5,6,7}, 0); |
| 127 | + RLP.nextItemLength(new byte[] {1,2,3,4,5,6,7}, 0); |
| 128 | + RLP.decodeStringItem(new byte[] {1,2,3,4,5,6,7}, 0); |
| 129 | + RLP.decodeInt(new byte[] {1,2,3,4,5,6,7}, 0); |
| 130 | + RLP.decode2OneItem(new byte[] {1,2,3,4,5,6,7}, 0); |
| 131 | + RLP.decode2(new byte[] {1,2,3,4,5,6,7}, 1); |
| 132 | + RLP.decode2(new byte[] {1,2,3,4,5,6,7}); |
| 133 | + thrown.expect(ClassCastException.class); |
| 134 | + RLP.unwrapList(new byte[] {1,2,3,4,5,6,7}); |
| 135 | + } |
| 136 | + |
| 137 | +} |
0 commit comments