Skip to content

Commit

Permalink
reenable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ettec committed Nov 23, 2024
1 parent f61ceec commit 0e042c9
Showing 1 changed file with 115 additions and 111 deletions.
226 changes: 115 additions & 111 deletions core/services/relay/evm/evmtesting/run_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ package evmtesting

import (
"encoding/binary"
"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"

"github.com/smartcontractkit/chainlink-common/pkg/types"
. "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with .
clcommontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/read"

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

const (
Expand All @@ -39,138 +44,137 @@ func RunChainComponentsInLoopEvmTests[T TestingT[T]](t T, it ChainComponentsInte

func RunContractReaderEvmTests[T TestingT[T]](t T, it *EVMChainComponentsInterfaceTester[T]) {
RunContractReaderInterfaceTests[T](t, it, false)
/*
testCases := []Testcase[T]{
{
Name: ContractReaderDynamicTypedTopicsFilterAndCorrectReturn,
Test: func(t T) {
it.Setup(t)
anyString := "foo"
ctx := it.Helper.Context(t)
cr := it.GetContractReader(t)
bindings := it.GetBindings(t)
require.NoError(t, cr.Bind(ctx, bindings))
type DynamicEvent struct {
Field string
}
SubmitTransactionToCW(t, it, "triggerEventWithDynamicTopic", DynamicEvent{Field: anyString}, bindings[0], types.Unconfirmed)

input := struct{ Field string }{Field: anyString}
tp := cr.(clcommontypes.ContractTypeProvider)
testCases := []Testcase[T]{
{
Name: ContractReaderDynamicTypedTopicsFilterAndCorrectReturn,
Test: func(t T) {
it.Setup(t)

anyString := "foo"
ctx := it.Helper.Context(t)

readName := types.BoundContract{
Address: bindings[0].Address,
Name: AnyContractName,
}.ReadIdentifier(triggerWithDynamicTopic)
cr := it.GetContractReader(t)
bindings := it.GetBindings(t)
require.NoError(t, cr.Bind(ctx, bindings))

output, err := tp.CreateContractType(readName, false)
require.NoError(t, err)
rOutput := reflect.Indirect(reflect.ValueOf(output))
type DynamicEvent struct {
Field string
}
SubmitTransactionToCW(t, it, "triggerEventWithDynamicTopic", DynamicEvent{Field: anyString}, bindings[0], types.Unconfirmed)

require.Eventually(t, func() bool {
return cr.GetLatestValue(ctx, readName, primitives.Unconfirmed, input, output) == nil
}, it.MaxWaitTimeForEvents(), 100*time.Millisecond)
input := struct{ Field string }{Field: anyString}
tp := cr.(clcommontypes.ContractTypeProvider)

assert.Equal(t, &anyString, rOutput.FieldByName("Field").Interface())
topic, err := abi.MakeTopics([]any{anyString})
require.NoError(t, err)
assert.Equal(t, &topic[0][0], rOutput.FieldByName("FieldHash").Interface())
},
readName := types.BoundContract{
Address: bindings[0].Address,
Name: AnyContractName,
}.ReadIdentifier(triggerWithDynamicTopic)

output, err := tp.CreateContractType(readName, false)
require.NoError(t, err)
rOutput := reflect.Indirect(reflect.ValueOf(output))

require.Eventually(t, func() bool {
return cr.GetLatestValue(ctx, readName, primitives.Unconfirmed, input, output) == nil
}, it.MaxWaitTimeForEvents(), 100*time.Millisecond)

assert.Equal(t, &anyString, rOutput.FieldByName("Field").Interface())
topic, err := abi.MakeTopics([]any{anyString})
require.NoError(t, err)
assert.Equal(t, &topic[0][0], rOutput.FieldByName("FieldHash").Interface())
},
{
Name: ContractReaderMultipleTopicCanFilterTogether,
Test: func(t T) {
it.Setup(t)
ctx := it.Helper.Context(t)
cr := it.GetContractReader(t)
bindings := it.GetBindings(t)
require.NoError(t, cr.Bind(ctx, bindings))
triggerFourTopics(t, it, int32(1), int32(2), int32(3))
triggerFourTopics(t, it, int32(2), int32(2), int32(3))
triggerFourTopics(t, it, int32(1), int32(3), int32(3))
triggerFourTopics(t, it, int32(1), int32(2), int32(4))
var bound types.BoundContract
for idx := range bindings {
if bindings[idx].Name == AnyContractName {
bound = bindings[idx]
}
},
{
Name: ContractReaderMultipleTopicCanFilterTogether,
Test: func(t T) {
it.Setup(t)
ctx := it.Helper.Context(t)
cr := it.GetContractReader(t)
bindings := it.GetBindings(t)

require.NoError(t, cr.Bind(ctx, bindings))

triggerFourTopics(t, it, int32(1), int32(2), int32(3))
triggerFourTopics(t, it, int32(2), int32(2), int32(3))
triggerFourTopics(t, it, int32(1), int32(3), int32(3))
triggerFourTopics(t, it, int32(1), int32(2), int32(4))

var bound types.BoundContract
for idx := range bindings {
if bindings[idx].Name == AnyContractName {
bound = bindings[idx]
}
}

var latest struct{ Field1, Field2, Field3 int32 }
params := struct{ Field1, Field2, Field3 int32 }{Field1: 1, Field2: 2, Field3: 3}
var latest struct{ Field1, Field2, Field3 int32 }
params := struct{ Field1, Field2, Field3 int32 }{Field1: 1, Field2: 2, Field3: 3}

time.Sleep(it.MaxWaitTimeForEvents())
time.Sleep(it.MaxWaitTimeForEvents())

require.NoError(t, cr.GetLatestValue(ctx, bound.ReadIdentifier(triggerWithAllTopics), primitives.Unconfirmed, params, &latest))
assert.Equal(t, int32(1), latest.Field1)
assert.Equal(t, int32(2), latest.Field2)
assert.Equal(t, int32(3), latest.Field3)
},
require.NoError(t, cr.GetLatestValue(ctx, bound.ReadIdentifier(triggerWithAllTopics), primitives.Unconfirmed, params, &latest))
assert.Equal(t, int32(1), latest.Field1)
assert.Equal(t, int32(2), latest.Field2)
assert.Equal(t, int32(3), latest.Field3)
},
{
Name: ContractReaderFilteringCanBeDoneOnHashedIndexedTopics,
Test: func(t T) {
it.Setup(t)
cr := it.GetContractReader(t)
ctx := it.Helper.Context(t)
bindings := it.GetBindings(t)
require.NoError(t, cr.Bind(ctx, bindings))
triggerFourTopicsWithHashed(t, it, "1", [32]uint8{2}, [32]byte{5})
triggerFourTopicsWithHashed(t, it, "2", [32]uint8{2}, [32]byte{3})
triggerFourTopicsWithHashed(t, it, "1", [32]uint8{3}, [32]byte{3})
var bound types.BoundContract
for idx := range bindings {
if bindings[idx].Name == AnyContractName {
bound = bindings[idx]
}
}
},
{
Name: ContractReaderFilteringCanBeDoneOnHashedIndexedTopics,
Test: func(t T) {
it.Setup(t)

cr := it.GetContractReader(t)
ctx := it.Helper.Context(t)
bindings := it.GetBindings(t)

require.NoError(t, cr.Bind(ctx, bindings))

var latest struct {
Field3 [32]byte
triggerFourTopicsWithHashed(t, it, "1", [32]uint8{2}, [32]byte{5})
triggerFourTopicsWithHashed(t, it, "2", [32]uint8{2}, [32]byte{3})
triggerFourTopicsWithHashed(t, it, "1", [32]uint8{3}, [32]byte{3})

var bound types.BoundContract
for idx := range bindings {
if bindings[idx].Name == AnyContractName {
bound = bindings[idx]
}
params := struct {
Field1 string
Field2 [32]uint8
Field3 [32]byte
}{Field1: "1", Field2: [32]uint8{2}, Field3: [32]byte{5}}
time.Sleep(it.MaxWaitTimeForEvents())
require.NoError(t, cr.GetLatestValue(ctx, bound.ReadIdentifier(triggerWithAllTopicsWithHashed), primitives.Unconfirmed, params, &latest))
// only checking Field3 topic makes sense since it isn't hashed, to check other fields we'd have to replicate solidity encoding and hashing
assert.Equal(t, [32]uint8{5}, latest.Field3)
},
}

var latest struct {
Field3 [32]byte
}
params := struct {
Field1 string
Field2 [32]uint8
Field3 [32]byte
}{Field1: "1", Field2: [32]uint8{2}, Field3: [32]byte{5}}

time.Sleep(it.MaxWaitTimeForEvents())
require.NoError(t, cr.GetLatestValue(ctx, bound.ReadIdentifier(triggerWithAllTopicsWithHashed), primitives.Unconfirmed, params, &latest))
// only checking Field3 topic makes sense since it isn't hashed, to check other fields we'd have to replicate solidity encoding and hashing
assert.Equal(t, [32]uint8{5}, latest.Field3)
},
{
Name: ContractReaderBindReturnsErrorOnMissingContractAtAddress,
Test: func(t T) {
it.Setup(t)
},
{
Name: ContractReaderBindReturnsErrorOnMissingContractAtAddress,
Test: func(t T) {
it.Setup(t)

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

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

require.ErrorIs(t, err, read.NoContractExistsError{Err: clcommontypes.ErrInternal, Address: addr})
},
require.ErrorIs(t, err, read.NoContractExistsError{Err: clcommontypes.ErrInternal, Address: addr})
},
}
RunTests(t, it, testCases)*/
},
}
RunTests(t, it, testCases)
}

func RunContractReaderInLoopTests[T TestingT[T]](t T, it ChainComponentsInterfaceTester[T]) {
RunContractReaderInterfaceTests[T](t, it, false)

testCases := []Testcase[T]{
{
Name: ContractReaderQueryKeyFilterOnDataWordsWithValueComparator,
Expand Down

0 comments on commit 0e042c9

Please sign in to comment.