Skip to content

Commit a121158

Browse files
committed
Applied new mosaicRestriction model
Fixed tests
1 parent 710949d commit a121158

14 files changed

+311
-211
lines changed

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -186,39 +186,6 @@ describe('AccountHttp', () => {
186186
});
187187
});
188188

189-
describe('Setup Test AccountAddressRestriction', () => {
190-
let listener: Listener;
191-
before (() => {
192-
listener = new Listener(config.apiUrl);
193-
return listener.open();
194-
});
195-
after(() => {
196-
return listener.close();
197-
});
198-
199-
it('Announce AccountRestrictionTransaction', (done) => {
200-
const addressPropertyFilter = AccountRestrictionModification.createForAddress(
201-
AccountRestrictionModificationAction.Add,
202-
account3.address,
203-
);
204-
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
205-
Deadline.create(),
206-
AccountRestrictionType.AllowIncomingAddress,
207-
[addressPropertyFilter],
208-
NetworkType.MIJIN_TEST,
209-
);
210-
const signedTransaction = addressModification.signWith(account, generationHash);
211-
listener.confirmed(account.address).subscribe(() => {
212-
done();
213-
});
214-
listener.status(account.address).subscribe((error) => {
215-
console.log('Error:', error);
216-
assert(false);
217-
done();
218-
});
219-
transactionHttp.announce(signedTransaction);
220-
});
221-
});
222189
describe('Setup test multisig account', () => {
223190
let listener: Listener;
224191
before (() => {
@@ -284,28 +251,6 @@ describe('AccountHttp', () => {
284251
});
285252
});
286253

287-
describe('getAccountRestrictions', () => {
288-
it('should call getAccountRestrictions successfully', (done) => {
289-
setTimeout(() => {
290-
restrictionHttp.getAccountRestrictions(accountAddress).subscribe((accountRestrictions) => {
291-
deepEqual(accountRestrictions.accountRestrictions.address, accountAddress);
292-
done();
293-
});
294-
}, 1000);
295-
});
296-
});
297-
298-
describe('getAccountRestrictionsFromAccounts', () => {
299-
it('should call getAccountRestrictionsFromAccounts successfully', (done) => {
300-
setTimeout(() => {
301-
restrictionHttp.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => {
302-
deepEqual(accountRestrictions[0]!.accountRestrictions.address, accountAddress);
303-
done();
304-
});
305-
}, 1000);
306-
});
307-
});
308-
309254
describe('getMultisigAccountGraphInfo', () => {
310255
it('should call getMultisigAccountGraphInfo successfully', (done) => {
311256
setTimeout(() => {
@@ -411,39 +356,6 @@ describe('AccountHttp', () => {
411356
transactionHttp.announce(signedTransaction);
412357
});
413358
});
414-
describe('Remove test AccountRestriction - Address', () => {
415-
let listener: Listener;
416-
before (() => {
417-
listener = new Listener(config.apiUrl);
418-
return listener.open();
419-
});
420-
after(() => {
421-
return listener.close();
422-
});
423-
424-
it('Announce AccountRestrictionTransaction', (done) => {
425-
const addressPropertyFilter = AccountRestrictionModification.createForAddress(
426-
AccountRestrictionModificationAction.Remove,
427-
account3.address,
428-
);
429-
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
430-
Deadline.create(),
431-
AccountRestrictionType.AllowIncomingAddress,
432-
[addressPropertyFilter],
433-
NetworkType.MIJIN_TEST,
434-
);
435-
const signedTransaction = addressModification.signWith(account, generationHash);
436-
listener.confirmed(account.address).subscribe(() => {
437-
done();
438-
});
439-
listener.status(account.address).subscribe((error) => {
440-
console.log('Error:', error);
441-
assert(false);
442-
done();
443-
});
444-
transactionHttp.announce(signedTransaction);
445-
});
446-
});
447359

448360
describe('Restore test multisig Accounts', () => {
449361
let listener: Listener;

e2e/infrastructure/RestrictionHttp.spec.ts

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import { Deadline } from '../../src/model/transaction/Deadline';
3737
import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction/MosaicAddressRestrictionTransaction';
3838
import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction';
3939
import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction';
40-
import { Transaction } from '../../src/model/transaction/Transaction';
4140
import { UInt64 } from '../../src/model/UInt64';
4241

4342
describe('RestrictionHttp', () => {
@@ -259,10 +258,10 @@ describe('RestrictionHttp', () => {
259258
describe('getMosaicAddressRestriction', () => {
260259
it('should call getMosaicAddressRestriction successfully', (done) => {
261260
setTimeout(() => {
262-
restrictionHttp.getMosaicAddressRestriction(mosaicId, accountAddress).subscribe((mosaicRestriction) => {
261+
restrictionHttp.getMosaicAddressRestriction(mosaicId, account3.address).subscribe((mosaicRestriction) => {
263262
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
264263
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.ADDRESS);
265-
deepEqual(mosaicRestriction.targetAddress.plain(), accountAddress.plain());
264+
deepEqual(mosaicRestriction.targetAddress.plain(), account3.address.plain());
266265
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
267266
done();
268267
});
@@ -273,10 +272,10 @@ describe('RestrictionHttp', () => {
273272
describe('getMosaicAddressRestrictions', () => {
274273
it('should call getMosaicAddressRestrictions successfully', (done) => {
275274
setTimeout(() => {
276-
restrictionHttp.getMosaicAddressRestrictions(mosaicId, [accountAddress]).subscribe((mosaicRestriction) => {
275+
restrictionHttp.getMosaicAddressRestrictions(mosaicId, [account3.address]).subscribe((mosaicRestriction) => {
277276
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
278277
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.ADDRESS);
279-
deepEqual(mosaicRestriction[0].targetAddress.plain(), accountAddress.plain());
278+
deepEqual(mosaicRestriction[0].targetAddress.plain(), account3.address.plain());
280279
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
281280
done();
282281
});
@@ -290,7 +289,12 @@ describe('RestrictionHttp', () => {
290289
restrictionHttp.getMosaicGlobalRestriction(mosaicId).subscribe((mosaicRestriction) => {
291290
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
292291
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.GLOBAL);
293-
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
292+
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex())!.referenceMosaicId.toHex(),
293+
new MosaicId(UInt64.fromUint(0).toHex()).toHex());
294+
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex())!.restrictionType,
295+
MosaicRestrictionType.GE);
296+
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex())!.restrictionValue.toString(),
297+
UInt64.fromUint(0).toString());
294298
done();
295299
});
296300
}, 1000);
@@ -303,10 +307,54 @@ describe('RestrictionHttp', () => {
303307
restrictionHttp.getMosaicGlobalRestrictions([mosaicId]).subscribe((mosaicRestriction) => {
304308
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
305309
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.GLOBAL);
306-
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
310+
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex())!.referenceMosaicId.toHex(),
311+
new MosaicId(UInt64.fromUint(0).toHex()).toHex());
312+
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex())!.restrictionType,
313+
MosaicRestrictionType.GE);
314+
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex())!.restrictionValue.toString(),
315+
UInt64.fromUint(0).toString());
307316
done();
308317
});
309318
}, 1000);
310319
});
311320
});
321+
322+
/**
323+
* =========================
324+
* House Keeping
325+
* =========================
326+
*/
327+
describe('Remove test AccountRestriction - Address', () => {
328+
let listener: Listener;
329+
before (() => {
330+
listener = new Listener(config.apiUrl);
331+
return listener.open();
332+
});
333+
after(() => {
334+
return listener.close();
335+
});
336+
337+
it('Announce AccountRestrictionTransaction', (done) => {
338+
const addressPropertyFilter = AccountRestrictionModification.createForAddress(
339+
AccountRestrictionModificationAction.Remove,
340+
account3.address,
341+
);
342+
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
343+
Deadline.create(),
344+
AccountRestrictionType.AllowIncomingAddress,
345+
[addressPropertyFilter],
346+
NetworkType.MIJIN_TEST,
347+
);
348+
const signedTransaction = addressModification.signWith(account, generationHash);
349+
listener.confirmed(account.address).subscribe(() => {
350+
done();
351+
});
352+
listener.status(account.address).subscribe((error) => {
353+
console.log('Error:', error);
354+
assert(false);
355+
done();
356+
});
357+
transactionHttp.announce(signedTransaction);
358+
});
359+
});
312360
});

src/infrastructure/RestrictionHttp.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class RestrictionHttp extends Http implements RestrictionRepository {
9999
return observableFrom(
100100
this.restrictionRoutesApi.getMosaicAddressRestriction(mosaicId.toHex(), address.plain())).pipe(
101101
map((response: { response: ClientResponse; body: MosaicAddressRestrictionDTO; }) => {
102-
const payload = response.body;
102+
const payload = response.body.mosaicRestrictionEntry;
103103
const restirctionItems = new Map<string, string>();
104104
return new MosaicAddressRestriction(
105105
payload.compositeHash,
@@ -133,11 +133,11 @@ export class RestrictionHttp extends Http implements RestrictionRepository {
133133
return mosaicAddressRestrictionsDTO.map((payload) => {
134134
const restirctionItems = new Map<string, string>();
135135
return new MosaicAddressRestriction(
136-
payload.compositeHash,
137-
payload.entryType,
138-
new MosaicId(payload.mosaicId),
139-
Address.createFromEncoded(payload.targetAddress),
140-
payload.restrictions.map((restriction) => {
136+
payload.mosaicRestrictionEntry.compositeHash,
137+
payload.mosaicRestrictionEntry.entryType,
138+
new MosaicId(payload.mosaicRestrictionEntry.mosaicId),
139+
Address.createFromEncoded(payload.mosaicRestrictionEntry.targetAddress),
140+
payload.mosaicRestrictionEntry.restrictions.map((restriction) => {
141141
return restirctionItems.set(restriction.key, restriction.value);
142142
}),
143143
);
@@ -157,21 +157,19 @@ export class RestrictionHttp extends Http implements RestrictionRepository {
157157
return observableFrom(
158158
this.restrictionRoutesApi.getMosaicGlobalRestriction(mosaicId.toHex())).pipe(
159159
map((response: { response: ClientResponse; body: MosaicGlobalRestrictionDTO; }) => {
160-
const payload = response.body;
161-
const restirctionItems = new Map<string, MosaicGlobalRestrictionItem[]>();
160+
const payload = response.body.mosaicRestrictionEntry;
161+
const restirctionItems = new Map<string, MosaicGlobalRestrictionItem>();
162162
return new MosaicGlobalRestriction(
163163
payload.compositeHash,
164-
payload.entryType,
164+
payload.entryType.valueOf(),
165165
new MosaicId(payload.mosaicId),
166166
payload.restrictions.map((restriction) => {
167167
return restirctionItems.set(restriction.key,
168-
restriction.restriction.map((item) => {
169-
return new MosaicGlobalRestrictionItem(
170-
new MosaicId(item.referenceMosaicId),
171-
item.restrictionValue,
172-
item.restrictionType,
173-
);
174-
}));
168+
new MosaicGlobalRestrictionItem(
169+
new MosaicId(restriction.restriction.referenceMosaicId),
170+
restriction.restriction.restrictionValue,
171+
restriction.restriction.restrictionType,
172+
));
175173
}),
176174
);
177175
}),
@@ -194,20 +192,18 @@ export class RestrictionHttp extends Http implements RestrictionRepository {
194192
map((response: { response: ClientResponse; body: MosaicGlobalRestrictionDTO[]; }) => {
195193
const mosaicGlobalRestrictionsDTO = response.body;
196194
return mosaicGlobalRestrictionsDTO.map((payload) => {
197-
const restirctionItems = new Map<string, MosaicGlobalRestrictionItem[]>();
195+
const restirctionItems = new Map<string, MosaicGlobalRestrictionItem>();
198196
return new MosaicGlobalRestriction(
199-
payload.compositeHash,
200-
payload.entryType,
201-
new MosaicId(payload.mosaicId),
202-
payload.restrictions.map((restriction) => {
197+
payload.mosaicRestrictionEntry.compositeHash,
198+
payload.mosaicRestrictionEntry.entryType.valueOf(),
199+
new MosaicId(payload.mosaicRestrictionEntry.mosaicId),
200+
payload.mosaicRestrictionEntry.restrictions.map((restriction) => {
203201
return restirctionItems.set(restriction.key,
204-
restriction.restriction.map((item) => {
205-
return new MosaicGlobalRestrictionItem(
206-
new MosaicId(item.referenceMosaicId),
207-
item.restrictionValue,
208-
item.restrictionType,
209-
);
210-
}));
202+
new MosaicGlobalRestrictionItem(
203+
new MosaicId(restriction.restriction.referenceMosaicId),
204+
restriction.restriction.restrictionValue,
205+
restriction.restriction.restrictionType,
206+
));
211207
}),
212208
);
213209
});

0 commit comments

Comments
 (0)