-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathWalletTestCommittee001.java
More file actions
131 lines (113 loc) · 5.18 KB
/
WalletTestCommittee001.java
File metadata and controls
131 lines (113 loc) · 5.18 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
package stest.tron.wallet.committee;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import java.util.HashMap;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.tron.api.GrpcAPI.EmptyMessage;
import org.tron.api.GrpcAPI.PaginatedMessage;
import org.tron.api.GrpcAPI.ProposalList;
import org.tron.api.WalletGrpc;
import org.tron.api.WalletSolidityGrpc;
import org.tron.core.Wallet;
import stest.tron.wallet.common.client.Configuration;
import stest.tron.wallet.common.client.Parameter.CommonConstant;
import stest.tron.wallet.common.client.utils.PublicMethed;
@Slf4j
public class WalletTestCommittee001 {
private static final long now = System.currentTimeMillis();
private final String testKey002 = Configuration.getByPath("testng.conf")
.getString("foundationAccount.key1");
private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);
private final String testKey003 = Configuration.getByPath("testng.conf")
.getString("foundationAccount.key2");
private final byte[] toAddress = PublicMethed.getFinalAddress(testKey003);
//Witness 47.93.9.236
private final String witnessKey001 = Configuration.getByPath("testng.conf")
.getString("witness.key1");
//Witness 47.93.33.201
private final String witnessKey002 = Configuration.getByPath("testng.conf")
.getString("witness.key2");
//Witness 123.56.10.6
private final String witnessKey003 = Configuration.getByPath("testng.conf")
.getString("witness.key3");
//Wtiness 39.107.80.135
private final String witnessKey004 = Configuration.getByPath("testng.conf")
.getString("witness.key4");
//Witness 47.93.184.2
private final String witnessKey005 = Configuration.getByPath("testng.conf")
.getString("witness.key5");
private final byte[] witness001Address = PublicMethed.getFinalAddress(witnessKey001);
private final byte[] witness002Address = PublicMethed.getFinalAddress(witnessKey002);
private final byte[] witness003Address = PublicMethed.getFinalAddress(witnessKey003);
private final byte[] witness004Address = PublicMethed.getFinalAddress(witnessKey004);
private final byte[] witness005Address = PublicMethed.getFinalAddress(witnessKey005);
private ManagedChannel channelFull = null;
private ManagedChannel channelSolidity = null;
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;
private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list")
.get(0);
private String soliditynode = Configuration.getByPath("testng.conf")
.getStringList("solidityNode.ip.list").get(0);
/**
* constructor.
*/
@BeforeClass
public void beforeClass() {
channelFull = ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext()
.build();
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
channelSolidity = ManagedChannelBuilder.forTarget(soliditynode)
.usePlaintext()
.build();
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
}
@Test
public void testListProposals() {
//List proposals
ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build());
Optional<ProposalList> listProposals = Optional.ofNullable(proposalList);
final Integer beforeProposalCount = listProposals.get().getProposalsCount();
//CreateProposal
final long now = System.currentTimeMillis();
HashMap<Long, Long> proposalMap = new HashMap<Long, Long>();
proposalMap.put(0L, 1000000L);
PublicMethed.createProposal(witness001Address, witnessKey001, proposalMap, blockingStubFull);
//List proposals
proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build());
listProposals = Optional.ofNullable(proposalList);
Integer afterProposalCount = listProposals.get().getProposalsCount();
Assert.assertTrue(beforeProposalCount + 1 == afterProposalCount);
logger.info(Long.toString(listProposals.get().getProposals(0).getCreateTime()));
logger.info(Long.toString(now));
//Assert.assertTrue(listProposals.get().getProposals(0).getCreateTime() >= now);
Assert.assertTrue(listProposals.get().getProposals(0).getParametersMap().equals(proposalMap));
//getProposalListPaginated
PaginatedMessage.Builder pageMessageBuilder = PaginatedMessage.newBuilder();
pageMessageBuilder.setOffset(0);
pageMessageBuilder.setLimit(1);
ProposalList paginatedProposalList = blockingStubFull
.getPaginatedProposalList(pageMessageBuilder.build());
Assert.assertTrue(paginatedProposalList.getProposalsCount() >= 1);
}
/**
* constructor.
*/
@AfterClass
public void shutdown() throws InterruptedException {
if (channelFull != null) {
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
if (channelSolidity != null) {
channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
}
}