Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d17805d
add 3 cases for iscontract
mumianhua Mar 21, 2024
9e815fe
upgrade dependency version
XvZipo Apr 23, 2024
961acfa
upgrade dependency version
XvZipo Apr 23, 2024
38a1a6e
upgrade dependency version
XvZipo Apr 23, 2024
306a0d9
upgrade dependency version
XvZipo Apr 23, 2024
eef77dc
upgrade dependency version
XvZipo Apr 23, 2024
b3d7b5a
upgrade dependency version
XvZipo Apr 23, 2024
292d453
downgrade dependency version logback
XvZipo Apr 23, 2024
3a43079
upgrade dependency version logback
XvZipo Apr 23, 2024
ceb2ce0
upgrade dependency version slf4j
XvZipo Apr 23, 2024
1454933
upgrade dependency version logback
XvZipo Apr 23, 2024
8b6ace1
delete dependency version sf4j
XvZipo Apr 23, 2024
2f12b66
upgrade dependency version sf4j
XvZipo Apr 23, 2024
66d29af
downgrade dependency version logback
XvZipo Apr 23, 2024
2c564d6
upgrade dependency version logback
XvZipo Apr 23, 2024
e330bc5
upgrade dependency version grpc-netty 1.63
XvZipo Apr 24, 2024
3db9107
upgrade dependency version bcprov-jdk18on
XvZipo Apr 24, 2024
4ff9045
upgrade dependency version guava
XvZipo Apr 24, 2024
51910a3
upgrade dependency version aspectjrt
XvZipo Apr 24, 2024
976ed40
upgrade dependency version zeromq
XvZipo Apr 24, 2024
aad4ad1
delete briandilley.jsonrpc4j
XvZipo Apr 24, 2024
8ab0f85
update guava-jre
XvZipo Apr 24, 2024
ef615e9
delete httpasyncclient
XvZipo Apr 24, 2024
7e5ca66
update dependency
XvZipo Apr 24, 2024
582c3e2
update zeromq and delete AspectJ
XvZipo Apr 24, 2024
1a10f02
downgrade logback-classic to 1.2.13
XvZipo Apr 24, 2024
601b17d
upgrade logback-classic to 1.3.14
XvZipo Apr 24, 2024
a278bdd
add trident 0.9.0 case
XvZipo May 20, 2024
1060343
modify testng.conf to set 81,82 proposal as 1,1500
XvZipo May 20, 2024
5509d94
delete old jar file
XvZipo May 20, 2024
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
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ subprojects {
}

dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25'
compile "org.slf4j:jcl-over-slf4j:1.7.25"
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
compile group: 'org.slf4j', name: 'slf4j-api', version: '2.0.2'
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: '2.0.2'
compile "org.slf4j:jcl-over-slf4j:2.0.2"
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.14'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
compile group: 'com.google.guava', name: 'guava', version: '24.1-jre'
compile group: 'com.google.guava', name: 'guava', version: '32.0.0-jre'
compile "com.google.code.findbugs:jsr305:3.0.0"
compile group: 'org.springframework', name: 'spring-context', version: '4.2.4.RELEASE'
compile group: 'org.springframework', name: 'spring-tx', version: '4.2.4.RELEASE'
compile group: 'org.springframework', name: 'spring-context', version: '5.3.27'
compile group: 'org.springframework', name: 'spring-tx', version: '5.3.27'
compile "org.apache.commons:commons-lang3:3.4"
compile group: 'org.apache.commons', name: 'commons-math', version: '2.2'
compile "org.apache.commons:commons-collections4:4.0"
compile "org.apache.commons:commons-collections4:4.1"
compile group: 'joda-time', name: 'joda-time', version: '2.3'
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.11'
compile group: 'org.mongodb', name: 'bson', version: '4.6.0'
Expand Down
10 changes: 5 additions & 5 deletions protocol/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.google.protobuf'

