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