Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aizaiz committed Nov 26, 2018
2 parents bdcce23 + 1d8b0cc commit 75d3ee2
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 279 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apostille-library",
"version": "0.0.0-development",
"version": "0.0.0",
"description": "A novel & holistic blockchain notarization and timestamping with transferable, updatable, branded, and conjointly owned notarizations.",
"keywords": [
"blockchain",
Expand All @@ -12,7 +12,7 @@
"homepage": "https://nem.io/wp-content/themes/nem/files/ApostilleWhitePaper.pdf",
"repository": {
"type": "git",
"url": "https://github.com/NEM-Apostille/Apostille-library"
"url": "https://github.com/luxtagofficial/Apostille-library/"
},
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
9 changes: 8 additions & 1 deletion src/model/apostille/Apostille.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ const nem = nemSDK.default;
* @class Apostille
*/
class Apostille {

/**
* @description init apostille
* @static
* @param {string} seed
* @param {Account} generatorAccount
* @returns {Apostille}
* @memberof Apostille
*/
public static init(
seed: string,
generatorAccount: Account): Apostille {
Expand Down
276 changes: 206 additions & 70 deletions tests/e2e/PrivateApostille/Apostille.spec.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,214 @@
import CryptoJS from 'crypto-js';
import { Account, Address, NetworkType } from 'nem2-sdk';
import sinon from 'sinon';
import { Initiator, PublicApostille, SHA256 } from '../../../index';

const fileName = 'FileName.pdf';
// A funny but valid private key
const pk = 'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aaee';
const signer = Account.createFromPrivateKey(pk, NetworkType.MIJIN_TEST);

beforeAll(() => {
jest.setTimeout(10000);
});

// Simulate the file content
const fileContent = CryptoJS.enc.Utf8.parse('Public apostille is awesome !');
const hashFunction = new SHA256();
// import { Account, NetworkType } from 'nem2-sdk';

describe('announce function should work properly', () => {
// const seed = '.N:@N%5SVjj3Wkmr-';
// // A funny but valid private key
// const sk = 'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aaee';
// const generator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);

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);
// beforeAll(() => {
// jest.setTimeout(10000);
// });

publicApostille.update(fileContent, hashFunction);
publicApostille.announce();
}).toThrow();
describe('Create functionn should work properly', () => {
it.skip('skip', () => {
expect('').toMatch('');
});

it('should throw error if try to announce more than once', async () => {
const initiator = new Initiator(signer);
const sinkAddress = Address.createFromRawAddress( 'SCKPEZ-5ZAPYO-PXVF6U-YLHINF-CLYZHO-YCIO3P-KGVV');
const publicApostille = new PublicApostille(
initiator,
fileName,
sinkAddress);
publicApostille.update(fileContent, hashFunction);
await publicApostille.announce();

expect(publicApostille.announced).toBeTruthy();
expect(() => {
publicApostille.announce();
}).toThrow();
});
// it.skip('should throw an error if you try to create an apostille more than once', async () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator);
// expect.assertions(1);
// await privateApostille.create(initiator, 'raw');
// return privateApostille.create(initiator, 'raw').catch((e) => {
// expect(e.message).toMatch(Errors[Errors.APOSTILLE_ALREADY_CREATED]);
// });
// });

test('updating an public apostille should be allowed as many times as we want', async () => {
const initiator = new Initiator(signer);
const sinkAddress = Address.createFromRawAddress( 'SCKPEZ-5ZAPYO-PXVF6U-YLHINF-CLYZHO-YCIO3P-KGVV');
const publicApostille = new PublicApostille(
initiator,
fileName,
sinkAddress);

publicApostille.update(CryptoJS.enc.Utf8.parse('Public apostille is awesome !'), hashFunction);
await publicApostille.announce();
publicApostille.update(CryptoJS.enc.Utf8.parse('Public apostille can be updated'), hashFunction);
await publicApostille.announce();
publicApostille.update(CryptoJS.enc.Utf8.parse('as many times as we want'), hashFunction);
await publicApostille.announce();
});
// it.skip('should create a transfer transaction', () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator);
// return privateApostille.create(initiator, 'raw').then(() => {
// // tslint:disable-next-line:no-string-literal
// expect(privateApostille['transactions'][0].type).toEqual(TransactionType.TRANSFER);
// });
// });

// it.skip('should create an aggregate complete transaction', () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator, creator.publicAccount, true);
// return privateApostille.create(initiator, 'raw').then(() => {
// // tslint:disable-next-line:no-string-literal
// expect(privateApostille['transactions'][0].type).toEqual(TransactionType.AGGREGATE_COMPLETE);
// });
// });

// it.skip('should create an aggregate bounded transaction', () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator, creator.publicAccount, false);
// return privateApostille.create(initiator, 'raw').then(() => {
// // tslint:disable-next-line:no-string-literal
// expect(privateApostille['transactions'][0].type).toEqual(TransactionType.AGGREGATE_BONDED);
// });
// });

test('announce should work properly', async () => {
const stubannounce = sinon.stub(PublicApostille.prototype, 'announce');
const initiator = new Initiator(signer);
const sinkAddress = Address.createFromRawAddress( 'SCKPEZ-5ZAPYO-PXVF6U-YLHINF-CLYZHO-YCIO3P-KGVV');
const publicApostille = new PublicApostille(
initiator,
fileName,
sinkAddress);

publicApostille.update(CryptoJS.enc.Utf8.parse('Public apostille is awesome !'), hashFunction);
await publicApostille.announce();
expect(stubannounce.called).toBeTruthy();
});
});

// describe('update function should work properly', () => {

// it.skip('should throw an error if we try to update before creating', async () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator);
// expect.assertions(1);
// return privateApostille.update(initiator, 'raw').catch((e) => {
// expect(e.message).toMatch(Errors[Errors.APOSTILLE_NOT_CREATED]);
// });
// });

// it.skip('should create a transfer transaction', async () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator);
// expect.assertions(1);
// await privateApostille.create(initiator, 'raw');
// await privateApostille.update(initiator, 'update');
// // tslint:disable-next-line:no-string-literal
// expect(privateApostille['transactions'][1].type).toEqual(TransactionType.TRANSFER);
// });

// it.skip('should create an aggregate complete transaction', async () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator, creator.publicAccount, true);
// expect.assertions(1);
// await privateApostille.create(initiator, 'raw');
// await privateApostille.update(initiator, 'update');
// // tslint:disable-next-line:no-string-literal
// expect(privateApostille['transactions'][0].type).toEqual(TransactionType.AGGREGATE_COMPLETE);
// });

// it.skip('should create an aggregate bounded transaction', async () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator, creator.publicAccount, false);
// expect.assertions(1);
// await privateApostille.create(initiator, 'raw');
// await privateApostille.update(initiator, 'update');
// // tslint:disable-next-line:no-string-literal
// expect(privateApostille['transactions'][0].type).toEqual(TransactionType.AGGREGATE_BONDED);
// });

// });

// describe('associate function should work properly', () => {

// it.skip('should create an aggregate bounded transaction', async () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator, creator.publicAccount, false);
// expect.assertions(1);
// await privateApostille.create(initiator, 'raw');
// await privateApostille.update(initiator, 'update');
// privateApostille.associate([initiator.account.publicAccount], 1, 1);
// // tslint:disable-next-line:no-string-literal
// expect(privateApostille['transactions'][2].type).toEqual(TransactionType.MODIFY_MULTISIG_ACCOUNT);
// });

// });

// describe('transfer function should work properly', () => {

// it.skip('should create an aggregate complete transaction', async () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// // const initiator = new Initiator(creator, creator.publicAccount, false);
// expect.assertions(1);
// privateApostille.transfer([creator], true, [creator.publicAccount], [creator.publicAccount], 0, 0);
// // tslint:disable-next-line:no-string-literal
// expect(privateApostille['transactions'][0].type).toEqual(TransactionType.AGGREGATE_COMPLETE);
// });

// it.skip('should create an aggregate complete transaction', async () => {
// const privateApostille = Apostille.init(seed, generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// // const initiator = new Initiator(creator, creator.publicAccount, false);
// expect.assertions(1);
// privateApostille.transfer([creator], false, [], [], 0, 0);
// // tslint:disable-next-line:no-string-literal
// expect(privateApostille['transactions'][0].type).toEqual(TransactionType.AGGREGATE_BONDED);
// });

// });

// describe('isCreated function should work properly', () => {

// it.skip('should return false before creation', async () => {
// const privateApostille = Apostille.init('QUleqZedaOUtlSh', generator);
// expect.assertions(1);
// return privateApostille.isCreated().then((result) => {
// expect(result).toBeFalsy();
// });
// });

// it('should return true after creation', async () => {
// const privateApostille = Apostille.init('new random seed', generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator);
// expect.assertions(1);
// await privateApostille.create(initiator, 'raw');
// return privateApostille.isCreated().then((result) => {
// expect(result).toBeTruthy();
// });
// });

// it.skip('should return true for an already created apostille', async () => {
// const privateApostille = Apostille.init('MIJIN_TEST', generator);
// expect.assertions(1);
// return privateApostille.isCreated().then((result) => {
// expect(result).toBeTruthy();
// });
// });

// it.skip('should throw an error if we don\'t specefy mijin endpoint url', () => {
// const MJgenerator = Account.createFromPrivateKey(sk, NetworkType.MIJIN);
// try {
// return Apostille.init('k7u*VTsVCk6h,FdN', MJgenerator);
// } catch (e) {
// expect(e.message).toMatch(Errors[Errors.MIJIN_ENDPOINT_NEEDED]);
// }
// });

// it.skip('should return false before an announce', () => {
// const MTgenerator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const apostilleMT = Apostille.init('QUleqZedaOUtlSh', MTgenerator);
// return apostilleMT.isCreated().then((MT) => {
// expect(MT).toBeFalsy();
// });
// });

// it.skip('should return true after an announce', async () => {
// const privateApostille = Apostille.init('_934@Ve*,tM(3MN-', generator);
// const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
// const initiator = new Initiator(creator);
// privateApostille.created = true;
// await privateApostille.update(initiator, 'update');
// await privateApostille.announce();
// return privateApostille.isCreated().then((result) => {
// expect(result).toBeTruthy();
// });
// });

// it.skip('should return true for an already announced apostille', () => {
// const privateApostille = Apostille.init('MIJIN_TEST', generator);
// return privateApostille.isCreated().then((result) => {
// expect(result).toBeTruthy();
// });
// });
// });

// TODO: check the order of transactions
// TODO: no transfer transaction should exist after a multisig modification
Loading

0 comments on commit 75d3ee2

Please sign in to comment.