@Test public void testStorage_existing() throws Exception { DiskBlockStore store = new DiskBlockStore(params, temp); // Check the first block in a new store is the genesis block. StoredBlock genesis = store.getChainHead(); // Test locking try { store = new DiskBlockStore(params, temp); fail(); } catch (BlockStoreException ex) { // expected } store.close(); // Reopen. store = new DiskBlockStore(params, temp); // Build a new block. StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader()); store.put(b1); store.setChainHead(b1); store.close(); // Check we can get it back out again if we reopen the store. store = new DiskBlockStore(params, temp); StoredBlock b2 = store.get(b1.getHeader().getHash()); assertEquals(b1, b2); // Check the chain head was stored correctly also. assertEquals(b1, store.getChainHead()); store.close(); }
@Test public void testStorage() throws Exception { DiskBlockStore store = new DiskBlockStore(params, temp); // Check the first block in a new store is the genesis block. StoredBlock genesis = store.getChainHead(); assertEquals(params.genesisBlock, genesis.getHeader()); // Build a new block. StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader()); store.put(b1); store.setChainHead(b1); store.close(); // Check we can get it back out again if we rebuild the store object. store = new DiskBlockStore(params, temp); StoredBlock b2 = store.get(b1.getHeader().getHash()); assertEquals(b1, b2); // Check the chain head was stored correctly also. assertEquals(b1, store.getChainHead()); store.close(); }