diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/util/BlockchainImporter.java b/pantheon/src/main/java/tech/pegasys/pantheon/util/BlockchainImporter.java index ff939cadd9..005ed11ab0 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/util/BlockchainImporter.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/util/BlockchainImporter.java @@ -174,6 +174,7 @@ public class BlockchainImporter extends BlockImporter { final ProtocolContext context = pantheonController.getProtocolContext(); final GenesisConfig genesis = pantheonController.getGenesisConfig(); checkNotNull(isSkipBlocks); + final BlockHeader genesisHeader = genesis.getBlock().getHeader(); final long startTime = System.currentTimeMillis(); long lapStartTime = startTime; @@ -227,6 +228,11 @@ public class BlockchainImporter extends BlockImporter { body = new BlockBody(rlp.readList(Transaction::readFrom), rlp.readList(headerReader)); rlp.leaveList(); receipts = rlp.readList(TransactionReceipt::readFrom); + if (header.getNumber() == genesisHeader.getNumber()) { + // Don't import genesis block + previousHeader = header; + continue; + } final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(header.getNumber()); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockchainImporterTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockchainImporterTest.java index f90d2cd0a7..c53e110fa3 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockchainImporterTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockchainImporterTest.java @@ -44,11 +44,18 @@ public final class BlockchainImporterTest { BlockchainImporter blockImporter = new BlockchainImporter(); @Test - public void blockImport() throws Exception { + public void importBlocksWithoutValidation() throws Exception { + blockImportTest(true); + } + + @Test + public void importBlocksWithValidation() throws Exception { + blockImportTest(false); + } + + private void blockImportTest(final boolean skipValidation) throws Exception { final URL importFileURL = - getClass() - .getClassLoader() - .getResource("tech/pegasys/pantheon/ethereum/jsonrpc/json-rpc-test.bin"); + getClass().getClassLoader().getResource("tech/pegasys/pantheon/util/blockchain-import.bin"); assertThat(importFileURL).isNotNull(); final Path source = new File(importFileURL.toURI()).toPath(); @@ -57,7 +64,7 @@ public final class BlockchainImporterTest { final URL genesisJsonUrl = getClass() .getClassLoader() - .getResource("tech/pegasys/pantheon/ethereum/jsonrpc/jsonRpcTestGenesis.json"); + .getResource("tech/pegasys/pantheon/util/blockchain-import-genesis-file.json"); assertThat(genesisJsonUrl).isNotNull(); final String genesisJson = Resources.toString(genesisJsonUrl, Charsets.UTF_8); final KeyPair keyPair = loadKeyPair(target); @@ -73,7 +80,7 @@ public final class BlockchainImporterTest { miningParams, keyPair); final BlockchainImporter.ImportResult result = - blockImporter.importBlockchain(source, ctrl, true, 1, 1, false, false, null); + blockImporter.importBlockchain(source, ctrl, skipValidation, 1, 1, false, false, null); System.out.println(source); System.out.println(target); diff --git a/pantheon/src/test/resources/tech/pegasys/pantheon/ethereum/jsonrpc/jsonRpcTestGenesis.json b/pantheon/src/test/resources/tech/pegasys/pantheon/util/blockchain-import-genesis-file.json similarity index 100% rename from pantheon/src/test/resources/tech/pegasys/pantheon/ethereum/jsonrpc/jsonRpcTestGenesis.json rename to pantheon/src/test/resources/tech/pegasys/pantheon/util/blockchain-import-genesis-file.json diff --git a/pantheon/src/test/resources/tech/pegasys/pantheon/ethereum/jsonrpc/json-rpc-test.bin b/pantheon/src/test/resources/tech/pegasys/pantheon/util/blockchain-import.bin similarity index 100% rename from pantheon/src/test/resources/tech/pegasys/pantheon/ethereum/jsonrpc/json-rpc-test.bin rename to pantheon/src/test/resources/tech/pegasys/pantheon/util/blockchain-import.bin