Skip to content

Commit

Permalink
perf(PublicApostille): removed network type
Browse files Browse the repository at this point in the history
removed the network type from public apostille constructor

BREAKING CHANGE: removed network type from public apostille constructor
  • Loading branch information
khawarizmus committed Jul 17, 2018
1 parent 234d24b commit a61121a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 41 deletions.
16 changes: 8 additions & 8 deletions src/PublicApostille.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);
}
}
/**
Expand Down Expand Up @@ -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
Expand Down
32 changes: 1 addition & 31 deletions tests/unit/Public/Functionalities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion tests/unit/Public/Getters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Public/Hashs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a61121a

Please sign in to comment.