1212import java .util .ArrayList ;
1313import java .util .List ;
1414import java .util .Map ;
15+ import java .util .Set ;
1516import java .util .concurrent .atomic .AtomicInteger ;
1617import java .util .stream .Collectors ;
1718import java .util .stream .IntStream ;
2021import org .junit .Assert ;
2122import org .junit .Before ;
2223import org .junit .Test ;
24+ import org .testng .collections .Sets ;
2325import org .tron .common .application .TronApplicationContext ;
2426import org .tron .common .crypto .ECKey ;
27+ import org .tron .common .runtime .RuntimeImpl ;
2528import org .tron .common .utils .ByteArray ;
2629import org .tron .common .utils .FileUtil ;
2730import org .tron .common .utils .JsonUtil ;
31+ import org .tron .common .utils .ReflectUtils ;
2832import org .tron .common .utils .Sha256Hash ;
2933import org .tron .common .utils .StringUtil ;
3034import org .tron .common .utils .Utils ;
3842import org .tron .core .capsule .TransactionCapsule ;
3943import org .tron .core .capsule .WitnessCapsule ;
4044import org .tron .core .config .DefaultConfig ;
45+ import org .tron .core .config .Parameter ;
4146import org .tron .core .config .args .Args ;
4247import org .tron .core .consensus .ConsensusService ;
48+ import org .tron .core .db .accountstate .AccountStateEntity ;
49+ import org .tron .core .db .accountstate .TrieService ;
50+ import org .tron .core .db .accountstate .storetrie .AccountStateStoreTrie ;
4351import org .tron .core .exception .AccountResourceInsufficientException ;
4452import org .tron .core .exception .BadBlockException ;
4553import org .tron .core .exception .BadItemException ;
6775import org .tron .core .store .ExchangeStore ;
6876import org .tron .core .store .ExchangeV2Store ;
6977import org .tron .core .store .IncrementalMerkleTreeStore ;
78+ import org .tron .core .store .StoreFactory ;
7079import org .tron .protos .Protocol .Account ;
7180import org .tron .protos .Protocol .Block ;
7281import org .tron .protos .Protocol .Transaction ;
@@ -142,6 +151,17 @@ public void updateRecentTransaction() throws Exception {
142151 0 , ByteString .copyFrom (new byte [64 ]));
143152 b .addTransaction (trx );
144153 dbManager .updateRecentTransaction (b );
154+ try {
155+ dbManager .consumeBandwidth (trx , new TransactionTrace (trx , StoreFactory .getInstance (),
156+ new RuntimeImpl ()));
157+ } catch (Exception e ) {
158+ Assert .assertTrue (e instanceof ContractValidateException );
159+ }
160+ dbManager .consumeMemoFee (trx , new TransactionTrace (trx , StoreFactory .getInstance (),
161+ new RuntimeImpl ()));
162+ Assert .assertTrue (dbManager .getTxListFromPending ().isEmpty ());
163+ Assert .assertNull (dbManager .getTxFromPending (trx .getTransactionId ().toString ()));
164+ Assert .assertEquals (0 , dbManager .getPendingSize ());
145165 Assert .assertEquals (1 , chainManager .getRecentTransactionStore ().size ());
146166 byte [] key = ByteArray .subArray (ByteArray .fromLong (1 ), 6 , 8 );
147167 byte [] value = chainManager .getRecentTransactionStore ().get (key ).getData ();
@@ -212,6 +232,9 @@ public void pushBlock() {
212232 } catch (Exception e ) {
213233 Assert .assertTrue ("pushBlock is error" , false );
214234 }
235+ TrieService trieService = context .getBean (TrieService .class );
236+ Assert .assertTrue (trieService .getFullAccountStateRootHash ().length > 0 );
237+ Assert .assertTrue (trieService .getSolidityAccountStateRootHash ().length > 0 );
215238
216239 if (isUnlinked ) {
217240 Assert .assertEquals ("getBlockIdByNum is error" ,
@@ -233,10 +256,50 @@ public void pushBlock() {
233256 } catch (ItemNotFoundException e ) {
234257 Assert .assertTrue (true );
235258 }
236-
259+ try {
260+ dbManager .getBlockChainHashesOnFork (blockCapsule2 .getBlockId ());
261+ } catch (Exception e ) {
262+ Assert .assertTrue (e instanceof NonCommonBlockException );
263+ }
237264 Assert .assertTrue ("hasBlocks is error" , chainManager .hasBlocks ());
238265 }
239266
267+ @ Test
268+ public void transactionTest () {
269+ TransactionCapsule trans0 = new TransactionCapsule (Transaction .newBuilder ()
270+ .setRawData (Transaction .raw .newBuilder ().setData (ByteString .copyFrom (
271+ new byte [Parameter .ChainConstant .BLOCK_SIZE + Constant .ONE_THOUSAND ]))).build (),
272+ ContractType .ShieldedTransferContract );
273+ ShieldContract .ShieldedTransferContract trx1 = ShieldContract .ShieldedTransferContract
274+ .newBuilder ()
275+ .setFromAmount (10 )
276+ .setToAmount (10 )
277+ .build ();
278+ TransactionCapsule trans = new TransactionCapsule (trx1 , ContractType .ShieldedTransferContract );
279+ try {
280+ dbManager .pushTransaction (trans0 );
281+ dbManager .pushTransaction (trans );
282+ } catch (Exception e ) {
283+ Assert .assertTrue (e instanceof TaposException );
284+ }
285+ dbManager .rePush (trans0 );
286+ ReflectUtils .invokeMethod (dbManager ,"filterOwnerAddress" ,
287+ new Class []{trans .getClass (), Set .class },trans , Sets .newHashSet ());
288+ Assert .assertNotNull (dbManager .getTxListFromPending ());
289+
290+ try {
291+ dbManager .validateTapos (trans );
292+ } catch (Exception e ) {
293+ Assert .assertTrue (e instanceof TaposException );
294+ }
295+ try {
296+ dbManager .pushVerifiedBlock (chainManager .getHead ());
297+ dbManager .getBlockChainHashesOnFork (chainManager .getHeadBlockId ());
298+ } catch (Exception e ) {
299+ Assert .assertTrue (e instanceof TaposException );
300+ }
301+ }
302+
240303 @ Test
241304 public void GetterInstanceTest () {
242305
@@ -260,6 +323,24 @@ public void GetterInstanceTest() {
260323
261324 }
262325
326+ @ Test
327+ public void entityTest () {
328+ AccountStateStoreTrie trie = context .getBean (AccountStateStoreTrie .class );
329+ Assert .assertNull (trie .getAccount ("" .getBytes ()));
330+ Assert .assertNull (trie .getAccount ("" .getBytes (), "" .getBytes ()));
331+ Assert .assertNull (trie .getSolidityAccount ("" .getBytes ()));
332+ Assert .assertTrue (trie .isEmpty ());
333+ AccountStateEntity entity = new AccountStateEntity ();
334+ AccountStateEntity parsedEntity = AccountStateEntity .parse ("" .getBytes ());
335+ Assert .assertTrue (parsedEntity != null );
336+ Assert .assertTrue (parsedEntity .getAccount () != null );
337+ Assert .assertTrue (org .tron .core .db .api .pojo .Account .of () != null );
338+ Assert .assertTrue (org .tron .core .db .api .pojo .AssetIssue .of () != null );
339+ Assert .assertTrue (org .tron .core .db .api .pojo .Block .of () != null );
340+ Assert .assertTrue (org .tron .core .db .api .pojo .Transaction .of () != null );
341+
342+ }
343+
263344 @ Test
264345 public void getHeadTest () {
265346 try {
0 commit comments