-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
286 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.