Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update simulated geth client wrapper & LogPoller tests #13204

Merged
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e00693e
Re-run make generate, fix fluxmonitorv2 & ocr2keeper tests
reductionista May 15, 2024
ecf5baa
Update SimulatedBackendClient to wrap simulated.Backend & simulated.C…
reductionista May 6, 2024
f5d9d1c
Update LogPoller helper
reductionista May 8, 2024
a928754
Add support for switching rpc clients in simulated geth
reductionista May 10, 2024
c63a471
Fix TestLogPoller_BackupPollAndSaveLogsSkippingLogsThatAreTooOld
reductionista May 10, 2024
f721d1a
Fix TestLogPoller_ReorgDeeperThanFinality
reductionista May 10, 2024
5643732
Fix Test_PollAndSavePersistsFinalityInBlocks
reductionista May 10, 2024
82787a9
Fix Test_PollAndQueryFinalizedBlocks
reductionista May 10, 2024
5bd0199
update listener_v2_log_listener_test
reductionista May 13, 2024
81aa9b7
Fix chainreader & config poller tests
reductionista May 13, 2024
d31bfda
Update keeper integration tests
reductionista May 15, 2024
459aa1d
Re-run make generate
reductionista May 15, 2024
aec7ffe
Update BackupLogPoller test
reductionista May 22, 2024
2b2cb35
.
reductionista May 29, 2024
105f76d
Update TestLogPoller_PollAndSaveLogsDeepReorg
reductionista May 24, 2024
7d0ddf4
Not sure how this was working before
reductionista May 24, 2024
260ce9a
Update TestLogPoller_PollAndSaveLogs
reductionista May 28, 2024
cb9e710
Update TestLogPoller_Blocktimestamps
reductionista May 28, 2024
8342115
Update TestLogPoller_BackupPollAndSaveLogsWithPollerNotWorking
reductionista May 28, 2024
b443b6c
Address PR review comments
reductionista May 28, 2024
29abe17
Update types in vrf tests
reductionista May 29, 2024
2c270cf
Update keepers, fluxmointor, transmitter,ocr test types
reductionista May 29, 2024
44ad072
re-generate KeystoneForwarder
reductionista May 29, 2024
03fcd08
Replace optimismMode with chainFamily enum
reductionista May 29, 2024
9afe36e
Update more types GenesisAlloc, GenesisAccount, llo
reductionista May 29, 2024
d78d549
Fix some more compilation errors (fluxmonitor2, vrf, ocr2, functions)
reductionista May 29, 2024
1a6e9ff
Fix lint errors, remove unused logpoller test definitions
reductionista May 29, 2024
9f13b72
Run go-generate again on KeystoneForwarder
reductionista May 29, 2024
ca0909e
Re-run "make generate" one more time, this time without any failures …
reductionista May 29, 2024
a73f062
Re-generate generation version db for keystone
reductionista May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 78 additions & 44 deletions core/chains/evm/client/simulated_backend_client.go

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions core/chains/evm/forwarders/forwarder_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"testing"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"

