Skip to content

Commit

Permalink
common: allow TransactionMonitoring config group to be omitted
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Jul 21, 2023
1 parent ee3d6ad commit 1855520
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# this file is missing the whole `transactionMonitoring` entry, and is still valid
networkIdentifier: mainnet
gateway:
url: http://gateway
indexerOptions:
address: "0x4e8a4C63Df58bf59Fef513aB67a76319a9faf448"
mnemonic: word ivory whale diesel slab pelican voyage oxygen chat find tobacco sport
url: http://indexer
geoCoordinates: [25.1, -71.2]
restakeRewards: true
rebateClaimThreshold: 400
rebateClaimBatchThreshold: 5000
rebateClaimMaxBatchSize: 10
poiDisputeMonitoring: false
poiDisputableEpochs: 5
defaultAllocationAmount: 0.05
voucherRedemptionThreshold: 2
voucherRedemptionBatchThreshold: 2000
voucherRedemptionMaxBatchSize: 15
allocationManagementMode: "auto"
autoAllocationMinBatchSize: 20
subgraphs:
networkSubgraph:
deployment: QmPK1s3pNYLi9ERiq3BDxKa4XosgWwFRQUydHUtz4YgpqB
epochSubgraph:
url: http://subgraph
networkProvider:
url: http://provider
dai:
contractAddress: "0x4e8a4C63Df58bf59Fef513aB67a76319a9faf448"
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as fs from 'fs'
import * as path from 'path'
import * as YAML from 'yaml'
import { NetworkSpecification, IndexerOptions } from '../network-specification'
import {
NetworkSpecification,
IndexerOptions,
TransactionMonitoring,
} from '../network-specification'

function readYamlFile(p: string): string {
const filePath = path.join(__dirname, 'network-specification-files', p)
Expand All @@ -16,6 +20,16 @@ describe('Network Specification deserialization', () => {
NetworkSpecification.parse(validFile)
})
})

describe('Successful deserialization with missing defaults', () => {
test('Valid specification file', () => {
const validFile = readYamlFile('valid-missing.yml')
const parsed = NetworkSpecification.parse(validFile)
const expectedDefaults = TransactionMonitoring.parse({})
expect(expectedDefaults).not.toEqual({}) // Ensures default is not an empty object
expect(parsed.transactionMonitoring).toStrictEqual(expectedDefaults)
})
})
})

interface FailedDeserializationTest {
Expand Down
2 changes: 2 additions & 0 deletions packages/indexer-common/src/network-specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export const TransactionMonitoring = z
maxTransactionAttempts: z.number().nonnegative().finite().default(0),
})
.strict()
.default({}) // This means defaults will be used for instantiation when the TransactionMonitoring group is absent.

export type TransactionMonitoring = z.infer<typeof TransactionMonitoring>

// Generic subgraph specification
Expand Down

0 comments on commit 1855520

Please sign in to comment.