This repository was archived by the owner on Aug 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 370
Feat: Added an option to fast forward the ledger state #1196
Merged
GalRogozinski
merged 11 commits into
iotaledger:dev-localsnapshots
from
iotadevelopment:merge_fastforward
Nov 29, 2018
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0cea9ad
Feat: added an option to fast forward the ledger state
d7d6f7c
Docs: fixed a typo in the docs
de804a8
Refactor: renamed test methods to comply with codacy
475ed05
Refactor: refactored the tests and new methods
8816f42
Docs: fixed a typo in the docs
21c7440
Refactor: refactored the mock classes and the test
4e564dc
Refactor: renamed setup method
83c92d1
Refactor: refactored some code
75df251
Refactor: refactor according to requests
b12e923
Refactor: removed unused import
624bf53
Refactor: refactored some more code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/iota/iri/service/milestone/MilestoneService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.iota.iri; | ||
|
||
import com.iota.iri.controllers.TransactionViewModel; | ||
import com.iota.iri.model.Hash; | ||
import com.iota.iri.model.IntegerIndex; | ||
import com.iota.iri.model.StateDiff; | ||
import com.iota.iri.model.persistables.Milestone; | ||
import com.iota.iri.model.persistables.Transaction; | ||
import com.iota.iri.storage.Tangle; | ||
import com.iota.iri.utils.Pair; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Contains utilities that help to mock the retrieval of database entries from the tangle.<br /> | ||
* <br /> | ||
* Mocking the tangle allows us to write unit tests that perform much faster than spinning up a new database for every | ||
* test.<br /> | ||
*/ | ||
public class TangleMockUtils { | ||
//region [mockMilestone] /////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
/** | ||
* Registers a {@link Milestone} in the mocked tangle that can consequently be accessed by the tested classes.<br /> | ||
* <br /> | ||
* It first creates the {@link Milestone} with the given details and then mocks the retrieval methods of the tangle | ||
* to return this object. In addition to mocking the specific retrieval method for the given hash, we also mock the | ||
* retrieval method for the "latest" entity so the mocked tangle returns the elements in the order that they were | ||
* mocked / created (which allows the mocked tangle to behave just like a normal one).<br /> | ||
* <br /> | ||
* Note: We return the mocked object which allows us to set additional fields or modify it after "injecting" it into | ||
* the mocked tangle.<br /> | ||
* | ||
* @param tangle mocked tangle object that shall retrieve a milestone object when being queried for it | ||
* @param hash transaction hash of the milestone | ||
* @param index milestone index of the milestone | ||
* @return the Milestone object that be returned by the mocked tangle upon request | ||
*/ | ||
public static Milestone mockMilestone(Tangle tangle, Hash hash, int index) { | ||
Milestone milestone = new Milestone(); | ||
milestone.hash = hash; | ||
milestone.index = new IntegerIndex(index); | ||
|
||
try { | ||
Mockito.when(tangle.load(Milestone.class, new IntegerIndex(index))).thenReturn(milestone); | ||
Mockito.when(tangle.getLatest(Milestone.class, IntegerIndex.class)).thenReturn(new Pair<>(milestone.index, | ||
milestone)); | ||
} catch (Exception e) { | ||
// the exception can not be raised since we mock | ||
} | ||
|
||
return milestone; | ||
} | ||
|
||
//endregion //////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
//region [mockTransaction] ///////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
public static Transaction mockTransaction(Tangle tangle, Hash hash) { | ||
Transaction transaction = new Transaction(); | ||
transaction.bytes = new byte[0]; | ||
transaction.type = TransactionViewModel.FILLED_SLOT; | ||
transaction.parsed = true; | ||
|
||
try { | ||
Mockito.when(tangle.load(Transaction.class, hash)).thenReturn(transaction); | ||
Mockito.when(tangle.getLatest(Transaction.class, Hash.class)).thenReturn(new Pair<>(hash, transaction)); | ||
} catch (Exception e) { | ||
// the exception can not be raised since we mock | ||
} | ||
|
||
return transaction; | ||
} | ||
|
||
//endregion //////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
//region [mockStateDiff] /////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
public static StateDiff mockStateDiff(Tangle tangle, Hash hash, Map<Hash, Long> balanceDiff) { | ||
StateDiff stateDiff = new StateDiff(); | ||
stateDiff.state = balanceDiff; | ||
|
||
try { | ||
Mockito.when(tangle.load(StateDiff.class, hash)).thenReturn(stateDiff); | ||
Mockito.when(tangle.getLatest(StateDiff.class, Hash.class)).thenReturn(new Pair<>(hash, stateDiff)); | ||
} catch (Exception e) { | ||
// the exception can not be raised since we mock | ||
} | ||
|
||
return stateDiff; | ||
} | ||
|
||
//endregion //////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks nicer :-)