Skip to content

Commit

Permalink
Merge branch 'ph4' into ph4-refactor-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Oct 10, 2023
2 parents bcbd4e6 + 9903915 commit d253043
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/beekeeper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
K3S_VERSION: "v1.22.17+k3s1"
REPLICA: 3
RUN_TYPE: "PR RUN"
SETUP_CONTRACT_IMAGE_TAG: "0.9.9"
SETUP_CONTRACT_IMAGE_TAG: "1.0.4"
BEELOCAL_BRANCH: "main"
BEEKEEPER_BRANCH: "master"
BEEKEEPER_METRICS_ENABLED: false
Expand Down
34 changes: 21 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ require (
github.com/btcsuite/btcd v0.22.3
github.com/casbin/casbin/v2 v2.35.0
github.com/coreos/go-semver v0.3.0
github.com/ethereum/go-ethereum v1.12.2
github.com/ethereum/go-ethereum v1.13.2
github.com/ethersphere/go-price-oracle-abi v0.1.0
github.com/ethersphere/go-storage-incentives-abi v0.6.0-rc5
github.com/ethersphere/go-storage-incentives-abi v0.6.0-rc8
github.com/ethersphere/go-sw3-abi v0.4.0
github.com/ethersphere/langos v1.0.0
github.com/go-playground/validator/v10 v10.11.1
Expand All @@ -32,7 +32,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0
github.com/prometheus/client_golang v1.14.0
github.com/spf13/afero v1.6.0
github.com/spf13/cobra v1.0.0
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.8.1
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand All @@ -42,12 +42,12 @@ require (
gitlab.com/nolash/go-mockbytes v0.0.7
go.uber.org/atomic v1.10.0
go.uber.org/goleak v1.1.12
golang.org/x/crypto v0.9.0
golang.org/x/crypto v0.12.0
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad
golang.org/x/net v0.10.0
golang.org/x/sync v0.3.0
golang.org/x/sys v0.9.0
golang.org/x/term v0.8.0
golang.org/x/sys v0.11.0
golang.org/x/term v0.11.0
golang.org/x/time v0.3.0
gopkg.in/yaml.v2 v2.4.0
resenje.org/multex v0.1.0
Expand All @@ -56,14 +56,23 @@ require (
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/bits-and-blooms/bitset v1.5.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.10.0 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

require (
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
Expand Down Expand Up @@ -97,7 +106,7 @@ require (
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.4
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
Expand Down Expand Up @@ -154,10 +163,10 @@ require (
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.6 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/uber/jaeger-lib v2.2.0+incompatible // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wealdtech/go-multicodec v1.4.0 // indirect
Expand All @@ -167,11 +176,10 @@ require (
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
nhooyr.io/websocket v1.8.7 // indirect
Expand Down
92 changes: 50 additions & 42 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func (m *mockContract) Claim(context.Context, []redistribution.Proof) (common.Ha
return common.Hash{}, nil
}

func (m *mockContract) Commit(context.Context, []byte, uint32) (common.Hash, error) {
func (m *mockContract) Commit(context.Context, []byte, uint64) (common.Hash, error) {
m.mtx.Lock()
defer m.mtx.Unlock()
m.callsList = append(m.callsList, commitCall)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storageincentives/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func (a *Agent) commit(ctx context.Context, sample sampler.Data, round uint64) e
return err
}

txHash, err := a.contract.Commit(ctx, obfuscatedHash, uint32(round))
txHash, err := a.contract.Commit(ctx, obfuscatedHash, round)
if err != nil {
a.metrics.ErrCommit.Inc()
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/storageincentives/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (m *mockContract) Claim(context.Context, []redistribution.Proof) (common.Ha
return common.Hash{}, nil
}

func (m *mockContract) Commit(context.Context, []byte, uint32) (common.Hash, error) {
func (m *mockContract) Commit(context.Context, []byte, uint64) (common.Hash, error) {
m.mtx.Lock()
defer m.mtx.Unlock()
m.callsList = append(m.callsList, commitCall)
Expand Down
4 changes: 2 additions & 2 deletions pkg/storageincentives/redistribution/redistribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Contract interface {
IsPlaying(context.Context, uint8) (bool, error)
IsWinner(context.Context) (bool, error)
Claim(context.Context, []Proof) (common.Hash, error)
Commit(context.Context, []byte, uint32) (common.Hash, error)
Commit(context.Context, []byte, uint64) (common.Hash, error)
Reveal(context.Context, uint8, []byte, []byte) (common.Hash, error)
}

Expand Down Expand Up @@ -115,7 +115,7 @@ func (c *contract) Claim(ctx context.Context, proofs []Proof) (common.Hash, erro
}

// Commit submits the obfusHash hash by sending a transaction to the blockchain.
func (c *contract) Commit(ctx context.Context, obfusHash []byte, round uint32) (common.Hash, error) {
func (c *contract) Commit(ctx context.Context, obfusHash []byte, round uint64) (common.Hash, error) {
callData, err := c.incentivesContractABI.Pack("commit", common.BytesToHash(obfusHash), common.BytesToHash(c.overlay.Bytes()), round)
if err != nil {
return common.Hash{}, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/storageincentives/redistribution/redistribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestRedistribution(t *testing.T) {
var obfus [32]byte
testobfus := common.Hex2Bytes("hash")
copy(obfus[:], testobfus)
expectedCallData, err := redistributionContractABI.Pack("commit", obfus, common.BytesToHash(owner.Bytes()), uint32(0))
expectedCallData, err := redistributionContractABI.Pack("commit", obfus, common.BytesToHash(owner.Bytes()), uint64(0))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestRedistribution(t *testing.T) {
redistributionContractABI,
)

_, err = contract.Commit(ctx, testobfus, uint32(0))
_, err = contract.Commit(ctx, testobfus, 0)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestRedistribution(t *testing.T) {
t.Run("invalid call data", func(t *testing.T) {
t.Parallel()

expectedCallData, err := redistributionContractABI.Pack("commit", common.BytesToHash(common.Hex2Bytes("some hash")), common.BytesToHash(common.Hex2Bytes("some address")), uint32(0))
expectedCallData, err := redistributionContractABI.Pack("commit", common.BytesToHash(common.Hex2Bytes("some hash")), common.BytesToHash(common.Hex2Bytes("some address")), uint64(0))
if err != nil {
t.Fatal(err)
}
Expand All @@ -433,7 +433,7 @@ func TestRedistribution(t *testing.T) {
redistributionContractABI,
)

_, err = contract.Commit(ctx, common.Hex2Bytes("hash"), uint32(0))
_, err = contract.Commit(ctx, common.Hex2Bytes("hash"), 0)
if err == nil {
t.Fatal("expected error")
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/transaction/backendmock/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

type backendMock struct {
codeAt func(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
callContract func(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
sendTransaction func(ctx context.Context, tx *types.Transaction) error
suggestGasPrice func(ctx context.Context) (*big.Int, error)
suggestGasTipCap func(ctx context.Context) (*big.Int, error)
Expand All @@ -38,7 +39,10 @@ func (m *backendMock) CodeAt(ctx context.Context, contract common.Address, block
return nil, errors.New("not implemented")
}

func (*backendMock) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
func (m *backendMock) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
if m.callContract != nil {
return m.callContract(ctx, call, blockNumber)
}
return nil, errors.New("not implemented")
}

Expand Down Expand Up @@ -161,6 +165,12 @@ type optionFunc func(*backendMock)

func (f optionFunc) apply(r *backendMock) { f(r) }

func WithCallContractFunc(f func(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)) Option {
return optionFunc(func(s *backendMock) {
s.callContract = f
})
}

func WithCodeAtFunc(f func(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)) Option {
return optionFunc(func(s *backendMock) {
s.codeAt = f
Expand Down
48 changes: 42 additions & 6 deletions pkg/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethersphere/bee/pkg/crypto"
"github.com/ethersphere/bee/pkg/log"
"github.com/ethersphere/bee/pkg/sctx"
Expand Down Expand Up @@ -596,20 +597,55 @@ func (t *transactionService) UnwrapABIError(ctx context.Context, req *TxRequest,
return nil
}

res, cErr := t.Call(ctx, req)
if cErr != nil {
_, cErr := t.Call(ctx, req)
if cErr == nil {
return err
}
err = fmt.Errorf("%w: %s", err, cErr) //nolint:errorlint

if reason, uErr := abi.UnpackRevert(res); uErr == nil {
var derr rpc.DataError
if !errors.As(cErr, &derr) {
return err
}

res, ok := derr.ErrorData().(string)
if !ok {
return err
}
buf := common.FromHex(res)

if reason, uErr := abi.UnpackRevert(buf); uErr == nil {
return fmt.Errorf("%w: %s", err, reason)
}

for _, abiError := range abiErrors {
if bytes.Equal(res[:4], abiError.ID[:4]) {
//abiError.Unpack(res[4:])
return fmt.Errorf("%w: %s", err, abiError)
if !bytes.Equal(buf[:4], abiError.ID[:4]) {
continue
}

data, uErr := abiError.Unpack(buf)
if uErr != nil {
continue
}

values, ok := data.([]interface{})
if !ok {
values = make([]interface{}, len(abiError.Inputs))
for i := range values {
values[i] = "?"
}
}

params := make([]string, len(abiError.Inputs))
for i, input := range abiError.Inputs {
if input.Name == "" {
input.Name = fmt.Sprintf("arg%d", i)
}
params[i] = fmt.Sprintf("%s=%v", input.Name, values[i])

}

return fmt.Errorf("%w: %s(%s)", err, abiError.Name, strings.Join(params, ","))
}

return err
Expand Down
Loading

0 comments on commit d253043

Please sign in to comment.