Skip to content

Commit

Permalink
close #200
Browse files Browse the repository at this point in the history
  • Loading branch information
M4rc0Russ0 committed Mar 6, 2024
1 parent 891f739 commit 49a63c8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,6 +83,10 @@ public int deleteUnspentBySlotGreaterThan(Long slot) {
return utxoRepository.deleteBySlotGreaterThan(slot);
}

public List<TxInput> findSpentBySlotGreaterThan(Long slot) {
return spentOutputRepository.findBySpentAtSlotGreaterThan(slot).stream().map(mapper::toTxInput).toList();
}

@Override
public int deleteSpentBySlotGreaterThan(Long slot) {
return spentOutputRepository.deleteBySpentAtSlotGreaterThan(slot);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TxInputEntity, UtxoId> {
int deleteBySpentAtSlotGreaterThan(Long slot);

List<TxInputEntity> findBySpentAtSlotGreaterThan(Long slot);
}

Original file line number Diff line number Diff line change
@@ -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<TxInput> spentBySlotGreaterThan = utxoStorage.findSpentBySlotGreaterThan(1000L);
List<TxInput> compoprbar = new ArrayList<>();
Assertions.assertEquals(spentBySlotGreaterThan,compoprbar);
}
}

0 comments on commit 49a63c8

Please sign in to comment.