github.com/ethereum-optimism/optimism/l2geth@v0.0.0-20230612200230-50b04ade19e3/rollup/fees/rollup_fee_test.go (about) 1 package fees 2 3 import ( 4 "errors" 5 "math/big" 6 "testing" 7 8 "github.com/ethereum-optimism/optimism/l2geth/common" 9 ) 10 11 func TestPaysEnough(t *testing.T) { 12 tests := map[string]struct { 13 opts *PaysEnoughOpts 14 err error 15 }{ 16 "missing-gas-price": { 17 opts: &PaysEnoughOpts{ 18 UserGasPrice: nil, 19 ExpectedGasPrice: new(big.Int), 20 ThresholdUp: nil, 21 ThresholdDown: nil, 22 }, 23 err: errMissingInput, 24 }, 25 "missing-fee": { 26 opts: &PaysEnoughOpts{ 27 UserGasPrice: nil, 28 ExpectedGasPrice: nil, 29 ThresholdUp: nil, 30 ThresholdDown: nil, 31 }, 32 err: errMissingInput, 33 }, 34 "equal-fee": { 35 opts: &PaysEnoughOpts{ 36 UserGasPrice: common.Big1, 37 ExpectedGasPrice: common.Big1, 38 ThresholdUp: nil, 39 ThresholdDown: nil, 40 }, 41 err: nil, 42 }, 43 "fee-too-low": { 44 opts: &PaysEnoughOpts{ 45 UserGasPrice: common.Big1, 46 ExpectedGasPrice: common.Big2, 47 ThresholdUp: nil, 48 ThresholdDown: nil, 49 }, 50 err: ErrGasPriceTooLow, 51 }, 52 "fee-threshold-down": { 53 opts: &PaysEnoughOpts{ 54 UserGasPrice: common.Big1, 55 ExpectedGasPrice: common.Big2, 56 ThresholdUp: nil, 57 ThresholdDown: new(big.Float).SetFloat64(0.5), 58 }, 59 err: nil, 60 }, 61 "fee-threshold-up": { 62 opts: &PaysEnoughOpts{ 63 UserGasPrice: common.Big256, 64 ExpectedGasPrice: common.Big1, 65 ThresholdUp: new(big.Float).SetFloat64(1.5), 66 ThresholdDown: nil, 67 }, 68 err: ErrGasPriceTooHigh, 69 }, 70 "fee-too-low-high": { 71 opts: &PaysEnoughOpts{ 72 UserGasPrice: new(big.Int).SetUint64(10_000), 73 ExpectedGasPrice: new(big.Int).SetUint64(1), 74 ThresholdUp: new(big.Float).SetFloat64(3), 75 ThresholdDown: new(big.Float).SetFloat64(0.8), 76 }, 77 err: ErrGasPriceTooHigh, 78 }, 79 "fee-too-low-down": { 80 opts: &PaysEnoughOpts{ 81 UserGasPrice: new(big.Int).SetUint64(1), 82 ExpectedGasPrice: new(big.Int).SetUint64(10_000), 83 ThresholdUp: new(big.Float).SetFloat64(3), 84 ThresholdDown: new(big.Float).SetFloat64(0.8), 85 }, 86 err: ErrGasPriceTooLow, 87 }, 88 "fee-too-low-down-2": { 89 opts: &PaysEnoughOpts{ 90 UserGasPrice: new(big.Int).SetUint64(0), 91 ExpectedGasPrice: new(big.Int).SetUint64(10_000), 92 ThresholdUp: new(big.Float).SetFloat64(3), 93 ThresholdDown: new(big.Float).SetFloat64(0.8), 94 }, 95 err: ErrGasPriceTooLow, 96 }, 97 } 98 99 for name, tt := range tests { 100 t.Run(name, func(t *testing.T) { 101 err := PaysEnough(tt.opts) 102 if !errors.Is(err, tt.err) { 103 t.Fatalf("%s: got %s, expected %s", name, err, tt.err) 104 } 105 }) 106 } 107 }