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

Feature/add test validate unique chain name #168

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions v2/workflows/workflows/__tests__/registry.unique.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getRegistry } from '../test-utils';

const registry = getRegistry();

it('registry', () => {
registry.validateUnique()
});
18 changes: 18 additions & 0 deletions v2/workflows/workflows/src/registry.ts
Original file line number Diff line number Diff line change
@@ -214,6 +214,24 @@ export class Registry {
});
}

public validateUnique() {
const seen = new Set<string>(); // set to store unique chain_names
const duplicates = new Set<string>(); // set to store duplicate chain_names

this.chains.forEach(chain => {
let chainName = chain.chain_name
if (seen.has(chainName)) {
duplicates.add(chainName)
} else {
seen.add(chainName)
}
})
const duplicatesArr = Array.from(duplicates)
if (duplicatesArr.length > 0) {
throw new Error(`duplicates found: ${duplicatesArr.join(', ')}`)
}
}

public get count() {
return {
chains: this.chains.length,