Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hash meddler error #285

Merged
merged 2 commits into from
Jan 27, 2025
Merged
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
64 changes: 64 additions & 0 deletions db/meddler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package db

import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
)

func TestHashMeddler_PreWrite(t *testing.T) {
t.Parallel()

hex := "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
hash := common.HexToHash(hex)

tests := []struct {
name string
fieldPtr interface{}
wantValue interface{}
wantErr bool
}{
{
name: "Valid common.Hash",
fieldPtr: hash,
wantValue: hex,
wantErr: false,
},
{
name: "Valid *common.Hash",
fieldPtr: &hash,
wantValue: hex,
wantErr: false,
},
{
name: "Nil *common.Hash",
fieldPtr: (*common.Hash)(nil),
wantValue: []byte{},
wantErr: false,
},
{
name: "Invalid type",
fieldPtr: "invalid",
wantValue: nil,
wantErr: true,
},
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

h := HashMeddler{}
gotValue, err := h.PreWrite(tt.fieldPtr)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.wantValue, gotValue)
}
})
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/0xPolygon/cdk-contracts-tooling v0.0.1
github.com/0xPolygon/cdk-data-availability v0.0.11
github.com/0xPolygon/cdk-rpc v0.0.0-20241004114257-6c3cb6eebfb6
github.com/0xPolygon/zkevm-ethtx-manager v0.2.2
github.com/0xPolygon/zkevm-ethtx-manager v0.2.4
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.6
github.com/ethereum/go-ethereum v1.14.10
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
Expand All @@ -21,7 +21,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.24
github.com/mitchellh/mapstructure v1.5.0
github.com/pelletier/go-toml/v2 v2.2.2
github.com/rubenv/sql-migrate v1.7.0
github.com/rubenv/sql-migrate v1.7.1
github.com/russross/meddler v1.0.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/0xPolygon/cdk-data-availability v0.0.11 h1:enmlyFYCvmDmcX/2fnDjWnn3sv
github.com/0xPolygon/cdk-data-availability v0.0.11/go.mod h1:20WaXcSp7ggoxWePL9ReKSuqksHUx5h8LNQ+b56OHJE=
github.com/0xPolygon/cdk-rpc v0.0.0-20241004114257-6c3cb6eebfb6 h1:FXL/rcO7/GtZ3kRFw+C7J6vmGnl8gcazg+Gh/NVmnas=
github.com/0xPolygon/cdk-rpc v0.0.0-20241004114257-6c3cb6eebfb6/go.mod h1:2scWqMMufrQXu7TikDgQ3BsyaKoX8qP26D6E262vSOg=
github.com/0xPolygon/zkevm-ethtx-manager v0.2.2 h1:2brK20gXMzogp6MHCSJyRfSwuQlpy7UcExHwuhE/abc=
github.com/0xPolygon/zkevm-ethtx-manager v0.2.2/go.mod h1:7yqxH0zbYd6zoqIOdUwq55a9r7Syo1hZrvzm2mHmzUI=
github.com/0xPolygon/zkevm-ethtx-manager v0.2.4 h1:OrtSD8jLVeQnN+1I0c7U/3+EYSd+h3wm1vygrDAXBZg=
github.com/0xPolygon/zkevm-ethtx-manager v0.2.4/go.mod h1:v5HY2RjDKov3AnLkcLEo8pJ2J6GH0JI5oA6YwikG9/c=
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.6 h1:+XsCHXvQezRdMnkI37Wa/nV4sOZshJavxNzRpH/R6dw=
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.6/go.mod h1:X4Su/M/+hSISqdl9yomKlRsbTyuZHsRohporyHsP8gg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down Expand Up @@ -372,8 +372,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/rubenv/sql-migrate v1.7.0 h1:HtQq1xyTN2ISmQDggnh0c9U3JlP8apWh8YO2jzlXpTI=
github.com/rubenv/sql-migrate v1.7.0/go.mod h1:S4wtDEG1CKn+0ShpTtzWhFpHHI5PvCUtiGI+C+Z2THE=
github.com/rubenv/sql-migrate v1.7.1 h1:f/o0WgfO/GqNuVg+6801K/KW3WdDSupzSjDYODmiUq4=
github.com/rubenv/sql-migrate v1.7.1/go.mod h1:Ob2Psprc0/3ggbM6wCzyYVFFuc6FyZrb2AS+ezLDFb4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/meddler v1.0.1 h1:JLR7Z4M4iGm1nr7DIURBq18UW8cTrm+qArUFgOhELo8=
Expand Down
Loading