"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/core/types"
"github.com/ethereum/go-ethereum/ethclient/simulated"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/utils"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
Expand Down Expand Up @@ -42,26 +42,26 @@ func TestFwdMgr_MaybeForwardTransaction(t *testing.T) {
owner := testutils.MustNewSimTransactor(t)
ctx := testutils.Context(t)

ec := backends.NewSimulatedBackend(map[common.Address]core.GenesisAccount{
b := simulated.NewBackend(types.GenesisAlloc{
owner.From: {
Balance: big.NewInt(0).Mul(big.NewInt(10), big.NewInt(1e18)),
},
}, 10e6)
t.Cleanup(func() { ec.Close() })
}, simulated.WithBlockGasLimit(10e6))
t.Cleanup(func() { b.Close() })
linkAddr := common.HexToAddress("0x01BE23585060835E02B77ef475b0Cc51aA1e0709")
operatorAddr, _, _, err := operator_wrapper.DeployOperator(owner, ec, linkAddr, owner.From)
operatorAddr, _, _, err := operator_wrapper.DeployOperator(owner, b.Client(), linkAddr, owner.From)
require.NoError(t, err)
forwarderAddr, _, forwarder, err := authorized_forwarder.DeployAuthorizedForwarder(owner, ec, linkAddr, owner.From, operatorAddr, []byte{})
forwarderAddr, _, forwarder, err := authorized_forwarder.DeployAuthorizedForwarder(owner, b.Client(), linkAddr, owner.From, operatorAddr, []byte{})
require.NoError(t, err)
ec.Commit()
b.Commit()
_, err = forwarder.SetAuthorizedSenders(owner, []common.Address{owner.From})
require.NoError(t, err)
ec.Commit()
b.Commit()
authorized, err := forwarder.GetAuthorizedSenders(nil)
require.NoError(t, err)
t.Log(authorized)

evmClient := client.NewSimulatedBackendClient(t, ec, testutils.FixtureChainID)
evmClient := client.NewSimulatedBackendClient(t, b, testutils.FixtureChainID)

lpOpts := logpoller.Opts{
PollPeriod: 100 * time.Millisecond,
Expand Down Expand Up @@ -109,21 +109,21 @@ func TestFwdMgr_AccountUnauthorizedToForward_SkipsForwarding(t *testing.T) {
cfg := configtest.NewTestGeneralConfig(t)
evmcfg := evmtest.NewChainScopedConfig(t, cfg)
owner := testutils.MustNewSimTransactor(t)
ec := backends.NewSimulatedBackend(map[common.Address]core.GenesisAccount{
b := simulated.NewBackend(types.GenesisAlloc{
owner.From: {
Balance: big.NewInt(0).Mul(big.NewInt(10), big.NewInt(1e18)),
},
}, 10e6)
t.Cleanup(func() { ec.Close() })
}, simulated.WithBlockGasLimit(10e6))
t.Cleanup(func() { b.Close() })
linkAddr := common.HexToAddress("0x01BE23585060835E02B77ef475b0Cc51aA1e0709")
operatorAddr, _, _, err := operator_wrapper.DeployOperator(owner, ec, linkAddr, owner.From)
operatorAddr, _, _, err := operator_wrapper.DeployOperator(owner, b.Client(), linkAddr, owner.From)
require.NoError(t, err)

forwarderAddr, _, _, err := authorized_forwarder.DeployAuthorizedForwarder(owner, ec, linkAddr, owner.From, operatorAddr, []byte{})
forwarderAddr, _, _, err := authorized_forwarder.DeployAuthorizedForwarder(owner, b.Client(), linkAddr, owner.From, operatorAddr, []byte{})
require.NoError(t, err)
ec.Commit()
b.Commit()

evmClient := client.NewSimulatedBackendClient(t, ec, testutils.FixtureChainID)
evmClient := client.NewSimulatedBackendClient(t, b, testutils.FixtureChainID)
lpOpts := logpoller.Opts{
PollPeriod: 100 * time.Millisecond,
FinalityDepth: 2,
Expand Down
42 changes: 26 additions & 16 deletions core/chains/evm/logpoller/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import (
"time"

pkgerrors "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/accounts/abi"
"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/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient/simulated"

"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/log_emitter"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
Expand All @@ -37,7 +38,8 @@ type TestHarness struct {
ChainID, ChainID2 *big.Int
ORM, ORM2 logpoller.ORM
LogPoller logpoller.LogPollerTest
Client *backends.SimulatedBackend
Client *client.SimulatedBackendClient
Backend evmtypes.Backend
Owner *bind.TransactOpts
Emitter1, Emitter2 *log_emitter.LogEmitter
EmitterAddress1, EmitterAddress2 common.Address
Expand All @@ -52,36 +54,37 @@ func SetupTH(t testing.TB, opts logpoller.Opts) TestHarness {
o := logpoller.NewORM(chainID, db, lggr)
o2 := logpoller.NewORM(chainID2, db, lggr)
owner := testutils.MustNewSimTransactor(t)
ec := backends.NewSimulatedBackend(map[common.Address]core.GenesisAccount{

backend := simulated.NewBackend(types.GenesisAlloc{
owner.From: {
Balance: big.NewInt(0).Mul(big.NewInt(10), big.NewInt(1e18)),
},
}, 10e6)
}, simulated.WithBlockGasLimit(10e6))

// Poll period doesn't matter, we intend to call poll and save logs directly in the test.
// Set it to some insanely high value to not interfere with any tests.
esc := client.NewSimulatedBackendClient(t, ec, chainID)
// Mark genesis block as finalized to avoid any nulls in the tests
//TODO OK to drop?
//head := esc.Backend().Blockchain().CurrentHeader()
//esc.Backend().Blockchain().SetFinalized(head)

esc := client.NewSimulatedBackendClient(t, backend, chainID)

if opts.PollPeriod == 0 {
opts.PollPeriod = 1 * time.Hour
}
lp := logpoller.NewLogPoller(o, esc, lggr, opts)
emitterAddress1, _, emitter1, err := log_emitter.DeployLogEmitter(owner, ec)
emitterAddress1, _, emitter1, err := log_emitter.DeployLogEmitter(owner, backend.Client())
require.NoError(t, err)
emitterAddress2, _, emitter2, err := log_emitter.DeployLogEmitter(owner, ec)
emitterAddress2, _, emitter2, err := log_emitter.DeployLogEmitter(owner, backend.Client())
require.NoError(t, err)
ec.Commit()
backend.Commit()

return TestHarness{
Lggr: lggr,
ChainID: chainID,
ChainID2: chainID2,
ORM: o,
ORM2: o2,
LogPoller: lp,
Client: ec,
Client: esc,
Backend: backend,
Owner: owner,
Emitter1: emitter1,
Emitter2: emitter2,
Expand Down Expand Up @@ -112,3 +115,10 @@ func (th *TestHarness) assertHaveCanonical(t *testing.T, start, end int) {
assert.Equal(t, chainBlk.Hash().Bytes(), blk.BlockHash.Bytes(), "block %v", i)
}
}

// Simulates an RPC failover event to an alternate rpc server. This can also be used to
// simulate switching back to the primary rpc after it recovers.
func (th *TestHarness) SetActiveClient(backend evmtypes.Backend, chainFamily evmtypes.ChainFamily) {
th.Backend = backend
th.Client.SetBackend(backend, chainFamily)
}
1 change: 1 addition & 0 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mathutil"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
Expand Down
Loading
Loading