congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
BestBlock
Code IndexAdd Tabnine to your IDE (free)

How to use
BestBlock
in
io.yggdrash.core.net

Best Java code snippets using io.yggdrash.core.net.BestBlock (Showing top 10 results out of 315)

origin: yggdrash/yggdrash

private List<Proto.BestBlock> bestBlocksByPeer(Peer peer) {
  List<Proto.BestBlock> bestBlocks = new ArrayList<>();
  for (BestBlock bb : peer.getBestBlocks()) {
    Proto.BestBlock bestBlock = Proto.BestBlock.newBuilder()
        .setBranch(ByteString.copyFrom(bb.getBranchId().getBytes()))
        .setIndex(bb.getIndex()).build();
    bestBlocks.add(bestBlock);
  }
  return bestBlocks;
}
origin: yggdrash/yggdrash

  public static BestBlock of(BranchId branchId, long index) {
    BestBlock bestBlock = new BestBlock();
    bestBlock.setBranchId(branchId);
    bestBlock.setIndex(index);
    return bestBlock;
  }
}
origin: yggdrash/yggdrash

@Test
public void testBestBlock() {
  BestBlock bb = BestBlock.of(branchId, 0);
  assert bb.getBranchId().equals(branchId);
  assert bb.getIndex() == 0;
}
origin: yggdrash/yggdrash

  private BestBlock toBestBlock(Proto.BestBlock bestBlock) {
    BranchId branchId = BranchId.of(bestBlock.getBranch().toByteArray());
    long index = bestBlock.getIndex();
    return BestBlock.of(branchId, index);
  }
}
origin: yggdrash/yggdrash

  @Test
  public void shouldBeUniqueSameBranchInTheList() {
    // arrange
    BestBlock bb1 = BestBlock.of(branchId, 0);
    BestBlock bb2 = BestBlock.of(branchId, 2);
    assert bb1.hashCode() == bb2.hashCode();
    assert bb1.equals(bb2);

    // act
    Set<BestBlock> bestBlocks = new HashSet<>();
    bestBlocks.add(bb1);
    bestBlocks.add(bb2);

    // assert
    assert bestBlocks.size() == 1;

    // act again
    bestBlocks.add(BestBlock.of(TestConstants.YEED, 0));

    // assert again
    assert bestBlocks.size() == 2;

  }
}
origin: yggdrash/yggdrash

@Override
public boolean equals(Object o) {
  if (this == o) {
    return true;
  }
  if (o == null || getClass() != o.getClass()) {
    return false;
  }
  BestBlock bestBlock = (BestBlock) o;
  return branchId.equals(bestBlock.getBranchId());
}
origin: yggdrash/yggdrash

  @Test
  public void testBestBlock() {
    // arrange
    Peer peer = Peer.valueOf("ynode://75bff16c@127.0.0.1:32918");
    BestBlock bb = BestBlock.of(TestConstants.STEM, 0);

    // act
    peer.updateBestBlock(bb);

    //assert
    assertThat(peer.getBestBlocks()).containsOnly(bb);
  }
}
origin: yggdrash/yggdrash

@Test
public void chainedBlock() {
  BlockHusk genesis = BlockChainTestUtils.genesisBlock();
  peerHandlerGroup.chainedBlock(BlockChainTestUtils.genesisBlock());
  for (BestBlock bestBlock : OWNER.getBestBlocks()) {
    assert !bestBlock.getBranchId().equals(genesis.getBranchId()) ||
        bestBlock.getIndex() == genesis.getIndex();
  }
}
origin: yggdrash/yggdrash

@Test
public void findPeers() {
  doAnswer((invocationOnMock) -> {
    StreamObserver<Proto.BlockList> argument = invocationOnMock.getArgument(1);
    argument.onNext(null);
    argument.onCompleted();
    return null;
  }).when(peerService).findPeers(findPeersRequestCaptor.capture(), any());
  Peer owner = Peer.valueOf("ynode://75bff16c@127.0.0.1:32918");
  owner.updateBestBlock(BestBlock.of(TestConstants.STEM, 0));
  peerHandler.findPeers(owner);
  verify(peerService).findPeers(findPeersRequestCaptor.capture(), any());
  assertEquals("127.0.0.1", findPeersRequestCaptor.getValue().getIp());
  assertEquals(32918, findPeersRequestCaptor.getValue().getPort());
  Proto.BestBlock bestBlock = findPeersRequestCaptor.getValue().getBestBlocks(0);
  assertArrayEquals(TestConstants.STEM.getBytes(), bestBlock.getBranch().toByteArray());
  assertEquals(0, bestBlock.getIndex());
}
origin: yggdrash/yggdrash

  @Test
  public void testUpdatedWithLatestPeer() {
    // arrange
    Peer newPeerWithBestBlock = Peer.valueOf(peer1.getYnodeUri());
    newPeerWithBestBlock.updateBestBlock(BestBlock.of(TestConstants.STEM, 0));

    bucket.addPeer(peer1);
    assert bucket.findByPeer(peer1).getBestBlocks().size() == 0;

    // act
    bucket.addPeer(newPeerWithBestBlock);

    // assert
    assert bucket.getPeers().size() == 1;
    assert bucket.findByPeer(peer1).getBestBlocks().size() == 1;
  }
}
io.yggdrash.core.netBestBlock

Most used methods

  • getBranchId
  • of
  • getIndex
  • <init>
  • equals
  • hashCode
  • setBranchId
  • setIndex

Popular in Java

  • Making http requests using okhttp
  • addToBackStack (FragmentTransaction)
  • getSupportFragmentManager (FragmentActivity)
  • onCreateOptionsMenu (Activity)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • JFileChooser (javax.swing)
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now