-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
735 additions
and
28 deletions.
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
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
versionNumber='1.11.0' | ||
versionNumber='1.12.0' | ||
// Remove org.ethereum.db.migrate.MigrateHeaderSourceTotalDiff with databaseVersion > 6 | ||
databaseVersion=6 |
64 changes: 64 additions & 0 deletions
64
ethereumj-core/src/test/java/org/ethereum/core/ChainTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.ethereum.core; | ||
|
||
import org.ethereum.core.genesis.GenesisJson; | ||
import org.ethereum.core.genesis.GenesisLoader; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.InputStream; | ||
import java.math.BigInteger; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author alexbraz | ||
* @since 29/03/2019 | ||
*/ | ||
public class ChainTest { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger("test"); | ||
|
||
Block genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream("/genesis/olympic.json")); | ||
GenesisJson genesisJson = GenesisLoader.loadGenesisJson((InputStream) getClass().getResourceAsStream("/genesis/olympic.json")); | ||
|
||
@Test | ||
public void testContainsBlock() { | ||
Chain c = new Chain(); | ||
c.add(genesis); | ||
assertEquals(genesis, c.getLast()); | ||
} | ||
|
||
@Test | ||
public void testBlockHashNotNull() { | ||
Chain c = new Chain(); | ||
c.add(genesis); | ||
assertNotNull(c.getLast().getHash()); | ||
} | ||
|
||
@Test | ||
public void testDifficultyGenesisCorrectLoadedAndConverted() { | ||
Chain c = new Chain(); | ||
c.add(genesis); | ||
assertEquals(new BigInteger(genesisJson.getDifficulty().replace("0x", ""), 16).intValue(), c.getLast().getDifficultyBI().intValue()); | ||
} | ||
|
||
@Test | ||
public void testParentOnTheChain() { | ||
Chain c = new Chain(); | ||
c.add(genesis); | ||
Block block = new Block(genesis.getHeader(), genesis.getTransactionsList(), null); | ||
assertFalse(c.isParentOnTheChain(block)); | ||
} | ||
|
||
@Test | ||
public void testParentOnTheChain2() { | ||
Chain c = new Chain(); | ||
c.add(genesis); | ||
assertFalse(c.isParentOnTheChain(genesis)); | ||
} | ||
|
||
|
||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
ethereumj-core/src/test/java/org/ethereum/core/PremineRawTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.ethereum.core; | ||
|
||
import org.junit.Test; | ||
|
||
import java.math.BigInteger; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author alexbraz | ||
* @since 29/03/2019 | ||
*/ | ||
public class PremineRawTest { | ||
|
||
@Test | ||
public void testPremineRawNotNull() { | ||
|
||
byte[] addr = "0xcf0f482f2c1ef1f221f09e3cf14122fce0424f94".getBytes(); | ||
PremineRaw pr = new PremineRaw(addr, BigInteger.ONE, Denomination.ETHER); | ||
|
||
assertTrue(pr.getDenomination() == Denomination.ETHER); | ||
assertEquals(pr.value, BigInteger.ONE); | ||
assertNotNull(pr.getAddr()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
ethereumj-core/src/test/java/org/ethereum/datasource/BatchSourceWriterTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.ethereum.datasource; | ||
|
||
import org.junit.Test; | ||
|
||
import java.math.BigInteger; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
/** | ||
* @author alexbraz | ||
* @since 29/03/2019 | ||
*/ | ||
public class BatchSourceWriterTest { | ||
|
||
@Test | ||
public void testFlush() { | ||
BatchSource batchSource = mock(BatchSource.class); | ||
BatchSourceWriter<String, BigInteger> bsw = new BatchSourceWriter(batchSource); | ||
bsw.put("KEY", BigInteger.ONE); | ||
assertTrue(bsw.flushImpl()); | ||
} | ||
|
||
@Test | ||
public void testValues() { | ||
BatchSource batchSource = mock(BatchSource.class); | ||
BatchSourceWriter<String, BigInteger> bsw = new BatchSourceWriter(batchSource); | ||
bsw.put("ONE", BigInteger.ONE); | ||
bsw.put("TEN", BigInteger.TEN); | ||
bsw.put("ZERO", BigInteger.ZERO); | ||
|
||
bsw.buf.forEach((K, v) -> { | ||
assertEquals(v, bsw.buf.get(K)); | ||
}); | ||
|
||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
ethereumj-core/src/test/java/org/ethereum/datasource/BlockReplayTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.ethereum.datasource; | ||
|
||
import org.ethereum.core.Block; | ||
import org.ethereum.core.Genesis; | ||
import org.ethereum.datasource.inmem.HashMapDB; | ||
import org.ethereum.db.IndexedBlockStore; | ||
import org.ethereum.db.TransactionStore; | ||
import org.ethereum.listener.BlockReplay; | ||
import org.ethereum.listener.EthereumListener; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.spongycastle.util.encoders.Hex; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static java.math.BigInteger.ZERO; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* @author alexbraz | ||
* @since 29/03/2019 | ||
*/ | ||
public class BlockReplayTest { | ||
private static final Logger logger = LoggerFactory.getLogger("test"); | ||
|
||
|
||
BlockReplay replay; | ||
EthereumListener listener; | ||
private List<Block> blocks = new ArrayList<>(); | ||
private BigInteger totDifficulty = ZERO; | ||
Block genesis = Genesis.getInstance(); | ||
|
||
@Before | ||
public void setup() throws URISyntaxException, IOException { | ||
URL scenario1 = ClassLoader | ||
.getSystemResource("blockstore/load.dmp"); | ||
|
||
File file = new File(scenario1.toURI()); | ||
List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); | ||
|
||
IndexedBlockStore indexedBlockStore = indexedBlockStore = new IndexedBlockStore(); | ||
indexedBlockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>()); | ||
|
||
TransactionStore txStore = new TransactionStore(new HashMapDB<>()); | ||
|
||
listener = mock(EthereumListener.class); | ||
|
||
replay = new BlockReplay(indexedBlockStore, txStore, listener, 0L); | ||
for (String blockRLP : strData) { | ||
|
||
Block block = new Block( | ||
Hex.decode(blockRLP)); | ||
|
||
if (block.getNumber() % 1000 == 0) | ||
logger.info("adding block.hash: [{}] block.number: [{}]", | ||
block.getShortHash(), | ||
block.getNumber()); | ||
|
||
blocks.add(block); | ||
totDifficulty = totDifficulty.add(block.getDifficultyBI()); | ||
indexedBlockStore.saveBlock(block, totDifficulty, true); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void testReplayBlock() { | ||
IndexedBlockStore i = mock(IndexedBlockStore.class); | ||
when(i.getChainBlockByNumber(anyLong())).thenReturn(genesis); | ||
TransactionStore txStore = new TransactionStore(new HashMapDB<>()); | ||
replay = new BlockReplay(i, txStore, listener, 0L); | ||
replay.replay(); | ||
|
||
verify(listener, times(1)).onBlock(any()); | ||
} | ||
|
||
@Test | ||
public void testListenerNoConnection() { | ||
replay.onNoConnections(); | ||
verify(listener, times(1)).onNoConnections(); | ||
|
||
replay.onSyncDone(null); | ||
verify(listener, times(1)).onSyncDone(any()); | ||
|
||
replay.onNodeDiscovered(any()); | ||
verify(listener, times(1)).onNodeDiscovered(any()); | ||
|
||
replay.onEthStatusUpdated(any(), any()); | ||
verify(listener, times(1)).onEthStatusUpdated(any(), any()); | ||
|
||
replay.onHandShakePeer(any(), any()); | ||
verify(listener, times(1)).onHandShakePeer(any(), any()); | ||
|
||
replay.onPeerAddedToSyncPool(any()); | ||
verify(listener, times(1)).onPeerAddedToSyncPool(any()); | ||
|
||
replay.onPeerDisconnect(anyString(), anyLong()); | ||
verify(listener, times(1)).onPeerDisconnect(anyString(), anyLong()); | ||
|
||
replay.onPendingStateChanged(any()); | ||
verify(listener, times(1)).onPendingStateChanged(any()); | ||
|
||
replay.onPendingTransactionUpdate(any(), any(), any()); | ||
verify(listener, times(1)).onPendingTransactionUpdate(any(), any(), any()); | ||
|
||
replay.onRecvMessage(any(), any()); | ||
verify(listener, times(1)).onRecvMessage(any(), any()); | ||
|
||
replay.onTransactionExecuted(any()); | ||
verify(listener, times(1)).onTransactionExecuted(any()); | ||
|
||
replay.onSendMessage(any(), any()); | ||
verify(listener, times(1)).onSendMessage(any(), any()); | ||
|
||
replay.onVMTraceCreated(anyString(), anyString()); | ||
verify(listener, times(1)).onVMTraceCreated(anyString(), anyString()); | ||
|
||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.