Skip to content

Commit 4971648

Browse files
committed
Fixed bug in restrictions Map
1 parent b18f4fb commit 4971648

File tree

4 files changed

+43
-44
lines changed

4 files changed

+43
-44
lines changed

src/infrastructure/RestrictionHttp.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ export class RestrictionHttp extends Http implements RestrictionRepository {
101101
map((response: { response: ClientResponse; body: MosaicAddressRestrictionDTO; }) => {
102102
const payload = response.body.mosaicRestrictionEntry;
103103
const restirctionItems = new Map<string, string>();
104+
payload.restrictions.forEach((restriction) => {
105+
restirctionItems.set(restriction.key, restriction.value);
106+
});
104107
return new MosaicAddressRestriction(
105108
payload.compositeHash,
106109
payload.entryType,
107110
new MosaicId(payload.mosaicId),
108111
Address.createFromEncoded(payload.targetAddress),
109-
payload.restrictions.map((restriction) => {
110-
return restirctionItems.set(restriction.key, restriction.value);
111-
}),
112+
restirctionItems,
112113
);
113114
}),
114115
catchError((error) => throwError(error)),
@@ -132,14 +133,15 @@ export class RestrictionHttp extends Http implements RestrictionRepository {
132133
const mosaicAddressRestrictionsDTO = response.body;
133134
return mosaicAddressRestrictionsDTO.map((payload) => {
134135
const restirctionItems = new Map<string, string>();
136+
payload.mosaicRestrictionEntry.restrictions.forEach((restriction) => {
137+
restirctionItems.set(restriction.key, restriction.value);
138+
});
135139
return new MosaicAddressRestriction(
136140
payload.mosaicRestrictionEntry.compositeHash,
137141
payload.mosaicRestrictionEntry.entryType,
138142
new MosaicId(payload.mosaicRestrictionEntry.mosaicId),
139143
Address.createFromEncoded(payload.mosaicRestrictionEntry.targetAddress),
140-
payload.mosaicRestrictionEntry.restrictions.map((restriction) => {
141-
return restirctionItems.set(restriction.key, restriction.value);
142-
}),
144+
restirctionItems,
143145
);
144146
});
145147
}),
@@ -159,18 +161,18 @@ export class RestrictionHttp extends Http implements RestrictionRepository {
159161
map((response: { response: ClientResponse; body: MosaicGlobalRestrictionDTO; }) => {
160162
const payload = response.body.mosaicRestrictionEntry;
161163
const restirctionItems = new Map<string, MosaicGlobalRestrictionItem>();
164+
payload.restrictions.forEach((restriction) =>
165+
restirctionItems.set(restriction.key,
166+
new MosaicGlobalRestrictionItem(
167+
new MosaicId(restriction.restriction.referenceMosaicId),
168+
restriction.restriction.restrictionValue,
169+
restriction.restriction.restrictionType,
170+
)));
162171
return new MosaicGlobalRestriction(
163172
payload.compositeHash,
164173
payload.entryType.valueOf(),
165174
new MosaicId(payload.mosaicId),
166-
payload.restrictions.map((restriction) => {
167-
return restirctionItems.set(restriction.key,
168-
new MosaicGlobalRestrictionItem(
169-
new MosaicId(restriction.restriction.referenceMosaicId),
170-
restriction.restriction.restrictionValue,
171-
restriction.restriction.restrictionType,
172-
));
173-
}),
175+
restirctionItems,
174176
);
175177
}),
176178
catchError((error) => throwError(error)),
@@ -193,18 +195,18 @@ export class RestrictionHttp extends Http implements RestrictionRepository {
193195
const mosaicGlobalRestrictionsDTO = response.body;
194196
return mosaicGlobalRestrictionsDTO.map((payload) => {
195197
const restirctionItems = new Map<string, MosaicGlobalRestrictionItem>();
198+
payload.mosaicRestrictionEntry.restrictions.forEach((restriction) =>
199+
restirctionItems.set(restriction.key,
200+
new MosaicGlobalRestrictionItem(
201+
new MosaicId(restriction.restriction.referenceMosaicId),
202+
restriction.restriction.restrictionValue,
203+
restriction.restriction.restrictionType,
204+
)));
196205
return new MosaicGlobalRestriction(
197206
payload.mosaicRestrictionEntry.compositeHash,
198207
payload.mosaicRestrictionEntry.entryType.valueOf(),
199208
new MosaicId(payload.mosaicRestrictionEntry.mosaicId),
200-
payload.mosaicRestrictionEntry.restrictions.map((restriction) => {
201-
return restirctionItems.set(restriction.key,
202-
new MosaicGlobalRestrictionItem(
203-
new MosaicId(restriction.restriction.referenceMosaicId),
204-
restriction.restriction.restrictionValue,
205-
restriction.restriction.restrictionType,
206-
));
207-
}),
209+
restirctionItems,
208210
);
209211
});
210212
}),

src/model/restriction/MosaicAddressRestriction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class MosaicAddressRestriction {
5050
/**
5151
* Mosaic restriction items
5252
*/
53-
public readonly restrictions: Array<Map<string, string>>) {
53+
public readonly restrictions: Map<string, string>) {
5454

5555
}
5656
}

