Skip to content

Commit d747838

Browse files
committed
Changed metadata transaction value to use hex
Fixed a few issues in mosaic restriction tests
1 parent 4971648 commit d747838

File tree

3 files changed

+87
-15
lines changed

3 files changed

+87
-15
lines changed

e2e/infrastructure/RestrictionHttp.spec.ts

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('RestrictionHttp', () => {
5454
let restrictionHttp: RestrictionHttp;
5555
let transactionHttp: TransactionHttp;
5656
let mosaicId: MosaicId;
57+
let referenceMosaicId: MosaicId;
5758
let generationHash: string;
5859
let config;
5960

@@ -122,6 +123,40 @@ describe('RestrictionHttp', () => {
122123
});
123124
});
124125

126+
describe('MosaicDefinitionTransaction', () => {
127+
let listener: Listener;
128+
before (() => {
129+
listener = new Listener(config.apiUrl);
130+
return listener.open();
131+
});
132+
after(() => {
133+
return listener.close();
134+
});
135+
it('standalone', (done) => {
136+
const nonce = MosaicNonce.createRandom();
137+
referenceMosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
138+
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
139+
Deadline.create(),
140+
nonce,
141+
referenceMosaicId,
142+
MosaicFlags.create( true, true, true),
143+
3,
144+
UInt64.fromUint(1000),
145+
NetworkType.MIJIN_TEST,
146+
);
147+
const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash);
148+
listener.confirmed(account.address).subscribe(() => {
149+
done();
150+
});
151+
listener.status(account.address).subscribe((error) => {
152+
console.log('Error:', error);
153+
assert(false);
154+
done();
155+
});
156+
transactionHttp.announce(signedTransaction);
157+
});
158+
});
159+
125160
describe('Setup Test AccountAddressRestriction', () => {
126161
let listener: Listener;
127162
before (() => {
@@ -156,7 +191,42 @@ describe('RestrictionHttp', () => {
156191
});
157192
});
158193

159-
describe('MosaicGlobalRestrictionTransaction', () => {
194+
describe('MosaicGlobalRestrictionTransaction - Reference', () => {
195+
let listener: Listener;
196+
before (() => {
197+
listener = new Listener(config.apiUrl);
198+
return listener.open();
199+
});
200+
after(() => {
201+
return listener.close();
202+
});
203+
204+
it('standalone', (done) => {
205+
const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create(
206+
Deadline.create(),
207+
referenceMosaicId,
208+
UInt64.fromUint(60641),
209+
UInt64.fromUint(0),
210+
MosaicRestrictionType.NONE,
211+
UInt64.fromUint(0),
212+
MosaicRestrictionType.GE,
213+
NetworkType.MIJIN_TEST,
214+
);
215+
const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash);
216+
217+
listener.confirmed(account.address).subscribe(() => {
218+
done();
219+
});
220+
listener.status(account.address).subscribe((error) => {
221+
console.log('Error:', error);
222+
assert(false);
223+
done();
224+
});
225+
transactionHttp.announce(signedTransaction);
226+
});
227+
});
228+
229+
describe('MosaicGlobalRestrictionTransaction - with referenceMosaicId', () => {
160230
let listener: Listener;
161231
before (() => {
162232
listener = new Listener(config.apiUrl);
@@ -176,6 +246,8 @@ describe('RestrictionHttp', () => {
176246
UInt64.fromUint(0),
177247
MosaicRestrictionType.GE,
178248
NetworkType.MIJIN_TEST,
249+
// TODO:
250+
// referenceMosaicId,
179251
);
180252
const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash);
181253

@@ -262,7 +334,7 @@ describe('RestrictionHttp', () => {
262334
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
263335
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.ADDRESS);
264336
deepEqual(mosaicRestriction.targetAddress.plain(), account3.address.plain());
265-
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
337+
deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString());
266338
done();
267339
});
268340
}, 1000);
@@ -276,7 +348,7 @@ describe('RestrictionHttp', () => {
276348
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
277349
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.ADDRESS);
278350
deepEqual(mosaicRestriction[0].targetAddress.plain(), account3.address.plain());
279-
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
351+
deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString());
280352
done();
281353
});
282354
}, 1000);
@@ -289,11 +361,11 @@ describe('RestrictionHttp', () => {
289361
restrictionHttp.getMosaicGlobalRestriction(mosaicId).subscribe((mosaicRestriction) => {
290362
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
291363
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.GLOBAL);
292-
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex())!.referenceMosaicId.toHex(),
364+
deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(),
293365
new MosaicId(UInt64.fromUint(0).toHex()).toHex());
294-
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex())!.restrictionType,
366+
deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType,
295367
MosaicRestrictionType.GE);
296-
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex())!.restrictionValue.toString(),
368+
deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(),
297369
UInt64.fromUint(0).toString());
298370
done();
299371
});
@@ -307,11 +379,11 @@ describe('RestrictionHttp', () => {
307379
restrictionHttp.getMosaicGlobalRestrictions([mosaicId]).subscribe((mosaicRestriction) => {
308380
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
309381
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.GLOBAL);
310-
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex())!.referenceMosaicId.toHex(),
382+
deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(),
311383
new MosaicId(UInt64.fromUint(0).toHex()).toHex());
312-
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex())!.restrictionType,
384+
deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType,
313385
MosaicRestrictionType.GE);
314-
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex())!.restrictionValue.toString(),
386+
deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(),
315387
UInt64.fromUint(0).toString());
316388
done();
317389
});

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
384384
transactionDTO.targetPublicKey,
385385
UInt64.fromHex(transactionDTO.scopedMetadataKey),
386386
transactionDTO.valueSizeDelta,
387-
transactionDTO.value,
387+
convert.decodeHex(transactionDTO.value),
388388
transactionDTO.signature,
389389
transactionDTO.signerPublicKey ? PublicAccount.createFromPublicKey(transactionDTO.signerPublicKey,
390390
extractNetworkType(transactionDTO.version)) : undefined,
@@ -400,7 +400,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
400400
UInt64.fromHex(transactionDTO.scopedMetadataKey),
401401
new MosaicId(transactionDTO.targetMosaicId),
402402
transactionDTO.valueSizeDelta,
403-
transactionDTO.value,
403+
convert.decodeHex(transactionDTO.value),
404404
transactionDTO.signature,
405405
transactionDTO.signerPublicKey ? PublicAccount.createFromPublicKey(transactionDTO.signerPublicKey,
406406
extractNetworkType(transactionDTO.version)) : undefined,
@@ -416,7 +416,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
416416
UInt64.fromHex(transactionDTO.scopedMetadataKey),
417417
NamespaceId.createFromEncoded(transactionDTO.targetNamespaceId),
418418
transactionDTO.valueSizeDelta,
419-
transactionDTO.value,
419+
convert.decodeHex(transactionDTO.value),
420420
transactionDTO.signature,
421421
transactionDTO.signerPublicKey ? PublicAccount.createFromPublicKey(transactionDTO.signerPublicKey,
422422
extractNetworkType(transactionDTO.version)) : undefined,

