Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 1 addition & 5 deletions framework/src/test/java/org/tron/common/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
public class TestConstants {

public static final String TEST_CONF = "config-test.conf";
public static final String NET_CONF = "config.conf";
public static final String MAINNET_CONF = "config-test-mainnet.conf";
public static final String LOCAL_CONF = "config-localtest.conf";
public static final String STORAGE_CONF = "config-test-storagetest.conf";
public static final String INDEX_CONF = "config-test-index.conf";
public static final String SHIELD_CONF = "config-shield.conf";

/**
* Skips the current test on ARM64 where LevelDB JNI is unavailable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Before;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.runtime.RuntimeImpl;
import org.tron.common.runtime.TvmTestUtils;
import org.tron.common.utils.Commons;
Expand Down Expand Up @@ -75,7 +76,7 @@ public class BandWidthRuntimeOutOfTimeTest extends BaseTest {
"--storage-index-directory", indexDirectory,
"--debug"
},
"config-test-mainnet.conf"
TestConstants.TEST_CONF
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Before;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.runtime.RuntimeImpl;
import org.tron.common.runtime.TvmTestUtils;
import org.tron.common.utils.Commons;
Expand Down Expand Up @@ -76,7 +77,7 @@ public class BandWidthRuntimeOutOfTimeWithCheckTest extends BaseTest {
"--storage-index-directory", indexDirectory,
"--debug"
},
"config-test-mainnet.conf"
TestConstants.TEST_CONF
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.runtime.RuntimeImpl;
import org.tron.common.runtime.TvmTestUtils;
Expand Down Expand Up @@ -70,8 +71,9 @@ public static void init() {
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
"--debug",
},
"config-test-mainnet.conf"
TestConstants.TEST_CONF
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Before;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.runtime.RuntimeImpl;
import org.tron.common.runtime.TvmTestUtils;
import org.tron.common.utils.Commons;
Expand Down Expand Up @@ -77,7 +78,7 @@ public class BandWidthRuntimeWithCheckTest extends BaseTest {
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
},
"config-test-mainnet.conf"
TestConstants.TEST_CONF
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.Test;
import org.tron.api.GrpcAPI.ShieldedTRC20Parameters;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.ByteUtil;
import org.tron.common.utils.FileUtil;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class PrecompiledContractsVerifyProofTest extends BaseTest {

@BeforeClass
public static void init() {
Args.setParam(new String[]{"--output-directory", dbPath()}, "config-test.conf");
Args.setParam(new String[]{"--output-directory", dbPath()}, TestConstants.TEST_CONF);
DEFAULT_OVK = ByteArray
.fromHexString("030c8c2bc59fb3eb8afb047a8ea4b028743d23e7d38c6fa30908358431e2314d");
SHIELDED_CONTRACT_ADDRESS = WalletClient.decodeFromBase58Check(SHIELDED_CONTRACT_ADDRESS_STR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.tron.api.GrpcAPI.ShieldedTRC20TriggerContractParameters;
import org.tron.api.GrpcAPI.SpendAuthSigParameters;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.ByteUtil;
import org.tron.common.utils.PublicMethod;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class ShieldedTRC20BuilderTest extends BaseTest {
private static final byte[] PUBLIC_TO_ADDRESS;

static {
Args.setParam(new String[]{"--output-directory", dbPath()}, "config-test-mainnet.conf");
Args.setParam(new String[]{"--output-directory", dbPath()}, TestConstants.TEST_CONF);
SHIELDED_CONTRACT_ADDRESS = WalletClient.decodeFromBase58Check(SHIELDED_CONTRACT_ADDRESS_STR);
DEFAULT_OVK = ByteArray
.fromHexString("030c8c2bc59fb3eb8afb047a8ea4b028743d23e7d38c6fa30908358431e2314d");
Expand Down
11 changes: 2 additions & 9 deletions framework/src/test/java/org/tron/core/config/args/ArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public class ArgsTest {

@Test
public void get() {
Args.setParam(new String[] {"-c", TestConstants.TEST_CONF, "--keystore-factory"},
TestConstants.NET_CONF);
Args.setParam(new String[] {"-c", TestConstants.TEST_CONF, "--keystore-factory"}, "");
Comment thread
317787106 marked this conversation as resolved.
Outdated

CommonParameter parameter = Args.getInstance();

Expand All @@ -73,7 +72,7 @@ public void get() {

Assert.assertEquals("database", parameter.getStorage().getDbDirectory());

Assert.assertEquals(11, parameter.getSeedNode().getAddressList().size());
Assert.assertEquals(0, parameter.getSeedNode().getAddressList().size());

GenesisBlock genesisBlock = parameter.getGenesisBlock();

Expand Down Expand Up @@ -147,12 +146,6 @@ public void testIpFromLibP2p()
Assert.assertNotEquals(configuredExternalIp, parameter.getNodeExternalIp());
}

@Test
public void testOldRewardOpt() {
thrown.expect(IllegalArgumentException.class);
Args.setParam(new String[] {"-c", "args-test.conf"}, TestConstants.NET_CONF);
}

@Test
public void testInitService() {
Map<String,String> storage = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ public void testConstructor() {
public void testLocalWitnessConfig() throws IOException {
Args.setParam(
new String[]{"--output-directory", temporaryFolder.newFolder().toString(), "-w", "--debug"},
"config-localtest.conf");
TestConstants.SHIELD_CONF);
LocalWitnesses witness = Args.getLocalWitnesses();
Assert.assertNotNull(witness.getPrivateKey());
Assert.assertNotNull(witness.getWitnessAccountAddress());
Args.clearParam();
}

@Test
Expand All @@ -191,5 +192,6 @@ public void testNullLocalWitnessConfig() throws IOException {
LocalWitnesses witness = Args.getLocalWitnesses();
Assert.assertNull(witness.getPrivateKey());
Assert.assertNull(witness.getWitnessAccountAddress());
Args.clearParam();
}
}
107 changes: 105 additions & 2 deletions framework/src/test/java/org/tron/core/config/args/StorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,124 @@
package org.tron.core.config.args;

import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;
import org.iq80.leveldb.CompressionType;
import org.iq80.leveldb.Options;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.tron.common.TestConstants;
import org.tron.common.utils.FileUtil;
import org.tron.common.utils.StorageUtils;

public class StorageTest {

private static Storage storage;
private static final Storage storage;

static {
Args.setParam(new String[]{}, "config-test-storagetest.conf");
Args.setParam(new String[]{}, TestConstants.TEST_CONF);
storage = Args.getInstance().getStorage();
setupStorage();
}

/**
* set it as following:
*
* properties = [
* {
* name = "account",
* path = "storage_directory_test",
* createIfMissing = true,
* paranoidChecks = true,
* verifyChecksums = true,
* compressionType = 1, // compressed with snappy
* blockSize = 4096, // 4 KB = 4 * 1024 B
* writeBufferSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
* cacheSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
* maxOpenFiles = 100
* },
* {
* name = "account-index",
* path = "storage_directory_test",
* createIfMissing = true,
* paranoidChecks = true,
* verifyChecksums = true,
* compressionType = 1, // compressed with snappy
* blockSize = 4096, // 4 KB = 4 * 1024 B
* writeBufferSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
* cacheSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
* maxOpenFiles = 100
* },
* { # only for unit test
* name = "test_name",
* path = "test_path",
* createIfMissing = false,
* paranoidChecks = false,
* verifyChecksums = false,
* compressionType = 1,
* blockSize = 2,
* writeBufferSize = 3,
* cacheSize = 4,
* maxOpenFiles = 5
* },
* ]
*/
private static void setupStorage() {
StorageConfig sc = new StorageConfig();
try {
setPrivateField(sc, "defaultDbOption", makeOverride(50));
Comment thread
317787106 marked this conversation as resolved.
Outdated
setPrivateField(sc, "defaultMDbOption", makeOverride(500));
setPrivateField(sc, "defaultLDbOption", makeOverride(1000));
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
storage.setDefaultDbOptions(sc);

StorageConfig.PropertyConfig account = new StorageConfig.PropertyConfig();
account.setName("account");
account.setPath("storage_directory_test");
account.setCompressionType(1);
account.setBlockSize(4096);
account.setWriteBufferSize(10485760);
account.setCacheSize(10485760);
account.setMaxOpenFiles(100);

StorageConfig.PropertyConfig accountIndex = new StorageConfig.PropertyConfig();
accountIndex.setName("account-index");
accountIndex.setPath("storage_directory_test");
accountIndex.setCompressionType(1);
accountIndex.setBlockSize(4096);
accountIndex.setWriteBufferSize(10485760);
accountIndex.setCacheSize(10485760);
accountIndex.setMaxOpenFiles(100);

StorageConfig.PropertyConfig testName = new StorageConfig.PropertyConfig();
testName.setName("test_name");
testName.setPath("test_path");
testName.setCreateIfMissing(false);
testName.setParanoidChecks(false);
testName.setVerifyChecksums(false);
testName.setCompressionType(1);
testName.setBlockSize(2);
testName.setWriteBufferSize(3);
testName.setCacheSize(4);
testName.setMaxOpenFiles(5);

storage.setPropertyMapFromBean(Arrays.asList(account, accountIndex, testName));
}

private static StorageConfig.DbOptionOverride makeOverride(int maxOpenFiles) {
StorageConfig.DbOptionOverride o = new StorageConfig.DbOptionOverride();
o.setMaxOpenFiles(maxOpenFiles);
return o;
}

private static void setPrivateField(Object obj, String name, Object value)
throws ReflectiveOperationException {
Field f = StorageConfig.class.getDeclaredField(name);
f.setAccessible(true);
f.set(obj, value);
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.Before;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.runtime.RuntimeImpl;
import org.tron.common.runtime.TvmTestUtils;
import org.tron.common.utils.ByteArray;
Expand Down Expand Up @@ -67,7 +68,7 @@ public class TransactionTraceTest extends BaseTest {
"--storage-index-directory", indexDirectory,
"--debug"
},
"config-test-mainnet.conf"
TestConstants.TEST_CONF
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.Before;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.Sha256Hash;
import org.tron.core.capsule.AccountCapsule;
Expand All @@ -27,7 +28,7 @@ public class AssetUpdateHelperTest extends BaseTest {
private static boolean init;

static {
Args.setParam(new String[]{"-d", dbPath()}, "config-test-index.conf");
Args.setParam(new String[]{"-d", dbPath()}, TestConstants.TEST_CONF);
Args.getInstance().setSolidityNode(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.tron.common.TestConstants;
import org.tron.common.utils.ByteArray;
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.config.args.Args;
Expand All @@ -21,7 +22,7 @@ public class ApiUtilTest {

@BeforeClass
public static void init() {
Args.setParam(new String[]{}, "config-localtest.conf");
Args.setParam(new String[]{}, TestConstants.TEST_CONF);
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.junit.Ignore;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.ByteUtil;
import org.tron.common.zksnark.IncrementalMerkleTreeContainer;
Expand Down Expand Up @@ -82,7 +83,7 @@ public static void init() {
"--storage-index-directory", indexDirectory,
"--debug"
},
"config-test-mainnet.conf"
TestConstants.TEST_CONF
);
Args.getInstance().setAllowShieldedTransactionApi(true);
ZksnarkInitService.librustzcashInitZksnarkParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.Before;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.ByteUtil;
import org.tron.common.zksnark.IncrementalMerkleTreeContainer;
Expand Down Expand Up @@ -38,7 +39,7 @@ public class MerkleTreeTest extends BaseTest {
"--storage-index-directory", indexDirectory,
"--debug"
},
"config-test-mainnet.conf"
TestConstants.TEST_CONF
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.Before;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.TestConstants;
import org.tron.common.utils.ByteArray;
import org.tron.core.Wallet;
import org.tron.core.capsule.AssetIssueCapsule;
Expand Down Expand Up @@ -39,7 +40,7 @@ public class NoteEncDecryTest extends BaseTest {
private Wallet wallet;

static {
Args.setParam(new String[]{"--output-directory", dbPath()}, "config-localtest.conf");
Args.setParam(new String[]{"--output-directory", dbPath()}, TestConstants.SHIELD_CONF);
FROM_ADDRESS = Wallet.getAddressPreFixString() + "a7d8a35b260395c14aa456297662092ba3b76fc0";
}

Expand Down
Loading
Loading