-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat][test-tool][v0.1.0] add plugin test tool #53
Open
sulc23
wants to merge
4
commits into
AntChainOpenLabs:main
Choose a base branch
from
sulc23:feat/tester
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
antchain-bridge-plugin-test/antchain-bridge-plugin-tester/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
66 changes: 66 additions & 0 deletions
66
antchain-bridge-plugin-test/antchain-bridge-plugin-tester/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
|
||
<groupId>com.ali.antchain</groupId> | ||
<artifactId>antchain-bridge-plugin-tester</artifactId> | ||
<version>0.1.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>PlugsTest</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.alipay.antchain.bridge</groupId> | ||
<artifactId>antchain-bridge-plugin-lib</artifactId> | ||
<version>0.2.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alipay.antchain.bridge</groupId> | ||
<artifactId>antchain-bridge-spi</artifactId> | ||
<version>0.2.3</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.web3j</groupId> | ||
<artifactId>core</artifactId> | ||
<version>4.9.8</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.24</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.28</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.2.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
25 changes: 25 additions & 0 deletions
25
...gin-test/antchain-bridge-plugin-tester/src/main/java/com/ali/antchain/EthPluginsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ali.antchain; | ||
|
||
import com.ali.antchain.Test.GetContextTest; | ||
import com.ali.antchain.Test.ShutDownTest; | ||
import com.ali.antchain.Test.StartUpTest; | ||
import com.ali.antchain.config.EthereumConfig; | ||
import com.alipay.antchain.bridge.commons.bbc.AbstractBBCContext; | ||
import com.alipay.antchain.bridge.commons.bbc.DefaultBBCContext; | ||
import com.alipay.antchain.bridge.plugins.spi.bbc.AbstractBBCService; | ||
|
||
public class EthPluginsTest extends PluginsTest { | ||
public EthPluginsTest(AbstractBBCContext context, AbstractBBCService service) { | ||
super(context, service); | ||
} | ||
EthereumConfig config; | ||
public void EthConfigInit(String url,String key,long gasPrice,long gasLimit) { | ||
this.config = new EthereumConfig(); | ||
config.setUrl(url); | ||
config.setPrivateKey(key); | ||
config.setGasPrice(gasPrice); | ||
config.setGasLimit(gasLimit); | ||
this.context = new DefaultBBCContext(); | ||
context.setConfForBlockchainClient(config.toJsonString().getBytes()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...plugin-test/antchain-bridge-plugin-tester/src/main/java/com/ali/antchain/PluginsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.ali.antchain; | ||
|
||
import com.ali.antchain.Test.GetContextTest; | ||
import com.ali.antchain.Test.ShutDownTest; | ||
import com.ali.antchain.Test.StartUpTest; | ||
import com.alipay.antchain.bridge.commons.bbc.AbstractBBCContext; | ||
import com.alipay.antchain.bridge.plugins.spi.bbc.AbstractBBCService; | ||
|
||
public class PluginsTest { | ||
|
||
AbstractBBCContext context; | ||
AbstractBBCService service; | ||
|
||
public PluginsTest(AbstractBBCContext context, AbstractBBCService service) { | ||
this.context = context; | ||
this.service = service; | ||
} | ||
|
||
public void startup() throws Exception { | ||
StartUpTest.run(context, service); | ||
} | ||
|
||
public void shutdown() throws Exception { | ||
ShutDownTest.run(context,service); | ||
} | ||
|
||
public void getcontext() throws Exception { | ||
GetContextTest.run(context,service); | ||
} | ||
|
||
public void setupamcontract() throws Exception {} | ||
|
||
public void setupsdpcontract() throws Exception {} | ||
|
||
public void querysdpmessageseq() throws Exception {} | ||
|
||
public void setprotocol() throws Exception { | ||
|
||
} | ||
|
||
public void setamcontractandlocaldomain() throws Exception { | ||
|
||
} | ||
|
||
|
||
// public static void main(String[] args) throws Exception{ | ||
// String url = "http://127.0.0.1:7545"; | ||
// String key = "0x45cfa3b6addf98274bfd9e3482a695406c7dcc99e1588bd6e0127b8fc06ae916"; | ||
// long gasPrice = 2300000000L; | ||
// long gasLimit = 3000000; | ||
// PlugsTest test = new PlugsTest(url,key,gasPrice,gasLimit); | ||
//// test.ethinit.init(); | ||
// test.startup(); | ||
// } | ||
|
||
|
||
} |
82 changes: 82 additions & 0 deletions
82
...n-bridge-plugin-tester/src/main/java/com/ali/antchain/Test/ETHQuerySDPMessageSeqTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.ali.antchain.Test; | ||
|
||
import cn.hutool.crypto.digest.DigestUtil; | ||
import com.ali.antchain.service.EthereumBBCService; | ||
import com.alipay.antchain.bridge.commons.bbc.AbstractBBCContext; | ||
|
||
public class ETHQuerySDPMessageSeqTest { | ||
|
||
boolean setupBBC; | ||
|
||
|
||
public static void run(AbstractBBCContext context) throws Exception { | ||
ETHQuerySDPMessageSeqTest ETHQuerySDPMessageSeqTest = new ETHQuerySDPMessageSeqTest(); | ||
ETHQuerySDPMessageSeqTest.querysdpmessageseq(context); | ||
} | ||
|
||
public void querysdpmessageseq(AbstractBBCContext context) throws Exception { | ||
EthereumBBCService ethereumBBCService = new EthereumBBCService(); | ||
ethereumBBCService.startup(context); | ||
|
||
if (setupBBC) { | ||
System.out.println("The BBC has already been set up."); | ||
}else { | ||
RelayAmPrepare.relayamprepare(context); | ||
} | ||
// //set up am | ||
// ethereumBBCService.setupAuthMessageContract(); | ||
// | ||
// // set up sdp | ||
// ethereumBBCService.setupSDPMessageContract(); | ||
// | ||
// ethereumBBCService.setProtocol( | ||
// context.getSdpContract().getContractAddress(), | ||
// "0"); | ||
// | ||
// // set am to sdp | ||
// ethereumBBCService.setAmContract(context.getAuthMessageContract().getContractAddress()); | ||
// | ||
// // set local domain to sdp | ||
// ethereumBBCService.setLocalDomain("receiverDomain"); | ||
// | ||
// // check contract ready | ||
// AbstractBBCContext ctxCheck = ethereumBBCService.getContext(); | ||
// | ||
// System.out.println(ctxCheck.getAuthMessageContract().getStatus()); | ||
// System.out.println(ctxCheck.getSdpContract().getStatus()); | ||
// | ||
// Web3j web3j = Web3j.build(new HttpService("http://127.0.0.1:7545")); | ||
// Credentials credentials = Credentials.create("0x45cfa3b6addf98274bfd9e3482a695406c7dcc99e1588bd6e0127b8fc06ae916"); | ||
// | ||
// RawTransactionManager rawTransactionManager = new RawTransactionManager( | ||
// web3j, credentials, web3j.ethChainId().send().getChainId().longValue()); | ||
// | ||
// AppContract appContract = AppContract.deploy( | ||
// web3j, | ||
// rawTransactionManager, | ||
// new DefaultGasProvider() | ||
// ).send(); | ||
// | ||
// TransactionReceipt receipt = appContract.setProtocol(ethereumBBCService.getBbcContext().getSdpContract().getContractAddress()).send(); | ||
// if (receipt.isStatusOK()) { | ||
// System.out.println("set protocol(" + appContract.getContractAddress()+ ") to app contract(" +ethereumBBCService.getBbcContext().getSdpContract().getContractAddress()+ ")"); | ||
// } else { | ||
// throw new Exception(String.format("failed to set protocol(%s) to app contract(%s)", | ||
// appContract.getContractAddress(), | ||
// ethereumBBCService.getBbcContext().getSdpContract().getContractAddress())); | ||
// } | ||
// System.out.println(receipt); | ||
// } | ||
|
||
// query seq | ||
long seq = ethereumBBCService.querySDPMessageSeq( | ||
"senderDomain", | ||
DigestUtil.sha256Hex("senderID"), | ||
"receiverDomain", | ||
DigestUtil.sha256Hex("receiverID") | ||
); | ||
System.out.println(seq); | ||
|
||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...plugin-tester/src/main/java/com/ali/antchain/Test/ETHSetAmContractAndLocalDomainTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.ali.antchain.Test; | ||
|
||
import cn.hutool.core.util.HexUtil; | ||
import com.ali.antchain.abi.SDPMsg; | ||
import com.ali.antchain.service.EthereumBBCService; | ||
import com.alipay.antchain.bridge.commons.bbc.AbstractBBCContext; | ||
import org.web3j.tx.gas.DefaultGasProvider; | ||
|
||
public class ETHSetAmContractAndLocalDomainTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setAmContract setLocaldmain建议分开,这是两个接口,之前的单测是为了方便写在一起了,这里作为一个通用测试工具的话,需要对每个接口进行单元测试。还有这两接口的测试你看下涉及的内容,只是调用bbc接口就可以了,说明也不涉及eth特有的部分 |
||
|
||
public static void run(AbstractBBCContext context) throws Exception { | ||
ETHSetAmContractAndLocalDomainTest ETHSetAmContractAndLocalDomainTest = new ETHSetAmContractAndLocalDomainTest(); | ||
ETHSetAmContractAndLocalDomainTest.setamcontractandlocaldomain(context); | ||
} | ||
public void setamcontractandlocaldomain(AbstractBBCContext context) throws Exception { | ||
EthereumBBCService ethereumBBCService = new EthereumBBCService(); | ||
// start up | ||
ethereumBBCService.startup(context); | ||
|
||
// set up am | ||
ethereumBBCService.setupAuthMessageContract(); | ||
|
||
// set up sdp | ||
ethereumBBCService.setupSDPMessageContract(); | ||
|
||
// get context | ||
AbstractBBCContext ctx = ethereumBBCService.getContext(); | ||
|
||
System.out.println(ctx.getAuthMessageContract().getStatus()); | ||
System.out.println(ctx.getSdpContract().getStatus()); | ||
|
||
// set am to sdp | ||
ethereumBBCService.setAmContract(ctx.getAuthMessageContract().getContractAddress()); | ||
|
||
String amAddr = SDPMsg.load( | ||
ethereumBBCService.getBbcContext().getSdpContract().getContractAddress(), | ||
ethereumBBCService.getWeb3j(), | ||
ethereumBBCService.getCredentials(), | ||
new DefaultGasProvider() | ||
).getAmAddress().send(); | ||
System.out.println("amAddr: {"+amAddr+"}"); | ||
|
||
// check contract status | ||
ctx = ethereumBBCService.getContext(); | ||
System.out.println(ctx.getSdpContract().getStatus()); | ||
|
||
// set the domain | ||
ethereumBBCService.setLocalDomain("receiverDomain"); | ||
|
||
byte[] rawDomain = SDPMsg.load( | ||
ethereumBBCService.getBbcContext().getSdpContract().getContractAddress(), | ||
ethereumBBCService.getWeb3j(), | ||
ethereumBBCService.getCredentials(), | ||
new DefaultGasProvider() | ||
).getLocalDomain().send(); | ||
System.out.println("domain: {"+HexUtil.encodeHexStr(rawDomain)+ "}"); | ||
|
||
// check contract status | ||
ctx = ethereumBBCService.getContext(); | ||
System.out.println(ctx.getSdpContract().getStatus()); | ||
|
||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...antchain-bridge-plugin-tester/src/main/java/com/ali/antchain/Test/ETHSetProtocolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.ali.antchain.Test; | ||
|
||
import com.ali.antchain.abi.AuthMsg; | ||
import com.ali.antchain.service.EthereumBBCService; | ||
import com.alipay.antchain.bridge.commons.bbc.AbstractBBCContext; | ||
import org.web3j.tx.gas.DefaultGasProvider; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class ETHSetProtocolTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 用通用测试类,不涉及eth特有的操作 |
||
|
||
public static void run(AbstractBBCContext context) throws Exception { | ||
ETHSetProtocolTest ETHSetProtocolTest = new ETHSetProtocolTest(); | ||
ETHSetProtocolTest.setprotocol(context); | ||
} | ||
public void setprotocol(AbstractBBCContext context) throws Exception { | ||
EthereumBBCService ethereumBBCService = new EthereumBBCService(); | ||
// start up | ||
ethereumBBCService.startup(context); | ||
|
||
// set up am | ||
ethereumBBCService.setupAuthMessageContract(); | ||
|
||
// set up sdp | ||
ethereumBBCService.setupSDPMessageContract(); | ||
|
||
// get context | ||
AbstractBBCContext ctx = ethereumBBCService.getContext(); | ||
System.out.println(ctx.getAuthMessageContract().getStatus()); | ||
System.out.println(ctx.getSdpContract().getStatus()); | ||
|
||
// set protocol to am (sdp type: 0) | ||
ethereumBBCService.setProtocol( | ||
ctx.getSdpContract().getContractAddress(), | ||
"0"); | ||
|
||
String addr = AuthMsg.load( | ||
ethereumBBCService.getBbcContext().getAuthMessageContract().getContractAddress(), | ||
ethereumBBCService.getWeb3j(), | ||
ethereumBBCService.getCredentials(), | ||
new DefaultGasProvider() | ||
).getProtocol(BigInteger.ZERO).send(); | ||
System.out.println("protocol: {" + addr + "}"); | ||
|
||
// check am status | ||
ctx = ethereumBBCService.getContext(); | ||
System.out.println(ctx.getAuthMessageContract().getStatus()); | ||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个类直接用通用的测试类即可,不涉及eth特有的操作