Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/gasprice: implement feeHistory API #23033

Merged
merged 10 commits into from
Jun 28, 2021
Prev Previous commit
Next Next commit
eth/gasprice: fixed tests and return errors correctly
  • Loading branch information
zsfelfoldi committed Jun 28, 2021
commit dded1582c17b772edbf28421287f2552cface3dd
4 changes: 3 additions & 1 deletion eth/gasprice/feehistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ func (f *Oracle) FeeHistory(ctx context.Context, blockCount int, lastBlockNumber
pendingBlock *types.Block
pendingReceipts types.Receipts
)
pendingBlock, pendingReceipts, lastBlockNumber, blockCount, err = f.resolveBlockRange(ctx, lastBlockNumber, blockCount, maxHistory)
if pendingBlock, pendingReceipts, lastBlockNumber, blockCount, err = f.resolveBlockRange(ctx, lastBlockNumber, blockCount, maxHistory); err != nil {
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to return directly if the block count is 0 here. It's cleaner

firstBlockNumber = lastBlockNumber + 1 - rpc.BlockNumber(blockCount)

processNext := int64(firstBlockNumber)
Expand Down
7 changes: 3 additions & 4 deletions eth/gasprice/feehistory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ func TestFeeHistory(t *testing.T) {
{false, 0, 0, 10, 30, []float64{20, 10}, 0, 0, errInvalidPercentiles},
{false, 0, 0, 1000000000, 30, nil, 0, 31, nil},
{false, 0, 0, 1000000000, rpc.LatestBlockNumber, nil, 0, 33, nil},
{false, 0, 0, 10, 40, nil, 31, 2, nil},
{true, 0, 0, 10, 40, nil, 31, 2, nil},
{false, 0, 0, 10, 400, nil, 0, 0, nil},
{false, 0, 0, 10, 40, nil, 0, 0, errRequestBeyondHead},
{true, 0, 0, 10, 40, nil, 0, 0, errRequestBeyondHead},
{false, 20, 2, 100, rpc.LatestBlockNumber, nil, 13, 20, nil},
{false, 20, 2, 100, rpc.LatestBlockNumber, []float64{0, 10}, 31, 2, nil},
{false, 20, 2, 100, 100, []float64{0, 10}, 31, 2, nil},
{false, 20, 2, 100, 32, []float64{0, 10}, 31, 2, nil},
{false, 0, 0, 1, rpc.PendingBlockNumber, nil, 0, 0, nil},
{false, 0, 0, 2, rpc.PendingBlockNumber, nil, 32, 1, nil},
{true, 0, 0, 2, rpc.PendingBlockNumber, nil, 32, 2, nil},
Expand Down