@Test public void toOptionalLong() { Collector<Long, ?, OptionalLong> collector = OptionalCollectors.toOptionalLong(); assertThat(Stream.<Long>empty().collect(collector)).isEmpty(); assertThat(Stream.of((Long) null).collect(collector)).isEmpty(); assertThat(Stream.of(1L).collect(collector)).hasValue(1L); assertThatThrownBy( () -> Stream.of(1L, 2L).collect(collector)) .isInstanceOf(IllegalStateException.class) .hasMessage("Multiple values for optional: ['1', '2', ...]"); assertThatThrownBy( () -> Stream.of(1L, null).collect(collector)) .isInstanceOf(IllegalStateException.class) .hasMessage("Multiple values for optional: ['1', null, ...]"); assertThatThrownBy( () -> Stream.of(null, 2L).collect(collector)) .isInstanceOf(IllegalStateException.class) .hasMessage("Multiple values for optional: [null, '2', ...]"); }
@Test public void testMapToOptionalLong() { assertThat(handle.select("select id from something where name = 'ford'") .collectInto(OptionalLong.class)) .isEmpty(); assertThat(handle.select("select null from something where name = 'eric'") .collectInto(OptionalLong.class)) .isEmpty(); assertThat(handle.select("select id from something where name = 'eric'") .collectInto(OptionalLong.class)) .hasValue(1L); assertThatThrownBy(() -> handle.select("select id from something") .collectInto(OptionalLong.class)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Multiple values for optional"); }
@Test public void testBindOptionalLong() { assertThat(handle.createQuery("SELECT :value") .bind("value", OptionalLong.empty()) .collectInto(OptionalLong.class)) .isEmpty(); assertThat(handle.createQuery("SELECT :value") .bind("value", OptionalLong.of(123)) .collectInto(OptionalLong.class)) .hasValue(123); }
@Test public void shouldNotReturnEmptyOptionalWhenBlockNumberNotSpecified() { final GenesisConfigOptions config = fromConfigOptions(emptyMap()); assertThat(config.getHomesteadBlockNumber()).isEmpty(); assertThat(config.getDaoForkBlock()).isEmpty(); assertThat(config.getTangerineWhistleBlockNumber()).isEmpty(); assertThat(config.getSpuriousDragonBlockNumber()).isEmpty(); assertThat(config.getByzantiumBlockNumber()).isEmpty(); assertThat(config.getConstantinopleBlockNumber()).isEmpty(); assertThat(config.getConstantinopleFixBlockNumber()).isEmpty(); }
@Test public void shouldReturnEmptyOptionalAsMaximumNonceWhenNoTransactionsPresent() { assertThat(transactions.getNextNonceForSender(SENDER1)).isEmpty(); }
@Test public void shouldSupportEmptyGenesisConfig() { final GenesisConfigOptions config = GenesisConfigFile.fromConfig("{}").getConfigOptions(); assertThat(config.isEthHash()).isFalse(); assertThat(config.isIbft()).isFalse(); assertThat(config.isClique()).isFalse(); assertThat(config.getHomesteadBlockNumber()).isEmpty(); }
@Test public void roundTripWithHash() { for (final boolean reverse : Arrays.asList(true, false)) { final Hash hash = Hash.hash(BytesValue.wrap(new byte[10])); final int skip = 10; final int maxHeaders = 128; final GetBlockHeadersMessage initialMessage = GetBlockHeadersMessage.create(hash, maxHeaders, skip, reverse); final MessageData raw = new RawMessage(EthPV62.GET_BLOCK_HEADERS, initialMessage.getData()); final GetBlockHeadersMessage message = GetBlockHeadersMessage.readFrom(raw); Assertions.assertThat(message.blockNumber()).isEmpty(); Assertions.assertThat(message.hash().get()).isEqualTo(hash); Assertions.assertThat(message.reverse()).isEqualTo(reverse); Assertions.assertThat(message.skip()).isEqualTo(skip); Assertions.assertThat(message.maxHeaders()).isEqualTo(maxHeaders); } }
@Test public void shouldReturnEmptyOptionalAsMaximumNonceWhenLastTransactionForSenderRemoved() { final Transaction transaction = transactionWithNonceAndSender(1, KEYS1); transactions.addRemoteTransaction(transaction); transactions.removeTransaction(transaction); assertThat(transactions.getNextNonceForSender(SENDER1)).isEmpty(); }