forked from bianjieai/opb-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientTest.java
102 lines (88 loc) · 3.91 KB
/
ClientTest.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
package irita.sdk;
import com.google.protobuf.GeneratedMessageV3;
import irita.sdk.client.BaseClient;
import irita.sdk.client.IritaClient;
import irita.sdk.config.ClientConfig;
import irita.sdk.config.OpbConfig;
import irita.sdk.constant.enums.BroadcastMode;
import irita.sdk.key.KeyManager;
import irita.sdk.key.KeyManagerFactory;
import irita.sdk.model.*;
import irita.sdk.model.block.BlockDetail;
import irita.sdk.model.tx.Condition;
import irita.sdk.model.tx.EventQueryBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import proto.nft.Tx;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class ClientTest {
private IritaClient client;
@BeforeEach
public void init() {
String mnemonic = "opera vivid pride shallow brick crew found resist decade neck expect apple chalk belt sick author know try tank detail tree impact hand best";
KeyManager km = KeyManagerFactory.createDefault();
km.recover(mnemonic);
String nodeUri = "http://101.132.67.8:26657";
String grpcAddr = "http://101.132.67.8:9090";
String chainId = "wenchangchain";
ClientConfig clientConfig = new ClientConfig(nodeUri, grpcAddr, chainId);
// OpbConfig opbConfig = new OpbConfig("", "", "");
OpbConfig opbConfig = null;
client = new IritaClient(clientConfig, opbConfig, km);
assertEquals("iaa1ytemz2xqq2s73ut3ys8mcd6zca2564a5lfhtm3", km.getCurrentKeyInfo().getAddress());
}
@Test
@Disabled
public void queryAccount() {
String addr = "iaa1ytemz2xqq2s73ut3ys8mcd6zca2564a5lfhtm3";
Account account = client.getBaseClient().queryAccount(addr);
assertEquals(addr, account.getAddress());
}
@Test
@Disabled
public void simulateTx() throws IOException {
BaseClient baseClient = client.getBaseClient();
BaseTx baseTx = new BaseTx(10000, new Fee("10000", "uirita"), BroadcastMode.Commit);
Account account = baseClient.queryAccount(baseTx);
Tx.MsgIssueDenom msg = Tx.MsgIssueDenom
.newBuilder()
.setId("testfjdsklf21A3")
.setName("testfjdsklf213")
.setSchema("nullschema")
.setSender(account.getAddress())
.build();
List<GeneratedMessageV3> msgs = Collections.singletonList(msg);
GasInfo gasInfo = baseClient.simulateTx(msgs, baseTx, null);
System.out.println(gasInfo);
}
@Test
@Disabled
public void queryTx() throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
String hash = "D49C463FAB1273ADE4D3CABE61E069DE56BBDF778200CB2B78E26A2659035127";//tibc
ResultQueryTx resultQueryTx = client.getBaseClient().queryTx(hash);
assertNotNull(resultQueryTx);
}
@Test
@Disabled
public void queryTxs() throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
EventQueryBuilder builder = EventQueryBuilder.newEventQueryBuilder()
.AddCondition(Condition.newCond("tibc_nft_transfer", "sender").eq("iaa18e23vvukxgatgzm4fgqkdggxecurkf39ytw7ue"));
// .AddCondition(Condition.newCond("send_packet", "packet_sequence").eq(4));
int page = 1;
int size = 10;
ResultSearchTxs resultSearchTxs = client.getBaseClient().queryTxs(builder, page, size);
assertNotNull(resultSearchTxs);
}
@Test
@Disabled
public void queryBlock() throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
BlockDetail blockDetail = client.getBaseClient().queryBlock("33105");
assertNotNull(blockDetail);
}
}