-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #438 store donation in transaction table. Add donation to the t…
…reasury amount during ledger state calculation. (#441) * feat: #438 store donation in transaction table. Add donation to the treasury amount during ledger state calculation. * fix: #438 fix sonatype warning
- Loading branch information
Showing
11 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...loxbean/cardano/yaci/store/transaction/storage/impl/TransactionStorageReaderImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.bloxbean.cardano.yaci.store.transaction.storage.impl; | ||
|
||
import com.bloxbean.cardano.yaci.store.transaction.domain.Txn; | ||
import com.bloxbean.cardano.yaci.store.transaction.storage.TransactionStorage; | ||
import com.bloxbean.cardano.yaci.store.transaction.storage.TransactionStorageReader; | ||
import com.bloxbean.cardano.yaci.store.transaction.storage.impl.mapper.TxnMapper; | ||
import com.bloxbean.cardano.yaci.store.transaction.storage.impl.mapper.TxnMapperImpl; | ||
import com.bloxbean.cardano.yaci.store.transaction.storage.impl.repository.TxnEntityRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
|
||
import java.util.List; | ||
|
||
import static com.bloxbean.cardano.client.common.ADAConversionUtil.adaToLovelace; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DataJpaTest | ||
class TransactionStorageReaderImplTest { | ||
|
||
@Autowired | ||
private TxnEntityRepository txnEntityRepository; | ||
|
||
private TransactionStorage transactionStorage; | ||
private TransactionStorageReader transactionStorageReader; | ||
|
||
private TxnMapper mapper; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
mapper = new TxnMapperImpl(); | ||
transactionStorageReader = new TransactionStorageReaderImpl(txnEntityRepository, mapper, null); | ||
transactionStorage = new TransactionStorageImpl(txnEntityRepository, mapper, null); | ||
} | ||
|
||
@Test | ||
void getTotalDonation() { | ||
Txn txn1 = Txn.builder() | ||
.txHash("0000000100000") | ||
.epoch(4) | ||
.treasuryDonation(adaToLovelace(30)) | ||
.build(); | ||
|
||
Txn txn2 = Txn.builder() | ||
.txHash("1000000100000") | ||
.epoch(4) | ||
.treasuryDonation(adaToLovelace(90)) | ||
.build(); | ||
|
||
Txn txn3 = Txn.builder() | ||
.txHash("2000000100000") | ||
.epoch(4) | ||
.build(); | ||
|
||
|
||
Txn txn4 = Txn.builder() | ||
.txHash("3000000100000") | ||
.epoch(5) | ||
.treasuryDonation(adaToLovelace(50)) | ||
.build(); | ||
|
||
Txn txn5 = Txn.builder() | ||
.txHash("4000000100000") | ||
.epoch(5) | ||
.treasuryDonation(adaToLovelace(10)) | ||
.build(); | ||
|
||
Txn txn6 = Txn.builder() | ||
.txHash("6000000100000") | ||
.epoch(6) | ||
.build(); | ||
|
||
|
||
transactionStorage.saveAll(List.of(txn1, txn2, txn3, txn4, txn5, txn6)); | ||
|
||
var epoch4Donation = transactionStorageReader.getTotalDonation(4); | ||
var epoch5Donation = transactionStorageReader.getTotalDonation(5); | ||
var epoch6Donation = transactionStorageReader.getTotalDonation(6); | ||
|
||
assertThat(epoch4Donation).isEqualTo(adaToLovelace(120)); | ||
assertThat(epoch5Donation).isEqualTo(adaToLovelace(60)); | ||
assertThat(epoch6Donation).isNull(); | ||
|
||
} | ||
} |