@Test public void shouldTolerateMissingDepositContract(@TempDir final File tempDir) throws IOException { final File networkFile = new File(tempDir, "network.yml"); assertThat(networkFile).doesNotExist(); final Bytes4 fork = dataStructureUtil.randomFork().getCurrent_version(); final Eth1Address eth1Address = null; assertThat(DatabaseNetwork.init(networkFile, fork, eth1Address)) .isEqualTo(new DatabaseNetwork(fork.toHexString().toLowerCase(), "")); assertThat(networkFile).exists(); }
public static DatabaseNetwork init( final File source, Bytes4 forkVersion, Eth1Address depositContract) throws IOException { final String forkVersionString = forkVersion.toHexString().toLowerCase(); final String depositContractString = depositContract == null ? "" : depositContract.toHexString().toLowerCase(); final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory().disable(WRITE_DOC_START_MARKER)); if (source.exists()) { final DatabaseNetwork databaseNetwork = objectMapper.readerFor(DatabaseNetwork.class).readValue(source); if (!forkVersionString.equals(databaseNetwork.forkVersion)) { throw new DatabaseStorageException( formatMessage("fork version", forkVersionString, databaseNetwork.forkVersion)); } if (databaseNetwork.depositContract != null && !databaseNetwork.depositContract.equals(depositContractString)) { throw new DatabaseStorageException( formatMessage( "deposit contract", depositContractString, databaseNetwork.depositContract)); } return databaseNetwork; } else { DatabaseNetwork databaseNetwork = new DatabaseNetwork(forkVersionString, depositContractString); objectMapper.writerFor(DatabaseNetwork.class).writeValue(source, databaseNetwork); return databaseNetwork; } }
DatabaseNetwork { public static DatabaseNetwork init( final File source, Bytes4 forkVersion, Eth1Address depositContract) throws IOException { final String forkVersionString = forkVersion.toHexString().toLowerCase(); final String depositContractString = depositContract == null ? "" : depositContract.toHexString().toLowerCase(); final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory().disable(WRITE_DOC_START_MARKER)); if (source.exists()) { final DatabaseNetwork databaseNetwork = objectMapper.readerFor(DatabaseNetwork.class).readValue(source); if (!forkVersionString.equals(databaseNetwork.forkVersion)) { throw new DatabaseStorageException( formatMessage("fork version", forkVersionString, databaseNetwork.forkVersion)); } if (databaseNetwork.depositContract != null && !databaseNetwork.depositContract.equals(depositContractString)) { throw new DatabaseStorageException( formatMessage( "deposit contract", depositContractString, databaseNetwork.depositContract)); } return databaseNetwork; } else { DatabaseNetwork databaseNetwork = new DatabaseNetwork(forkVersionString, depositContractString); objectMapper.writerFor(DatabaseNetwork.class).writeValue(source, databaseNetwork); return databaseNetwork; } } }
DatabaseNetwork { public static DatabaseNetwork init( final File source, Bytes4 forkVersion, Eth1Address depositContract) throws IOException { final String forkVersionString = forkVersion.toHexString().toLowerCase(); final String depositContractString = depositContract == null ? "" : depositContract.toHexString().toLowerCase(); final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory().disable(WRITE_DOC_START_MARKER)); if (source.exists()) { final DatabaseNetwork databaseNetwork = objectMapper.readerFor(DatabaseNetwork.class).readValue(source); if (!forkVersionString.equals(databaseNetwork.forkVersion)) { throw new DatabaseStorageException( formatMessage("fork version", forkVersionString, databaseNetwork.forkVersion)); } if (databaseNetwork.depositContract != null && !databaseNetwork.depositContract.equals(depositContractString)) { throw new DatabaseStorageException( formatMessage( "deposit contract", depositContractString, databaseNetwork.depositContract)); } return databaseNetwork; } else { DatabaseNetwork databaseNetwork = new DatabaseNetwork(forkVersionString, depositContractString); objectMapper.writerFor(DatabaseNetwork.class).writeValue(source, databaseNetwork); return databaseNetwork; } } @JsonCreator  DatabaseNetwork(
      @JsonProperty("fork_version") final String forkVersion,
      @JsonProperty("deposit_contract") final String depositContract); }
DatabaseNetwork { public static DatabaseNetwork init( final File source, Bytes4 forkVersion, Eth1Address depositContract) throws IOException { final String forkVersionString = forkVersion.toHexString().toLowerCase(); final String depositContractString = depositContract == null ? "" : depositContract.toHexString().toLowerCase(); final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory().disable(WRITE_DOC_START_MARKER)); if (source.exists()) { final DatabaseNetwork databaseNetwork = objectMapper.readerFor(DatabaseNetwork.class).readValue(source); if (!forkVersionString.equals(databaseNetwork.forkVersion)) { throw new DatabaseStorageException( formatMessage("fork version", forkVersionString, databaseNetwork.forkVersion)); } if (databaseNetwork.depositContract != null && !databaseNetwork.depositContract.equals(depositContractString)) { throw new DatabaseStorageException( formatMessage( "deposit contract", depositContractString, databaseNetwork.depositContract)); } return databaseNetwork; } else { DatabaseNetwork databaseNetwork = new DatabaseNetwork(forkVersionString, depositContractString); objectMapper.writerFor(DatabaseNetwork.class).writeValue(source, databaseNetwork); return databaseNetwork; } } @JsonCreator  DatabaseNetwork(
      @JsonProperty("fork_version") final String forkVersion,
      @JsonProperty("deposit_contract") final String depositContract); static DatabaseNetwork init(
      final File source, Bytes4 forkVersion, Eth1Address depositContract); @Override boolean equals(final Object o); @Override int hashCode(); }
DatabaseNetwork { public static DatabaseNetwork init( final File source, Bytes4 forkVersion, Eth1Address depositContract) throws IOException { final String forkVersionString = forkVersion.toHexString().toLowerCase(); final String depositContractString = depositContract == null ? "" : depositContract.toHexString().toLowerCase(); final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory().disable(WRITE_DOC_START_MARKER)); if (source.exists()) { final DatabaseNetwork databaseNetwork = objectMapper.readerFor(DatabaseNetwork.class).readValue(source); if (!forkVersionString.equals(databaseNetwork.forkVersion)) { throw new DatabaseStorageException( formatMessage("fork version", forkVersionString, databaseNetwork.forkVersion)); } if (databaseNetwork.depositContract != null && !databaseNetwork.depositContract.equals(depositContractString)) { throw new DatabaseStorageException( formatMessage( "deposit contract", depositContractString, databaseNetwork.depositContract)); } return databaseNetwork; } else { DatabaseNetwork databaseNetwork = new DatabaseNetwork(forkVersionString, depositContractString); objectMapper.writerFor(DatabaseNetwork.class).writeValue(source, databaseNetwork); return databaseNetwork; } } @JsonCreator  DatabaseNetwork(
      @JsonProperty("fork_version") final String forkVersion,
      @JsonProperty("deposit_contract") final String depositContract); static DatabaseNetwork init(
      final File source, Bytes4 forkVersion, Eth1Address depositContract); @Override boolean equals(final Object o); @Override int hashCode();  }