Skip to content

Commit 7925588

Browse files
author
Baha
committed
fix: AccountMetadataTransaction value string type changed to byte array
1 parent b792bce commit 7925588

File tree

10 files changed

+31
-28
lines changed

10 files changed

+31
-28
lines changed

e2e/infrastructure/MetadataHttp.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { deepEqual } from 'assert';
1818
import { expect } from 'chai';
1919
import { firstValueFrom } from 'rxjs';
2020
import { take, toArray } from 'rxjs/operators';
21+
import { Convert } from '../..';
2122
import { MetadataPaginationStreamer, MetadataRepository, Order } from '../../src/infrastructure';
2223
import { Metadata, MetadataType, UInt64 } from '../../src/model';
2324
import { Account, Address } from '../../src/model/account';
@@ -115,7 +116,7 @@ describe('MetadataHttp', () => {
115116
account.address,
116117
UInt64.fromUint(6),
117118
23,
118-
`Test account meta value`,
119+
Convert.utf8ToUint8(`Test account meta value`),
119120
networkType,
120121
helper.maxFee,
121122
);

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe('TransactionHttp', () => {
196196
account.address,
197197
UInt64.fromUint(5),
198198
10,
199-
Convert.uint8ToUtf8(new Uint8Array(10)),
199+
new Uint8Array(10),
200200
networkType,
201201
helper.maxFee,
202202
);

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
393393
extractRecipient(transactionDTO.targetAddress),
394394
UInt64.fromHex(transactionDTO.scopedMetadataKey),
395395
transactionDTO.valueSizeDelta,
396-
convert.decodeHex(transactionDTO.value),
396+
convert.utf8ToUint8(transactionDTO.value),
397397
signature,
398398
signer,
399399
transactionInfo,

src/infrastructure/transaction/SerializeTransactionToJSON.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => {
246246
scopedMetadataKey: accountMetadataTx.scopedMetadataKey.toHex(),
247247
valueSizeDelta: accountMetadataTx.valueSizeDelta,
248248
valueSize: accountMetadataTx.value.length,
249-
value: Convert.utf8ToHex(accountMetadataTx.value),
249+
value: accountMetadataTx.value,
250250
};
251251
} else if (transaction.type === TransactionType.MOSAIC_METADATA) {
252252
const mosaicMetadataTx = transaction as MosaicMetadataTransaction;

src/model/transaction/AccountMetadataTransaction.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class AccountMetadataTransaction extends Transaction {
6060
targetAddress: UnresolvedAddress,
6161
scopedMetadataKey: UInt64,
6262
valueSizeDelta: number,
63-
value: string,
63+
value: Uint8Array,
6464
networkType: NetworkType,
6565
maxFee: UInt64 = new UInt64([0, 0]),
6666
signature?: string,
@@ -111,10 +111,10 @@ export class AccountMetadataTransaction extends Transaction {
111111
*/
112112
public readonly valueSizeDelta: number,
113113
/**
114-
* String value with UTF-8 encoding.
114+
* xor of previous and the new value
115115
* Difference between the previous value and new value.
116116
*/
117-
public readonly value: string,
117+
public readonly value: Uint8Array,
118118
signature?: string,
119119
signer?: PublicAccount,
120120
transactionInfo?: TransactionInfo,
@@ -142,7 +142,7 @@ export class AccountMetadataTransaction extends Transaction {
142142
UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(builder.getTargetAddress().unresolvedAddress)),
143143
new UInt64(builder.getScopedMetadataKey()),
144144
builder.getValueSizeDelta(),
145-
Convert.uint8ToUtf8(builder.getValue()),
145+
builder.getValue(),
146146
networkType,
147147
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMetadataTransactionBuilder).fee.amount),
148148
signature,
@@ -167,7 +167,7 @@ export class AccountMetadataTransaction extends Transaction {
167167
new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)),
168168
this.scopedMetadataKey.toDTO(),
169169
this.valueSizeDelta,
170-
Convert.utf8ToUint8(this.value),
170+
this.value,
171171
);
172172
return transactionBuilder;
173173
}
@@ -185,7 +185,7 @@ export class AccountMetadataTransaction extends Transaction {
185185
new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)),
186186
this.scopedMetadataKey.toDTO(),
187187
this.valueSizeDelta,
188-
Convert.utf8ToUint8(this.value),
188+
this.value,
189189
);
190190
}
191191

