Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
stops submitting zero val bundles to the spent addresses service
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-moser committed Sep 11, 2019
1 parent 490bf73 commit 8f2a242
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public void persistSpentAddresses(Collection<TransactionViewModel> transactions)
}

public void persistValidatedSpentAddressesAsync(Collection<TransactionViewModel> transactions) {
if(transactions.stream().noneMatch(tx -> tx.value() < 0)){
return;
}
asyncSpentAddressesPersistor.submit(() -> {
try {
List<Hash> spentAddresses = transactions.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.iota.iri.service.spentaddresses.impl;

import com.iota.iri.BundleValidator;
import com.iota.iri.TangleMockUtils;
import com.iota.iri.controllers.TransactionViewModel;
import com.iota.iri.service.snapshot.SnapshotProvider;
import com.iota.iri.service.spentaddresses.SpentAddressesProvider;
import com.iota.iri.storage.Tangle;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

public class SpentAddressesServiceImplTest {

@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();

@Mock
private Tangle tangle;

@Mock
private BundleValidator bundleValidator;

@Mock
private SnapshotProvider snapshotProvider;

@Mock
private SpentAddressesProvider spentAddressesProvider;

@Test
public void doesntPersistZeroValueBundles() throws Exception {
SpentAddressesServiceImpl spentAddressesService = new SpentAddressesServiceImpl();
spentAddressesService.init(tangle, snapshotProvider, spentAddressesProvider, bundleValidator, null);
List<TransactionViewModel> bundle = TangleMockUtils.mockValidBundle(tangle, bundleValidator, 1);
spentAddressesService.persistValidatedSpentAddressesAsync(bundle);
verify(spentAddressesProvider, never()).saveAddressesBatch(any());
}
}

0 comments on commit 8f2a242

Please sign in to comment.