nonce as integer for preloaded contracts (#7850)

* fixes #7749
Signed-off-by: vaidikcode <vaidikbhardwaj00@gmail.com>

* tests
Signed-off-by: vaidikcode <vaidikbhardwaj00@gmail.com>

* spotless format fix
Signed-off-by: vaidikcode <vaidikbhardwaj00@gmail.com>

---------

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/7864/head
Vaidik 4 weeks ago committed by GitHub
parent ef9d1ab38e
commit 2054e12071
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      config/src/main/java/org/hyperledger/besu/config/GenesisReader.java
  2. 15
      config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java

@ -80,7 +80,9 @@ interface GenesisReader {
final var on = normalizeKeys((ObjectNode) entry.getValue());
return new GenesisAccount(
Address.fromHexString(entry.getKey()),
JsonUtil.getString(on, "nonce").map(ParserUtils::parseUnsignedLong).orElse(0L),
JsonUtil.getValueAsString(on, "nonce")
.map(ParserUtils::parseUnsignedLong)
.orElse(0L),
JsonUtil.getString(on, "balance")
.map(ParserUtils::parseBalance)
.orElse(Wei.ZERO),

@ -17,6 +17,7 @@ package org.hyperledger.besu.config;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.config.GenesisReader.ALLOCATION_FIELD;
import static org.hyperledger.besu.config.GenesisReader.CONFIG_FIELD;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
@ -27,6 +28,7 @@ import java.nio.file.Path;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@ -111,4 +113,17 @@ public class GenesisReaderTest {
entry.put("balance", balance.toShortHexString());
return entry;
}
@Test
void testNonceHandlingAsStringAndInteger() {
ObjectNode accountNode = JsonNodeFactory.instance.objectNode();
accountNode.put("nonce", 10);
String nonceAsStringFromInt = JsonUtil.getValueAsString(accountNode, "nonce").orElse("");
assertEquals("10", nonceAsStringFromInt, "Nonce should convert integer to string correctly");
accountNode.put("nonce", "20");
String nonceAsStringDirect = JsonUtil.getValueAsString(accountNode, "nonce").orElse("");
assertEquals("20", nonceAsStringDirect, "Nonce should keep string as string correctly");
}
}

Loading…
Cancel
Save