Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Dec 18, 2023
1 parent b577b5e commit 23b1b84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 17 additions & 10 deletions src/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,23 @@ export const registerDidMethodNetwork = ({
const key = `${blockchain}:${network}`;

const existedFlag = DidMethodNetwork[method][key];
if (typeof existedFlag === 'number' && existedFlag !== networkFlag) {
throw new Error(
`DID method network '${method}' with blockchain '${blockchain}' and network '${network}' already registered with another flag '${existedFlag.toString(
2
)}'`
);
}

if (Object.values(DidMethodNetwork[method]).includes(networkFlag)) {
throw new Error(`DID network flag ${DidMethodNetwork[method][key]} is already registered`);
if (typeof existedFlag === 'number') {
const isSameFlag = existedFlag === networkFlag;
if (!isSameFlag) {
throw new Error(
`DID method network '${method}' with blockchain '${blockchain}' and network '${network}' already registered with another flag '${existedFlag.toString(
2
)}'`
);
}
} else {
if (Object.values(DidMethodNetwork[method]).includes(networkFlag)) {
throw new Error(
`DID network flag ${networkFlag.toString(
2
)} is already registered for the another for '${method}'`
);
}
}
DidMethodNetwork[method][key] = networkFlag;
};
4 changes: 2 additions & 2 deletions tests/did.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ describe('DID tests', () => {
method: DidMethod.Iden3,
blockchain: Blockchain.ReadOnly,
network: 'network',
networkFlag: 0b01000000 | 0b00000011,
networkFlag: 0b11000000 | 0b00000011,
chainId: 104
}
},
Expand Down Expand Up @@ -436,7 +436,7 @@ describe('DID tests', () => {
network: 'supa_net',
networkFlag: 0b00010000 | 0b00000001
},
err: 'DID network flag undefined is already registered'
err: `DID network flag 10001 is already registered for the another for 'iden3'`
}
];
for (let i = 0; i < testCases.length; i++) {
Expand Down

0 comments on commit 23b1b84

Please sign in to comment.