Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ test {
exclude 'org/tron/common/runtime/vm/WithdrawRewardTest.class'
}
maxHeapSize = "1024m"
doFirst {
forkEvery = 100
jvmArgs "-XX:MetaspaceSize=128m","-XX:MaxMetaspaceSize=256m", "-XX:+UseG1GC"
}
}

task stest(type: Test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ public static boolean hasIpv4Stack(Set<String> ipSet) {
}

private P2pConfig getConfig() {
P2pConfig config = new P2pConfig();
return updateConfig(config);
}

private P2pConfig updateConfig(P2pConfig config) {
List<InetSocketAddress> seeds = parameter.getSeedNode().getAddressList();
seeds.addAll(nodePersistService.dbRead());
logger.debug("Seed InetSocketAddress: {}", seeds);
P2pConfig config = new P2pConfig();
config.getSeedNodes().addAll(seeds);
config.getActiveNodes().addAll(parameter.getActiveNodes());
config.getTrustNodes().addAll(parameter.getPassiveNodes());
Expand Down
13 changes: 13 additions & 0 deletions framework/src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ node {
solidityPort = 8091
}

# use your ipv6 address for node discovery and tcp connection, default false
enableIpv6 = false

# if your node's highest block num is below than all your pees', try to acquire new connection. default false
effectiveCheckEnable = false

dns {
# dns urls to get nodes, url format tree://{pubkey}@{domain}, default empty
treeUrls = [
#"tree://APFGGTFOBVE2ZNAB3CSMNNX6RRK3ODIRLP2AA5U4YFAA6MSYZUYTQ@nodes1.example.org",
]
}

rpc {
port = 50051
#solidityPort = 50061
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@

public class ArgsTest {

private static final String dbPath = "output_arg_test";

@Before
public void init() {
Args.setParam(new String[]{"--output-directory", "output-directory", "--p2p-disable", "true",
Args.setParam(new String[]{"--output-directory", dbPath, "--p2p-disable", "true",
"--debug"}, Constant.TEST_CONF);
}

@After
public void destroy() {
Args.clearParam();
FileUtil.deleteDir(new File("output-directory"));
FileUtil.deleteDir(new File(dbPath));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.tron.common.crypto.Hash;
import org.tron.common.runtime.TvmTestUtils;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.WalletUtil;
import org.tron.core.Wallet;
import org.tron.core.vm.LogInfoTriggerParser;
import org.tron.protos.contract.SmartContractOuterClass.SmartContract.ABI;
Expand Down Expand Up @@ -57,6 +58,8 @@ public synchronized void testEventParser() {
+ "000000000";
ABI abi = TvmTestUtils.jsonStr2Abi(abiStr);

Assert.assertFalse(WalletUtil.isConstant(abi, new byte[3]));

byte[] data = ByteArray.fromHexString(dataStr);
List<byte[]> topicList = new LinkedList<>();
topicList.add(Hash.sha3(eventSign.getBytes()));
Expand Down
6 changes: 6 additions & 0 deletions framework/src/test/java/org/tron/core/WalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,12 @@ public void testGetDelegatedResourceV2() {

Protocol.Account account = Protocol.Account.newBuilder()
.setAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))).build();

AccountCapsule accountCapsule = dbManager.getAccountStore()
.get(ByteArray.fromHexString(OWNER_ADDRESS));
accountCapsule.addAssetV2("testv2".getBytes(), 1L);
dbManager.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);

wallet.getAccount(account);
wallet.getProposalList();
wallet.getWitnessList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ public void validateCheck() {
Assert.assertEquals("Bad chain parameter value, valid range is [0, 1_000_000_000_000L]",
e.getMessage());
}

forkUtils.getManager().getDynamicPropertiesStore()
.statsByVersion(ForkBlockVersionEnum.ENERGY_LIMIT.getValue(), stats);
forkUtils.reset();
}

@Test
Expand Down
28 changes: 28 additions & 0 deletions framework/src/test/java/org/tron/core/db/ManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ public void pushBlock() {
}
}

try {
chainManager.getBlockIdByNum(-1);
Assert.fail();
} catch (ItemNotFoundException e) {
Assert.assertTrue(true);
}

Assert.assertTrue("hasBlocks is error", chainManager.hasBlocks());
}

Expand Down Expand Up @@ -933,4 +940,25 @@ private BlockCapsule createTestBlockCapsuleError(long time,
blockCapsule.sign(ByteArray.fromHexString(addressToProvateKeys.get(witnessAddress)));
return blockCapsule;
}

@Test
public void testExpireTransaction() {
TransferContract tc =
TransferContract.newBuilder()
.setAmount(10)
.setOwnerAddress(ByteString.copyFromUtf8("aaa"))
.setToAddress(ByteString.copyFromUtf8("bbb"))
.build();
TransactionCapsule trx = new TransactionCapsule(tc, ContractType.TransferContract);
long latestBlockTime = dbManager.getDynamicPropertiesStore().getLatestBlockHeaderTimestamp();
trx.setExpiration(latestBlockTime - 100);
try {
dbManager.validateCommon(trx);
Assert.fail();
} catch (TransactionExpirationException e) {
Assert.assertTrue(true);
} catch (TooBigTransactionException e) {
Assert.fail();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.tron.core.db;

import com.google.protobuf.ByteString;
import java.io.File;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.tron.api.GrpcAPI;
import org.tron.api.GrpcAPI.Return.response_code;
import org.tron.common.application.TronApplicationContext;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.FileUtil;
import org.tron.common.utils.Sha256Hash;
import org.tron.core.Constant;
import org.tron.core.Wallet;
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.config.DefaultConfig;
import org.tron.core.config.args.Args;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.contract.BalanceContract.TransferContract;

@Slf4j
public class TransactionExpireTest {

private String dbPath = "output_expire_test";
private TronApplicationContext context;
private Wallet wallet;
private Manager dbManager;
private BlockCapsule blockCapsule;

@Before
public void init() {
Args.setParam(new String[] {"--output-directory", dbPath}, Constant.TEST_CONF);
CommonParameter.PARAMETER.setMinEffectiveConnection(0);

context = new TronApplicationContext(DefaultConfig.class);
wallet = context.getBean(Wallet.class);
dbManager = context.getBean(Manager.class);

blockCapsule = new BlockCapsule(
1,
Sha256Hash.wrap(ByteString.copyFrom(
ByteArray.fromHexString(
"0304f784e4e7bae517bcab94c3e0c9214fb4ac7ff9d7d5a937d1f40031f87b81"))),
1,
ByteString.copyFromUtf8("testAddress"));
dbManager.getDynamicPropertiesStore().saveLatestBlockHeaderNumber(blockCapsule.getNum());
dbManager.getDynamicPropertiesStore()
.saveLatestBlockHeaderTimestamp(blockCapsule.getTimeStamp());
dbManager.updateRecentBlock(blockCapsule);
}

@After
public void removeDb() {
Args.clearParam();
context.destroy();
if (FileUtil.deleteDir(new File(dbPath))) {
logger.info("Release resources successful.");
} else {
logger.info("Release resources failure.");
}
}

@Test
public void testExpireTransaction() {
TransferContract transferContract = TransferContract.newBuilder()
.setAmount(1L)
.setOwnerAddress(ByteString.copyFrom(Args.getLocalWitnesses()
.getWitnessAccountAddress(CommonParameter.getInstance().isECKeyCryptoEngine())))
.setToAddress(ByteString.copyFrom(ByteArray.fromHexString(
(Wallet.getAddressPreFixString() + "A389132D6639FBDA4FBC8B659264E6B7C90DB086"))))
.build();
TransactionCapsule transactionCapsule =
new TransactionCapsule(transferContract, ContractType.TransferContract);
transactionCapsule.setReference(blockCapsule.getNum(), blockCapsule.getBlockId().getBytes());
Assert.assertEquals(1, blockCapsule.getTimeStamp());

long blockTimeStamp = blockCapsule.getTimeStamp();
transactionCapsule.setExpiration(blockTimeStamp - 1);
transactionCapsule.sign(ByteArray.fromHexString(Args.getLocalWitnesses().getPrivateKey()));

GrpcAPI.Return result = wallet.broadcastTransaction(transactionCapsule.getInstance());
Assert.assertEquals(response_code.TRANSACTION_EXPIRATION_ERROR, result.getCode());
}
}
84 changes: 43 additions & 41 deletions framework/src/test/java/org/tron/core/net/BaseNet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Before;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.tron.common.application.Application;
import org.tron.common.application.ApplicationFactory;
import org.tron.common.application.TronApplicationContext;
Expand All @@ -34,20 +34,20 @@
import org.tron.core.services.RpcApiService;

@Slf4j
public abstract class BaseNet {
public class BaseNet {

private static String dbPath = "output-net";
private static String dbDirectory = "net-database";
private static String indexDirectory = "net-index";
private static int port = 10000;

protected TronApplicationContext context;
protected static TronApplicationContext context;

private RpcApiService rpcApiService;
private Application appT;
private TronNetDelegate tronNetDelegate;
private static RpcApiService rpcApiService;
private static Application appT;
private static TronNetDelegate tronNetDelegate;

private ExecutorService executorService = Executors.newFixedThreadPool(1);
private static ExecutorService executorService = Executors.newFixedThreadPool(1);

public static Channel connect(ByteToMessageDecoder decoder) throws InterruptedException {
NioEventLoopGroup group = new NioEventLoopGroup(1);
Expand All @@ -73,49 +73,51 @@ protected void initChannel(Channel ch) throws Exception {
return b.connect(Constant.LOCAL_HOST, port).sync().channel();
}

@Before
public void init() throws Exception {
executorService.execute(new Runnable() {
@Override
public void run() {
logger.info("Full node running.");
Args.setParam(
new String[]{
"--output-directory", dbPath,
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory
},
"config.conf"
);
CommonParameter parameter = Args.getInstance();
parameter.setNodeListenPort(port);
parameter.getSeedNode().getAddressList().clear();
parameter.setNodeExternalIp(Constant.LOCAL_HOST);
context = new TronApplicationContext(DefaultConfig.class);
appT = ApplicationFactory.create(context);
rpcApiService = context.getBean(RpcApiService.class);
appT.addService(rpcApiService);
appT.initServices(parameter);
appT.startServices();
appT.startup();
tronNetDelegate = context.getBean(TronNetDelegate.class);
rpcApiService.blockUntilShutdown();
@BeforeClass
public static void init() throws Exception {
executorService.execute(() -> {
logger.info("Full node running.");
Args.setParam(
new String[]{
"--output-directory", dbPath,
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory
},
"config.conf"
);
CommonParameter parameter = Args.getInstance();
parameter.setNodeListenPort(port);
parameter.getSeedNode().getAddressList().clear();
parameter.setNodeExternalIp(Constant.LOCAL_HOST);
context = new TronApplicationContext(DefaultConfig.class);
appT = ApplicationFactory.create(context);
rpcApiService = context.getBean(RpcApiService.class);
appT.addService(rpcApiService);
appT.initServices(parameter);
appT.startServices();
appT.startup();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
//ignore
}
tronNetDelegate = context.getBean(TronNetDelegate.class);
rpcApiService.blockUntilShutdown();
});
int tryTimes = 0;
while (++tryTimes < 100 && tronNetDelegate == null) {
Thread.sleep(3000);
}
do {
Thread.sleep(3000); //coverage consumerInvToSpread,consumerInvToFetch in AdvService.init
} while (++tryTimes < 100 && tronNetDelegate == null);
}

@After
public void destroy() {
@AfterClass
public static void destroy() {
Collection<PeerConnection> peerConnections = ReflectUtils
.invokeMethod(tronNetDelegate, "getActivePeer");
for (PeerConnection peer : peerConnections) {
peer.getChannel().close();
}

Args.clearParam();
context.destroy();
FileUtil.deleteDir(new File(dbPath));
}
Expand Down
5 changes: 5 additions & 0 deletions framework/src/test/java/org/tron/core/net/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public Class<?> getAnswerMessage() {
messageStatistics.addTcpOutMessage(message4);
messageStatistics.addTcpInMessage(message5);
messageStatistics.addTcpOutMessage(message5);
try {
Thread.sleep(2000);// so that gap > 1 in MessageCount.update method
} catch (InterruptedException e) {
//ignore
}
messageStatistics.addTcpInMessage(message6);
messageStatistics.addTcpOutMessage(message6);
messageStatistics.addTcpInMessage(message7);
Expand Down
Loading