Skip to content

Commit

Permalink
prettify code + latest Seth
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed May 6, 2024
1 parent f897175 commit 55abcc9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 37 deletions.
5 changes: 4 additions & 1 deletion integration-tests/contracts/multicall.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/smartcontractkit/seth"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"

"github.com/smartcontractkit/chainlink/integration-tests/wrappers"
)

const (
Expand Down Expand Up @@ -63,7 +65,8 @@ func MultiCallLogTriggerLoadGen(
if err != nil {
return nil, err
}
boundContract := bind.NewBoundContract(contractAddress, multiCallABI, client.Client, client.Client, client.Client)
wrapper := wrappers.MustNewWrappedContractBackend(nil, client)
boundContract := bind.NewBoundContract(contractAddress, multiCallABI, wrapper, wrapper, wrapper)

var call []Call
for i, d := range logTriggerData {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
github.com/smartcontractkit/seth v0.1.7-0.20240430100854-89fa69e6992e
github.com/smartcontractkit/seth v0.1.7-0.20240506102232-b5f1f946fb9d
github.com/smartcontractkit/wasp v0.4.7
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1535,8 +1535,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c h1:lIyMbTaF2H0Q71vkwZHX/Ew4KF2BxiKhqEXwF8rn+KI=
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM=
github.com/smartcontractkit/seth v0.1.7-0.20240430100854-89fa69e6992e h1:LyX0EdZDkXZd5/Qt1vfWJ9MlrzYlmVFnOUxFhpfEywA=
github.com/smartcontractkit/seth v0.1.7-0.20240430100854-89fa69e6992e/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero=
github.com/smartcontractkit/seth v0.1.7-0.20240506102232-b5f1f946fb9d h1:LY/mHhJIQTAGo2JXvTJg4qeY1yfnEwn2eqPqPa0J49g=
github.com/smartcontractkit/seth v0.1.7-0.20240506102232-b5f1f946fb9d/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero=
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 h1:yiKnypAqP8l0OX0P3klzZ7SCcBUxy5KqTAKZmQOvSQE=
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:q6f4fe39oZPdsh1i57WznEZgxd8siidMaSFq3wdPmVg=
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:Dai1bn+Q5cpeGMQwRdjOdVjG8mmFFROVkSKuUgBErRQ=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/load/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240214231432-4ad5eb95178c
github.com/smartcontractkit/chainlink/v2 v2.9.0-beta0.0.20240216210048-da02459ddad8
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
github.com/smartcontractkit/seth v0.1.7-0.20240430100854-89fa69e6992e
github.com/smartcontractkit/seth v0.1.7-0.20240506102232-b5f1f946fb9d
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1
github.com/smartcontractkit/wasp v0.4.7
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/load/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1526,8 +1526,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c h1:lIyMbTaF2H0Q71vkwZHX/Ew4KF2BxiKhqEXwF8rn+KI=
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM=
github.com/smartcontractkit/seth v0.1.7-0.20240430100854-89fa69e6992e h1:LyX0EdZDkXZd5/Qt1vfWJ9MlrzYlmVFnOUxFhpfEywA=
github.com/smartcontractkit/seth v0.1.7-0.20240430100854-89fa69e6992e/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero=
github.com/smartcontractkit/seth v0.1.7-0.20240506102232-b5f1f946fb9d h1:LY/mHhJIQTAGo2JXvTJg4qeY1yfnEwn2eqPqPa0J49g=
github.com/smartcontractkit/seth v0.1.7-0.20240506102232-b5f1f946fb9d/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero=
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 h1:yiKnypAqP8l0OX0P3klzZ7SCcBUxy5KqTAKZmQOvSQE=
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:q6f4fe39oZPdsh1i57WznEZgxd8siidMaSFq3wdPmVg=
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:Dai1bn+Q5cpeGMQwRdjOdVjG8mmFFROVkSKuUgBErRQ=
Expand Down
66 changes: 36 additions & 30 deletions integration-tests/wrappers/contract_caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,116 +51,116 @@ func (w *WrappedContractBackend) getGethClient() *ethclient.Client {
}

func (w *WrappedContractBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call CodeAt")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call CodeAt")
}

client := w.getGethClient()
return client.CodeAt(ctx, contract, blockNumber)
}

func (w *WrappedContractBackend) PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call PendingCodeAt")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call PendingCodeAt")
}

