Skip to content

Commit

Permalink
Merge pull request #24 from ElrondNetwork/metering
Browse files Browse the repository at this point in the history
Minor fix in `checkForZeroUint64Fields()` for WASM Opcodes
  • Loading branch information
camilbancioiu authored Nov 11, 2019
2 parents 452355e + 4c4c232 commit c3fa8da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/gasSchedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions config/gasSchedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit c3fa8da

Please sign in to comment.