|
1 | 1 | import { |
2 | 2 | convertSubgraphBasedRulesToDeploymentBased, |
3 | 3 | consolidateAllocationDecisions, |
| 4 | + resolveTargetDeployments, |
4 | 5 | } from '../agent' |
5 | 6 | import { |
6 | 7 | INDEXING_RULE_GLOBAL, |
@@ -208,3 +209,122 @@ describe('consolidateAllocationDecisions function', () => { |
208 | 209 | expect(result).not.toContain(a) |
209 | 210 | }) |
210 | 211 | }) |
| 212 | + |
| 213 | +describe('resolveTargetDeployments function', () => { |
| 214 | + const alwaysDeployment = new SubgraphDeploymentID( |
| 215 | + 'QmXZiV6S13ha6QXq4dmaM3TB4CHcDxBMvGexSNu9Kc28EH', |
| 216 | + ) |
| 217 | + const offchainDeployment = new SubgraphDeploymentID( |
| 218 | + 'QmRKs2ZfuwvmZA3QAWmCqrGUjV9pxtBUDP3wuc6iVGnjA2', |
| 219 | + ) |
| 220 | + const allocationDeployment = new SubgraphDeploymentID( |
| 221 | + 'QmULAfA3eS5yojxeSR2KmbyuiwCGYPjymsFcpa6uYsu6CJ', |
| 222 | + ) |
| 223 | + const offchainArgDeployment = new SubgraphDeploymentID( |
| 224 | + 'QmWmyoMoctfbAaiEs2G46gpeUmhqFRDW6KWo64y5r581Vz', |
| 225 | + ) |
| 226 | + |
| 227 | + it('includes OFFCHAIN rules when allocationDecisions is empty (manual mode)', () => { |
| 228 | + const rules = { |
| 229 | + 'eip155:42161': [ |
| 230 | + { |
| 231 | + identifier: offchainDeployment.ipfsHash, |
| 232 | + identifierType: SubgraphIdentifierType.DEPLOYMENT, |
| 233 | + decisionBasis: IndexingDecisionBasis.OFFCHAIN, |
| 234 | + } as IndexingRuleAttributes, |
| 235 | + ], |
| 236 | + } |
| 237 | + |
| 238 | + const result = resolveTargetDeployments({}, rules, []) |
| 239 | + |
| 240 | + expect(result.size).toBe(1) |
| 241 | + expect([...result].map(d => d.ipfsHash)).toContain( |
| 242 | + offchainDeployment.ipfsHash, |
| 243 | + ) |
| 244 | + }) |
| 245 | + |
| 246 | + it('includes offchainSubgraphs from startup args', () => { |
| 247 | + const result = resolveTargetDeployments({}, {}, [offchainArgDeployment]) |
| 248 | + |
| 249 | + expect(result.size).toBe(1) |
| 250 | + expect([...result].map(d => d.ipfsHash)).toContain( |
| 251 | + offchainArgDeployment.ipfsHash, |
| 252 | + ) |
| 253 | + }) |
| 254 | + |
| 255 | + it('includes deployments from allocationDecisions', () => { |
| 256 | + const allocationDecisions = { |
| 257 | + 'eip155:42161': [{ deployment: allocationDeployment, toAllocate: true }], |
| 258 | + } |
| 259 | + |
| 260 | + const result = resolveTargetDeployments(allocationDecisions, {}, []) |
| 261 | + |
| 262 | + expect(result.size).toBe(1) |
| 263 | + expect(result).toContain(allocationDeployment) |
| 264 | + }) |
| 265 | + |
| 266 | + /** |
| 267 | + * BUG TEST: In manual allocation mode, networkDeploymentAllocationDecisions is empty |
| 268 | + * because evaluateDeployments is skipped. This means decisionBasis: ALWAYS rules |
| 269 | + * are not included in targetDeployments, causing those subgraphs to be paused. |
| 270 | + * |
| 271 | + * This test should FAIL with the current buggy code and PASS after the fix. |
| 272 | + */ |
| 273 | + it('includes ALWAYS rules when allocationDecisions is empty (manual mode)', () => { |
| 274 | + const rules = { |
| 275 | + 'eip155:42161': [ |
| 276 | + { |
| 277 | + identifier: alwaysDeployment.ipfsHash, |
| 278 | + identifierType: SubgraphIdentifierType.DEPLOYMENT, |
| 279 | + decisionBasis: IndexingDecisionBasis.ALWAYS, |
| 280 | + } as IndexingRuleAttributes, |
| 281 | + ], |
| 282 | + } |
| 283 | + |
| 284 | + // In manual mode, allocationDecisions is empty because evaluateDeployments is skipped |
| 285 | + const result = resolveTargetDeployments({}, rules, []) |
| 286 | + |
| 287 | + // ALWAYS rules should still be included in targetDeployments |
| 288 | + expect(result.size).toBe(1) |
| 289 | + expect([...result].map(d => d.ipfsHash)).toContain( |
| 290 | + alwaysDeployment.ipfsHash, |
| 291 | + ) |
| 292 | + }) |
| 293 | + |
| 294 | + it('combines all sources correctly', () => { |
| 295 | + const allocationDecisions = { |
| 296 | + 'eip155:42161': [{ deployment: allocationDeployment, toAllocate: true }], |
| 297 | + } |
| 298 | + const rules = { |
| 299 | + 'eip155:42161': [ |
| 300 | + { |
| 301 | + identifier: offchainDeployment.ipfsHash, |
| 302 | + identifierType: SubgraphIdentifierType.DEPLOYMENT, |
| 303 | + decisionBasis: IndexingDecisionBasis.OFFCHAIN, |
| 304 | + } as IndexingRuleAttributes, |
| 305 | + { |
| 306 | + identifier: alwaysDeployment.ipfsHash, |
| 307 | + identifierType: SubgraphIdentifierType.DEPLOYMENT, |
| 308 | + decisionBasis: IndexingDecisionBasis.ALWAYS, |
| 309 | + } as IndexingRuleAttributes, |
| 310 | + ], |
| 311 | + } |
| 312 | + |
| 313 | + const result = resolveTargetDeployments(allocationDecisions, rules, [ |
| 314 | + offchainArgDeployment, |
| 315 | + ]) |
| 316 | + |
| 317 | + // Should include: allocationDeployment, offchainDeployment, alwaysDeployment, offchainArgDeployment |
| 318 | + expect(result.size).toBe(4) |
| 319 | + expect(result).toContain(allocationDeployment) |
| 320 | + expect([...result].map(d => d.ipfsHash)).toContain( |
| 321 | + offchainDeployment.ipfsHash, |
| 322 | + ) |
| 323 | + expect([...result].map(d => d.ipfsHash)).toContain( |
| 324 | + alwaysDeployment.ipfsHash, |
| 325 | + ) |
| 326 | + expect([...result].map(d => d.ipfsHash)).toContain( |
| 327 | + offchainArgDeployment.ipfsHash, |
| 328 | + ) |
| 329 | + }) |
| 330 | +}) |
0 commit comments