client := w.getGethClient()
return client.PendingCodeAt(ctx, contract)
}

func (w *WrappedContractBackend) CodeAtHash(ctx context.Context, contract common.Address, blockHash common.Hash) ([]byte, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call CodeAtHash")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call CodeAtHash")
}

client := w.getGethClient()
return client.CodeAtHash(ctx, contract, blockHash)
}

func (w *WrappedContractBackend) CallContractAtHash(ctx context.Context, call ethereum.CallMsg, blockHash common.Hash) ([]byte, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call CallContractAtHash")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call CallContractAtHash")
}

client := w.getGethClient()
return client.CallContractAtHash(ctx, call, blockHash)
}

func (w *WrappedContractBackend) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call HeaderByNumber")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call HeaderByNumber")
}

client := w.getGethClient()
return client.HeaderByNumber(ctx, number)
}

func (w *WrappedContractBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
if w.getErrorFromContext(ctx) != nil {
return 0, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call PendingNonceAt")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return 0, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call PendingNonceAt")
}

client := w.getGethClient()
return client.PendingNonceAt(ctx, account)
}

func (w *WrappedContractBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call SuggestGasPrice")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call SuggestGasPrice")
}

client := w.getGethClient()
return client.SuggestGasPrice(ctx)
}

func (w *WrappedContractBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call SuggestGasTipCap")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call SuggestGasTipCap")
}

client := w.getGethClient()
return client.SuggestGasTipCap(ctx)
}

func (w *WrappedContractBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) {
if w.getErrorFromContext(ctx) != nil {
return 0, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call EstimateGas")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return 0, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call EstimateGas")
}

client := w.getGethClient()
return client.EstimateGas(ctx, call)
}

func (w *WrappedContractBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error {
if w.getErrorFromContext(ctx) != nil {
return errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call SendTransaction")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call SendTransaction")
}

client := w.getGethClient()
return client.SendTransaction(ctx, tx)
}

func (w *WrappedContractBackend) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call FilterLogs")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call FilterLogs")
}

client := w.getGethClient()
return client.FilterLogs(ctx, query)
}

func (w *WrappedContractBackend) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call SubscribeFilterLogs")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call SubscribeFilterLogs")
}

client := w.getGethClient()
return client.SubscribeFilterLogs(ctx, query, ch)
}

func (w *WrappedContractBackend) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call CallContract")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call CallContract")
}

var hex hexutil.Bytes
Expand All @@ -173,8 +173,8 @@ func (w *WrappedContractBackend) CallContract(ctx context.Context, msg ethereum.
}

func (w *WrappedContractBackend) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
if w.getErrorFromContext(ctx) != nil {
return nil, errors.Wrapf(w.getErrorFromContext(ctx), "the context you passed had an error set. Won't call PendingCallContract")
if ctxErr := w.getErrorFromContext(ctx); ctxErr != nil {
return nil, errors.Wrapf(ctxErr, "the context you passed had an error set. Won't call PendingCallContract")
}

var hex hexutil.Bytes
Expand All @@ -187,8 +187,14 @@ func (w *WrappedContractBackend) PendingCallContract(ctx context.Context, msg et
}

func (w *WrappedContractBackend) getErrorFromContext(ctx context.Context) error {
if ctx.Value("error") != nil {
return ctx.Value("error").(error)
if ctxErr := ctx.Value("error"); ctxErr != nil {
if v, ok := ctxErr.(error); ok {
return v
}
if v, ok := ctxErr.(seth.ContextErrorValue); ok {
return v.Error
}
return errors.Wrapf(errors.New("unknown error type"), "error in context: %v", ctxErr)
}

return nil
Expand Down

0 comments on commit 55abcc9

Please sign in to comment.