-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathClientTest.java
More file actions
136 lines (122 loc) · 5.45 KB
/
ClientTest.java
File metadata and controls
136 lines (122 loc) · 5.45 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package irita.sdk;
import com.google.protobuf.GeneratedMessageV3;
import irita.sdk.client.BaseClient;
import irita.sdk.client.IritaClient;
import irita.sdk.constant.enums.BroadcastMode;
import irita.sdk.crypto.eth.LegacyTransaction;
import irita.sdk.model.*;
import irita.sdk.model.block.BlockDetail;
import irita.sdk.model.tx.Condition;
import irita.sdk.model.tx.EventQueryBuilder;
import irita.sdk.model.tx.Events;
import irita.sdk.util.Bech32Utils;
import irita.sdk.util.KeyUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.web3j.utils.Numeric;
import proto.nft.Tx;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.List;
import static irita.sdk.constant.Constant.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class ClientTest extends ConfigTest {
private IritaClient client;
public static final String mnemonic = "start vacant crop magnet cricket math quarter pass emotion hidden tray lake rail drift length wreck lock voice type nose whisper this impose test";
@BeforeEach
public void init() {
client = getTestClient();
}
@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", "ugas"), 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 queryTxFeePayer() throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
String hash = "20AA3CCE20FA2DA71ACED7F5B81D42C4440297F2E6F8297372CC6246AE5E270B";//
ResultQueryTx resultQueryTx = client.getBaseClient().queryTx(hash);
assertNotNull(resultQueryTx);
// 判断是否是智能合约交易
if (resultQueryTx.getTx().getBody().getMsgs().get(0) instanceof proto.ethermint.evm.v1.Tx.MsgEthereumTx) {
List<GeneratedMessageV3> messageList = resultQueryTx.getTx().getBody().getMsgs();
for (GeneratedMessageV3 generatedMessageV3 : messageList) {
proto.ethermint.evm.v1.Tx.MsgEthereumTx msgEthereumTx = proto.ethermint.evm.v1.Tx.MsgEthereumTx.parseFrom(generatedMessageV3.toByteString());
System.out.println(msgEthereumTx.getData().getTypeUrl());
LegacyTransaction legacyTransaction;
switch (msgEthereumTx.getData().getTypeUrl()){
case DYNAMIC_FEE_TX:
proto.ethermint.evm.v1.Tx.DynamicFeeTx dynamicFeeTx = proto.ethermint.evm.v1.Tx.DynamicFeeTx.parseFrom(msgEthereumTx.getData().getValue());
legacyTransaction = new LegacyTransaction(dynamicFeeTx);
break;
case LEGACY_TX:
proto.ethermint.evm.v1.Tx.LegacyTx legacyTx = proto.ethermint.evm.v1.Tx.LegacyTx.parseFrom(msgEthereumTx.getData().getValue());
legacyTransaction = new LegacyTransaction(legacyTx);
break;
case ACCESS_LIST_TX:
// AccessListTx需要测试后方可
// proto.ethermint.evm.v1.Tx.AccessListTx accessListTx = proto.ethermint.evm.v1.Tx.AccessListTx.parseFrom(msgEthereumTx.getData().getValue());
// legacyTransaction = new LegacyTransaction(accessListTx);
System.out.println("ACCESS_LIST_TX type is temporarily not supported");
return;
default:
System.out.println("Transaction Type not exist");
return;
}
System.out.println("付钱的人是:"+ legacyTransaction.getSender());
}
return;
}
String granter = resultQueryTx.getTx().getAuthInfo().getFee().getGranter();
String payer = resultQueryTx.getTx().getAuthInfo().getFee().getPayer();
String txSigner = KeyUtils.parseAddrFromPubKeyAny(resultQueryTx.getTx().getAuthInfo().getSignerInfos(0).getPublicKey());
System.out.println("付钱的人是:" + (!"".equals(granter) ? granter : (!"".equals(payer) ? payer : txSigner)));
}
@Test
@Disabled
public void queryBlock() throws IOException {
BlockDetail blockDetail = client.getBaseClient().queryBlock("10254529");
assertNotNull(blockDetail);
}
}