diff --git a/stores/utxo/src/main/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/UtxoStorageImpl.java b/stores/utxo/src/main/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/UtxoStorageImpl.java index 3e57d0b85..c8b6f4515 100644 --- a/stores/utxo/src/main/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/UtxoStorageImpl.java +++ b/stores/utxo/src/main/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/UtxoStorageImpl.java @@ -8,6 +8,7 @@ import com.bloxbean.cardano.yaci.store.utxo.storage.UtxoStorage; import com.bloxbean.cardano.yaci.store.utxo.storage.impl.mapper.UtxoMapper; import com.bloxbean.cardano.yaci.store.utxo.storage.impl.model.AddressUtxoEntity; +import com.bloxbean.cardano.yaci.store.utxo.storage.impl.model.TxInputEntity; import com.bloxbean.cardano.yaci.store.utxo.storage.impl.model.UtxoId; import com.bloxbean.cardano.yaci.store.utxo.storage.impl.repository.TxInputRepository; import com.bloxbean.cardano.yaci.store.utxo.storage.impl.repository.UtxoRepository; @@ -82,6 +83,10 @@ public int deleteUnspentBySlotGreaterThan(Long slot) { return utxoRepository.deleteBySlotGreaterThan(slot); } + public List findSpentBySlotGreaterThan(Long slot) { + return spentOutputRepository.findBySpentAtSlotGreaterThan(slot).stream().map(mapper::toTxInput).toList(); + } + @Override public int deleteSpentBySlotGreaterThan(Long slot) { return spentOutputRepository.deleteBySpentAtSlotGreaterThan(slot); diff --git a/stores/utxo/src/main/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/repository/TxInputRepository.java b/stores/utxo/src/main/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/repository/TxInputRepository.java index 5318f2869..7f7b4ef8b 100644 --- a/stores/utxo/src/main/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/repository/TxInputRepository.java +++ b/stores/utxo/src/main/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/repository/TxInputRepository.java @@ -1,12 +1,17 @@ package com.bloxbean.cardano.yaci.store.utxo.storage.impl.repository; +import com.bloxbean.cardano.yaci.store.utxo.storage.impl.model.AddressUtxoEntity; import com.bloxbean.cardano.yaci.store.utxo.storage.impl.model.TxInputEntity; import com.bloxbean.cardano.yaci.store.utxo.storage.impl.model.UtxoId; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface TxInputRepository extends JpaRepository { int deleteBySpentAtSlotGreaterThan(Long slot); + + List findBySpentAtSlotGreaterThan(Long slot); } diff --git a/stores/utxo/src/test/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/UtxoStorageImplTest.java b/stores/utxo/src/test/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/UtxoStorageImplTest.java new file mode 100644 index 000000000..1a559b047 --- /dev/null +++ b/stores/utxo/src/test/java/com/bloxbean/cardano/yaci/store/utxo/storage/impl/UtxoStorageImplTest.java @@ -0,0 +1,42 @@ +package com.bloxbean.cardano.yaci.store.utxo.storage.impl; + +import com.bloxbean.cardano.yaci.store.common.domain.TxInput; +import com.bloxbean.cardano.yaci.store.utxo.storage.impl.mapper.UtxoMapper; +import com.bloxbean.cardano.yaci.store.utxo.storage.impl.repository.TxInputRepository; +import com.bloxbean.cardano.yaci.store.utxo.storage.impl.repository.UtxoRepository; +import org.jooq.DSLContext; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + + +@DataJpaTest +class UtxoStorageImplTest { + + + @Autowired + private UtxoRepository utxoRepository; + @Autowired + private TxInputRepository spentOutputRepository; + @Mock + private DSLContext dsl; + @Mock + private UtxoCache utxoCache; + + @Test + public void findSpentBySlotGreaterThanEmpty() { + UtxoStorageImpl utxoStorage = new UtxoStorageImpl(utxoRepository, spentOutputRepository, dsl, utxoCache); + List spentBySlotGreaterThan = utxoStorage.findSpentBySlotGreaterThan(1000L); + List compoprbar = new ArrayList<>(); + Assertions.assertEquals(spentBySlotGreaterThan,compoprbar); + } +} \ No newline at end of file