From 4c4c2325bd7e62d5bf7192019702ddb8f10a4096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 11 Nov 2019 10:41:48 +0200 Subject: [PATCH] Modify checkForZeroUint64Fields() to verify uint32 fields as well --- config/gasSchedule.go | 2 +- config/gasSchedule_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/config/gasSchedule.go b/config/gasSchedule.go index 5d4c19a9f..63eff451d 100644 --- a/config/gasSchedule.go +++ b/config/gasSchedule.go @@ -91,7 +91,7 @@ func checkForZeroUint64Fields(arg interface{}) error { v := reflect.ValueOf(arg) for i := 0; i < v.NumField(); i++ { field := v.Field(i) - if field.Kind() != reflect.Uint64 { + if field.Kind() != reflect.Uint64 && field.Kind() != reflect.Uint32 { continue } if field.Uint() == 0 { diff --git a/config/gasSchedule_test.go b/config/gasSchedule_test.go index c323254f1..23f835e6a 100644 --- a/config/gasSchedule_test.go +++ b/config/gasSchedule_test.go @@ -55,3 +55,23 @@ func TestDecode_ArwenGas(t *testing.T) { fmt.Printf("%+v\n", ethOp) } + +func TestDecode_ZeroGasCostError(t *testing.T) { + gasMap := make(map[string]uint64) + gasMap = FillGasMapWithWASMOpcodeValues(gasMap, 1) + + wasmCosts := &WASMOpcodeCost{} + err := mapstructure.Decode(gasMap, wasmCosts) + assert.Nil(t, err) + + err = checkForZeroUint64Fields(*wasmCosts) + assert.Nil(t, err) + + gasMap["BrIf"] = 0 + wasmCosts = &WASMOpcodeCost{} + err = mapstructure.Decode(gasMap, wasmCosts) + assert.Nil(t, err) + + err = checkForZeroUint64Fields(*wasmCosts) + assert.Error(t, err) +}