@@ -73,6 +73,7 @@ public void test01EventQueryForTransactionFreezeBalanceV2() throws InterruptedEx
7373 public void run () {
7474 while (true ) {
7575 zmq .ZMQ .Event event = zmq .ZMQ .Event .read (moniter .base ());
76+ logger .info ("!!!!{} {}" , event .event , event .addr );
7677 System .out .println (event .event + " " + event .addr );
7778 }
7879 }
@@ -84,43 +85,50 @@ public void run() {
8485 Boolean sendTransaction = true ;
8586 Integer retryTimes = 40 ;
8687 transactionIdList = new ArrayList <>();
87- while (retryTimes -- > 0 ) {
88- if (sendTransaction ) {
89- String txid = PublicMethed .freezeBalanceV2AndGetTxId (freezeAccount ,
90- maxFeeLimit , 0 , freezeAccountKey , blockingStubFull );
88+ ArrayList <byte []> messageArray = new ArrayList <byte []>();
89+ Thread readLoopThread = new Thread (
90+ new Runnable () {
91+ public void run () {
92+ while (true ) {
93+ byte [] message = req .recv ();
94+ messageArray .add (message );
95+ }
96+ }
97+ });
98+ readLoopThread .start ();
99+ boolean success = false ;
91100
92- transactionIdList .add (txid );
93- PublicMethed .waitProduceNextBlock (blockingStubFull );
94- if (PublicMethed .getTransactionInfoById (txid , blockingStubFull ).get ().getResultValue ()
95- == 0 ) {
96- sendTransaction = false ;
97- }
101+ while (retryTimes -- > 0 ) {
102+ if (success ){
103+ break ;
98104 }
99- byte [] message = req .recv ();
100-
101-
102- if (message != null ) {
103- transactionMessage = new String (message );
104- logger .info ("transaction message:" + transactionMessage );
105-
106- if (!transactionMessage .equals ("transactionTrigger" )
107- && !transactionMessage .isEmpty ()
108- && transactionMessage .contains ("transactionId" )) {
109- JSONObject data = JSON .parseObject (transactionMessage );
110- String id = data .getString ("transactionId" );
111- logger .info ("trxId : " + id );
112- if (transactionIdList .contains (id )) {
113- logger .info ("find target tx, begin to Assert and abort loop" );
114- Assert .assertEquals (data .getString ("contractType" ), "FreezeBalanceV2Contract" );
115- Assert .assertEquals (data .getString ("fromAddress" ), Base58 .encode58Check (freezeAccount ));
116- Assert .assertEquals (data .getString ("assetName" ), "trx" );
117- Assert .assertEquals (data .getLong ("assetAmount" ), maxFeeLimit );
118- break ;
105+ String txid = PublicMethed .freezeBalanceV2AndGetTxId (freezeAccount ,
106+ maxFeeLimit , 0 , freezeAccountKey , blockingStubFull );
107+ transactionIdList .add (txid );
108+ PublicMethed .waitProduceNextBlock (blockingStubFull );
109+
110+ for (byte [] message : messageArray ){
111+ if (message != null ) {
112+ transactionMessage = new String (message );
113+ logger .info ("transaction message:" + transactionMessage );
114+
115+ if (!transactionMessage .equals ("transactionTrigger" )
116+ && !transactionMessage .isEmpty ()
117+ && transactionMessage .contains ("transactionId" )) {
118+ JSONObject data = JSON .parseObject (transactionMessage );
119+ String id = data .getString ("transactionId" );
120+ logger .info ("trxId : " + id );
121+ if (transactionIdList .contains (id )) {
122+ logger .info ("find target tx, begin to Assert and abort loop" );
123+ Assert .assertEquals (data .getString ("contractType" ), "FreezeBalanceV2Contract" );
124+ Assert .assertEquals (data .getString ("fromAddress" ), Base58 .encode58Check (freezeAccount ));
125+ Assert .assertEquals (data .getString ("assetName" ), "trx" );
126+ Assert .assertEquals (data .getLong ("assetAmount" ), maxFeeLimit );
127+ success = true ;
128+ break ;
129+ }
119130 }
120-
121131 }
122- } else {
123- sendTransaction = true ;
124132 }
125133 }
126134 logger .info ("Final transaction message:" + transactionMessage );
@@ -166,47 +174,58 @@ public void run() {
166174 req .setReceiveTimeOut (10000 );
167175 String transactionMessage = "" ;
168176 Boolean sendTransaction = true ;
169- Integer retryTimes = 20 ;
177+ Integer retryTimes = 40 ;
170178 transactionIdList = new ArrayList <>();
179+ ArrayList <byte []> messageArray = new ArrayList <byte []>();
180+ Thread readLoopThread = new Thread (
181+ new Runnable () {
182+ public void run () {
183+ while (true ) {
184+ byte [] message = req .recv ();
185+ messageArray .add (message );
186+ }
187+ }
188+ });
189+ readLoopThread .start ();
190+ boolean success = false ;
191+
171192 Long unfreezeAmount = 10000000L ;
172193 while (retryTimes -- > 0 ) {
173- if (sendTransaction ) {
174- String txid = PublicMethed .unFreezeBalanceV2AndGetTxId (freezeAccount ,
175- freezeAccountKey , unfreezeAmount , 0 , blockingStubFull );
176-
177- transactionIdList .add (txid );
178- PublicMethed .waitProduceNextBlock (blockingStubFull );
179- if (PublicMethed .getTransactionInfoById (txid , blockingStubFull ).get ().getResultValue ()
180- == 0 ) {
181- sendTransaction = false ;
182- }
194+ if (success ){
195+ break ;
183196 }
184- byte [] message = req .recv ();
185-
186-
187- if (message != null ) {
188- transactionMessage = new String (message );
189- logger .info ("transaction message:" + transactionMessage );
190-
191- if (!transactionMessage .equals ("transactionTrigger" )
192- && !transactionMessage .isEmpty ()
193- && transactionMessage .contains ("transactionId" )) {
194- JSONObject data = JSON .parseObject (transactionMessage );
195- String id = data .getString ("transactionId" );
196- if (transactionIdList .contains (id )) {
197- logger .info ("find target tx, begin to Assert and abort loop" );
198- logger .info ("trxId : " + data .getString ("transactionId" ));
199- Assert .assertEquals (data .getString ("contractType" ), "UnfreezeBalanceV2Contract" );
200- Assert .assertEquals (data .getString ("fromAddress" ), Base58 .encode58Check (freezeAccount ));
201- Assert .assertEquals (data .getString ("assetName" ), "trx" );
202- Assert .assertEquals (data .getLong ("assetAmount" ), unfreezeAmount );
203- break ;
197+ String txid = PublicMethed .unFreezeBalanceV2AndGetTxId (freezeAccount ,
198+ freezeAccountKey , unfreezeAmount , 0 , blockingStubFull );
199+
200+ transactionIdList .add (txid );
201+ PublicMethed .waitProduceNextBlock (blockingStubFull );
202+
203+
204+ for (byte [] message : messageArray ){
205+ if (message != null ) {
206+ transactionMessage = new String (message );
207+ logger .info ("transaction message:" + transactionMessage );
208+
209+ if (!transactionMessage .equals ("transactionTrigger" )
210+ && !transactionMessage .isEmpty ()
211+ && transactionMessage .contains ("transactionId" )) {
212+ JSONObject data = JSON .parseObject (transactionMessage );
213+ String id = data .getString ("transactionId" );
214+ if (transactionIdList .contains (id )) {
215+ logger .info ("find target tx, begin to Assert and abort loop" );
216+ logger .info ("trxId : " + data .getString ("transactionId" ));
217+ Assert .assertEquals (data .getString ("contractType" ), "UnfreezeBalanceV2Contract" );
218+ Assert .assertEquals (data .getString ("fromAddress" ), Base58 .encode58Check (freezeAccount ));
219+ Assert .assertEquals (data .getString ("assetName" ), "trx" );
220+ Assert .assertEquals (data .getLong ("assetAmount" ), unfreezeAmount );
221+ success = true ;
222+ break ;
223+ }
204224 }
205-
206225 }
207- } else {
208- sendTransaction = true ;
209226 }
227+
228+
210229 }
211230 logger .info ("Final transaction message:" + transactionMessage );
212231 logger .info ("retryTimes: " + retryTimes );
@@ -239,11 +258,12 @@ public void test03EventQueryForTransactionDelegateResource() throws InterruptedE
239258 PublicMethed .freezeBalanceV2AndGetTxId (freezeAccount ,
240259 maxFeeLimit , 0 , freezeAccountKey , blockingStubFull );
241260 PublicMethed .waitProduceNextBlock (blockingStubFull );
261+ ZMQ .Context context = ZMQ .context (1 );
262+ ZMQ .Socket req = context .socket (ZMQ .SUB );
242263
243264 List <String > transactionIdList = new ArrayList <>();
244265
245- ZMQ .Context context = ZMQ .context (1 );
246- ZMQ .Socket req = context .socket (ZMQ .SUB );
266+
247267
248268 req .subscribe ("transactionTrigger" );
249269 final ZMQ .Socket moniter = context .socket (ZMQ .PAIR );
@@ -264,45 +284,54 @@ public void run() {
264284 Boolean sendTransaction = true ;
265285 Integer retryTimes = 20 ;
266286 transactionIdList = new ArrayList <>();
287+ ArrayList <byte []> messageArray = new ArrayList <byte []>();
288+ Thread readLoopThread = new Thread (
289+ new Runnable () {
290+ public void run () {
291+ while (true ) {
292+ byte [] message = req .recv ();
293+ messageArray .add (message );
294+ }
295+ }
296+ });
297+ readLoopThread .start ();
298+ boolean success = false ;
299+
267300 Long delegateAmount = 10000000L ;
268301 while (retryTimes -- > 0 ) {
269- if (sendTransaction ) {
270- String txid = PublicMethed .delegateResourceV2AndGetTxId (freezeAccount ,
271- delegateAmount , 0 , receiverAddress , freezeAccountKey , blockingStubFull );
272-
273- transactionIdList .add (txid );
274- PublicMethed .waitProduceNextBlock (blockingStubFull );
275- if (PublicMethed .getTransactionInfoById (txid , blockingStubFull ).get ().getResultValue ()
276- == 0 ) {
277- sendTransaction = false ;
278- }
302+ if (success ) {
303+ break ;
279304 }
280- byte [] message = req .recv ();
281-
282-
283- if (message != null ) {
284- transactionMessage = new String (message );
285- logger .info ("transaction message:" + transactionMessage );
305+ String txid = PublicMethed .delegateResourceV2AndGetTxId (freezeAccount ,
306+ delegateAmount , 0 , receiverAddress , freezeAccountKey , blockingStubFull );
307+
308+ transactionIdList .add (txid );
309+ PublicMethed .waitProduceNextBlock (blockingStubFull );
310+
311+ for (byte [] message : messageArray ) {
312+ if (message != null ) {
313+ transactionMessage = new String (message );
314+ logger .info ("transaction message:" + transactionMessage );
315+
316+ if (!transactionMessage .equals ("transactionTrigger" )
317+ && !transactionMessage .isEmpty ()
318+ && transactionMessage .contains ("transactionId" )) {
319+ JSONObject data = JSON .parseObject (transactionMessage );
320+ String id = data .getString ("transactionId" );
321+ if (transactionIdList .contains (id )) {
322+ logger .info ("find target tx, begin to Assert and abort loop" );
323+ logger .info ("trxId : " + id );
324+ Assert .assertEquals (data .getString ("contractType" ), "DelegateResourceContract" );
325+ Assert .assertEquals (data .getString ("fromAddress" ), Base58 .encode58Check (freezeAccount ));
326+ Assert .assertEquals (data .getString ("toAddress" ), Base58 .encode58Check (receiverAddress ));
327+ Assert .assertEquals (data .getString ("assetName" ), "trx" );
328+ Assert .assertEquals (data .getLong ("assetAmount" ), delegateAmount );
329+ success = true ;
330+ break ;
331+ }
286332
287- if (!transactionMessage .equals ("transactionTrigger" )
288- && !transactionMessage .isEmpty ()
289- && transactionMessage .contains ("transactionId" )) {
290- JSONObject data = JSON .parseObject (transactionMessage );
291- String id = data .getString ("transactionId" );
292- if (transactionIdList .contains (id )) {
293- logger .info ("find target tx, begin to Assert and abort loop" );
294- logger .info ("trxId : " + id );
295- Assert .assertEquals (data .getString ("contractType" ), "DelegateResourceContract" );
296- Assert .assertEquals (data .getString ("fromAddress" ), Base58 .encode58Check (freezeAccount ));
297- Assert .assertEquals (data .getString ("toAddress" ), Base58 .encode58Check (receiverAddress ));
298- Assert .assertEquals (data .getString ("assetName" ), "trx" );
299- Assert .assertEquals (data .getLong ("assetAmount" ), delegateAmount );
300- break ;
301333 }
302-
303334 }
304- } else {
305- sendTransaction = true ;
306335 }
307336 }
308337 logger .info ("Final transaction message:" + transactionMessage );
0 commit comments