Skip to content

Commit

Permalink
set the minimum price (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickyan86 authored Sep 11, 2019
1 parent 70a56a6 commit 3973a42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ftservice/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
price = new(big.Int).Div(prices, weights)
}

if price.Cmp(gpo.defaultPrice) < 0 {
price = gpo.defaultPrice
}

gpo.cacheLock.Lock()
gpo.lastHead = headHash
gpo.lastPrice = price
Expand Down
15 changes: 15 additions & 0 deletions ftservice/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@ func TestSuggestPrice(t *testing.T) {
t.Fatal(err)
}
assert.Equal(t, price, gasPrice)

// test the Minimum configuration

cfg1 := Config{
Blocks: 5,
Default: big.NewInt(10),
}
gpo = NewOracle(newTestBlockChain(price), cfg1)

gasPrice, err = gpo.SuggestPrice(context.Background())
if err != nil {
t.Fatal(err)
}
assert.Equal(t, big.NewInt(10), gasPrice)

}

0 comments on commit 3973a42

Please sign in to comment.