Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/services/workflows/metering/metering.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,9 @@ func (r *Report) creditToSpendingLimits(
// accepts fractional decimals ("0.001158"), scientific notation ("1e18"),
// and negatives ("-5")
func parseNativeGasUnits(s string) (decimal.Decimal, error) {
if strings.ContainsAny(s, "eE") {
return decimal.Zero, fmt.Errorf("spend value in gas units %q is not a non-negative integer", s)
}
value, err := decimal.NewFromString(s)
if err != nil {
return decimal.Zero, err
Expand Down
4 changes: 3 additions & 1 deletion core/services/workflows/metering/metering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,9 @@ func Test_parseNativeGasUnits(t *testing.T) {
{name: "integer", input: "115800", want: "115800"},
{name: "large integer", input: "34440000000000", want: "34440000000000"},
{name: "zero", input: "0", want: "0"},
{name: "exponent with integer value is accepted", input: "1e18", want: "1000000000000000000"},
{name: "exponent with integer value rejected", input: "1e18", wantErr: true},
{name: "max exponent rejected", input: "1e2147483647", wantErr: true},
{name: "min exponent rejected", input: "1e-2147483648", wantErr: true},
{name: "fractional rejected", input: "0.001158", wantErr: true},
{name: "fractional wei rejected", input: "0.5", wantErr: true},
{name: "negative rejected", input: "-5", wantErr: true},
Expand Down
Loading