src/infrastructure/transaction/SerializeTransactionToJSON.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => {
191191
scopedMetadataKey: (transaction as AccountMetadataTransaction).scopedMetadataKey.toHex(),
192192
valueSizeDelta: (transaction as AccountMetadataTransaction).valueSizeDelta,
193193
valueSize: (transaction as AccountMetadataTransaction).value.length,
194-
value: (transaction as AccountMetadataTransaction).value,
194+
value: Convert.utf8ToHex((transaction as AccountMetadataTransaction).value),
195195

196196
};
197197
case TransactionType.MOSAIC_METADATA_TRANSACTION:
@@ -201,7 +201,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => {
201201
valueSizeDelta: (transaction as MosaicMetadataTransaction).valueSizeDelta,
202202
targetMosaicId: (transaction as MosaicMetadataTransaction).targetMosaicId.id.toHex(),
203203
valueSize: (transaction as MosaicMetadataTransaction).value.length,
204-
value: (transaction as MosaicMetadataTransaction).value,
204+
value: Convert.utf8ToHex((transaction as MosaicMetadataTransaction).value),
205205

206206
};
207207
case TransactionType.NAMESPACE_METADATA_TRANSACTION:
@@ -211,7 +211,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => {
211211
valueSizeDelta: (transaction as NamespaceMetadataTransaction).valueSizeDelta,
212212
targetNamespaceId: (transaction as NamespaceMetadataTransaction).targetNamespaceId.id.toHex(),
213213
valueSize: (transaction as NamespaceMetadataTransaction).value.length,
214-
value: (transaction as NamespaceMetadataTransaction).value,
214+
value: Convert.utf8ToHex((transaction as NamespaceMetadataTransaction).value),
215215

216216
};
217217
default:

0 commit comments

Comments
 (0)