Skip to content

Commit

Permalink
Run estimate gas lazily in web3 tests
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Sheehy <[email protected]>
  • Loading branch information
steven-sheehy committed Jan 11, 2025
1 parent c1fa7bc commit c2b3343
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.math.BigInteger;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -85,7 +86,7 @@ public class TestWeb3jService implements Web3jService {
private Address sender = Address.fromHexString("");
private boolean isEstimateGas = false;
private String transactionResult;
private String estimatedGas;
private Supplier<String> estimatedGas;
private long value = 0L;
private boolean persistContract = true;
private byte[] contractRuntime;
Expand All @@ -101,6 +102,10 @@ public TestWeb3jService(ContractExecutionService contractExecutionService, Domai
this.web3j = Web3j.build(this);
}

public String getEstimatedGas() {
return estimatedGas != null ? estimatedGas.get() : null;
}

public void setSender(String sender) {
this.sender = Address.fromHexString(sender);
}
Expand All @@ -110,6 +115,7 @@ public void setEstimateGas(final boolean isEstimateGas) {
}

public void reset() {
this.estimatedGas = null;
this.isEstimateGas = false;
this.contractRuntime = null;
this.persistContract = true;
Expand Down Expand Up @@ -210,7 +216,8 @@ private EthSendTransaction sendEthCall(RawTransaction rawTransaction, String tra
res.setId(request.getId());
res.setJsonrpc(request.getJsonrpc());

transactionResult = estimatedGas = mirrorNodeResult;
transactionResult = mirrorNodeResult;
estimatedGas = () -> mirrorNodeResult;
return res;
}

Expand All @@ -227,7 +234,7 @@ private EthCall ethCall(List<Transaction> reqParams, Request request) {
// Then get the estimated gas
final var serviceParametersForEstimate =
serviceParametersForExecutionSingle(transaction, ETH_ESTIMATE_GAS, blockType);
estimatedGas = contractExecutionService.processCall(serviceParametersForEstimate);
estimatedGas = () -> contractExecutionService.processCall(serviceParametersForEstimate);
}

final var ethCall = new EthCall();
Expand Down

0 comments on commit c2b3343

Please sign in to comment.