Skip to content

Commit

Permalink
make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Jan 24, 2025
1 parent daabd1d commit 1257f5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions pkg/codec/by_item_type_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package codec

import (
"fmt"
"log"
"reflect"

"github.com/smartcontractkit/chainlink-common/pkg/types"
Expand Down Expand Up @@ -51,7 +50,6 @@ func (b *byItemTypeModifier) RetypeToOffChain(onChainType reflect.Type, itemType

mod, ok := b.modByitemType[head]
if !ok {
log.Println(mod)
return nil, fmt.Errorf("%w: cannot find modifier for %s", types.ErrInvalidType, itemType)
}

Expand All @@ -78,11 +76,12 @@ func (b *byItemTypeModifier) transform(
head, tail = ItemTyper(itemType).Next()
}

if mod, ok := b.modByitemType[head]; ok {
return transform(mod, val, tail)
mod, ok := b.modByitemType[head]
if !ok {
return nil, fmt.Errorf("%w: cannot find modifier for %s", types.ErrInvalidType, itemType)
}

return val, nil
return transform(mod, val, tail)
}

var _ Modifier = &byItemTypeModifier{}
6 changes: 3 additions & 3 deletions pkg/codec/renamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func TestRenamer(t *testing.T) {
D string
}

renamer := codec.NewRenamer(map[string]string{"A": "X", "C": "Z"})
invalidRenamer := codec.NewRenamer(map[string]string{"W": "X", "C": "Z"})
nestedRenamer := codec.NewRenamer(map[string]string{"A": "X", "B.A": "X", "B.C": "Z", "C.A": "X", "C.C": "Z", "B": "Y"})
renamer := codec.NewPathTraverseRenamer(map[string]string{"A": "X", "C": "Z"}, true)
invalidRenamer := codec.NewPathTraverseRenamer(map[string]string{"W": "X", "C": "Z"}, true)
nestedRenamer := codec.NewPathTraverseRenamer(map[string]string{"A": "X", "B.A": "X", "B.C": "Z", "C.A": "X", "C.C": "Z", "B": "Y"}, true)
t.Run("RetypeToOffChain renames fields keeping structure", func(t *testing.T) {
offChainType, err := renamer.RetypeToOffChain(reflect.TypeOf(testStruct{}), "")
require.NoError(t, err)
Expand Down

0 comments on commit 1257f5a

Please sign in to comment.