src/service/MetadataTransactionService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ export class MetadataTransactionService {
6969
const metadata = metadatas.data[0];
7070
const currentValueByte = Convert.utf8ToUint8(metadata.metadataEntry.value);
7171
const newValueBytes = Convert.utf8ToUint8(value);
72+
const xoredBytes = Convert.hexToUint8(Convert.xor(currentValueByte, newValueBytes));
73+
7274
return AccountMetadataTransaction.create(
7375
deadline,
7476
targetAddress,
7577
key,
7678
newValueBytes.length - currentValueByte.length,
77-
Convert.decodeHex(Convert.xor(currentValueByte, newValueBytes)),
79+
xoredBytes,
7880
networkType,
7981
maxFee,
8082
);
@@ -85,7 +87,7 @@ export class MetadataTransactionService {
8587
targetAddress,
8688
key,
8789
newValueBytes.length,
88-
value,
90+
Convert.utf8ToUint8(value),
8991
networkType,
9092
maxFee,
9193
);

test/core/utils/TransactionMapping.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ describe('TransactionMapping - createFromPayload', () => {
523523
account.address,
524524
UInt64.fromUint(1000),
525525
1,
526-
Convert.uint8ToUtf8(new Uint8Array(10)),
526+
new Uint8Array(10),
527527
TestNetworkType,
528528
);
529529
const mosaicMetadataTransaction = MosaicMetadataTransaction.create(
@@ -872,7 +872,7 @@ describe('TransactionMapping - createFromPayload', () => {
872872
account.address,
873873
UInt64.fromUint(1000),
874874
1,
875-
Convert.uint8ToUtf8(new Uint8Array(10)),
875+
new Uint8Array(10),
876876
TestNetworkType,
877877
);
878878

@@ -1552,7 +1552,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () =>
15521552
account.address,
15531553
UInt64.fromUint(1000),
15541554
1,
1555-
'Test Value',
1555+
Convert.utf8ToUint8('Test Value'),
15561556
TestNetworkType,
15571557
);
15581558

@@ -1566,7 +1566,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () =>
15661566
expect(transaction.targetAddress.equals(account.address)).to.be.true;
15671567
expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex());
15681568
expect(transaction.valueSizeDelta).to.be.equal(1);
1569-
expect(transaction.value).to.be.equal('Test Value');
1569+
expect(Convert.uint8ToHex(transaction.value)).to.be.equal(Convert.utf8ToHex('Test Value'));
15701570
});
15711571

15721572
it('should create MosaicMetadataTransaction', () => {

test/core/utils/TransactionMappingWithSignatures.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign
534534
account.address,
535535
UInt64.fromUint(1000),
536536
1,
537-
Convert.uint8ToUtf8(new Uint8Array(10)),
537+
new Uint8Array(10),
538538
NetworkType.TEST_NET,
539539
);
540540
const mosaicMetadataTransaction = MosaicMetadataTransaction.create(
@@ -969,7 +969,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign
969969
account.address,
970970
UInt64.fromUint(1000),
971971
1,
972-
Convert.uint8ToUtf8(new Uint8Array(10)),
972+
new Uint8Array(10),
973973
NetworkType.TEST_NET,
974974
undefined,
975975
testSignature,

test/model/transaction/AccountMetadataTransaction.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('AccountMetadataTransaction', () => {
4141
account.address,
4242
UInt64.fromUint(1000),
4343
1,
44-
Convert.uint8ToUtf8(new Uint8Array(10)),
44+
new Uint8Array(10),
4545
TestNetworkType,
4646
);
4747

@@ -55,7 +55,7 @@ describe('AccountMetadataTransaction', () => {
5555
account.address,
5656
UInt64.fromUint(1000),
5757
1,
58-
Convert.uint8ToUtf8(new Uint8Array(10)),
58+
new Uint8Array(10),
5959
TestNetworkType,
6060
new UInt64([1, 0]),
6161
);
@@ -70,7 +70,7 @@ describe('AccountMetadataTransaction', () => {
7070
account.address,
7171
UInt64.fromUint(1000),
7272
1,
73-
Convert.uint8ToUtf8(new Uint8Array(10)),
73+
new Uint8Array(10),
7474
TestNetworkType,
7575
);
7676

@@ -88,7 +88,7 @@ describe('AccountMetadataTransaction', () => {
8888
account.address,
8989
UInt64.fromUint(1000),
9090
1,
91-
Convert.uint8ToUtf8(new Uint8Array(10)),
91+
new Uint8Array(10),
9292
TestNetworkType,
9393
);
9494

@@ -105,7 +105,7 @@ describe('AccountMetadataTransaction', () => {
105105
account.address,
106106
UInt64.fromUint(1000),
107107
1,
108-
Convert.uint8ToUtf8(new Uint8Array(10)),
108+
new Uint8Array(10),
109109
TestNetworkType,
110110
);
111111

@@ -122,7 +122,7 @@ describe('AccountMetadataTransaction', () => {
122122
account.address,
123123
UInt64.fromUint(1000),
124124
1,
125-
Convert.uint8ToUtf8(new Uint8Array(10)),
125+
new Uint8Array(10),
126126
TestNetworkType,
127127
);
128128

@@ -141,7 +141,7 @@ describe('AccountMetadataTransaction', () => {
141141
account.address,
142142
UInt64.fromUint(1000),
143143
1,
144-
Convert.uint8ToUtf8(new Uint8Array(10)),
144+
new Uint8Array(10),
145145
TestNetworkType,
146146
);
147147

@@ -157,7 +157,7 @@ describe('AccountMetadataTransaction', () => {
157157
account.address,
158158
UInt64.fromUint(1000),
159159
1,
160-
Convert.uint8ToUtf8(new Uint8Array(10)),
160+
new Uint8Array(10),
161161
TestNetworkType,
162162
);
163163

@@ -179,7 +179,7 @@ describe('AccountMetadataTransaction', () => {
179179
alias,
180180
UInt64.fromUint(1000),
181181
1,
182-
Convert.uint8ToUtf8(new Uint8Array(10)),
182+
new Uint8Array(10),
183183
TestNetworkType,
184184
);
185185

test/service/MetadataTransactionservice.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('MetadataTransactionService', () => {
124124
.subscribe((transaction: AccountMetadataTransaction) => {
125125
expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA);
126126
expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex());
127-
expect(Convert.utf8ToHex(transaction.value)).to.be.equal(
127+
expect(Convert.uint8ToHex(transaction.value)).to.be.equal(
128128
Convert.xor(Convert.utf8ToUint8(value), Convert.utf8ToUint8(value + deltaValue)),
129129
);
130130
expect(transaction.valueSizeDelta).to.be.equal(deltaValue.length);

0 commit comments

Comments
 (0)