@@ -176,25 +176,18 @@ describe('TronWeb.transactionBuilder', function () {
176176 ) ;
177177 } ) ;
178178
179- it ( 'should send 10 sun from default address to accounts[1] for more than 2 times in one block' , async function ( ) {
180- let firstBlockNum = '' ;
181- let loopTimes = 0 ;
182- for ( let i = 0 ; i < 100 ; i ++ ) {
183- loopTimes ++ ;
184- const txHeader = await tronWeb . trx . getCurrentRefBlockParams ( ) ;
185- txHeader . timestamp += new Date ( ) . getMilliseconds ( ) ; // to avoid txID duplication
179+ it ( 'should send 10 sun from default address to accounts[1] for 10 times in one block' , async function ( ) {
180+ const curTime = Date . now ( ) ;
181+ const txHeader = await tronWeb . trx . getCurrentRefBlockParams ( ) ;
182+ const originTimestamp = txHeader . timestamp ;
183+ for ( let i = 0 ; i < 10 ; i ++ ) {
184+ // to avoid txID duplication
185+ txHeader . timestamp = originTimestamp + Date . now ( ) - curTime ;
186186 const res = await broadcaster (
187187 tronWeb . transactionBuilder . sendTrx ( accounts . b58 [ 1 ] , 10 , undefined , { blockHeader : txHeader } )
188188 ) ;
189- if ( firstBlockNum === '' ) {
190- firstBlockNum = res . transaction . raw_data . ref_block_bytes ;
191- } else {
192- if ( firstBlockNum !== res . transaction . raw_data . ref_block_bytes ) break ;
193- }
194-
195189 assert . isTrue ( res . receipt . result ) ;
196190 }
197- assert . isAtLeast ( loopTimes , 2 , 'loopTimes is less than 2 times, should rerun' ) ;
198191 } ) ;
199192 } ) ;
200193
@@ -2355,8 +2348,8 @@ describe('TronWeb.transactionBuilder', function () {
23552348
23562349 const params = [
23572350 [ transactions [ 0 ] , accounts . hex [ 7 ] , { permissionId : 2 } ] ,
2358- [ transactions [ 1 ] , accounts . hex [ 7 ] ] ,
23592351 [ transactions [ 2 ] , accounts . hex [ 7 ] , { blockHeader : await tronWeb . trx . getCurrentRefBlockParams ( ) } ] ,
2352+ [ transactions [ 1 ] , accounts . hex [ 7 ] ] ,
23602353 ] ;
23612354 for ( const param of params ) {
23622355 const contractAddress = param [ 0 ] . contract_address ;
@@ -2518,12 +2511,11 @@ describe('TronWeb.transactionBuilder', function () {
25182511 const functionSelector = 'store(uint256)' ;
25192512 const parameter = [ { type : 'uint256' , value : 1 } ] ;
25202513 const options : TriggerConstantContractOptions = { } ;
2521- let firstBlockNum = '' ;
2522- let loopTimes = 0 ;
2523- for ( let i = 0 ; i < 100 ; i ++ ) {
2524- loopTimes ++ ;
2525- const txHeader = await tronWeb . trx . getCurrentRefBlockParams ( ) ;
2526- txHeader . timestamp += new Date ( ) . getMilliseconds ( ) ;
2514+ const curTime = Date . now ( ) ;
2515+ const txHeader = await tronWeb . trx . getCurrentRefBlockParams ( ) ;
2516+ const originTimestamp = txHeader . timestamp ;
2517+ for ( let i = 0 ; i < 10 ; i ++ ) {
2518+ txHeader . timestamp = originTimestamp + Date . now ( ) - curTime ; // ensure unique timestamp
25272519 options . blockHeader = txHeader ;
25282520 const tx = await tronWeb . transactionBuilder . triggerSmartContract (
25292521 contractAddress ,
@@ -2532,15 +2524,9 @@ describe('TronWeb.transactionBuilder', function () {
25322524 parameter ,
25332525 issuerAddress
25342526 ) ;
2535- if ( firstBlockNum === '' ) {
2536- firstBlockNum = tx . transaction . raw_data . ref_block_bytes ;
2537- } else {
2538- if ( firstBlockNum !== tx . transaction . raw_data . ref_block_bytes ) break ;
2539- }
25402527 const { receipt } = await broadcaster ( null , accounts . pks [ 6 ] , tx . transaction ) ;
25412528 assert . isTrue ( receipt . result ) ;
25422529 }
2543- assert . isAtLeast ( loopTimes , 2 , 'loopTimes is less than 2 times, should rerun' ) ;
25442530 } ) ;
25452531 } ) ;
25462532
0 commit comments