2020-08-01 22:09:06 +00:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGasBurn(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
used int64
|
|
|
|
limit int64
|
|
|
|
refund int64
|
|
|
|
burn int64
|
|
|
|
}{
|
2020-08-05 00:09:39 +00:00
|
|
|
{100, 200, 10, 90},
|
|
|
|
{100, 150, 30, 20},
|
|
|
|
{1000, 1300, 240, 60},
|
|
|
|
{500, 700, 140, 60},
|
2020-08-01 22:09:06 +00:00
|
|
|
{200, 200, 0, 0},
|
|
|
|
{20000, 21000, 1000, 0},
|
|
|
|
{0, 2000, 0, 2000},
|
2020-08-05 00:09:39 +00:00
|
|
|
{500, 651, 121, 30},
|
|
|
|
{500, 5000, 0, 4500},
|
|
|
|
{7499e6, 7500e6, 1000000, 0},
|
|
|
|
{7500e6 / 2, 7500e6, 375000000, 3375000000},
|
|
|
|
{1, 7500e6, 0, 7499999999},
|
2020-08-01 22:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(fmt.Sprintf("%v", test), func(t *testing.T) {
|
2020-08-06 19:05:16 +00:00
|
|
|
refund, toBurn := ComputeGasOverestimationBurn(test.used, test.limit)
|
2020-08-05 00:09:39 +00:00
|
|
|
assert.Equal(t, test.refund, refund, "refund")
|
|
|
|
assert.Equal(t, test.burn, toBurn, "burned")
|
2020-08-01 22:09:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|