diff --git a/src/PublicApostille.ts b/src/PublicApostille.ts index 0c2593f..ec2053e 100644 --- a/src/PublicApostille.ts +++ b/src/PublicApostille.ts @@ -22,6 +22,12 @@ class PublicApostille { * @memberof PublicApostille */ private address: Address; + /** + * @description - the network type the public apostille + * @private + * @memberof PublicApostille + */ + private networkType: NetworkType; /** * @description - the hash uncluding the magical byte of this public apostille * @private @@ -45,17 +51,14 @@ class PublicApostille { constructor( private initiatorAccount: Initiator, public readonly fileName: string, - public readonly networkType: NetworkType, sinkAddress?: string, ) { + this.networkType = initiatorAccount.account.address.networkType; if (sinkAddress) { const newSink = Address.createFromRawAddress(sinkAddress); - if (newSink.networkType !== networkType) { - throw new Error(Errors[Errors.NETWORK_TYPE_MISMATCHED]); - } this.address = newSink; } else { - this.address = Address.createFromRawAddress(Sinks[networkType]); + this.address = Address.createFromRawAddress(Sinks[this.networkType]); } } /** @@ -104,9 +107,6 @@ class PublicApostille { transactionHttp = new TransactionHttp(HistoricalEndpoints[this.networkType]); listener = new Listener(HistoricalEndpoints[this.networkType]); } - if (this.initiatorAccount.account.address.networkType !== this.networkType) { - throw new Error(Errors[Errors.NETWORK_TYPE_MISMATCHED]); - } if (this.initiatorAccount.multisigAccount) { // we need to wrap the creation transaction in an aggregate transaction diff --git a/tests/unit/Public/Functionalities.spec.ts b/tests/unit/Public/Functionalities.spec.ts index bdf507f..70e574f 100644 --- a/tests/unit/Public/Functionalities.spec.ts +++ b/tests/unit/Public/Functionalities.spec.ts @@ -12,45 +12,18 @@ beforeAll(() => { jest.setTimeout(10000); }); -describe('constructor of public apostilee should work properly', () => { - it('should throw error if network type of initiator and sink address dont match', () => { - expect(() => { - const initiator = new Initiator(signer); - const publicApostille = new PublicApostille( - initiator, - fileName, - NetworkType.MAIN_NET, - 'SCKPEZ-5ZAPYO-PXVF6U-YLHINF-CLYZHO-YCIO3P-KGVV'); - }).toThrow(); - }); -}); - // Simulate the file content const fileContent = CryptoJS.enc.Utf8.parse('Public apostille is awesome !'); const hashFunction = new SHA256(); describe('announce function should work properly', () => { - it('should throw error if network type of initiator and the apostille dont match', () => { - expect(() => { - const initiator = new Initiator(signer); - const publicApostille = new PublicApostille( - initiator, - fileName, - NetworkType.MAIN_NET); - - publicApostille.update(fileContent, hashFunction); - publicApostille.announce(); - }).toThrow(); - }); - it('should throw error if network type is mijin and we don\'t specefy an endpoint', () => { expect(() => { const initiator = new Initiator(signer); const publicApostille = new PublicApostille( initiator, - fileName, - NetworkType.MIJIN); + fileName,); publicApostille.update(fileContent, hashFunction); publicApostille.announce(); @@ -62,7 +35,6 @@ describe('announce function should work properly', () => { const publicApostille = new PublicApostille( initiator, fileName, - NetworkType.MIJIN_TEST, 'SCKPEZ-5ZAPYO-PXVF6U-YLHINF-CLYZHO-YCIO3P-KGVV'); publicApostille.update(fileContent, hashFunction); await publicApostille.announce(); @@ -78,7 +50,6 @@ describe('announce function should work properly', () => { const publicApostille = new PublicApostille( initiator, fileName, - NetworkType.MIJIN_TEST, 'SCKPEZ-5ZAPYO-PXVF6U-YLHINF-CLYZHO-YCIO3P-KGVV'); publicApostille.update(CryptoJS.enc.Utf8.parse('Public apostille is awesome !'), hashFunction); @@ -95,7 +66,6 @@ describe('announce function should work properly', () => { const publicApostille = new PublicApostille( initiator, fileName, - NetworkType.MIJIN_TEST, 'SCKPEZ-5ZAPYO-PXVF6U-YLHINF-CLYZHO-YCIO3P-KGVV'); publicApostille.update(CryptoJS.enc.Utf8.parse('Public apostille is awesome !'), hashFunction); diff --git a/tests/unit/Public/Getters.spec.ts b/tests/unit/Public/Getters.spec.ts index 69ae31e..b31bc17 100644 --- a/tests/unit/Public/Getters.spec.ts +++ b/tests/unit/Public/Getters.spec.ts @@ -10,7 +10,6 @@ const initiator = new Initiator(signer); const publicApostille = new PublicApostille( initiator, fileName, - NetworkType.MIJIN_TEST, 'SCKPEZ-5ZAPYO-PXVF6U-YLHINF-CLYZHO-YCIO3P-KGVV'); describe('getters should work properly', () => { diff --git a/tests/unit/Public/Hashs.spec.ts b/tests/unit/Public/Hashs.spec.ts index c5f5018..e1efa23 100644 --- a/tests/unit/Public/Hashs.spec.ts +++ b/tests/unit/Public/Hashs.spec.ts @@ -45,7 +45,7 @@ hashArray.forEach((hash) => { false, {}, false, nem.model.network.data.testnet.id); - newPublicApostille = new PublicApostille(initiator, fileName, NetworkType.TEST_NET); + newPublicApostille = new PublicApostille(initiator, fileName); hashType = chooseHash(hash); newPublicApostille.update(fileContent, hashType);