@@ -19,6 +19,7 @@ import { Account } from '../../../src/model/account/Account';
1919import { Address } from '../../../src/model/account/Address' ;
2020import { NetworkType } from '../../../src/model/blockchain/NetworkType' ;
2121import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic' ;
22+ import { NamespaceId } from '../../../src/model/namespace/NamespaceId' ;
2223import { Deadline } from '../../../src/model/transaction/Deadline' ;
2324import { PlainMessage } from '../../../src/model/transaction/PlainMessage' ;
2425import { TransferTransaction } from '../../../src/model/transaction/TransferTransaction' ;
@@ -42,7 +43,8 @@ describe('TransferTransaction', () => {
4243
4344 expect ( transferTransaction . message . payload ) . to . be . equal ( 'test-message' ) ;
4445 expect ( transferTransaction . mosaics . length ) . to . be . equal ( 0 ) ;
45- expect ( transferTransaction . recipient . plain ( ) ) . to . be . equal ( 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC' ) ;
46+ expect ( transferTransaction . recipient ) . to . be . instanceof ( Address ) ;
47+ expect ( ( transferTransaction . recipient as Address ) . plain ( ) ) . to . be . equal ( 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC' ) ;
4648
4749 const signedTransaction = transferTransaction . signWith ( account ) ;
4850
@@ -65,7 +67,8 @@ describe('TransferTransaction', () => {
6567
6668 expect ( transferTransaction . message . payload ) . to . be . equal ( 'test-message' ) ;
6769 expect ( transferTransaction . mosaics . length ) . to . be . equal ( 1 ) ;
68- expect ( transferTransaction . recipient . plain ( ) ) . to . be . equal ( 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC' ) ;
70+ expect ( transferTransaction . recipient ) . to . be . instanceof ( Address ) ;
71+ expect ( ( transferTransaction . recipient as Address ) . plain ( ) ) . to . be . equal ( 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC' ) ;
6972
7073 const signedTransaction = transferTransaction . signWith ( account ) ;
7174
@@ -76,4 +79,75 @@ describe('TransferTransaction', () => {
7679 '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000100746573742D6D657373616765' +
7780 '44B262C46CEABB8500E1F50500000000' ) ;
7881 } ) ;
82+
83+ it ( 'should createComplete an TransferTransaction object with NamespaceId recipient' , ( ) => {
84+ const addressAlias = new NamespaceId ( 'nem.owner' ) ;
85+ const transferTransaction = TransferTransaction . create (
86+ Deadline . create ( ) ,
87+ addressAlias ,
88+ [
89+ NetworkCurrencyMosaic . createRelative ( 100 ) ,
90+ ] ,
91+ PlainMessage . create ( 'test-message' ) ,
92+ NetworkType . MIJIN_TEST ,
93+ ) ;
94+
95+ expect ( transferTransaction . message . payload ) . to . be . equal ( 'test-message' ) ;
96+ expect ( transferTransaction . mosaics . length ) . to . be . equal ( 1 ) ;
97+ expect ( transferTransaction . recipient ) . to . be . instanceof ( NamespaceId ) ;
98+ expect ( transferTransaction . recipient ) . to . be . equal ( addressAlias ) ;
99+ expect ( ( transferTransaction . recipient as NamespaceId ) . toHex ( ) ) . to . be . equal ( addressAlias . toHex ( ) ) ;
100+
101+ const signedTransaction = transferTransaction . signWith ( account ) ;
102+
103+ expect ( signedTransaction . payload . substring (
104+ 240 ,
105+ signedTransaction . payload . length ,
106+ ) ) . to . be . equal ( '9151776168D24257D8000000000000000000000000000000000D000100746573742D6D657373616765' +
107+ '44B262C46CEABB8500E1F50500000000' ) ;
108+ } ) ;
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+ } ) ;
79153} ) ;
0 commit comments