Skip to content

Commit

Permalink
Move the bind error test to evm testing so actual chains can run it t…
Browse files Browse the repository at this point in the history
…oo (#13652)
  • Loading branch information
nolag authored Jun 24, 2024
1 parent 7472812 commit 4c360d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
15 changes: 2 additions & 13 deletions core/services/relay/evm/chain_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/jmoiron/sqlx"
Expand All @@ -21,6 +20,7 @@ import (

clcommontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
. "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with .

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
Expand Down Expand Up @@ -144,20 +144,9 @@ func TestChainReaderEventsInitValidation(t *testing.T) {
func TestChainReader(t *testing.T) {
t.Parallel()
it := &EVMChainReaderInterfaceTester[*testing.T]{Helper: &helper{}}
// add new subtests here so that it can be run on real chains too
RunChainReaderEvmTests(t, it)
RunChainReaderInterfaceTests[*testing.T](t, commontestutils.WrapChainReaderTesterForLoop(it))

t.Run("Bind returns error on missing contract at address", func(t *testing.T) {
t.Parallel()
it.Setup(t)

addr := common.BigToAddress(big.NewInt(42))
reader := it.GetChainReader(t)

err := reader.Bind(context.Background(), []clcommontypes.BoundContract{{Name: AnyContractName, Address: addr.Hex(), Pending: true}})

require.ErrorIs(t, err, evm.NoContractExistsError{Address: addr})
})
}

type helper struct {
Expand Down
16 changes: 16 additions & 0 deletions core/services/relay/evm/evmtesting/run_tests.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package evmtesting

import (
"math/big"
"reflect"
"time"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

clcommontypes "github.com/smartcontractkit/chainlink-common/pkg/types"

. "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with .

"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
)

func RunChainReaderEvmTests[T TestingT[T]](t T, it *EVMChainReaderInterfaceTester[T]) {
Expand Down Expand Up @@ -68,6 +72,18 @@ func RunChainReaderEvmTests[T TestingT[T]](t T, it *EVMChainReaderInterfaceTeste
assert.Equal(t, int32(2), latest.Field2)
assert.Equal(t, int32(3), latest.Field3)
})

t.Run("Bind returns error on missing contract at address", func(t T) {
it.Setup(t)

addr := common.BigToAddress(big.NewInt(42))
reader := it.GetChainReader(t)

ctx := it.Helper.Context(t)
err := reader.Bind(ctx, []clcommontypes.BoundContract{{Name: AnyContractName, Address: addr.Hex(), Pending: true}})

require.ErrorIs(t, err, evm.NoContractExistsError{Address: addr})
})
}

func triggerFourTopics[T TestingT[T]](t T, it *EVMChainReaderInterfaceTester[T], i1, i2, i3 int32) {
Expand Down

0 comments on commit 4c360d1

Please sign in to comment.