Skip to content

Commit

Permalink
adapt old estimation test (which was overestimating)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedejinich committed Sep 15, 2021
1 parent 2e1fadb commit f649011
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rskj-core/src/test/java/co/rsk/mine/TransactionModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,18 @@ public void testGasEstimation() {
BigInteger nonce = repository.getAccountState(srcAddr).getNonce();
RskAddress contractAddress = new RskAddress(HashUtil.calcNewAddr(srcAddr.getBytes(), nonce.toByteArray()));
int gasLimit = 5000000; // start with 5M
int consumed = checkEstimateGas(callCallWithValue, 33557,gasLimit,srcAddr,contractAddress,web3, repository);
int consumed = checkEstimateGas(callCallWithValue, 33472,gasLimit,srcAddr,contractAddress,web3, repository);

// Now that I know the estimation, call again using the estimated value
// it should not fail. We set the gasLimit to the expected value plus 1 to
// differentiate between OOG and success.
int consumed2 = checkEstimateGas(callCallWithValue,33557,consumed+1, srcAddr,contractAddress,web3, repository);
int consumed2 = checkEstimateGas(callCallWithValue,33472,consumed+1, srcAddr,contractAddress,web3, repository);

Assert.assertEquals(consumed,consumed2);

consumed = checkEstimateGas(callUnfill, 46942,
gasLimit,srcAddr,contractAddress,web3, repository);
consumed2 = checkEstimateGas(callUnfill, 46942,
consumed+1,srcAddr,contractAddress,web3, repository);
consumed = checkEstimateGas(callUnfill, 46942, gasLimit,srcAddr,contractAddress,web3, repository);
consumed2 = checkEstimateGas(callUnfill, 46942, consumed+1,srcAddr,contractAddress,web3, repository);

Assert.assertEquals(consumed,consumed2);
}

Expand All @@ -303,7 +303,7 @@ public int checkEstimateGas(int method,int expectedValue,int gasLimit,
BigInteger gasReturned =BigIntegers.fromUnsignedByteArray(gasReturnedBytes);
int gasReturnedInt = gasReturned.intValueExact();
Assert.assertNotEquals(gasReturnedInt,gasLimit);
Assert.assertEquals(gasReturnedInt, expectedValue);
Assert.assertEquals(expectedValue, gasReturnedInt);
return gasReturnedInt;
}

Expand Down

0 comments on commit f649011

Please sign in to comment.