### Question:
ShaMap extends ShaMapInner { public ShaMap copy() { version = copies.incrementAndGet(); ShaMap copy = (ShaMap) copy(copies.incrementAndGet()); copy.copies = copies; return copy; } ShaMap();  ShaMap(boolean isCopy, int depth); ShaMap copy();  }### Answer:
@Test public void testCopyOnWrite() throws Exception { ShaMap sm = new ShaMap(); assertEquals(sm.hash(), H256("0")); ShaMap copy1 = sm.copy(); removeLeafTestHelper(copy1); sm.addLeaf(Leaf("01")); sm.addLeaf(Leaf("02")); sm.addLeaf(Leaf("023")); sm.addLeaf(Leaf("024")); assertEquals(copy1.hash(), Hash256.ZERO_256); ShaMap copy2 = sm.copy(); Hash256 copy2Hash = copy2.hash(); assertEquals(copy2Hash, sm.hash()); sm.removeLeaf(H256("01")); sm.removeLeaf(H256("02")); sm.removeLeaf(H256("023")); sm.removeLeaf(H256("024")); assertEquals(sm.hash(), Hash256.ZERO_256); removeLeafTestHelper(sm); copy2.invalidate(); assertEquals(copy2.hash(), copy2Hash); assertEquals(copy1.hash(), Hash256.ZERO_256); }