-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAppchainTest.java
114 lines (92 loc) · 3.9 KB
/
AppchainTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package cn.dmlab.bitxhub;
import cn.dmlab.crypto.ecdsa.ECKeyS256;
import cn.dmlab.utils.ByteUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.bouncycastle.util.encoders.Hex;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import pb.ArgOuterClass;
import pb.ReceiptOuterClass;
import java.io.FileInputStream;
import java.io.IOException;
@RunWith(JUnit4.class)
@Slf4j
public class AppchainTest {
private GrpcClient client;
private Config config = Config.defaultConfig();
@Before
public void setUp() {
config.setEcKey(ECKeyS256.fromPrivate(ByteUtil.hexStringToBytes("b6477143e17f889263044f6cf463dc37177ac4526c4c39a7a344198457024a2f")));
client = new GrpcClientImpl(config);
}
@After
public void tearDown() throws Exception {
client.stop();
}
@Test
@Ignore
public void registerAppchain() {
ReceiptOuterClass.Receipt receipt = register();
String ret = receipt.getRet().toStringUtf8();
JSONObject jsonObject = JSONObject.parseObject(ret);
String chainType = jsonObject.getString("chain_type");
Assert.assertEquals(chainType, "hyperchain");
}
@Test
@Ignore
public void adultAppchain() {
ReceiptOuterClass.Receipt receipt = register();
String ret = receipt.getRet().toStringUtf8();
JSONObject jsonObject = JSONObject.parseObject(ret);
ArgOuterClass.Arg[] adultArgs = Types.toArgArray(
Types.string(jsonObject.getString("id")), //应用链ID
Types.i32(1), //审核通过
Types.string("")); //desc
ReceiptOuterClass.Receipt adultReceipt = client.invokeBVMContract(BVMAddr.APPCHAIN_MANAGER_CONTRACT_ADDR, "Audit", adultArgs);
Assert.assertNotNull(adultReceipt);
}
@Test
@Ignore
public void deleteAppchain() {
ReceiptOuterClass.Receipt receipt = register();
String ret = receipt.getRet().toStringUtf8();
JSONObject jsonObject = JSONObject.parseObject(ret);
ArgOuterClass.Arg[] deleteArgs = Types.toArgArray(
Types.string(jsonObject.getString("id")));
ReceiptOuterClass.Receipt adultReceipt = client.invokeBVMContract(BVMAddr.APPCHAIN_MANAGER_CONTRACT_ADDR, "DeleteAppchain", deleteArgs);
Assert.assertNotNull(adultReceipt);
}
@Test
@Ignore
public void registerRule() throws IOException {
byte[] contractBytes = IOUtils.toByteArray(
new FileInputStream("target/test-classes/testdata/example.wasm"));
String contractAddress = client.deployContract(contractBytes);
Assert.assertNotNull(contractAddress);
ReceiptOuterClass.Receipt receipt = register();
String ret = receipt.getRet().toStringUtf8();
JSONObject jsonObject = JSONObject.parseObject(ret);
String appchainID = jsonObject.getString("id");
ArgOuterClass.Arg[] ruleArgs = Types.toArgArray(
Types.string(appchainID),
Types.string(contractAddress));
ReceiptOuterClass.Receipt ruleReceipt = client.invokeBVMContract(BVMAddr.RULE_MANAGER_CONTRACT_ADDR, "RegisterRule", ruleArgs);
Assert.assertNotNull(ruleReceipt);
}
ReceiptOuterClass.Receipt register() {
ArgOuterClass.Arg[] args = Types.toArgArray(
Types.string(""), //validators
Types.i32(0), //consensus_type
Types.string("hyperchain"), //chain_type
Types.string("税务链"), //name
Types.string("趣链税务链"), //desc
Types.string("1.8"),//version
Types.string("")); //public key
ReceiptOuterClass.Receipt receipt = client.invokeBVMContract(BVMAddr.APPCHAIN_MANAGER_CONTRACT_ADDR, "Register", args);
Assert.assertNotNull(receipt);
return receipt;
}
}