File tree Expand file tree Collapse file tree 2 files changed +13
-13
lines changed
main/java/org/tron/core/services/event
test/java/org/tron/core/event Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change 3939import org .tron .core .exception .BadItemException ;
4040import org .tron .core .services .event .bo .BlockEvent ;
4141import org .tron .core .services .event .bo .SmartContractTrigger ;
42+ import org .tron .core .services .jsonrpc .JsonRpcApiUtil ;
4243import org .tron .core .store .StoreFactory ;
4344import org .tron .protos .Protocol ;
4445import org .tron .protos .contract .SmartContractOuterClass ;
@@ -373,19 +374,7 @@ public List<TransactionLogTriggerCapsule> getTransactionLogTrigger(BlockCapsule
373374
374375 public long getEnergyPrice (long blockTime ) {
375376 String energyPriceHistory = manager .getDynamicPropertiesStore ().getEnergyPriceHistory ();
376-
377- String [] energyPrices = energyPriceHistory .split ("," );
378- String [] lastPrice = energyPrices [energyPrices .length - 1 ].split (":" );
379- long energyPrice = Long .parseLong (lastPrice [1 ]);
380-
381- for (int i = 1 ; i < energyPrices .length ; i ++) {
382- long effectiveTime = Long .parseLong (energyPrices [i ].split (":" )[0 ]);
383- if (blockTime < effectiveTime ) {
384- energyPrice = Long .parseLong (energyPrices [i - 1 ].split (":" )[1 ]);
385- break ;
386- }
387- }
388- return energyPrice ;
377+ return JsonRpcApiUtil .parseEnergyFee (blockTime , energyPriceHistory );
389378 }
390379
391380 public List <TransactionLogTriggerCapsule > getTransactionTriggers (BlockCapsule block ,
Original file line number Diff line number Diff line change @@ -150,6 +150,11 @@ public void test() throws Exception {
150150 });
151151 manager .pushBlock (blockCapsule );
152152
153+ // Set energy price history to test boundary cases
154+ manager .getDynamicPropertiesStore ().saveEnergyPriceHistory (
155+ manager .getDynamicPropertiesStore ().getEnergyPriceHistory ()
156+ + "," + time + ":210" );
157+
153158 EventPluginConfig config = new EventPluginConfig ();
154159 config .setSendQueueLength (1000 );
155160 config .setBindPort (5555 );
@@ -187,6 +192,12 @@ public void test() throws Exception {
187192 try {
188193 BlockEvent blockEvent = blockEventGet .getBlockEvent (1 );
189194 Assert .assertNotNull (blockEvent );
195+ Assert .assertEquals (1 , blockEvent .getTransactionLogTriggerCapsules ().size ());
196+
197+ // Here energy unit price should be 100 not 210,
198+ // cause block time is equal to 210`s effective time
199+ Assert .assertEquals (100 , blockEvent .getTransactionLogTriggerCapsules ()
200+ .get (0 ).getTransactionLogTrigger ().getEnergyUnitPrice ());
190201 } catch (Exception e ) {
191202 Assert .fail ();
192203 }
You can’t perform that action at this time.
0 commit comments