77import org .junit .Assert ;
88import org .testng .annotations .AfterClass ;
99import org .testng .annotations .Test ;
10+ import org .tron .common .crypto .ECKey ;
11+ import org .tron .common .utils .ByteArray ;
12+ import org .tron .common .utils .Utils ;
1013import stest .tron .wallet .common .client .Configuration ;
1114import stest .tron .wallet .common .client .utils .HttpMethed ;
1215import stest .tron .wallet .common .client .utils .PublicMethed ;
@@ -21,6 +24,9 @@ public class HttpTestMortgageMechanism01 {
2124 private final String witnessKey = Configuration .getByPath ("testng.conf" )
2225 .getString ("witness.key1" );
2326 private final byte [] witnessAddress = PublicMethed .getFinalAddress (witnessKey );
27+ private final String witnessKey2 = Configuration .getByPath ("testng.conf" )
28+ .getString ("witness.key2" );
29+ private final byte [] witnessAddress2 = PublicMethed .getFinalAddress (witnessKey2 );
2430 Long amount = 2048000000L ;
2531 String description = Configuration .getByPath ("testng.conf" )
2632 .getString ("defaultParameter.assetDescription" );
@@ -32,6 +38,9 @@ public class HttpTestMortgageMechanism01 {
3238 .get (1 );
3339 private String httpSoliditynode = Configuration .getByPath ("testng.conf" )
3440 .getStringList ("httpnode.ip.list" ).get (2 );
41+ private ECKey ecKey1 = new ECKey (Utils .getRandom ());
42+ private byte [] dev001Address = ecKey1 .getAddress ();
43+ private String dev001Key = ByteArray .toHexString (ecKey1 .getPrivKeyBytes ());
3544
3645 /**
3746 * constructor.
@@ -42,18 +51,39 @@ public void test01GetBrokerage() {
4251 responseContent = HttpMethed .parseResponseContent (response );
4352 HttpMethed .printJsonContent (responseContent );
4453 Assert .assertEquals ("20" , responseContent .getString ("brokerage" ));
54+
55+ response = HttpMethed .getBrokerageOnVisible (httpnode , witnessAddress2 , "true" );
56+ responseContent = HttpMethed .parseResponseContent (response );
57+ HttpMethed .printJsonContent (responseContent );
58+ Assert .assertEquals ("20" , responseContent .getString ("brokerage" ));
59+
60+ response = HttpMethed .getBrokerageOnVisible (httpnode , fromAddress , "false" );
61+ responseContent = HttpMethed .parseResponseContent (response );
62+ HttpMethed .printJsonContent (responseContent );
63+ Assert .assertEquals ("20" , responseContent .getString ("brokerage" ));
4564 }
4665
47- /**
48- * constructor.
49- */
5066 @ Test (enabled = true , description = "GetBrokerage from solidity by http" )
5167 public void test02GetBrokerageFromSolidity () {
5268 HttpMethed .waitToProduceOneBlockFromSolidity (httpnode , httpSoliditynode );
5369 response = HttpMethed .getBrokerageFromSolidity (httpSoliditynode , witnessAddress );
5470 responseContent = HttpMethed .parseResponseContent (response );
5571 HttpMethed .printJsonContent (responseContent );
5672 Assert .assertEquals ("20" , responseContent .getString ("brokerage" ));
73+
74+ HttpMethed .waitToProduceOneBlockFromSolidity (httpnode , httpSoliditynode );
75+ response = HttpMethed
76+ .getBrokerageFromSolidityOnVisible (httpSoliditynode , witnessAddress2 , "true" );
77+ responseContent = HttpMethed .parseResponseContent (response );
78+ HttpMethed .printJsonContent (responseContent );
79+ Assert .assertEquals ("20" , responseContent .getString ("brokerage" ));
80+
81+ HttpMethed .waitToProduceOneBlockFromSolidity (httpnode , httpSoliditynode );
82+ response = HttpMethed
83+ .getBrokerageFromSolidityOnVisible (httpSoliditynode , fromAddress , "false" );
84+ responseContent = HttpMethed .parseResponseContent (response );
85+ HttpMethed .printJsonContent (responseContent );
86+ Assert .assertEquals ("20" , responseContent .getString ("brokerage" ));
5787 }
5888
5989 /**
@@ -66,9 +96,35 @@ public void test03UpdateBrokerage() {
6696 HttpMethed .waitToProduceOneBlock (httpnode );
6797
6898 //update brokerage
69- response = HttpMethed .updateBrokerage (httpnode , witnessAddress , 30L , witnessKey );
99+ response = HttpMethed .updateBrokerage (httpnode , witnessAddress , 11L , witnessKey );
100+ Assert .assertTrue (HttpMethed .verificationResult (response ));
101+ HttpMethed .waitToProduceOneBlock (httpnode );
102+
103+ response = HttpMethed .sendCoin (httpnode , fromAddress , witnessAddress2 , amount , testKey002 );
70104 Assert .assertTrue (HttpMethed .verificationResult (response ));
71105 HttpMethed .waitToProduceOneBlock (httpnode );
106+
107+ //update brokerage onvisible true
108+ response = HttpMethed
109+ .updateBrokerageOnVisible (httpnode , witnessAddress2 , 24L , witnessKey2 , "true" );
110+ Assert .assertTrue (HttpMethed .verificationResult (response ));
111+ HttpMethed .waitToProduceOneBlock (httpnode );
112+
113+ //update brokerage onvisible false
114+ response = HttpMethed
115+ .updateBrokerageOnVisible (httpnode , witnessAddress , 88L , witnessKey , "false" );
116+ Assert .assertTrue (HttpMethed .verificationResult (response ));
117+ HttpMethed .waitToProduceOneBlock (httpnode );
118+
119+ //update brokerage onvisible false for notwitness
120+ response = HttpMethed .sendCoin (httpnode , fromAddress , dev001Address , amount , testKey002 );
121+ Assert .assertTrue (HttpMethed .verificationResult (response ));
122+ HttpMethed .waitToProduceOneBlock (httpnode );
123+
124+ response = HttpMethed
125+ .updateBrokerageOnVisible (httpnode , dev001Address , 78L , dev001Key , "true" );
126+ Assert .assertFalse (HttpMethed .verificationResult (response ));
127+ HttpMethed .waitToProduceOneBlock (httpnode );
72128 }
73129
74130 /**
@@ -79,9 +135,19 @@ public void test04GetReward() {
79135 response = HttpMethed .getReward (httpnode , witnessAddress );
80136 responseContent = HttpMethed .parseResponseContent (response );
81137 HttpMethed .printJsonContent (responseContent );
82- Assert .assertTrue ((
83- new BigInteger (responseContent .getString ("reward" )).compareTo (new BigInteger ("0" )) == 0 )
84- || (new BigInteger (responseContent .getString ("reward" ))
138+ Assert .assertTrue ((new BigInteger (responseContent .getString ("reward" ))
139+ .compareTo (new BigInteger ("0" ))) == 1 );
140+
141+ response = HttpMethed .getRewardOnVisible (httpnode , witnessAddress2 , "true" );
142+ responseContent = HttpMethed .parseResponseContent (response );
143+ HttpMethed .printJsonContent (responseContent );
144+ Assert .assertTrue ((new BigInteger (responseContent .getString ("reward" ))
145+ .compareTo (new BigInteger ("0" ))) == 1 );
146+
147+ response = HttpMethed .getRewardOnVisible (httpnode , witnessAddress , "false" );
148+ responseContent = HttpMethed .parseResponseContent (response );
149+ HttpMethed .printJsonContent (responseContent );
150+ Assert .assertTrue ((new BigInteger (responseContent .getString ("reward" ))
85151 .compareTo (new BigInteger ("0" ))) == 1 );
86152 }
87153
@@ -93,9 +159,19 @@ public void test05GetRewardFromSolidity() {
93159 response = HttpMethed .getRewardFromSolidity (httpSoliditynode , witnessAddress );
94160 responseContent = HttpMethed .parseResponseContent (response );
95161 HttpMethed .printJsonContent (responseContent );
96- Assert .assertTrue ((
97- new BigInteger (responseContent .getString ("reward" )).compareTo (new BigInteger ("0" )) == 0 )
98- || (new BigInteger (responseContent .getString ("reward" ))
162+ Assert .assertTrue ((new BigInteger (responseContent .getString ("reward" ))
163+ .compareTo (new BigInteger ("0" ))) == 1 );
164+
165+ response = HttpMethed .getRewardFromSolidityOnVisible (httpSoliditynode , witnessAddress , "true" );
166+ responseContent = HttpMethed .parseResponseContent (response );
167+ HttpMethed .printJsonContent (responseContent );
168+ Assert .assertTrue ((new BigInteger (responseContent .getString ("reward" ))
169+ .compareTo (new BigInteger ("0" ))) == 1 );
170+
171+ response = HttpMethed .getRewardFromSolidityOnVisible (httpSoliditynode , witnessAddress , "false" );
172+ responseContent = HttpMethed .parseResponseContent (response );
173+ HttpMethed .printJsonContent (responseContent );
174+ Assert .assertTrue ((new BigInteger (responseContent .getString ("reward" ))
99175 .compareTo (new BigInteger ("0" ))) == 1 );
100176 }
101177
0 commit comments