dependencies {
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.4.0'
compile group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.4.0'
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.16.3'
compile group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.25.2'
compile group: 'net.jcip', name: 'jcip-annotations', version: '1.0'

// checkstyleConfig "com.puppycrawl.tools:checkstyle:${versions.checkstyle}"
// google grpc
compile group: 'io.grpc', name: 'grpc-netty', version: '1.14.0'
compile group: 'io.grpc', name: 'grpc-protobuf', version: '1.14.0'
compile group: 'io.grpc', name: 'grpc-stub', version: '1.14.0'
compile group: 'io.grpc', name: 'grpc-netty', version: '1.63.0'
compile group: 'io.grpc', name: 'grpc-protobuf', version: '1.63.0'
compile group: 'io.grpc', name: 'grpc-stub', version: '1.63.0'
// end google grpc

compile group: 'com.google.api.grpc', name: 'googleapis-common-protos', version: '0.0.3'
Expand Down
44 changes: 22 additions & 22 deletions testcase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,62 +41,62 @@ dependencies {

testCompile group: 'org.testng', name: 'testng', version: '6.14.3'

compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'
compile group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: '1.78.1'

compile group: 'com.typesafe', name: 'config', version: '1.3.2'

compile "com.cedarsoftware:java-util:1.8.0"
compile "com.cedarsoftware:java-util:1.11.0"

compile group: 'com.beust', name: 'jcommander', version: '1.72'
compile group: 'com.beust', name: 'jcommander', version: '1.82'

compile group: 'junit', name: 'junit', version: '4.12'
compile group: 'junit', name: 'junit', version: '4.13.2'

compile group: 'net.jcip', name: 'jcip-annotations', version: '1.0'

compile group: 'com.google.inject', name: 'guice', version: '4.1.0'

compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.10.3'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.5'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.7.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.6'

compile group: 'io.dropwizard.metrics', name: 'metrics-core', version: '3.1.2'
compile group: 'com.github.davidb', name: 'metrics-influxdb', version: '0.8.2'

compile group: 'com.carrotsearch', name: 'java-sizeof', version: '0.0.5'

compile 'org.aspectj:aspectjrt:1.8.13'
compile 'org.aspectj:aspectjweaver:1.8.13'
compile 'org.aspectj:aspectjtools:1.8.13'
compile 'com.googlecode.cqengine:cqengine:2.12.4'
compile group: 'com.google.api.grpc', name: 'googleapis-common-protos', version: '0.0.3'
// compile 'org.aspectj:aspectjrt:1.9.22'
// compile 'org.aspectj:aspectjweaver:1.9.22'
// compile 'org.aspectj:aspectjtools:1.9.22'
// compile 'com.googlecode.cqengine:cqengine:3.6.0'
// compile group: 'com.google.api.grpc', name: 'googleapis-common-protos', version: '0.0.3'

// http
compile 'org.eclipse.jetty:jetty-server:9.4.11.v20180605'
compile 'org.eclipse.jetty:jetty-server:9.4.53.v20231009'
compile 'org.eclipse.jetty:jetty-servlet:9.4.11.v20180605'
compile 'com.alibaba:fastjson:1.2.70'
compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.1'
compile 'com.alibaba:fastjson:1.2.83'
compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.5'
// end http

// https://mvnrepository.com/artifact/com.github.briandilley.jsonrpc4j/jsonrpc4j
compile group: 'com.github.briandilley.jsonrpc4j', name: 'jsonrpc4j', version: '1.6'
// compile group: 'com.github.briandilley.jsonrpc4j', name: 'jsonrpc4j', version: '1.6'

// https://mvnrepository.com/artifact/javax.portlet/portlet-api
compileOnly group: 'javax.portlet', name: 'portlet-api', version: '3.0.1'

compile "io.vavr:vavr:0.9.2"
compile group: 'org.pf4j', name: 'pf4j', version: '2.5.0'
compile group: 'org.pf4j', name: 'pf4j', version: '3.10.0'

compile group: 'org.zeromq', name: 'jeromq', version: '0.5.0'
compile group: 'org.zeromq', name: 'jeromq', version: '0.6.0'
compile 'io.github.tronprotocol:zksnark-java-sdk:1.0.0'
compile project(":protocol")


// compile group: 'org.iq80.leveldb', name: 'leveldb', version: '0.12'
compile group: leveldbGroup, name: leveldbName, version: leveldbVersion
implementation 'io.grpc:grpc-netty-shaded:1.31.0'
implementation 'io.grpc:grpc-netty:1.31.0'
implementation 'io.grpc:grpc-protobuf:1.31.0'
implementation 'io.grpc:grpc-stub:1.31.0'
implementation 'com.google.guava:guava:28.0-jre'
implementation 'io.grpc:grpc-netty-shaded:1.63.0'
implementation 'io.grpc:grpc-netty:1.63.0'
implementation 'io.grpc:grpc-protobuf:1.63.0'
implementation 'io.grpc:grpc-stub:1.63.0'
implementation 'com.google.guava:guava:32.0-jre'
implementation fileTree(dir: 'libs', include: '*.jar')
}

Expand Down
Binary file not shown.
Binary file removed testcase/libs/core-0.8.0.jar
Binary file not shown.
Binary file added testcase/libs/core-0.9.0.jar
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.alibaba.fastjson.parser.ParserConfig;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.google.protobuf.ByteString;
import com.googlecode.cqengine.query.simple.In;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.google.gson.JsonObject;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import javassist.bytecode.BadBytecode;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class isContractCommand001 {
.getString("foundationAccount.key2");
private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey);
byte[] contractAddress = null;
byte[] contractA = null;
byte[] contractC = null;
ECKey ecKey1 = new ECKey(Utils.getRandom());
byte[] contractExcAddress = ecKey1.getAddress();
String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
Expand Down Expand Up @@ -71,6 +73,17 @@ public void beforeClass() {
contractAddress = PublicMethed
.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey,
contractExcAddress, blockingStubFull);


contractName = "C";
retMap = PublicMethed.getBycodeAbi(filePath, contractName);
code = retMap.get("byteCode").toString();
abi = retMap.get("abI").toString();
contractC = PublicMethed
.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey,
contractExcAddress, blockingStubFull);

