debug_accountAt - fixed issue with contract code (#3518)

* fixed bug with contract code > 32 bytes

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/3520/head
Sally MacFarlane 3 years ago committed by GitHub
parent a86274fcd0
commit 6e62e78fa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 19
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java
  3. 18
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAtTest.java

@ -8,6 +8,7 @@
### Bug Fixes
- Reject locally-sourced transactions below the minimum gas price when not mining. [#3397](https://github.com/hyperledger/besu/pull/3397)
- Fixed bug with contract address supplied to `debug_accountAt` [#3518](https://github.com/hyperledger/besu/pull/3518)
## 22.1.1

@ -39,6 +39,8 @@ import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import org.apache.tuweni.bytes.Bytes;
public class DebugAccountAt extends AbstractBlockParameterOrBlockHashMethod {
private final Supplier<BlockTracer> blockTracerSupplier;
@ -116,11 +118,20 @@ public class DebugAccountAt extends AbstractBlockParameterOrBlockHashMethod {
requestContext.getRequest().getId(), JsonRpcError.NO_ACCOUNT_FOUND);
}
return debugAccountAtResult(
account.get().getCode(),
Quantity.create(account.get().getNonce()),
Quantity.create(account.get().getBalance()),
Quantity.create(account.get().getCodeHash()));
}
protected ImmutableDebugAccountAtResult debugAccountAtResult(
final Bytes code, final String nonce, final String balance, final String codeHash) {
return ImmutableDebugAccountAtResult.builder()
.code(Quantity.create(account.get().getCode()))
.nonce(Quantity.create(account.get().getNonce()))
.balance(Quantity.create(account.get().getBalance()))
.codehash(Quantity.create(account.get().getCodeHash()))
.code(code.isEmpty() ? "0x0" : code.toHexString())
.nonce(nonce)
.balance(balance)
.codehash(codeHash)
.build();
}
}

@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionT
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableDebugAccountAtResult;
import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;
@ -32,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.Transaction;
import java.util.Collections;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -165,4 +167,20 @@ public class DebugAccountAtTest {
Assertions.assertThat(((JsonRpcErrorResponse) response).getError())
.isEqualByComparingTo(JsonRpcError.NO_ACCOUNT_FOUND);
}
@Test
public void testResult() {
final String codeString =
"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b27b880414610030575b";
final Bytes code = Bytes.fromHexString(codeString);
final String nonce = "0x1";
final String balance = "0xffff";
final String codeHash = "0xf5f334d41776ed2828fc910d488a05c57fe7c2352aab2d16e30539d7726e1562";
ImmutableDebugAccountAtResult result =
debugAccountAt.debugAccountAtResult(code, nonce, balance, codeHash);
Assertions.assertThat(result.getBalance()).isEqualTo(balance);
Assertions.assertThat(result.getNonce()).isEqualTo(nonce);
Assertions.assertThat(result.getCode()).isEqualTo(codeString);
Assertions.assertThat(result.getCodehash()).isEqualTo(codeHash);
}
}

Loading…
Cancel
Save