src/model/restriction/MosaicGlobalRestriction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class MosaicGlobalRestriction {
4646
/**
4747
* Mosaic restriction items
4848
*/
49-
public readonly restrictions: Array<Map<string, MosaicGlobalRestrictionItem>>) {
49+
public readonly restrictions: Map<string, MosaicGlobalRestrictionItem>) {
5050

5151
}
5252
}

test/model/restriction/MosaicRestriction.spec.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,16 @@ describe('MosaicRestrictions', () => {
4949
mosaicAddressRestrictionDTO.entryType,
5050
new MosaicId(mosaicAddressRestrictionDTO.mosaicId),
5151
Address.createFromEncoded(mosaicAddressRestrictionDTO.targetAddress),
52-
mosaicAddressRestrictionDTO.restrictions.map((item) => {
53-
const keyValue = new Map<string, string>();
54-
return keyValue.set(item.key, item.value);
55-
}),
52+
new Map<string, string>().set(mosaicAddressRestrictionDTO.restrictions[0].key,
53+
mosaicAddressRestrictionDTO.restrictions[0].value),
5654
);
5755

5856
expect(mosaicAddressRestriction.compositeHash).to.be.equal(hash);
5957
expect(mosaicAddressRestriction.entryType).to.be.equal(MosaicRestrictionEntryType.ADDRESS);
6058
expect(mosaicAddressRestriction.targetAddress.plain())
6159
.to.be.equal(Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142').plain());
62-
expect(mosaicAddressRestriction.restrictions.length).to.be.equal(1);
63-
expect(mosaicAddressRestriction.restrictions[0].get('testKey')).to.not.be.equal(undefined);
60+
expect(mosaicAddressRestriction.restrictions.size).to.be.equal(1);
61+
expect(mosaicAddressRestriction.restrictions.get('testKey')).to.not.be.equal(undefined);
6462
});
6563

6664
it('should createComplete an MosaicGlobalRestrictionItem object', () => {
@@ -100,24 +98,23 @@ describe('MosaicRestrictions', () => {
10098
mosaicGlobalRestrictionDTO.compositeHash,
10199
mosaicGlobalRestrictionDTO.entryType,
102100
new MosaicId(mosaicGlobalRestrictionDTO.mosaicId),
103-
mosaicGlobalRestrictionDTO.restrictions.map((item) => {
104-
const keyValue = new Map<string, MosaicGlobalRestrictionItem>();
105-
return keyValue.set(item.key,
106-
new MosaicGlobalRestrictionItem(
107-
new MosaicId(item.restriction.referenceMosaicId),
108-
item.restriction.restrictionValue,
109-
item.restriction.restrictionType,
110-
));
111-
}),
101+
new Map<string, MosaicGlobalRestrictionItem>().set(
102+
mosaicGlobalRestrictionDTO.restrictions[0].key,
103+
new MosaicGlobalRestrictionItem(
104+
new MosaicId(mosaicGlobalRestrictionDTO.restrictions[0].restriction.referenceMosaicId),
105+
mosaicGlobalRestrictionDTO.restrictions[0].restriction.restrictionValue,
106+
mosaicGlobalRestrictionDTO.restrictions[0].restriction.restrictionType,
107+
),
108+
),
112109
);
113110

114111
expect(mosaicGlobalRestriction.compositeHash).to.be.equal(hash);
115112
expect(mosaicGlobalRestriction.entryType).to.be.equal(MosaicRestrictionEntryType.ADDRESS);
116113
expect(mosaicGlobalRestriction.mosaicId.toHex()).to.be.equal('85BBEA6CC462B244');
117-
expect(mosaicGlobalRestriction.restrictions.length).to.be.equal(1);
118-
expect(mosaicGlobalRestriction.restrictions[0].get('testKey')).to.not.be.equal(undefined);
119-
expect(mosaicGlobalRestriction.restrictions[0].get('testKey')!.referenceMosaicId.toHex()).to.be.equal('85BBEA6CC462B244');
120-
expect(mosaicGlobalRestriction.restrictions[0].get('testKey')!.restrictionValue).to.be.equal('123');
121-
expect(mosaicGlobalRestriction.restrictions[0].get('testKey')!.restrictionType).to.be.equal(MosaicRestrictionType.EQ);
114+
expect(mosaicGlobalRestriction.restrictions.size).to.be.equal(1);
115+
expect(mosaicGlobalRestriction.restrictions.get('testKey')).to.not.be.equal(undefined);
116+
expect(mosaicGlobalRestriction.restrictions.get('testKey')!.referenceMosaicId.toHex()).to.be.equal('85BBEA6CC462B244');
117+
expect(mosaicGlobalRestriction.restrictions.get('testKey')!.restrictionValue).to.be.equal('123');
118+
expect(mosaicGlobalRestriction.restrictions.get('testKey')!.restrictionType).to.be.equal(MosaicRestrictionType.EQ);
122119
});
123120
});

0 commit comments

Comments
 (0)