PublicMethed.waitProduceNextBlock(blockingStubFull);
}


Expand Down Expand Up @@ -332,6 +345,99 @@ public void test05ActiveContractBeforeDeploy() {
Assert.assertEquals("CONTRACT_VALIDATE_ERROR", response.getCode().name());
Assert.assertFalse(response.getResult());
}

@Test(enabled = true, description = "deploy A in create2, A trigger B's iscontract in it's constructor")
public void test06TriggerInCreate2Constructor() {
String contractName = "A";
String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol";
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
String code = retMap.get("byteCode").toString();
String hexB = ByteArray.toHexString(contractAddress);
String testContractCode = code;
testContractCode += "000000000000000000000000" + hexB;
Long salt = 7L;

String param = "\"" + testContractCode + "\"," + salt;

String triggerTxid = PublicMethed.triggerContract(contractC,
"create2(bytes,uint256)", param, false, 0L,
1000000000L, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
Optional<Protocol.TransactionInfo> info = PublicMethed
.getTransactionInfoById(triggerTxid, blockingStubFull);
Assert.assertTrue(info.get().getResultValue() == 0);

String hexA = "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24);
logger.info("hexA: " + hexA);
contractA = ByteArray.fromHexString(hexA);
TransactionExtention transactionExtention = PublicMethed
.triggerConstantContractForExtention(contractA, "testConstructorView()", "", false, 0,
0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
logger.info("trigger A testConstructorView : " + transactionExtention.toString());
Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString());
Assert
.assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()));
}

@Test(enabled = true, description = "deploy A in create, A trigger B's iscontract in it's constructor")
public void test07TriggerInCreateConstructor() {
String contractName = "A";
String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol";
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
String code = retMap.get("byteCode").toString();
String hexB = ByteArray.toHexString(contractAddress);
String testContractCode = code;
testContractCode += "000000000000000000000000" + hexB;

String param = "\"" + testContractCode + "\"";

String triggerTxid = PublicMethed.triggerContract(contractC,
"create(bytes)", param, false, 0L,
1000000000L, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
Optional<Protocol.TransactionInfo> info = PublicMethed
.getTransactionInfoById(triggerTxid, blockingStubFull);
Assert.assertTrue(info.get().getResultValue() == 0);

String hexA = "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24);
logger.info("hexA: " + hexA);
contractA = ByteArray.fromHexString(hexA);
TransactionExtention transactionExtention = PublicMethed
.triggerConstantContractForExtention(contractA, "testConstructorView()", "", false, 0,
0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
logger.info("trigger A testConstructorView : " + transactionExtention.toString());
Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString());
Assert
.assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()));
}


