Skip to content

Commit 4c66df5

Browse files
author
Greg S
committed
PR #83: added tests for recipientToString() ; changed visibility to public
1 parent 053ab99 commit 4c66df5

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/model/transaction/TransferTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class TransferTransaction extends Transaction {
9494
* @internal
9595
* @returns {string}
9696
*/
97-
protected recipientToString(): string {
97+
public recipientToString(): string {
9898
if (this.recipient instanceof NamespaceId) {
9999
// namespaceId available, return hexadecimal notation
100100
return (this.recipient as NamespaceId).toHex();

test/model/transaction/TransferTransaction.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,48 @@ describe('TransferTransaction', () => {
106106
)).to.be.equal('9151776168D24257D8000000000000000000000000000000000D000100746573742D6D657373616765' +
107107
'44B262C46CEABB8500E1F50500000000');
108108
});
109+
110+
it('should format TransferTransaction payload with 25 bytes binary address', () => {
111+
const transferTransaction = TransferTransaction.create(
112+
Deadline.create(),
113+
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
114+
[
115+
NetworkCurrencyMosaic.createRelative(100),
116+
],
117+
PlainMessage.create('test-message'),
118+
NetworkType.MIJIN_TEST,
119+
);
120+
121+
// test recipientToString with Address recipient
122+
expect(transferTransaction.recipientToString()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
123+
124+
const signedTransaction = transferTransaction.signWith(account);
125+
126+
expect(signedTransaction.payload.substring(
127+
240,
128+
290,
129+
)).to.be.equal('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142');
130+
});
131+
132+
it('should format TransferTransaction payload with 8 bytes binary namespaceId', () => {
133+
const transferTransaction = TransferTransaction.create(
134+
Deadline.create(),
135+
new NamespaceId('nem.owner'),
136+
[
137+
NetworkCurrencyMosaic.createRelative(100),
138+
],
139+
PlainMessage.create('test-message'),
140+
NetworkType.MIJIN_TEST,
141+
);
142+
143+
// test recipientToString with NamespaceId recipient
144+
expect(transferTransaction.recipientToString()).to.be.equal('d85742d268617751');
145+
146+
const signedTransaction = transferTransaction.signWith(account);
147+
148+
expect(signedTransaction.payload.substring(
149+
240,
150+
290,
151+
)).to.be.equal('9151776168D24257D800000000000000000000000000000000');
152+
});
109153
});

0 commit comments

Comments
 (0)