Skip to content

Commit c184c4a

Browse files
author
wubin1
committed
add more unit test for transactionRet
1 parent 208d85f commit c184c4a

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/main/java/org/tron/core/capsule/TransactionRetCapsule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public void addTransactionInfo(TransactionInfo result) {
4040

4141
@Override
4242
public byte[] getData() {
43+
if (Objects.isNull(transactionRet)) {
44+
return null;
45+
}
4346
return transactionRet.toByteArray();
4447
}
4548

src/main/java/org/tron/core/db/Manager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,10 @@ public synchronized BlockCapsule generateBlock(
13891389
tmpSeesion.merge();
13901390
// push into block
13911391
blockCapsule.addTransaction(trx);
1392-
transationRetCapsule.addTransactionInfo(result);
1392+
1393+
if (Objects.nonNull(result)) {
1394+
transationRetCapsule.addTransactionInfo(result);
1395+
}
13931396
if (fromPending) {
13941397
iterator.remove();
13951398
}

src/test/java/org/tron/core/db/TransactionRetStoreTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,19 @@ public void get() throws BadItemException {
7373
TransactionInfoCapsule resultCapsule = transactionRetStore.getTransactionInfo(transactionId);
7474
Assert.assertNotNull("get transaction ret store", resultCapsule);
7575
}
76+
77+
@Test
78+
public void put() {
79+
TransactionInfoCapsule transactionInfoCapsule = new TransactionInfoCapsule();
80+
transactionInfoCapsule.setId(transactionId);
81+
transactionInfoCapsule.setFee(1000L);
82+
transactionInfoCapsule.setBlockNumber(100L);
83+
transactionInfoCapsule.setBlockTimeStamp(200L);
84+
85+
TransactionRetCapsule transactionRetCapsule = new TransactionRetCapsule();
86+
transactionRetCapsule.addTransactionInfo(transactionInfoCapsule.getInstance());
87+
Assert.assertNull("put transaction info error", transactionRetStore.getUnchecked(transactionInfoCapsule.getId()));
88+
transactionRetStore.put(transactionInfoCapsule.getId(), transactionRetCapsule);
89+
Assert.assertNotNull("get transaction info error", transactionRetStore.getUnchecked(transactionInfoCapsule.getId()));
90+
}
7691
}

0 commit comments

Comments
 (0)