public void Does_not_take_into_account_precompiles() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Array.Empty <byte>(), ExecutionType.Transaction, false); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Array.Empty <byte>(), ExecutionType.Call, true); tracer.ReportActionEnd(400, Array.Empty <byte>()); // this would not happen but we want to ensure that precompiles are ignored tracer.ReportActionEnd(600, Array.Empty <byte>()); tracer.CalculateEstimate(Build.A.Transaction.WithGasLimit(1000).TestObject).Should().Be(0); }
public void Does_not_take_into_account_precompiles() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Transaction, false); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Call, true); tracer.ReportActionEnd(400, Bytes.Empty); // this would not happen but we want to ensure that precompiles are ignored tracer.ReportActionEnd(600, Bytes.Empty); tracer.ExcessiveGas.Should().Be(600L); }
public void Easy_one_level_case() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(128, 0, Address.Zero, Address.Zero, Array.Empty <byte>(), ExecutionType.Transaction, false); tracer.ReportAction(100, 0, Address.Zero, Address.Zero, Array.Empty <byte>(), _executionType, false); tracer.ReportActionEnd(63, Array.Empty <byte>()); // second level tracer.ReportActionEnd(65, Array.Empty <byte>()); tracer.CalculateEstimate(Build.A.Transaction.WithGasLimit(128).TestObject).Should().Be(1); }
public void Easy_one_level_case() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(128, 0, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Transaction, false); tracer.ReportAction(100, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); tracer.ReportActionEnd(63, Bytes.Empty); // second level tracer.ReportActionEnd(65, Bytes.Empty); tracer.AdditionalGasRequired.Should().Be(1); }
public void Handles_well_top_level() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Array.Empty <byte>(), ExecutionType.Transaction, false); tracer.ReportActionEnd(600, Array.Empty <byte>()); tracer.CalculateEstimate(Build.A.Transaction.WithGasLimit(1000).TestObject).Should().Be(0); }
public void Handles_well_top_level() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Transaction, false); tracer.ReportActionEnd(600, Bytes.Empty); tracer.ExcessiveGas.Should().Be(600L); }
public void Handles_well_serial_calls() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Array.Empty <byte>(), ExecutionType.Transaction, false); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Array.Empty <byte>(), _executionType, false); tracer.ReportActionEnd(400, Array.Empty <byte>()); tracer.ReportAction(400, 0, Address.Zero, Address.Zero, Array.Empty <byte>(), _executionType, false); if (_executionType.IsAnyCreate()) { tracer.ReportActionEnd(200, Address.Zero, Array.Empty <byte>()); tracer.ReportActionEnd(300, Array.Empty <byte>()); } else { tracer.ReportActionEnd(200, Array.Empty <byte>()); tracer.ReportActionEnd(300, Array.Empty <byte>()); // should not happen } tracer.CalculateEstimate(Build.A.Transaction.WithGasLimit(1000).TestObject).Should().Be(14L); }
public void Handles_well_serial_calls() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Transaction, false); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); tracer.ReportActionEnd(400, Bytes.Empty); tracer.ReportAction(400, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); if (_executionType == ExecutionType.Create) { tracer.ReportActionEnd(200, Address.Zero, Bytes.Empty); tracer.ReportActionEnd(300, Bytes.Empty); } else { tracer.ReportActionEnd(200, Bytes.Empty); tracer.ReportActionEnd(300, Bytes.Empty); // should not happen } tracer.ExcessiveGas.Should().Be(203L); }
public void Handles_well_errors() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Transaction, false); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); tracer.ReportAction(400, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); if (_executionType.IsAnyCreate()) { tracer.ReportActionError(EvmExceptionType.Other); tracer.ReportActionEnd(400, Address.Zero, Bytes.Empty); tracer.ReportActionEnd(500, Bytes.Empty); // should not happen } else { tracer.ReportActionError(EvmExceptionType.Other); tracer.ReportActionEnd(400, Bytes.Empty); tracer.ReportActionEnd(500, Bytes.Empty); // should not happen } tracer.CalculateEstimate(Build.A.Transaction.WithGasLimit(1000).TestObject).Should().Be(24L); }
public void Handles_well_errors() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Transaction, false); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); tracer.ReportAction(400, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); if (_executionType == ExecutionType.Create) { tracer.ReportActionError(EvmExceptionType.Other); tracer.ReportActionEnd(400, Address.Zero, Bytes.Empty); tracer.ReportActionEnd(500, Bytes.Empty); // should not happen } else { tracer.ReportActionError(EvmExceptionType.Other); tracer.ReportActionEnd(400, Bytes.Empty); tracer.ReportActionEnd(500, Bytes.Empty); // should not happen } tracer.ExcessiveGas.Should().Be(406L); }
public void Handles_well_nested_calls_where_least_nested_defines_excess() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Transaction, false); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); tracer.ReportAction(400, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); if (_executionType.IsAnyCreate()) { tracer.ReportActionEnd(300, Address.Zero, Bytes.Empty); // second level tracer.ReportActionEnd(200, Address.Zero, Bytes.Empty); tracer.ReportActionEnd(500, Bytes.Empty); // should not happen } else { tracer.ReportActionEnd(300, Bytes.Empty); // second level tracer.ReportActionEnd(200, Bytes.Empty); tracer.ReportActionEnd(500, Bytes.Empty); // should not happen } tracer.CalculateEstimate(Build.A.Transaction.WithGasLimit(1000).TestObject).Should().Be(17); }
public void Handles_well_nested_calls_where_most_nested_defines_excess() { EstimateGasTracer tracer = new EstimateGasTracer(); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, ExecutionType.Transaction, false); tracer.ReportAction(1000, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); tracer.ReportAction(400, 0, Address.Zero, Address.Zero, Bytes.Empty, _executionType, false); if (_executionType == ExecutionType.Create) { tracer.ReportActionEnd(200, Address.Zero, Bytes.Empty); // second level tracer.ReportActionEnd(400, Address.Zero, Bytes.Empty); tracer.ReportActionEnd(500, Bytes.Empty); // should not happen } else { tracer.ReportActionEnd(200, Bytes.Empty); // second level tracer.ReportActionEnd(400, Bytes.Empty); tracer.ReportActionEnd(500, Bytes.Empty); // should not happen } tracer.ExcessiveGas.Should().Be(206L); }