BlocksManager { public synchronized boolean addOperation(OpOperation op) { if (blockchain == null) { return false; } Metric m = mBlockAddOpp.start(); op.makeImmutable(); boolean existing = dataManager.validateExistingOperation(op); if (!existing) { dataManager.insertOperation(op); } boolean added = false; try { added = blockchain.addOperation(op); } finally { if (!added && !existing) { dataManager.removeOperations(Collections.singleton(op.getHash())); } m.capture(); } return added; }  String getServerPrivateKey(); String getServerUser(); KeyPair getServerLoginKeyPair(); boolean isBlockCreationOn(); boolean isReplicateOn(); String getReplicateUrl(); synchronized void setReplicateOn(boolean on); synchronized void setBlockCreationOn(boolean on); synchronized void init(MetadataDb metadataDB, OpBlockChain initBlockchain); synchronized boolean unlockBlockchain(); synchronized boolean lockBlockchain(String msg); synchronized boolean validateOperation(OpOperation op); synchronized boolean removeOrphanedBlock(String blockHash); synchronized boolean addOperation(OpOperation op); synchronized OpBlock createBlock(); synchronized OpBlock createBlock(double minCapacity); synchronized boolean compact(); synchronized boolean clearQueue(); synchronized boolean replicate(); synchronized boolean replicateOneBlock(OpBlock block); synchronized Set<String> removeQueueOperations(Set<String> operationsToDelete); synchronized void bootstrap(String serverName, KeyPair serverLoginKeyPair); synchronized boolean revertOneBlock(); synchronized boolean revertSuperblock(); OpBlockChain getBlockchain(); Map<String, OpBlock> getOrphanedBlocks(); String getCurrentStateDescription(); String getCurrentState(); boolean isBlockchainPaused(); OpOperation generateHashAndSign(OpOperation op, KeyPair... keyPair); KeyPair getLoginKeyPairFromPwd(String name, String pwd); KeyPair getLoginKeyPair(String name, String privateKey); OpObject getLoginObj(String nickname); List<String> getBootstrapList(); Collection<OpIndexColumn> getIndicesForType(String type); OpIndexColumn getIndex(String type, String indexId); void setBootstrapList(List<String> bootstrapList); double getQueueCapacity(); Map<String, Map<String, OpIndexColumn>> getIndices(); static final String BOOT_STD_OPS_DEFINTIONS; static final String BOOT_STD_ROLES; static final String BOOT_STD_VALIDATION; @Value("${opendb.mgmt.publicKey}")
	private String serverPublicKey; }
@Test(expected = BlockchainValidationException.class) public void testVoteForFinishedVoteOp() throws FailedVerificationException { testFinishingVotingProcess(); OpOperation notValidVote = generateTwoVoteOperations().get(0); notValidVote.putObjectValue("hash", "a651b7887142a33cfd57117be59c0d01916e52479fa41cc6a7896bb1491ed6f5"); blocksManager.addOperation(notValidVote); }
@Test(expected = BlockchainValidationException.class) public void testAddFinishVoteOperationWithNotSameEditOp() throws FailedVerificationException { testVotingProcessForVoteOperation(); OpOperation finalOp = generateFinalOpWithRef(); finalOp.getEdited().clear(); finalOp.addEdited(getNotValidEditObj()); blocksManager.addOperation(finalOp); }
@Test public void testRemovingObject() throws FailedVerificationException { for (OpOperation op : generateStartOperationAndObject()) { assertTrue(blocksManager.addOperation(op)); } OpObject object = blockChain.getObjectByName(OP_ID, OBJ_ID); assertNotNull(object); assertTrue(blocksManager.addOperation(generateRemoveOp(OBJ_ID))); assertFalse(blockChain.getQueueOperations().isEmpty()); object = blockChain.getObjectByName(OP_ID, OBJ_ID); assertNull(object); }
@Test(expected = BlockchainValidationException.class) public void testRemovingNotExistingObject() throws FailedVerificationException { for (OpOperation op : generateStartOperationAndObject()) { assertTrue(blocksManager.addOperation(op)); } OpObject object = blockChain.getObjectByName(OP_ID, OBJ_ID + 1); assertNull(object); blocksManager.addOperation(generateRemoveOp(OBJ_ID + 1)); }
@Test public void testCreatingVoteOperation() throws FailedVerificationException { for (OpOperation op : generateStartOperationAndObject()) { blocksManager.addOperation(op); } blocksManager.addOperation(generateVoteObject()); OpObject voteObj = blockChain.getObjectByName(OP_VOTE, VOTE_OBJ_ID); assertNotNull(voteObj); assertEquals(F_OPEN, voteObj.getFieldByExpr(F_STATE)); }
@Test public void testVotingProcessForVoteOperation() throws FailedVerificationException { testCreatingVoteOperation(); for (OpOperation op : generateTwoVoteOperations()) { blocksManager.addOperation(op); } OpObject voteObj = blockChain.getObjectByName(OP_VOTE, VOTE_OBJ_ID); assertNotNull(voteObj); Map<List<String>, Object> votes = (Map<List<String>, Object>) voteObj.getFieldByExpr(F_VOTES); assertEquals(2, votes.size()); }
@Test @Ignore public void testFinishingVotingProcess() throws FailedVerificationException { testVotingProcessForVoteOperation(); blocksManager.addOperation(generateFinalOpWithRef()); OpObject editedObj = blockChain.getObjectByName(OP_ID, OBJ_ID); assertNotNull(editedObj); OpObject voteObj = blockChain.getObjectByName(OP_VOTE, VOTE_OBJ_ID); assertNotNull(voteObj); assertEquals(F_FINAL, voteObj.getFieldByExpr(F_STATE)); assertNull(editedObj.getFieldByExpr("lat")); assertEquals(12346L, editedObj.getFieldByExpr("lon")); }
@Test(expected = BlockchainValidationException.class) public void testFinishingVotingProcessWithNotValidRef() throws FailedVerificationException { testVotingProcessForVoteOperation(); OpOperation finalOp = generateFinalOpWithRef(); TreeMap<String, Object> refVote = new TreeMap<>(); refVote.put("vote", Arrays.asList(OP_VOTE, "")); finalOp.putObjectValue("ref", refVote); blocksManager.addOperation(finalOp); }