Skip to content

Commit 9db1e90

Browse files
committed
Updated tests
1 parent e339f33 commit 9db1e90

File tree

2 files changed

+299
-24
lines changed

2 files changed

+299
-24
lines changed

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 157 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,83 @@ describe('TransactionHttp', () => {
387387
transactionHttp.announce(signedTransaction);
388388
});
389389
});
390-
describe('AccountRestrictionTransaction - Address', () => {
390+
describe('AccountRestrictionTransaction - Outgoing Address', () => {
391+
let listener: Listener;
392+
before (() => {
393+
listener = new Listener(config.apiUrl);
394+
return listener.open();
395+
});
396+
after(() => {
397+
return listener.close();
398+
});
399+
400+
it('standalone', (done) => {
401+
const addressRestrictionFilter = AccountRestrictionModification.createForAddress(
402+
RestrictionModificationType.Add,
403+
account3.address,
404+
);
405+
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
406+
Deadline.create(),
407+
AccountRestrictionType.BlockOutgoingAddress,
408+
[addressRestrictionFilter],
409+
NetworkType.MIJIN_TEST,
410+
);
411+
const signedTransaction = addressModification.signWith(account, generationHash);
412+
413+
listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => {
414+
expect(transaction.modifications, 'Modifications').not.to.be.undefined;
415+
expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined;
416+
expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined;
417+
expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined;
418+
done();
419+
});
420+
listener.status(account.address).subscribe((error) => {
421+
console.log('Error:', error);
422+
assert(false);
423+
done();
424+
});
425+
transactionHttp.announce(signedTransaction);
426+
});
427+
});
428+
describe('AccountRestrictionTransaction - Outgoing Address', () => {
429+
let listener: Listener;
430+
before (() => {
431+
listener = new Listener(config.apiUrl);
432+
return listener.open();
433+
});
434+
after(() => {
435+
return listener.close();
436+
});
437+
it('aggregate', (done) => {
438+
const addressRestrictionFilter = AccountRestrictionModification.createForAddress(
439+
RestrictionModificationType.Remove,
440+
account3.address,
441+
);
442+
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
443+
Deadline.create(),
444+
AccountRestrictionType.BlockOutgoingAddress,
445+
[addressRestrictionFilter],
446+
NetworkType.MIJIN_TEST,
447+
);
448+
const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(),
449+
[addressModification.toAggregate(account.publicAccount)],
450+
NetworkType.MIJIN_TEST,
451+
[],
452+
);
453+
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
454+
listener.confirmed(account.address).subscribe((transaction: Transaction) => {
455+
done();
456+
});
457+
listener.status(account.address).subscribe((error) => {
458+
console.log('Error:', error);
459+
assert(false);
460+
done();
461+
});
462+
transactionHttp.announce(signedTransaction);
463+
});
464+
});
465+
466+
describe('AccountRestrictionTransaction - Incoming Address', () => {
391467
let listener: Listener;
392468
before (() => {
393469
listener = new Listener(config.apiUrl);
@@ -425,7 +501,7 @@ describe('TransactionHttp', () => {
425501
transactionHttp.announce(signedTransaction);
426502
});
427503
});
428-
describe('AccountRestrictionTransaction - Address', () => {
504+
describe('AccountRestrictionTransaction - Incoming Address', () => {
429505
let listener: Listener;
430506
before (() => {
431507
listener = new Listener(config.apiUrl);
@@ -537,7 +613,7 @@ describe('TransactionHttp', () => {
537613
transactionHttp.announce(signedTransaction);
538614
});
539615
});
540-
describe('AccountRestrictionTransaction - Operation', () => {
616+
describe('AccountRestrictionTransaction - Incoming Operation', () => {
541617
let listener: Listener;
542618
before (() => {
543619
listener = new Listener(config.apiUrl);
@@ -575,7 +651,7 @@ describe('TransactionHttp', () => {
575651
transactionHttp.announce(signedTransaction);
576652
});
577653
});
578-
describe('AccountRestrictionTransaction - Operation', () => {
654+
describe('AccountRestrictionTransaction - Incoming Operation', () => {
579655
let listener: Listener;
580656
before (() => {
581657
listener = new Listener(config.apiUrl);
@@ -612,6 +688,83 @@ describe('TransactionHttp', () => {
612688
transactionHttp.announce(signedTransaction);
613689
});
614690
});
691+
692+
describe('AccountRestrictionTransaction - Outgoing Operation', () => {
693+
let listener: Listener;
694+
before (() => {
695+
listener = new Listener(config.apiUrl);
696+
return listener.open();
697+
});
698+
after(() => {
699+
return listener.close();
700+
});
701+
702+
it('standalone', (done) => {
703+
const operationRestrictionFilter = AccountRestrictionModification.createForOperation(
704+
RestrictionModificationType.Add,
705+
TransactionType.LINK_ACCOUNT,
706+
);
707+
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
708+
Deadline.create(),
709+
AccountRestrictionType.BlockOutgoingTransactionType,
710+
[operationRestrictionFilter],
711+
NetworkType.MIJIN_TEST,
712+
);
713+
const signedTransaction = addressModification.signWith(account3, generationHash);
714+
715+
listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => {
716+
expect(transaction.modifications, 'Modifications').not.to.be.undefined;
717+
expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined;
718+
expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined;
719+
expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined;
720+
done();
721+
});
722+
listener.status(account3.address).subscribe((error) => {
723+
console.log('Error:', error);
724+
assert(false);
725+
done();
726+
});
727+
transactionHttp.announce(signedTransaction);
728+
});
729+
});
730+
describe('AccountRestrictionTransaction - Outgoing Operation', () => {
731+
let listener: Listener;
732+
before (() => {
733+
listener = new Listener(config.apiUrl);
734+
return listener.open();
735+
});
736+
after(() => {
737+
return listener.close();
738+
});
739+
it('aggregate', (done) => {
740+
const operationRestrictionFilter = AccountRestrictionModification.createForOperation(
741+
RestrictionModificationType.Remove,
742+
TransactionType.LINK_ACCOUNT,
743+
);
744+
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
745+
Deadline.create(),
746+
AccountRestrictionType.BlockOutgoingTransactionType,
747+
[operationRestrictionFilter],
748+
NetworkType.MIJIN_TEST,
749+
);
750+
const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(),
751+
[addressModification.toAggregate(account3.publicAccount)],
752+
NetworkType.MIJIN_TEST,
753+
[],
754+
);
755+
const signedTransaction = aggregateTransaction.signWith(account3, generationHash);
756+
listener.confirmed(account3.address).subscribe((transaction: Transaction) => {
757+
done();
758+
});
759+
listener.status(account3.address).subscribe((error) => {
760+
console.log('Error:', error);
761+
assert(false);
762+
done();
763+
});
764+
transactionHttp.announce(signedTransaction);
765+
});
766+
});
767+
615768
describe('AccountLinkTransaction', () => {
616769
let listener: Listener;
617770
before (() => {

test/model/transaction/AccountRestrictionTransaction.spec.ts

Lines changed: 142 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('AccountRestrictionTransaction', () => {
148148
expect(addressRestrictionTransaction.maxFee.lower).to.be.equal(1);
149149
});
150150

151-
it('should create address restriction transaction', () => {
151+
it('should create allow incmoing address restriction transaction', () => {
152152

153153
const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
154154
const addressRestrictionFilter = AccountRestrictionModification.createForAddress(
@@ -179,15 +179,24 @@ describe('AccountRestrictionTransaction', () => {
179179
address,
180180
);
181181

182-
expect(() => {
183-
AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
184-
Deadline.create(),
185-
AccountRestrictionType.Sentinel,
186-
[addressRestrictionFilter],
187-
NetworkType.MIJIN_TEST,
188-
);
189-
}).to.throw(Error, 'Restriction type is not allowed.');
190-
182+
const invalidType = [AccountRestrictionType.AllowIncomingTransactionType,
183+
AccountRestrictionType.AllowMosaic,
184+
AccountRestrictionType.AllowOutgoingTransactionType,
185+
AccountRestrictionType.BlockIncomingTransactionType,
186+
AccountRestrictionType.BlockMosaic,
187+
AccountRestrictionType.BlockOutgoingTransactionType,
188+
AccountRestrictionType.Sentinel,
189+
];
190+
invalidType.forEach((type) => {
191+
expect(() => {
192+
AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
193+
Deadline.create(),
194+
type,
195+
[addressRestrictionFilter],
196+
NetworkType.MIJIN_TEST,
197+
);
198+
}).to.throw(Error, 'Restriction type is not allowed.');
199+
});
191200
});
192201

193202
it('should create mosaic restriction transaction', () => {
@@ -213,23 +222,34 @@ describe('AccountRestrictionTransaction', () => {
213222

214223
});
215224

216-
it('should throw exception when create mosaic restriction transaction with wrong type', () => {
225+
it('should throw exception when create account mosaic restriction transaction with wrong type', () => {
217226

218227
const mosaicId = new MosaicId([2262289484, 3405110546]);
219228
const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic(
220229
RestrictionModificationType.Add,
221230
mosaicId,
222231
);
223232

224-
expect(() => {
225-
AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction(
226-
Deadline.create(),
227-
AccountRestrictionType.Sentinel,
228-
[mosaicRestrictionFilter],
229-
NetworkType.MIJIN_TEST,
230-
);
231-
}).to.throw(Error, 'Restriction type is not allowed.');
232-
233+
const invalidType = [AccountRestrictionType.AllowIncomingTransactionType,
234+
AccountRestrictionType.AllowIncomingAddress,
235+
AccountRestrictionType.AllowOutgoingTransactionType,
236+
AccountRestrictionType.BlockIncomingTransactionType,
237+
AccountRestrictionType.AllowOutgoingAddress,
238+
AccountRestrictionType.BlockOutgoingTransactionType,
239+
AccountRestrictionType.BlockIncomingAddress,
240+
AccountRestrictionType.BlockOutgoingAddress,
241+
AccountRestrictionType.Sentinel,
242+
];
243+
invalidType.forEach((type) => {
244+
expect(() => {
245+
AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction(
246+
Deadline.create(),
247+
type,
248+
[mosaicRestrictionFilter],
249+
NetworkType.MIJIN_TEST,
250+
);
251+
}).to.throw(Error, 'Restriction type is not allowed.');
252+
});
233253
});
234254

235255
it('should create operation restriction transaction', () => {
@@ -254,4 +274,106 @@ describe('AccountRestrictionTransaction', () => {
254274
)).to.be.equal('0401004E42');
255275

256276
});
277+
278+
it('should throw exception when create account operation restriction transaction with wrong type', () => {
279+
280+
const operation = TransactionType.ADDRESS_ALIAS;
281+
const operationRestrictionFilter = AccountRestrictionModification.createForOperation(
282+
RestrictionModificationType.Add,
283+
operation,
284+
);
285+
286+
const invalidType = [AccountRestrictionType.AllowIncomingAddress,
287+
AccountRestrictionType.AllowMosaic,
288+
AccountRestrictionType.BlockMosaic,
289+
AccountRestrictionType.AllowOutgoingAddress,
290+
AccountRestrictionType.BlockIncomingAddress,
291+
AccountRestrictionType.BlockOutgoingAddress,
292+
AccountRestrictionType.Sentinel,
293+
];
294+
invalidType.forEach((type) => {
295+
expect(() => {
296+
AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
297+
Deadline.create(),
298+
type,
299+
[operationRestrictionFilter],
300+
NetworkType.MIJIN_TEST,
301+
);
302+
}).to.throw(Error, 'Restriction type is not allowed.');
303+
});
304+
});
305+
306+
it('should create outgoing address restriction transaction', () => {
307+
308+
const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
309+
const addressRestrictionFilter = AccountRestrictionModification.createForAddress(
310+
RestrictionModificationType.Add,
311+
address,
312+
);
313+
let addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
314+
Deadline.create(),
315+
AccountRestrictionType.AllowOutgoingAddress,
316+
[addressRestrictionFilter],
317+
NetworkType.MIJIN_TEST,
318+
);
319+
320+
let signedTransaction = addressRestrictionTransaction.signWith(account, generationHash);
321+
322+
expect(signedTransaction.payload.substring(
323+
240,
324+
signedTransaction.payload.length,
325+
)).to.be.equal('4101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142');
326+
327+
addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
328+
Deadline.create(),
329+
AccountRestrictionType.BlockOutgoingAddress,
330+
[addressRestrictionFilter],
331+
NetworkType.MIJIN_TEST,
332+
);
333+
334+
signedTransaction = addressRestrictionTransaction.signWith(account, generationHash);
335+
336+
expect(signedTransaction.payload.substring(
337+
240,
338+
signedTransaction.payload.length,
339+
)).to.be.equal('C101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142');
340+
341+
});
342+
343+
it('should create outgoing operation restriction transaction', () => {
344+
345+
const operation = TransactionType.ADDRESS_ALIAS;
346+
const operationRestrictionFilter = AccountRestrictionModification.createForOperation(
347+
RestrictionModificationType.Add,
348+
operation,
349+
);
350+
let operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
351+
Deadline.create(),
352+
AccountRestrictionType.AllowOutgoingTransactionType,
353+
[operationRestrictionFilter],
354+
NetworkType.MIJIN_TEST,
355+
);
356+
357+
let signedTransaction = operationRestrictionTransaction.signWith(account, generationHash);
358+
359+
expect(signedTransaction.payload.substring(
360+
240,
361+
signedTransaction.payload.length,
362+
)).to.be.equal('4401004E42');
363+
364+
operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
365+
Deadline.create(),
366+
AccountRestrictionType.BlockOutgoingTransactionType,
367+
[operationRestrictionFilter],
368+
NetworkType.MIJIN_TEST,
369+
);
370+
371+
signedTransaction = operationRestrictionTransaction.signWith(account, generationHash);
372+
373+
expect(signedTransaction.payload.substring(
374+
240,
375+
signedTransaction.payload.length,
376+
)).to.be.equal('C401004E42');
377+
378+
});
257379
});

0 commit comments

Comments
 (0)