@@ -19,6 +19,7 @@ import { Account } from '../../../src/model/account/Account';
19
19
import { Address } from '../../../src/model/account/Address' ;
20
20
import { NetworkType } from '../../../src/model/blockchain/NetworkType' ;
21
21
import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic' ;
22
+ import { NamespaceId } from '../../../src/model/namespace/NamespaceId' ;
22
23
import { Deadline } from '../../../src/model/transaction/Deadline' ;
23
24
import { PlainMessage } from '../../../src/model/transaction/PlainMessage' ;
24
25
import { TransferTransaction } from '../../../src/model/transaction/TransferTransaction' ;
@@ -42,7 +43,8 @@ describe('TransferTransaction', () => {
42
43
43
44
expect ( transferTransaction . message . payload ) . to . be . equal ( 'test-message' ) ;
44
45
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' ) ;
46
48
47
49
const signedTransaction = transferTransaction . signWith ( account ) ;
48
50
@@ -65,7 +67,8 @@ describe('TransferTransaction', () => {
65
67
66
68
expect ( transferTransaction . message . payload ) . to . be . equal ( 'test-message' ) ;
67
69
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' ) ;
69
72
70
73
const signedTransaction = transferTransaction . signWith ( account ) ;
71
74
@@ -76,4 +79,75 @@ describe('TransferTransaction', () => {
76
79
'9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000100746573742D6D657373616765' +
77
80
'44B262C46CEABB8500E1F50500000000' ) ;
78
81
} ) ;
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
+ } ) ;
79
153
} ) ;
0 commit comments