From 136bd7ee5b006741a5193dba97ab79373f159f93 Mon Sep 17 00:00:00 2001 From: shiming Date: Fri, 16 Sep 2022 22:24:22 +0800 Subject: [PATCH 1/3] multi 4byte signature return --- 4byte/4byte.go | 34 +++++++++++++++------------------- 4byte/4byte_test.go | 16 +++++++++++----- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/4byte/4byte.go b/4byte/4byte.go index 4f6d4865..c236cfc8 100644 --- a/4byte/4byte.go +++ b/4byte/4byte.go @@ -1,7 +1,6 @@ package fourbyte import ( - "encoding/hex" "encoding/json" "io/ioutil" "net/http" @@ -12,40 +11,37 @@ const ( ) // Resolve resolves a method/event signature -func Resolve(str string) (string, error) { - return get("/api/v1/signatures/?hex_signature=" + str) +func Resolve(str string) ([]string, error) { + return get("/api/v1/signatures/?hex_signature=" + str + "&ordering=created_at") } -// ResolveBytes resolves a method/event signature in bytes -func ResolveBytes(b []byte) (string, error) { - return Resolve(hex.EncodeToString(b)) -} - -func get(path string) (string, error) { +func get(path string) ([]string, error) { req, err := http.Get(fourByteURL + path) if err != nil { - return "", err + return nil, err } defer req.Body.Close() data, err := ioutil.ReadAll(req.Body) if err != nil { - return "", err + return nil, err } var result struct { - Results []signatureResult + Results []struct { + TextSignature string `json:"text_signature"` + } } if err := json.Unmarshal(data, &result); err != nil { - return "", err + return nil, err } if len(result.Results) == 0 { - return "", nil + return nil, nil } - return result.Results[0].TextSignature, nil -} - -type signatureResult struct { - TextSignature string `json:"text_signature"` + signatures := make([]string, 0) + for _, r := range result.Results { + signatures = append(signatures, r.TextSignature) + } + return signatures, nil } diff --git a/4byte/4byte_test.go b/4byte/4byte_test.go index e6eb128b..9790a33a 100644 --- a/4byte/4byte_test.go +++ b/4byte/4byte_test.go @@ -1,14 +1,11 @@ package fourbyte import ( - "testing" - "github.com/stretchr/testify/assert" + "testing" ) func Test4Byte(t *testing.T) { - t.Skip("http api not stable, skip for now") - var cases = []struct { in, out string }{ @@ -24,7 +21,16 @@ func Test4Byte(t *testing.T) { for _, i := range cases { found, err := Resolve(i.in) assert.NoError(t, err) - assert.Equal(t, i.out, found) + assert.Equal(t, contains(found, i.out), true) } } + +func contains[T comparable](s []T, e T) bool { + for _, v := range s { + if v == e { + return true + } + } + return false +} From 6d01510be83e7acc148c0226993ce3827779fce7 Mon Sep 17 00:00:00 2001 From: shiming Date: Sat, 17 Sep 2022 22:45:11 +0800 Subject: [PATCH 2/3] upgrade golang.org/x/sys for fix unix syscall issue: https://github.com/huahuayu/ethgo/issues/2 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 40a2289c..49b27bd8 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( github.com/sirupsen/logrus v1.4.2 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect - golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect + golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect google.golang.org/appengine v1.6.5 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v2 v2.2.2 // indirect diff --git a/go.sum b/go.sum index 91dd4812..9747b118 100644 --- a/go.sum +++ b/go.sum @@ -138,6 +138,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc= +golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= From ff484c7ab35c4cc7f48f2f29c9cd692db851bea6 Mon Sep 17 00:00:00 2001 From: shiming Date: Sat, 17 Sep 2022 22:53:12 +0800 Subject: [PATCH 3/3] fix geth container connection issue issue reference: https://github.com/huahuayu/ethgo/issues/3 --- testutil/server.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testutil/server.go b/testutil/server.go index 3bc3206a..d4693ef7 100644 --- a/testutil/server.go +++ b/testutil/server.go @@ -114,7 +114,7 @@ func NewTestServer(t *testing.T, cb ServerConfigCallback) *TestServer { opts := &dockertest.RunOptions{ Repository: "ethereum/client-go", - Tag: "v1.10.15", + Tag: "v1.10.25", Cmd: args, Mounts: []string{ tmpDir + ":/eth1data", @@ -169,7 +169,8 @@ func (t *TestServer) WSAddr() string { // HTTPAddr returns the http endpoint func (t *TestServer) HTTPAddr() string { - return fmt.Sprintf("http://%s:8545", t.resource.Container.NetworkSettings.IPAddress) + port := t.resource.GetPort("8545/tcp") + return fmt.Sprintf("http://localhost:%s", port) } // ProcessBlock processes a new block