2020-08-07 02:01:58 +00:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBaseFee(t *testing.T) {
|
|
|
|
tests := []struct {
|
2020-10-06 20:12:16 +00:00
|
|
|
basefee uint64
|
|
|
|
limitUsed int64
|
|
|
|
noOfBlocks int
|
|
|
|
preSmoke, postSmoke uint64
|
2020-08-07 02:01:58 +00:00
|
|
|
}{
|
2020-10-06 20:12:16 +00:00
|
|
|
{100e6, 0, 1, 87.5e6, 87.5e6},
|
|
|
|
{100e6, 0, 5, 87.5e6, 87.5e6},
|
|
|
|
{100e6, build.BlockGasTarget, 1, 103.125e6, 100e6},
|
|
|
|
{100e6, build.BlockGasTarget * 2, 2, 103.125e6, 100e6},
|
|
|
|
{100e6, build.BlockGasLimit * 2, 2, 112.5e6, 112.5e6},
|
|
|
|
{100e6, build.BlockGasLimit * 1.5, 2, 110937500, 106.250e6},
|
2020-08-07 02:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(fmt.Sprintf("%v", test), func(t *testing.T) {
|
2020-10-06 20:12:16 +00:00
|
|
|
preSmoke := ComputeNextBaseFee(types.NewInt(test.basefee), test.limitUsed, test.noOfBlocks, build.UpgradeSmokeHeight-1)
|
|
|
|
assert.Equal(t, fmt.Sprintf("%d", test.preSmoke), preSmoke.String())
|
|
|
|
|
|
|
|
postSmoke := ComputeNextBaseFee(types.NewInt(test.basefee), test.limitUsed, test.noOfBlocks, build.UpgradeSmokeHeight+1)
|
|
|
|
assert.Equal(t, fmt.Sprintf("%d", test.postSmoke), postSmoke.String())
|
2020-08-07 02:01:58 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|