public void GetFeeHistory_HashParameter_ReturnsFailingWrapper() { FeeHistoryOracle feeHistoryOracle = GetSubstitutedFeeHistoryOracle(); ResultWrapper <FeeHistoryResults> expected = ResultWrapper <FeeHistoryResults> .Fail("newestBlock: Is not correct block number", ErrorCodes.InvalidParams); ResultWrapper <FeeHistoryResults> resultWrapper = feeHistoryOracle.GetFeeHistory(0, new BlockParameter(TestItem.KeccakA)); resultWrapper.Should().BeEquivalentTo(expected); }
public void GetFeeHistory_BlocksToCheckLess1_ReturnsFailingWrapper() { FeeHistoryOracle feeHistoryOracle = GetSubstitutedFeeHistoryOracle(); ResultWrapper <FeeHistoryResults> expected = ResultWrapper <FeeHistoryResults> .Fail("blockCount: Value 0 is less than 1", ErrorCodes.InvalidParams); ResultWrapper <FeeHistoryResults> resultWrapper = feeHistoryOracle.GetFeeHistory(0, BlockParameter.Latest); resultWrapper.Should().BeEquivalentTo(expected); }
public void GetFeeHistory_IfRewardPercentilesContainInvalidNumber_ResultsInFailure(double[] rewardPercentiles) { int blockCount = 10; IBlockFinder blockFinder = Substitute.For <IBlockFinder>(); blockFinder.FindBlock(BlockParameter.Latest).Returns(Build.A.Block.TestObject); FeeHistoryOracle feeHistoryOracle = GetSubstitutedFeeHistoryOracle(blockFinder: blockFinder); ResultWrapper <FeeHistoryResults> resultWrapper = feeHistoryOracle.GetFeeHistory(blockCount, BlockParameter.Latest, rewardPercentiles); resultWrapper.Result.Error.Should().Be("rewardPercentiles: Some values are below 0 or greater than 100."); resultWrapper.Result.ResultType.Should().Be(ResultType.Failure); }
public void GetFeeHistory_NewestBlockIsNull_ReturnsFailingWrapper() { IBlockFinder blockFinder = Substitute.For <IBlockFinder>(); blockFinder.FindBlock(Arg.Any <long>()).Returns((Block?)null); FeeHistoryOracle feeHistoryOracle = GetSubstitutedFeeHistoryOracle(blockFinder: blockFinder); ResultWrapper <FeeHistoryResults> expected = ResultWrapper <FeeHistoryResults> .Fail("newestBlock: Block is not available", ErrorCodes.ResourceUnavailable); ResultWrapper <FeeHistoryResults> resultWrapper = feeHistoryOracle.GetFeeHistory(1, new BlockParameter((long)0)); resultWrapper.Should().BeEquivalentTo(expected); }
public void GetFeeHistory_IfPendingBlockDoesNotExistAndLastBlockNumberGreaterThanHeadNumber_ReturnsError(long pendingBlockNumber, long lastBlockNumber) { IBlockFinder blockFinder = Substitute.For <IBlockFinder>(); blockFinder.FindPendingBlock().Returns(Build.A.Block.WithNumber(pendingBlockNumber).TestObject); FeeHistoryOracle feeHistoryOracle = GetSubstitutedFeeHistoryOracle(blockFinder: blockFinder); ResultWrapper <FeeHistoryResults> expected = ResultWrapper <FeeHistoryResults> .Fail("newestBlock: Block is not available", ErrorCodes.ResourceUnavailable); ResultWrapper <FeeHistoryResults> resultWrapper = feeHistoryOracle.GetFeeHistory(1, new BlockParameter(lastBlockNumber)); resultWrapper.Should().BeEquivalentTo(expected); }
public void GetFeeHistory_IfRewardPercentilesNotInAscendingOrder_ResultsInFailure() { int blockCount = 10; double[] rewardPercentiles = { 0, 2, 3, 5, 1 }; IBlockFinder blockFinder = Substitute.For <IBlockFinder>(); blockFinder.FindBlock(BlockParameter.Latest).Returns(Build.A.Block.TestObject); FeeHistoryOracle feeHistoryOracle = GetSubstitutedFeeHistoryOracle(blockFinder: blockFinder); ResultWrapper <FeeHistoryResults> resultWrapper = feeHistoryOracle.GetFeeHistory(blockCount, BlockParameter.Latest, rewardPercentiles); resultWrapper.Result.Error.Should().Be("rewardPercentiles: Value at index 4: 1 is less than or equal to the value at previous index 3: 5."); resultWrapper.Result.ResultType.Should().Be(ResultType.Failure); }
[TestCase(100, 40, 50, 49)] //Target gas used: 100/2 = 50 | Actual Gas used = 40 | Base Fee Delta = (((50-40)/50) * 50) / 8 = 1 | Next Base Fee = 50 - 1 = 49 public void GetFeeHistory_IfLondonEnabled_NextBaseFeePerGasCalculatedCorrectly(long gasLimit, long gasUsed, long baseFee, long expectedNextBaseFee) { int blockCount = 1; IBlockFinder blockFinder = Substitute.For <IBlockFinder>(); BlockHeader blockHeader = Build.A.BlockHeader.WithBaseFee((UInt256)baseFee).WithGasLimit(gasLimit).WithGasUsed(gasUsed).TestObject; BlockParameter newestBlock = new((long)0); Block headBlock = Build.A.Block.Genesis.WithHeader(blockHeader).TestObject; blockFinder.FindBlock(newestBlock).Returns(headBlock); ISpecProvider specProvider = GetSpecProviderWithEip1559EnabledAs(true); FeeHistoryOracle feeHistoryOracle = GetSubstitutedFeeHistoryOracle(blockFinder: blockFinder, specProvider: specProvider); ResultWrapper <FeeHistoryResults> resultWrapper = feeHistoryOracle.GetFeeHistory(blockCount, newestBlock); resultWrapper.Data.BaseFeePerGas ![1].Should().Be((UInt256)expectedNextBaseFee);