From e9c8a9aa6910b239eb2ff9959fd20c3084358228 Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Wed, 7 Sep 2022 18:23:06 +0200 Subject: [PATCH 1/5] To address should not be nil If it's nil, EstimateGas will return a "stack underflow" error. --- contract/contract.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/contract/contract.go b/contract/contract.go index c62f0ebf..e1f30995 100644 --- a/contract/contract.go +++ b/contract/contract.go @@ -88,14 +88,12 @@ func (j *jsonrpcTransaction) Build() error { if j.opts.GasLimit == 0 { msg := ðgo.CallMsg{ From: from, - To: nil, + To: &j.to, Data: j.input, Value: j.opts.Value, GasPrice: j.opts.GasPrice, } - if j.to != ethgo.ZeroAddress { - msg.To = &j.to - } + j.opts.GasLimit, err = j.client.EstimateGas(msg) if err != nil { return err From f6eddacd22721a01bbac95480c243119e8bb6121 Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Wed, 7 Sep 2022 21:58:57 +0200 Subject: [PATCH 2/5] Upgrade x/sys because it was failing in Darwin --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 40a2289c..d0f8a588 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-20220907062415-87db552b00fd // 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..b06b3dde 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-20220907062415-87db552b00fd h1:AZeIEzg+8RCELJYq8w+ODLVxFgLMMigSwO/ffKPEd9U= +golang.org/x/sys v0.0.0-20220907062415-87db552b00fd/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 3841d1e4d1d480e5bd51dfbb88de78ffe9b82b99 Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Sat, 10 Sep 2022 14:12:24 +0200 Subject: [PATCH 3/5] Try to make tests pass --- contract/contract.go | 1 + 1 file changed, 1 insertion(+) diff --git a/contract/contract.go b/contract/contract.go index e1f30995..4eba04f5 100644 --- a/contract/contract.go +++ b/contract/contract.go @@ -98,6 +98,7 @@ func (j *jsonrpcTransaction) Build() error { if err != nil { return err } + j.opts.GasLimit += 50000 } // calculate the nonce if j.opts.Nonce == 0 { From 8820b05a7349ba5e8afe16fdb06f50280aa4726a Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Mon, 12 Sep 2022 09:47:27 +0200 Subject: [PATCH 4/5] Undo for testing --- contract/contract.go | 6 ++++-- contract/contract_test.go | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/contract/contract.go b/contract/contract.go index 4eba04f5..4eb2ca96 100644 --- a/contract/contract.go +++ b/contract/contract.go @@ -88,12 +88,14 @@ func (j *jsonrpcTransaction) Build() error { if j.opts.GasLimit == 0 { msg := ðgo.CallMsg{ From: from, - To: &j.to, + To: nil, //&j.to, Data: j.input, Value: j.opts.Value, GasPrice: j.opts.GasPrice, } - + if j.to != ethgo.ZeroAddress { + msg.To = &j.to + } j.opts.GasLimit, err = j.client.EstimateGas(msg) if err != nil { return err diff --git a/contract/contract_test.go b/contract/contract_test.go index 492d55fe..d79d28b7 100644 --- a/contract/contract_test.go +++ b/contract/contract_test.go @@ -125,11 +125,11 @@ func TestContract_Deploy(t *testing.T) { i := NewContract(receipt.ContractAddress, abi, WithJsonRPC(p.Eth())) resp, err := i.Call("val_0", ethgo.Latest) assert.NoError(t, err) - assert.Equal(t, resp["0"], ethgo.Address{0x1}) + assert.Equal(t, ethgo.Address{0x1}, resp["0"]) resp, err = i.Call("val_1", ethgo.Latest) assert.NoError(t, err) - assert.Equal(t, resp["0"], big.NewInt(1000)) + assert.Equal(t, big.NewInt(1000), resp["0"]) } func TestContract_Transaction(t *testing.T) { From 1aa5a3485fcf6db83d8d8d85e511f75ac4d7b6df Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Mon, 12 Sep 2022 10:10:10 +0200 Subject: [PATCH 5/5] Revert gas limit --- contract/contract.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contract/contract.go b/contract/contract.go index 4eb2ca96..2a00725d 100644 --- a/contract/contract.go +++ b/contract/contract.go @@ -100,7 +100,7 @@ func (j *jsonrpcTransaction) Build() error { if err != nil { return err } - j.opts.GasLimit += 50000 + // j.opts.GasLimit += 50000 } // calculate the nonce if j.opts.Nonce == 0 {