Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Fix: nonce too low (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman authored Feb 22, 2024
1 parent 2a4752a commit 6456d8b
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ unit-tests: ## Runs unit tests

.PHONY: generate-mocks
generate-mocks: ## Generates mocks and other autogenerated types
$(GOENVVARS) go generate ./...
mockery
5 changes: 5 additions & 0 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func (e *Etherman) CheckTxWasMined(ctx context.Context, txHash common.Hash) (boo
return true, receipt, nil
}

// PendingNonce returns the pending nonce for the provided account
func (e *Etherman) PendingNonce(ctx context.Context, account common.Address) (uint64, error) {
return e.ethClient.PendingNonceAt(ctx, account)
}

// CurrentNonce returns the current nonce for the provided account
func (e *Etherman) CurrentNonce(ctx context.Context, account common.Address) (uint64, error) {
return e.ethClient.NonceAt(ctx, account, nil)
Expand Down
45 changes: 45 additions & 0 deletions etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,51 @@ func TestCheckTxWasMined(t *testing.T) {
})
}

func TestPendingNonce(t *testing.T) {
t.Parallel()
assert := assert.New(t)

t.Run("Returns the expected nonce value", func(t *testing.T) {
ethClient := mocks.NewEthereumClientMock(t)
ethman := getEtherman(ethClient)

ethClient.On(
"PendingNonceAt",
context.TODO(),
common.Address{},
).Return(
uint64(1),
nil,
).Once()

result, err := ethman.PendingNonce(context.TODO(), common.Address{})

assert.Equal(uint64(1), result)
assert.Nil(err)
ethClient.AssertExpectations(t)
})

t.Run("Returns the expected error", func(t *testing.T) {
ethClient := mocks.NewEthereumClientMock(t)
ethman := getEtherman(ethClient)

ethClient.On(
"PendingNonceAt",
context.TODO(),
common.Address{},
).Return(
uint64(0),
errors.New("NA NA NA!"),
).Once()

result, err := ethman.PendingNonce(context.TODO(), common.Address{})

assert.Equal(uint64(0), result)
assert.ErrorContains(err, "NA NA NA!")
ethClient.AssertExpectations(t)
})
}

func TestCurrentNonce(t *testing.T) {
t.Parallel()
assert := assert.New(t)
Expand Down
31 changes: 15 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/0xPolygon/cdk-data-availability v0.0.5
github.com/0xPolygonHermez/zkevm-node v0.5.12
github.com/0xPolygonHermez/zkevm-node v0.0.0-20240222104536-0204affc7436
github.com/ethereum/go-ethereum v1.13.11
github.com/jackc/pgconn v1.14.1
github.com/jackc/pgx/v4 v4.18.1
Expand All @@ -13,13 +13,13 @@ require (
github.com/rubenv/sql-migrate v1.6.1
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.26.0
github.com/urfave/cli/v2 v2.27.1
go.opentelemetry.io/otel/exporters/prometheus v0.44.0
go.opentelemetry.io/otel/sdk/metric v1.21.0
)

require (
github.com/0xPolygonHermez/zkevm-data-streamer v0.1.18 // indirect
github.com/0xPolygonHermez/zkevm-data-streamer v0.1.19 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
Expand Down Expand Up @@ -66,14 +66,14 @@ require (
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hermeznetwork/tracerr v0.3.2 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/iden3/go-iden3-crypto v0.0.15 // indirect
github.com/iden3/go-iden3-crypto v0.0.16 // indirect
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
Expand All @@ -95,15 +95,14 @@ require (
github.com/markbates/oncer v1.0.0 // indirect
github.com/markbates/safe v1.0.1 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/miguelmota/go-solidity-sha3 v0.1.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.47.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
Expand Down Expand Up @@ -134,19 +133,19 @@ require (
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 6456d8b

Please sign in to comment.