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

Non-EVM chains operator-ui support #11386

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
// FakeRelayerChainInteroperators is a fake chainlink.RelayerChainInteroperators.
// This exists because mockery generation doesn't understand how to produce an alias instead of the underlying type (which is not exported in this case).
type FakeRelayerChainInteroperators struct {
Relayers []loop.Relayer
EVMChains legacyevm.LegacyChainContainer
Nodes []types.NodeStatus
NodesErr error
Expand All @@ -45,7 +46,7 @@ func (f *FakeRelayerChainInteroperators) Get(id relay.ID) (loop.Relayer, error)
}

func (f *FakeRelayerChainInteroperators) Slice() []loop.Relayer {
panic("unimplemented")
return f.Relayers
}

func (f *FakeRelayerChainInteroperators) LegacyCosmosChains() chainlink.LegacyCosmosContainer {
Expand Down
21 changes: 15 additions & 6 deletions core/web/loader/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package loader

import (
"context"
"slices"

"github.com/graph-gophers/dataloader"

"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/chains"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
Expand All @@ -14,7 +16,7 @@ type chainBatcher struct {
app chainlink.Application
}

func (b *chainBatcher) loadByIDs(_ context.Context, keys dataloader.Keys) []*dataloader.Result {
func (b *chainBatcher) loadByIDs(ctx context.Context, keys dataloader.Keys) []*dataloader.Result {
// Create a map for remembering the order of keys passed in
keyOrder := make(map[string]int, len(keys))
// Collect the keys to search for
Expand All @@ -24,13 +26,20 @@ func (b *chainBatcher) loadByIDs(_ context.Context, keys dataloader.Keys) []*dat
keyOrder[key.String()] = ix
}

// Fetch the chains
cs, _, err := b.app.EVMORM().Chains(chainIDs...)
if err != nil {
return []*dataloader.Result{{Data: nil, Error: err}}
var cs []types.ChainStatus
relayers := b.app.GetRelayers().Slice()

for _, r := range relayers {
s, err := r.GetChainStatus(ctx)
if err != nil {
return []*dataloader.Result{{Data: nil, Error: err}}
}

if slices.Contains(chainIDs, s.ID) {
cs = append(cs, s)
}
}

// Construct the output array of dataloader results
results := make([]*dataloader.Result, len(keys))
for _, c := range cs {
ix, ok := keyOrder[c.ID]
Expand Down
33 changes: 23 additions & 10 deletions core/web/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink/v2/core/chains"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
evmtxmgrmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
evmutils "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"

ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
coremocks "github.com/smartcontractkit/chainlink/v2/core/internal/mocks"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
chainlinkmocks "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/feeds"
feedsMocks "github.com/smartcontractkit/chainlink/v2/core/services/feeds/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
jobORMMocks "github.com/smartcontractkit/chainlink/v2/core/services/job/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
testutils2 "github.com/smartcontractkit/chainlink/v2/core/web/testutils"
)

func TestLoader_Chains(t *testing.T) {
Expand All @@ -40,21 +41,33 @@ func TestLoader_Chains(t *testing.T) {
chain := toml.EVMConfig{ChainID: one, Chain: toml.Defaults(one)}
two := ubig.NewI(2)
chain2 := toml.EVMConfig{ChainID: two, Chain: toml.Defaults(two)}
evmORM := evmtest.NewTestConfigs(&chain, &chain2)
app.On("EVMORM").Return(evmORM)
config1, err := chain.TOMLString()
require.NoError(t, err)
config2, err := chain2.TOMLString()
require.NoError(t, err)

batcher := chainBatcher{app}
app.On("GetRelayers").Return(&chainlinkmocks.FakeRelayerChainInteroperators{Relayers: []loop.Relayer{
testutils2.MockRelayer{ChainStatus: commontypes.ChainStatus{
ID: "1",
Enabled: true,
Config: config1,
}}, testutils2.MockRelayer{ChainStatus: commontypes.ChainStatus{
ID: "2",
Enabled: true,
Config: config2,
}},
}})

batcher := chainBatcher{app}
keys := dataloader.NewKeysFromStrings([]string{"2", "1", "3"})
results := batcher.loadByIDs(ctx, keys)

assert.Len(t, results, 3)
config2, err := chain2.TOMLString()

require.NoError(t, err)
want2 := commontypes.ChainStatus{ID: "2", Enabled: true, Config: config2}
assert.Equal(t, want2, results[0].Data.(commontypes.ChainStatus))
config1, err := chain.TOMLString()
require.NoError(t, err)

want1 := commontypes.ChainStatus{ID: "1", Enabled: true, Config: config1}
assert.Equal(t, want1, results[1].Data.(commontypes.ChainStatus))
assert.Nil(t, results[2].Data)
Expand Down Expand Up @@ -367,7 +380,7 @@ func TestLoader_loadByEthTransactionID(t *testing.T) {
ctx := InjectDataloader(testutils.Context(t), app)

ethTxID := int64(3)
ethTxHash := utils.NewHash()
ethTxHash := evmutils.NewHash()

receipt := txmgr.Receipt{
ID: int64(1),
Expand Down
40 changes: 37 additions & 3 deletions core/web/resolver/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import (
"github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
evmtoml "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
chainlinkmocks "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/mocks"
"github.com/smartcontractkit/chainlink/v2/core/web/testutils"
)

func TestResolver_Chains(t *testing.T) {
Expand Down Expand Up @@ -70,13 +74,24 @@ ResendAfterThreshold = '1h0m0s'
name: "success",
authenticated: true,
before: func(f *gqlTestFramework) {
f.App.On("EVMORM").Return(f.Mocks.evmORM)

f.Mocks.evmORM.PutChains(evmtoml.EVMConfig{
chainConf := evmtoml.EVMConfig{
ChainID: &chainID,
Enabled: chain.Enabled,
Chain: chain.Chain,
})
}

chainConfToml, err2 := chainConf.TOMLString()
require.NoError(t, err2)

f.App.On("GetRelayers").Return(&chainlinkmocks.FakeRelayerChainInteroperators{Relayers: []loop.Relayer{
testutils.MockRelayer{ChainStatus: commontypes.ChainStatus{
ID: chainID.String(),
Enabled: *chain.Enabled,
Config: chainConfToml,
}},
}})

},
query: query,
result: fmt.Sprintf(`
Expand All @@ -93,6 +108,25 @@ ResendAfterThreshold = '1h0m0s'
}
}`, configTOMLEscaped),
},
unauthorizedTestCase(GQLTestCase{query: query}, "chains"),
{
name: "no chains",
authenticated: true,
before: func(f *gqlTestFramework) {
f.App.On("GetRelayers").Return(&chainlinkmocks.FakeRelayerChainInteroperators{Relayers: []loop.Relayer{}})

},
query: query,
result: `
{
"chains": {
"results": [],
"metadata": {
"total": 0
}
}
}`,
},
}

RunGQLTests(t, testCases)
Expand Down
43 changes: 39 additions & 4 deletions core/web/resolver/eth_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import (
"github.com/stretchr/testify/mock"

commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
mocks2 "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/web/testutils"

"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
Expand Down Expand Up @@ -102,10 +105,18 @@ func TestResolver_ETHKeys(t *testing.T) {
f.Mocks.chain.On("BalanceMonitor").Return(f.Mocks.balM)
f.Mocks.chain.On("Config").Return(f.Mocks.scfg)
f.Mocks.relayerChainInterops.EVMChains = legacyEVMChains
f.Mocks.relayerChainInterops.Relayers = []loop.Relayer{
testutils.MockRelayer{
ChainStatus: types.ChainStatus{
ID: "12",
Enabled: true,
},
NodeStatuses: nil,
},
}
f.Mocks.evmORM.PutChains(toml.EVMConfig{ChainID: &chainID})
f.Mocks.keystore.On("Eth").Return(f.Mocks.ethKs)
f.App.On("GetKeyStore").Return(f.Mocks.keystore)
f.App.On("EVMORM").Return(f.Mocks.evmORM)
f.App.On("GetRelayers").Return(f.Mocks.relayerChainInterops)

f.Mocks.scfg.On("EVM").Return(&evmMockConfig)
Expand Down Expand Up @@ -152,9 +163,17 @@ func TestResolver_ETHKeys(t *testing.T) {
f.Mocks.ethKs.On("GetAll").Return(keys, nil)
f.Mocks.relayerChainInterops.EVMChains = f.Mocks.legacyEVMChains
f.Mocks.evmORM.PutChains(toml.EVMConfig{ChainID: &chainID})
f.Mocks.relayerChainInterops.Relayers = []loop.Relayer{
testutils.MockRelayer{
ChainStatus: types.ChainStatus{
ID: "12",
Enabled: true,
},
NodeStatuses: nil,
},
}
f.Mocks.keystore.On("Eth").Return(f.Mocks.ethKs)
f.App.On("GetKeyStore").Return(f.Mocks.keystore)
f.App.On("EVMORM").Return(f.Mocks.evmORM)
f.App.On("GetRelayers").Return(f.Mocks.relayerChainInterops)
},
query: query,
Expand Down Expand Up @@ -304,14 +323,22 @@ func TestResolver_ETHKeys(t *testing.T) {
f.Mocks.ethClient.On("LINKBalance", mock.Anything, address, linkAddr).Return(commonassets.NewLinkFromJuels(12), gError)
f.Mocks.legacyEVMChains.On("Get", states[0].EVMChainID.String()).Return(f.Mocks.chain, nil)
f.Mocks.relayerChainInterops.EVMChains = f.Mocks.legacyEVMChains
f.Mocks.relayerChainInterops.Relayers = []loop.Relayer{
testutils.MockRelayer{
ChainStatus: types.ChainStatus{
ID: "12",
Enabled: true,
},
NodeStatuses: nil,
},
}
f.Mocks.chain.On("Client").Return(f.Mocks.ethClient)
f.Mocks.balM.On("GetEthBalance", address).Return(assets.NewEth(1))
f.Mocks.chain.On("BalanceMonitor").Return(f.Mocks.balM)
f.App.On("GetKeyStore").Return(f.Mocks.keystore)
f.Mocks.chain.On("Config").Return(f.Mocks.scfg)
f.Mocks.evmORM.PutChains(toml.EVMConfig{ChainID: &chainID})
f.App.On("GetRelayers").Return(f.Mocks.relayerChainInterops)
f.App.On("EVMORM").Return(f.Mocks.evmORM)
f.Mocks.scfg.On("EVM").Return(&evmMockConfig)
},
query: query,
Expand Down Expand Up @@ -361,9 +388,17 @@ func TestResolver_ETHKeys(t *testing.T) {
f.Mocks.legacyEVMChains.On("Get", states[0].EVMChainID.String()).Return(f.Mocks.chain, nil)
f.Mocks.relayerChainInterops.EVMChains = f.Mocks.legacyEVMChains
f.Mocks.evmORM.PutChains(toml.EVMConfig{ChainID: &chainID})
f.Mocks.relayerChainInterops.Relayers = []loop.Relayer{
testutils.MockRelayer{
ChainStatus: types.ChainStatus{
ID: "12",
Enabled: true,
},
NodeStatuses: nil,
},
}
f.Mocks.keystore.On("Eth").Return(f.Mocks.ethKs)
f.App.On("GetKeyStore").Return(f.Mocks.keystore)
f.App.On("EVMORM").Return(f.Mocks.evmORM)
f.App.On("GetRelayers").Return(f.Mocks.relayerChainInterops)
f.Mocks.scfg.On("EVM").Return(&evmMockConfig)
},
Expand Down
24 changes: 22 additions & 2 deletions core/web/resolver/eth_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import (
"github.com/ethereum/go-ethereum/common"
gqlerrors "github.com/graph-gophers/graphql-go/errors"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/types"
txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
chainlinkmocks "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/mocks"
"github.com/smartcontractkit/chainlink/v2/core/web/testutils"
)

func TestResolver_EthTransaction(t *testing.T) {
Expand Down Expand Up @@ -85,7 +89,15 @@ func TestResolver_EthTransaction(t *testing.T) {
}, nil)
f.App.On("TxmStorageService").Return(f.Mocks.txmStore)
f.Mocks.evmORM.PutChains(toml.EVMConfig{ChainID: &chainID})
f.App.On("EVMORM").Return(f.Mocks.evmORM)
f.App.On("GetRelayers").Return(&chainlinkmocks.FakeRelayerChainInteroperators{
Relayers: []loop.Relayer{
testutils.MockRelayer{ChainStatus: types.ChainStatus{
ID: "22",
Enabled: true,
Config: "",
}},
},
})
},
query: query,
variables: variables,
Expand Down Expand Up @@ -142,7 +154,15 @@ func TestResolver_EthTransaction(t *testing.T) {
}, nil)
f.App.On("TxmStorageService").Return(f.Mocks.txmStore)
f.Mocks.evmORM.PutChains(toml.EVMConfig{ChainID: &chainID})
f.App.On("EVMORM").Return(f.Mocks.evmORM)
f.App.On("GetRelayers").Return(&chainlinkmocks.FakeRelayerChainInteroperators{
Relayers: []loop.Relayer{
testutils.MockRelayer{ChainStatus: types.ChainStatus{
ID: "22",
Enabled: true,
Config: "",
}},
},
})
},
query: query,
variables: variables,
Expand Down
Loading
Loading