Skip to content

Commit

Permalink
fix clo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Aug 26, 2024
1 parent a591889 commit 39175a2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -65,7 +65,6 @@ func TestCCIPReader_CommitReportsGTETimestamp(t *testing.T) {
}

s := testSetup(ctx, t, chainD, chainD, nil, cfg)
s.sb.Commit()
tokenA := common.HexToAddress("123")
const numReports = 5

Expand Down Expand Up @@ -103,7 +102,6 @@ func TestCCIPReader_CommitReportsGTETimestamp(t *testing.T) {
var reports []plugintypes.CommitPluginReportWithMeta
var err error
require.Eventually(t, func() bool {
s.sb.Commit()
reports, err = s.reader.CommitReportsGTETimestamp(
ctx,
chainD,
Expand Down Expand Up @@ -322,7 +320,7 @@ func testSetup(ctx context.Context, t *testing.T, readerChain, destChain cciptyp
// Set up the genesis account with balance
blnc, ok := big.NewInt(0).SetString("999999999999999999999999999999999999", 10)
assert.True(t, ok)
alloc := map[common.Address]core.GenesisAccount{crypto.PubkeyToAddress(privateKey.PublicKey): {Balance: blnc}}
alloc := map[common.Address]ethtypes.Account{crypto.PubkeyToAddress(privateKey.PublicKey): {Balance: blnc}}
simulatedBackend := simulated.NewBackend(alloc, simulated.WithBlockGasLimit(0))
// Create a transactor

Expand Down
13 changes: 8 additions & 5 deletions core/capabilities/ccip/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"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/require"

Expand All @@ -23,6 +23,7 @@ import (
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccip_integration_tests/integrationhelpers"
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"

Expand Down Expand Up @@ -301,8 +302,8 @@ func createChains(t *testing.T, numChains int) map[uint64]chainBase {
chains := make(map[uint64]chainBase)

homeChainOwner := testutils.MustNewSimTransactor(t)
homeChainBackend := simulated.NewBackend(core.GenesisAlloc{
homeChainOwner.From: core.GenesisAccount{
homeChainBackend := simulated.NewBackend(types.GenesisAlloc{
homeChainOwner.From: types.Account{
Balance: assets.Ether(10_000).ToInt(),
},
}, simulated.WithBlockGasLimit(30e6))
Expand All @@ -315,8 +316,8 @@ func createChains(t *testing.T, numChains int) map[uint64]chainBase {

for chainID := chainsel.TEST_90000001.EvmChainID; len(chains) < numChains && chainID < chainsel.TEST_90000020.EvmChainID; chainID++ {
owner := testutils.MustNewSimTransactor(t)
backend := simulated.NewBackend(core.GenesisAlloc{
owner.From: core.GenesisAccount{
backend := simulated.NewBackend(types.GenesisAlloc{
owner.From: types.Account{
Balance: assets.Ether(10_000).ToInt(),
},
}, simulated.WithBlockGasLimit(30e6))
Expand Down Expand Up @@ -653,6 +654,7 @@ func setupUniverseBasics(t *testing.T, uni onchainUniverse) {
// =============================================================================
_, err := uni.linkToken.GrantMintRole(owner, owner.From)
require.NoError(t, err)
uni.backend.Commit()
_, err = uni.linkToken.Mint(owner, owner.From, e18Mult(1000))
require.NoError(t, err)
uni.backend.Commit()
Expand Down Expand Up @@ -799,6 +801,7 @@ func initRemoteChainsGasPrices(t *testing.T, uni onchainUniverse, universes map[
GasPriceUpdates: gasPriceUpdates,
})
require.NoError(t, err)
uni.backend.Commit()
}

func defaultPriceRegistryDestChainConfig(t *testing.T) price_registry.PriceRegistryDestChainConfig {
Expand Down
14 changes: 7 additions & 7 deletions core/services/ocr2/plugins/llo/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"time"

"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/core/types"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -171,7 +171,7 @@ func setupNode(
t *testing.T,
port int,
dbName string,
backend *backends.SimulatedBackend,
backend *simulated.Backend,
csaKey csakey.KeyV2,
) (app chainlink.Application, peerID string, clientPubKey credentials.StaticSizedPublicKey, ocr2kb ocr2key.KeyBundle, observedLogs *observer.ObservedLogs) {
k := big.NewInt(int64(port)) // keys unique to port
Expand Down Expand Up @@ -507,19 +507,19 @@ func addOCRJobsEVMPremiumLegacy(
return jobIDs
}

func setupV03Blockchain(t *testing.T) (*bind.TransactOpts, *backends.SimulatedBackend, *destination_verifier.DestinationVerifier, *destination_verifier_proxy.DestinationVerifierProxy, common.Address) {
func setupV03Blockchain(t *testing.T) (*bind.TransactOpts, *simulated.Backend, *destination_verifier.DestinationVerifier, *destination_verifier_proxy.DestinationVerifierProxy, common.Address) {
steve := testutils.MustNewSimTransactor(t) // config contract deployer and owner
genesisData := core.GenesisAlloc{steve.From: {Balance: assets.Ether(1000).ToInt()}}
genesisData := types.GenesisAlloc{steve.From: {Balance: assets.Ether(1000).ToInt()}}
backend := cltest.NewSimulatedBackend(t, genesisData, uint32(ethconfig.Defaults.Miner.GasCeil))
backend.Commit() // ensure starting block number at least 1

// Deploy verifier proxy
verifierProxyAddr, _, verifierProxy, err := destination_verifier_proxy.DeployDestinationVerifierProxy(steve, backend)
verifierProxyAddr, _, verifierProxy, err := destination_verifier_proxy.DeployDestinationVerifierProxy(steve, backend.Client())
require.NoError(t, err)
backend.Commit()

// Deploy verifier
verifierAddress, _, verifier, err := destination_verifier.DeployDestinationVerifier(steve, backend, verifierProxyAddr)
verifierAddress, _, verifier, err := destination_verifier.DeployDestinationVerifier(steve, backend.Client(), verifierProxyAddr)
require.NoError(t, err)
backend.Commit()

Expand Down
9 changes: 5 additions & 4 deletions core/services/ocr2/plugins/llo/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/hashicorp/consul/sdk/freeport"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -48,20 +49,20 @@ var (
nNodes = 4 // number of nodes (not including bootstrap)
)

func setupBlockchain(t *testing.T) (*bind.TransactOpts, *backends.SimulatedBackend, *channel_verifier.ChannelVerifier, common.Address, *channel_config_store.ChannelConfigStore, common.Address) {
func setupBlockchain(t *testing.T) (*bind.TransactOpts, *simulated.Backend, *channel_verifier.ChannelVerifier, common.Address, *channel_config_store.ChannelConfigStore, common.Address) {
steve := testutils.MustNewSimTransactor(t) // config contract deployer and owner
genesisData := core.GenesisAlloc{steve.From: {Balance: assets.Ether(1000).ToInt()}}
backend := cltest.NewSimulatedBackend(t, genesisData, uint32(ethconfig.Defaults.Miner.GasCeil))
backend.Commit()
backend.Commit() // ensure starting block number at least 1

// Deploy contracts
verifierProxyAddr, _, _, err := verifier_proxy.DeployVerifierProxy(steve, backend, common.Address{}) // zero address for access controller disables access control
verifierProxyAddr, _, _, err := verifier_proxy.DeployVerifierProxy(steve, backend.Client(), common.Address{}) // zero address for access controller disables access control
require.NoError(t, err)

verifierAddress, _, verifierContract, err := channel_verifier.DeployChannelVerifier(steve, backend, verifierProxyAddr)
verifierAddress, _, verifierContract, err := channel_verifier.DeployChannelVerifier(steve, backend.Client(), verifierProxyAddr)
require.NoError(t, err)
configStoreAddress, _, configStoreContract, err := channel_config_store.DeployChannelConfigStore(steve, backend)
configStoreAddress, _, configStoreContract, err := channel_config_store.DeployChannelConfigStore(steve, backend.Client())
require.NoError(t, err)

backend.Commit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"errors"
"fmt"
"io"
"math/rand/v2"
"math/rand"
"net/http"
"sync"
"testing"
"time"

"github.com/ethereum/go-ethereum/core/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -134,13 +135,13 @@ func Test_ChannelDefinitionCache_Integration(t *testing.T) {
orm := llo.NewORM(db, ETHMainnetChainSelector)

steve := testutils.MustNewSimTransactor(t) // config contract deployer and owner
genesisData := core.GenesisAlloc{steve.From: {Balance: assets.Ether(1000).ToInt()}}
genesisData := types.GenesisAlloc{steve.From: {Balance: assets.Ether(1000).ToInt()}}
backend := cltest.NewSimulatedBackend(t, genesisData, uint32(ethconfig.Defaults.Miner.GasCeil))
backend.Commit() // ensure starting block number at least 1

ethClient := client.NewSimulatedBackendClient(t, backend, testutils.SimulatedChainID)

configStoreAddress, _, configStoreContract, err := channel_config_store.DeployChannelConfigStore(steve, backend)
configStoreAddress, _, configStoreContract, err := channel_config_store.DeployChannelConfigStore(steve, backend.Client())
require.NoError(t, err)

lpOpts := logpoller.Opts{
Expand Down
29 changes: 15 additions & 14 deletions core/services/ocr2/plugins/mercury/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"time"

"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/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/hashicorp/consul/sdk/freeport"
"github.com/shopspring/decimal"
"github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
Expand All @@ -39,6 +39,7 @@ import (
v3 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v3"
v4 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v4"
datastreamsmercury "github.com/smartcontractkit/chainlink-data-streams/mercury"

"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/link_token_interface"
Expand Down Expand Up @@ -89,38 +90,38 @@ func detectPanicLogs(t *testing.T, logObservers []*observer.ObservedLogs) {
}
}

func setupBlockchain(t *testing.T) (*bind.TransactOpts, *backends.SimulatedBackend, *verifier.Verifier, common.Address) {
func setupBlockchain(t *testing.T) (*bind.TransactOpts, *simulated.Backend, *verifier.Verifier, common.Address) {
steve := testutils.MustNewSimTransactor(t) // config contract deployer and owner
genesisData := core.GenesisAlloc{steve.From: {Balance: assets.Ether(1000).ToInt()}}
backend := cltest.NewSimulatedBackend(t, genesisData, uint32(ethconfig.Defaults.Miner.GasCeil))
backend.Commit() // ensure starting block number at least 1
stopMining := cltest.Mine(backend, 1*time.Second) // Should be greater than deltaRound since we cannot access old blocks on simulated blockchain
backend.Commit() // ensure starting block number at least 1
commit, stopMining := cltest.Mine(backend, 1*time.Second) // Should be greater than deltaRound since we cannot access old blocks on simulated blockchain
t.Cleanup(stopMining)

// Deploy contracts
linkTokenAddress, _, linkToken, err := link_token_interface.DeployLinkToken(steve, backend)
linkTokenAddress, _, linkToken, err := link_token_interface.DeployLinkToken(steve, backend.Client())
require.NoError(t, err)
_, err = linkToken.Transfer(steve, steve.From, big.NewInt(1000))
require.NoError(t, err)
nativeTokenAddress, _, nativeToken, err := link_token_interface.DeployLinkToken(steve, backend)
nativeTokenAddress, _, nativeToken, err := link_token_interface.DeployLinkToken(steve, backend.Client())
require.NoError(t, err)
_, err = nativeToken.Transfer(steve, steve.From, big.NewInt(1000))
require.NoError(t, err)
verifierProxyAddr, _, verifierProxy, err := verifier_proxy.DeployVerifierProxy(steve, backend, common.Address{}) // zero address for access controller disables access control
verifierProxyAddr, _, verifierProxy, err := verifier_proxy.DeployVerifierProxy(steve, backend.Client(), common.Address{}) // zero address for access controller disables access control
require.NoError(t, err)
verifierAddress, _, verifier, err := verifier.DeployVerifier(steve, backend, verifierProxyAddr)
verifierAddress, _, verifier, err := verifier.DeployVerifier(steve, backend.Client(), verifierProxyAddr)
require.NoError(t, err)
_, err = verifierProxy.InitializeVerifier(steve, verifierAddress)
require.NoError(t, err)
rewardManagerAddr, _, rewardManager, err := reward_manager.DeployRewardManager(steve, backend, linkTokenAddress)
rewardManagerAddr, _, rewardManager, err := reward_manager.DeployRewardManager(steve, backend.Client(), linkTokenAddress)
require.NoError(t, err)
feeManagerAddr, _, _, err := fee_manager.DeployFeeManager(steve, backend, linkTokenAddress, nativeTokenAddress, verifierProxyAddr, rewardManagerAddr)
feeManagerAddr, _, _, err := fee_manager.DeployFeeManager(steve, backend.Client(), linkTokenAddress, nativeTokenAddress, verifierProxyAddr, rewardManagerAddr)
require.NoError(t, err)
_, err = verifierProxy.SetFeeManager(steve, feeManagerAddr)
require.NoError(t, err)
_, err = rewardManager.SetFeeManager(steve, feeManagerAddr)
require.NoError(t, err)
backend.Commit()
commit()

return steve, backend, verifier, verifierAddress
}
Expand Down Expand Up @@ -374,7 +375,7 @@ func integration_MercuryV1(t *testing.T) {

num, err := (&reportcodecv1.ReportCodec{}).CurrentBlockNumFromReport(ocr2types.Report(report.([]byte)))
require.NoError(t, err)
currentBlock, err := backend.BlockByNumber(testutils.Context(t), nil)
currentBlock, err := backend.Client().BlockByNumber(testutils.Context(t), nil)
require.NoError(t, err)

assert.GreaterOrEqual(t, currentBlock.Number().Int64(), num)
Expand Down Expand Up @@ -436,9 +437,9 @@ func integration_MercuryV1(t *testing.T) {
continue // already saw all oracles for this feed
}

num, err := (&reportcodecv1.ReportCodec{}).CurrentBlockNumFromReport(ocr2types.Report(report.([]byte)))
num, err := (&reportcodecv1.ReportCodec{}).CurrentBlockNumFromReport(report.([]byte))
require.NoError(t, err)
currentBlock, err := backend.BlockByNumber(testutils.Context(t), nil)
currentBlock, err := backend.Client().BlockByNumber(testutils.Context(t), nil)
require.NoError(t, err)

assert.GreaterOrEqual(t, currentBlock.Number().Int64(), num)
Expand Down
8 changes: 0 additions & 8 deletions integration-tests/load/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,6 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo=
github.com/go-logr/zapr v1.2.4/go.mod h1:FyHWQIzQORZ0QVE1BtVHv3cKtNLuXsbNLtpuhNapBOA=
<<<<<<< HEAD
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
=======
>>>>>>> 0294e1f3813c0643b61af828ec438307dcab3123
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
Expand Down Expand Up @@ -674,10 +670,6 @@ github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0
github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4=
github.com/gogo/status v1.1.1 h1:DuHXlSFHNKqTQ+/ACf5Vs6r4X/dH2EgIzR9Vr+H65kg=
github.com/gogo/status v1.1.1/go.mod h1:jpG3dM5QPcqu19Hg8lkUhBFBa3TcLs1DG7+2Jqci7oU=
<<<<<<< HEAD
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
=======
>>>>>>> 0294e1f3813c0643b61af828ec438307dcab3123
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
Expand Down

0 comments on commit 39175a2

Please sign in to comment.