|
|
|
@ -46,8 +46,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
assertBlockDataIsStored(blockchain, genesisBlock, Collections.emptyList()); |
|
|
|
|
assertBlockIsHead(blockchain, genesisBlock); |
|
|
|
@ -62,12 +61,10 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
// Write to kv store
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
// Initialize a new blockchain store with kvStore that already contains data
|
|
|
|
|
blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
assertBlockDataIsStored(blockchain, genesisBlock, Collections.emptyList()); |
|
|
|
|
assertBlockIsHead(blockchain, genesisBlock); |
|
|
|
@ -82,10 +79,10 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
// Write to kv store
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
// Initialize a new blockchain store with same kvStore, but different genesis block
|
|
|
|
|
new DefaultMutableBlockchain(gen.genesisBlock(), kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
createBlockchain(kvStore, gen.genesisBlock()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -94,8 +91,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
final BlockOptions options = |
|
|
|
|
new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); |
|
|
|
@ -114,8 +110,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(Hash.ZERO); |
|
|
|
|
final Block newBlock = gen.block(options); |
|
|
|
@ -129,8 +124,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
final BlockOptions options = |
|
|
|
|
new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); |
|
|
|
@ -148,8 +142,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
chain.stream().map(gen::receipts).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); |
|
|
|
|
for (int i = 1; i < chain.size(); i++) { |
|
|
|
|
blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); |
|
|
|
|
} |
|
|
|
@ -174,8 +167,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
final List<List<TransactionReceipt>> blockReceipts = |
|
|
|
|
chain.stream().map(gen::receipts).collect(Collectors.toList()); |
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); |
|
|
|
|
for (int i = 1; i < chain.size(); i++) { |
|
|
|
|
blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); |
|
|
|
|
} |
|
|
|
@ -232,8 +224,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
final List<List<TransactionReceipt>> blockReceipts = |
|
|
|
|
chain.stream().map(gen::receipts).collect(Collectors.toList()); |
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); |
|
|
|
|
for (int i = 1; i < chain.size(); i++) { |
|
|
|
|
blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); |
|
|
|
|
} |
|
|
|
@ -331,8 +322,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
final List<List<TransactionReceipt>> blockReceipts = |
|
|
|
|
chain.stream().map(gen::receipts).collect(Collectors.toList()); |
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); |
|
|
|
|
for (int i = 1; i < chain.size(); i++) { |
|
|
|
|
blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); |
|
|
|
|
} |
|
|
|
@ -421,8 +411,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
final List<List<TransactionReceipt>> blockReceipts = |
|
|
|
|
chain.stream().map(gen::receipts).collect(Collectors.toList()); |
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); |
|
|
|
|
for (int i = 1; i < chain.size(); i++) { |
|
|
|
|
blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); |
|
|
|
|
} |
|
|
|
@ -475,8 +464,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
final List<List<TransactionReceipt>> blockReceipts = |
|
|
|
|
chain.stream().map(gen::receipts).collect(Collectors.toList()); |
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(chain.get(0), kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); |
|
|
|
|
for (int i = 1; i < chain.size(); i++) { |
|
|
|
|
blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); |
|
|
|
|
} |
|
|
|
@ -553,8 +541,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
final BlockDataGenerator gen = new BlockDataGenerator(); |
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
assertThat(blockchain.removeObserver(7)).isFalse(); |
|
|
|
|
} |
|
|
|
@ -565,8 +552,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
final long observerId = blockchain.observeBlockAdded((block, chain) -> {}); |
|
|
|
|
assertThat(blockchain.observerCount()).isEqualTo(1); |
|
|
|
@ -581,8 +567,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
blockchain.observeBlockAdded(null); |
|
|
|
|
} |
|
|
|
@ -593,8 +578,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
final long observerId1 = blockchain.observeBlockAdded((block, chain) -> {}); |
|
|
|
|
assertThat(blockchain.observerCount()).isEqualTo(1); |
|
|
|
@ -621,8 +605,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
final BlockOptions options = |
|
|
|
|
new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); |
|
|
|
@ -646,8 +629,7 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
|
|
|
|
|
final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); |
|
|
|
|
final Block genesisBlock = gen.genesisBlock(); |
|
|
|
|
final DefaultMutableBlockchain blockchain = |
|
|
|
|
new DefaultMutableBlockchain(genesisBlock, kvStore, MainnetBlockHashFunction::createHash); |
|
|
|
|
final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); |
|
|
|
|
|
|
|
|
|
final BlockOptions options = |
|
|
|
|
new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); |
|
|
|
@ -724,4 +706,12 @@ public class DefaultMutableBlockchainTest { |
|
|
|
|
// Check reported chainhead td
|
|
|
|
|
assertEquals(td, blockchain.getChainHead().getTotalDifficulty()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private DefaultMutableBlockchain createBlockchain( |
|
|
|
|
final KeyValueStorage kvStore, final Block genesisBlock) { |
|
|
|
|
return new DefaultMutableBlockchain( |
|
|
|
|
genesisBlock, |
|
|
|
|
new KeyValueStoragePrefixedKeyBlockchainStorage( |
|
|
|
|
kvStore, MainnetBlockHashFunction::createHash)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|