Skip to content

Commit

Permalink
feat(feeds) add multichain to Test_CreateFeedsManagerChainConfig tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giogam committed Oct 11, 2024
1 parent ef641b8 commit 5baa1eb
Showing 1 changed file with 254 additions and 25 deletions.
279 changes: 254 additions & 25 deletions core/web/resolver/feeds_manager_chain_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,37 @@ func Test_CreateFeedsManagerChainConfig(t *testing.T) {
}
}
}`
variables = map[string]interface{}{
"input": map[string]interface{}{
"feedsManagerID": stringutils.FromInt64(mgrID),
"chainID": chainID,
"chainType": "EVM",
"accountAddr": accountAddr,
"accountAddrPubKey": acctAddrPubKey,
"adminAddr": adminAddr,
"fluxMonitorEnabled": false,
"ocr1Enabled": true,
"ocr1IsBootstrap": false,
"ocr1P2PPeerID": peerID.String,
"ocr1KeyBundleID": keyBundleID.String,
"ocr2Enabled": true,
"ocr2IsBootstrap": false,
"ocr2P2PPeerID": peerID.String,
"ocr2KeyBundleID": keyBundleID.String,
"ocr2Plugins": `{"commit":true,"execute":true,"median":false,"mercury":true,"rebalancer":true}`,
"ocr2ForwarderAddress": forwarderAddr,
},

withVariables = func(chainType string) map[string]interface{} {
variables := map[string]interface{}{
"input": map[string]interface{}{
"feedsManagerID": stringutils.FromInt64(mgrID),
"chainID": chainID,
"chainType": chainType,
"accountAddr": accountAddr,
"accountAddrPubKey": acctAddrPubKey,
"adminAddr": adminAddr,
"fluxMonitorEnabled": false,
"ocr1Enabled": true,
"ocr1IsBootstrap": false,
"ocr1P2PPeerID": peerID.String,
"ocr1KeyBundleID": keyBundleID.String,
"ocr2Enabled": true,
"ocr2IsBootstrap": false,
"ocr2P2PPeerID": peerID.String,
"ocr2KeyBundleID": keyBundleID.String,
"ocr2Plugins": `{"commit":true,"execute":true,"median":false,"mercury":true,"rebalancer":true}`,
"ocr2ForwarderAddress": forwarderAddr,
},
}
return variables
}
)

testCases := []GQLTestCase{
unauthorizedTestCase(GQLTestCase{query: mutation, variables: variables}, "createFeedsManagerChainConfig"),
unauthorizedTestCase(GQLTestCase{query: mutation, variables: withVariables("EVM")}, "createFeedsManagerChainConfig"),
{
name: "success",
name: "success EVM",
authenticated: true,
before: func(ctx context.Context, f *gqlTestFramework) {
f.App.On("GetFeedsService").Return(f.Mocks.feedsSvc)
Expand Down Expand Up @@ -136,7 +140,232 @@ func Test_CreateFeedsManagerChainConfig(t *testing.T) {
}, nil)
},
query: mutation,
variables: variables,
variables: withVariables("EVM"),
result: `
{
"createFeedsManagerChainConfig": {
"chainConfig": {
"id": "1"
}
}
}`,
},
{
name: "success Solana",
authenticated: true,
before: func(ctx context.Context, f *gqlTestFramework) {
f.App.On("GetFeedsService").Return(f.Mocks.feedsSvc)
f.Mocks.feedsSvc.On("CreateChainConfig", mock.Anything, feeds.ChainConfig{
FeedsManagerID: mgrID,
ChainType: feeds.ChainTypeSolana,
ChainID: chainID,
AccountAddress: accountAddr,
AccountAddressPublicKey: null.StringFrom(acctAddrPubKey),
AdminAddress: adminAddr,
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: false,
},
OCR1Config: feeds.OCR1Config{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: true,
},
},
}).Return(cfgID, nil)
f.Mocks.feedsSvc.On("GetChainConfig", mock.Anything, cfgID).Return(&feeds.ChainConfig{
ID: cfgID,
ChainType: feeds.ChainTypeSolana,
ChainID: chainID,
AccountAddress: accountAddr,
AccountAddressPublicKey: null.StringFrom(acctAddrPubKey),
AdminAddress: adminAddr,
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: false,
},
OCR1Config: feeds.OCR1Config{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: true,
},
},
}, nil)
},
query: mutation,
variables: withVariables("SOLANA"),
result: `
{
"createFeedsManagerChainConfig": {
"chainConfig": {
"id": "1"
}
}
}`,
},
{
name: "success Starknet",
authenticated: true,
before: func(ctx context.Context, f *gqlTestFramework) {
f.App.On("GetFeedsService").Return(f.Mocks.feedsSvc)
f.Mocks.feedsSvc.On("CreateChainConfig", mock.Anything, feeds.ChainConfig{
FeedsManagerID: mgrID,
ChainType: feeds.ChainTypeStarknet,
ChainID: chainID,
AccountAddress: accountAddr,
AccountAddressPublicKey: null.StringFrom(acctAddrPubKey),
AdminAddress: adminAddr,
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: false,
},
OCR1Config: feeds.OCR1Config{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: true,
},
},
}).Return(cfgID, nil)
f.Mocks.feedsSvc.On("GetChainConfig", mock.Anything, cfgID).Return(&feeds.ChainConfig{
ID: cfgID,
ChainType: feeds.ChainTypeStarknet,
ChainID: chainID,
AccountAddress: accountAddr,
AccountAddressPublicKey: null.StringFrom(acctAddrPubKey),
AdminAddress: adminAddr,
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: false,
},
OCR1Config: feeds.OCR1Config{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: true,
},
},
}, nil)
},
query: mutation,
variables: withVariables("STARKNET"),
result: `
{
"createFeedsManagerChainConfig": {
"chainConfig": {
"id": "1"
}
}
}`,
},
{
name: "success APTOS",
authenticated: true,
before: func(ctx context.Context, f *gqlTestFramework) {
f.App.On("GetFeedsService").Return(f.Mocks.feedsSvc)
f.Mocks.feedsSvc.On("CreateChainConfig", mock.Anything, feeds.ChainConfig{
FeedsManagerID: mgrID,
ChainType: feeds.ChainTypeAptos,
ChainID: chainID,
AccountAddress: accountAddr,
AccountAddressPublicKey: null.StringFrom(acctAddrPubKey),
AdminAddress: adminAddr,
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: false,
},
OCR1Config: feeds.OCR1Config{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: true,
},
},
}).Return(cfgID, nil)
f.Mocks.feedsSvc.On("GetChainConfig", mock.Anything, cfgID).Return(&feeds.ChainConfig{
ID: cfgID,
ChainType: feeds.ChainTypeAptos,
ChainID: chainID,
AccountAddress: accountAddr,
AccountAddressPublicKey: null.StringFrom(acctAddrPubKey),
AdminAddress: adminAddr,
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: false,
},
OCR1Config: feeds.OCR1Config{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: true,
},
},
}, nil)
},
query: mutation,
variables: withVariables("APTOS"),
result: `
{
"createFeedsManagerChainConfig": {
Expand All @@ -154,7 +383,7 @@ func Test_CreateFeedsManagerChainConfig(t *testing.T) {
f.Mocks.feedsSvc.On("CreateChainConfig", mock.Anything, mock.IsType(feeds.ChainConfig{})).Return(int64(0), sql.ErrNoRows)
},
query: mutation,
variables: variables,
variables: withVariables("EVM"),
result: `
{
"createFeedsManagerChainConfig": {
Expand All @@ -172,7 +401,7 @@ func Test_CreateFeedsManagerChainConfig(t *testing.T) {
f.Mocks.feedsSvc.On("GetChainConfig", mock.Anything, cfgID).Return(nil, sql.ErrNoRows)
},
query: mutation,
variables: variables,
variables: withVariables("EVM"),
result: `
{
"createFeedsManagerChainConfig": {
Expand Down

0 comments on commit 5baa1eb

Please sign in to comment.