@Test(enabled = true, description = "A call B's iscontract in it's constructor")
public void test08ConstructorCall() {
String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol";
String contractName = "A";
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
String code = retMap.get("byteCode").toString();
String abi = retMap.get("abI").toString();
String param = "\"" + Base58.encode58Check(contractAddress) + "\"";
String txid = PublicMethed
.deployContractWithConstantParame(contractName, abi, code, "constructor(address)",param,null,
maxFeeLimit, 0L, 100,
null, contractExcKey, contractExcAddress, blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
Optional<Protocol.TransactionInfo> info = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
Assert.assertTrue(info.get().getResultValue() == 0);
byte[] aContract = info.get().getContractAddress().toByteArray();

TransactionExtention transactionExtention = PublicMethed
.triggerConstantContractForExtention(aContract, "testConstructorView()", "", false, 0,
0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
logger.info("test08 A call B in constructor :" + transactionExtention.toString());
Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString());
Assert
.assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()));
}

/**
* constructor.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tron.trident.client;

import io.grpc.*;

public class HeaderClientInterceptor implements ClientInterceptor {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
headers.put(Metadata.Key.of("content-length", Metadata.ASCII_STRING_MARSHALLER), "5");
headers
.put(Metadata.Key.of("Content-Type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc");
headers
.put(Metadata.Key.of("Host", Metadata.ASCII_STRING_MARSHALLER), "grpc.demo.com");
headers
.put(Metadata.Key.of("x-trace-id", Metadata.ASCII_STRING_MARSHALLER), "testGroupAutoTest");
headers
.put(Metadata.Key.of("x-trace-path", Metadata.ASCII_STRING_MARSHALLER), "123 23123");
headers
.put(Metadata.Key.of("x-trace-name", Metadata.ASCII_STRING_MARSHALLER), "!@^&$!* ()^&%");
headers.put(Metadata.Key.of("my-header", Metadata.ASCII_STRING_MARSHALLER), "header-value");
super.start(responseListener, headers);
}
};
}

}
58 changes: 58 additions & 0 deletions testcase/src/test/java/tron/trident/client/TestApiKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package tron.trident.client;

import io.grpc.ClientInterceptor;
import io.grpc.StatusRuntimeException;
import lombok.extern.slf4j.Slf4j;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.tron.trident.core.ApiWrapper;
import org.tron.trident.core.Constant;
import org.tron.trident.core.exceptions.IllegalException;
import org.tron.trident.proto.Chain;
import tron.trident.utils.TestBase;

import java.util.ArrayList;
import java.util.List;



@Slf4j
public class TestApiKey extends TestBase {

@Test(enabled = true, description = "test header with api key")
public void test01HeaderWithApiKey() throws IllegalException {
wrapper.close();
wrapper = new ApiWrapper(
Constant.FULLNODE_NILE,
Constant.FULLNODE_NILE_SOLIDITY,
ownerKey, "dba1984e-b96d-4a6c-ac8f-919409625ba9"
);
Chain.Block block = wrapper.getNowBlock();
logger.info(block.toString());
Assert.assertTrue(block.toString().contains("block_header"));
wrapper.close();
}

@Test(enabled = true, description = "test header with clientInterceptors")
public void test02HeaderWithClientInterceptor() throws IllegalException {
wrapper.close();
List<ClientInterceptor> clientInterceptors = new ArrayList<>();
//custom header Class
ClientInterceptor interceptors = new HeaderClientInterceptor();
clientInterceptors.add(interceptors);
wrapper = new ApiWrapper(
Constant.FULLNODE_NILE,
Constant.FULLNODE_NILE_SOLIDITY,
ownerKey, clientInterceptors
);
Chain.Block block = wrapper.getNowBlock();
logger.info(block.toString());
Assert.assertTrue(block.toString().contains("block_header"));
wrapper.close();
}





}
Loading