1414 * limitations under the License.
1515 */
1616import { expect } from 'chai' ;
17- import { sha3_512 } from 'js-sha3' ;
17+ import * as CryptoJS from 'crypto-js' ;
18+ import { keccak_256 , sha3_256 } from 'js-sha3' ;
1819import { convert } from 'nem2-library' ;
1920import { Address } from '../../../src/model/account/Address' ;
2021import { NetworkType } from '../../../src/model/blockchain/NetworkType' ;
@@ -26,36 +27,137 @@ import {UInt64} from '../../../src/model/UInt64';
2627
2728describe ( 'SecretLockTransaction' , ( ) => {
2829
29- it ( 'should be created' , ( ) => {
30- const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7680ADA57' +
31- 'DCEC8EEE91C4E3BF3BFA9AF6FFDE90CD1D249D1C6121D7B759A001B1' ;
30+ it ( 'should be created with HashType: Op_Sha3_256 secret' , ( ) => {
31+ const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7' ;
3232 const recipient = Address . createFromRawAddress ( 'SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL' ) ;
3333 const secretLockTransaction = SecretLockTransaction . create (
3434 Deadline . create ( ) ,
3535 XEM . createAbsolute ( 10 ) ,
3636 UInt64 . fromUint ( 100 ) ,
37- HashType . SHA3_512 ,
38- sha3_512 . create ( ) . update ( convert . hexToUint8 ( proof ) ) . hex ( ) ,
37+ HashType . Op_Sha3_256 ,
38+ sha3_256 . create ( ) . update ( convert . hexToUint8 ( proof ) ) . hex ( ) ,
3939 recipient ,
4040 NetworkType . MIJIN_TEST ,
4141 ) ;
4242 expect ( secretLockTransaction . mosaic . id ) . to . be . equal ( XEM . MOSAIC_ID ) ;
4343 expect ( secretLockTransaction . mosaic . amount . equals ( UInt64 . fromUint ( 10 ) ) ) . to . be . equal ( true ) ;
4444 expect ( secretLockTransaction . duration . equals ( UInt64 . fromUint ( 100 ) ) ) . to . be . equal ( true ) ;
4545 expect ( secretLockTransaction . hashType ) . to . be . equal ( 0 ) ;
46- expect ( secretLockTransaction . secret ) . to . be . equal ( 'd23859866f93f2698a5b48586543c608d85a57c74e9ce92d86a0b25065d' +
47- '8155c16754d840026b8c536f2bcb963a7d867f034ec241b87162ac33daf7b707cb5f7' ) ;
46+ expect ( secretLockTransaction . secret ) . to . be . equal ( '9b3155b37159da50aa52d5967c509b410f5a36a3b1e31ecb5ac76675d79b4a5e' ) ;
4847 expect ( secretLockTransaction . recipient ) . to . be . equal ( recipient ) ;
4948 } ) ;
5049
51- it ( 'should throw exception when the input is not related to HashType ' , ( ) => {
50+ it ( 'should throw exception when the input is not related to HashTyp: Op_Sha3_256 ' , ( ) => {
5251 expect ( ( ) => {
5352 const recipient = Address . createFromRawAddress ( 'SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL' ) ;
5453 const secretLockTransaction = SecretLockTransaction . create (
5554 Deadline . create ( ) ,
5655 XEM . createAbsolute ( 10 ) ,
5756 UInt64 . fromUint ( 100 ) ,
58- HashType . SHA3_512 ,
57+ HashType . Op_Sha3_256 ,
58+ 'non valid hash' ,
59+ recipient ,
60+ NetworkType . MIJIN_TEST ,
61+ ) ;
62+ } ) . to . throw ( Error ) ;
63+ } ) ;
64+
65+ it ( 'should be created with HashType: Op_Keccak_256 secret' , ( ) => {
66+ const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7' ;
67+ const recipient = Address . createFromRawAddress ( 'SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL' ) ;
68+ const secretLockTransaction = SecretLockTransaction . create (
69+ Deadline . create ( ) ,
70+ XEM . createAbsolute ( 10 ) ,
71+ UInt64 . fromUint ( 100 ) ,
72+ HashType . Op_Keccak_256 ,
73+ keccak_256 . create ( ) . update ( convert . hexToUint8 ( proof ) ) . hex ( ) ,
74+ recipient ,
75+ NetworkType . MIJIN_TEST ,
76+ ) ;
77+ expect ( secretLockTransaction . mosaic . id ) . to . be . equal ( XEM . MOSAIC_ID ) ;
78+ expect ( secretLockTransaction . mosaic . amount . equals ( UInt64 . fromUint ( 10 ) ) ) . to . be . equal ( true ) ;
79+ expect ( secretLockTransaction . duration . equals ( UInt64 . fromUint ( 100 ) ) ) . to . be . equal ( true ) ;
80+ expect ( secretLockTransaction . hashType ) . to . be . equal ( 1 ) ;
81+ expect ( secretLockTransaction . secret ) . to . be . equal ( '241c1d54c18c8422def03aa16b4b243a8ba491374295a1a6965545e6ac1af314' ) ;
82+ expect ( secretLockTransaction . recipient ) . to . be . equal ( recipient ) ;
83+ } ) ;
84+
85+ it ( 'should throw exception when the input is not related to HashTyp: Op_Keccak_256' , ( ) => {
86+ expect ( ( ) => {
87+ const recipient = Address . createFromRawAddress ( 'SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL' ) ;
88+ const secretLockTransaction = SecretLockTransaction . create (
89+ Deadline . create ( ) ,
90+ XEM . createAbsolute ( 10 ) ,
91+ UInt64 . fromUint ( 100 ) ,
92+ HashType . Op_Keccak_256 ,
93+ 'non valid hash' ,
94+ recipient ,
95+ NetworkType . MIJIN_TEST ,
96+ ) ;
97+ } ) . to . throw ( Error ) ;
98+ } ) ;
99+ it ( 'should be created with HashType: Op_Hash_160 secret' , ( ) => {
100+ const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9' ;
101+ const recipient = Address . createFromRawAddress ( 'SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL' ) ;
102+ const secretLockTransaction = SecretLockTransaction . create (
103+ Deadline . create ( ) ,
104+ XEM . createAbsolute ( 10 ) ,
105+ UInt64 . fromUint ( 100 ) ,
106+ HashType . Op_Hash_160 ,
107+ CryptoJS . RIPEMD160 ( CryptoJS . SHA256 ( proof ) . toString ( CryptoJS . enc . Hex ) ) . toString ( CryptoJS . enc . Hex ) ,
108+ recipient ,
109+ NetworkType . MIJIN_TEST ,
110+ ) ;
111+ expect ( secretLockTransaction . mosaic . id ) . to . be . equal ( XEM . MOSAIC_ID ) ;
112+ expect ( secretLockTransaction . mosaic . amount . equals ( UInt64 . fromUint ( 10 ) ) ) . to . be . equal ( true ) ;
113+ expect ( secretLockTransaction . duration . equals ( UInt64 . fromUint ( 100 ) ) ) . to . be . equal ( true ) ;
114+ expect ( secretLockTransaction . hashType ) . to . be . equal ( 2 ) ;
115+ expect ( secretLockTransaction . secret ) . to . be . equal ( '3fc43d717d824302e3821de8129ea2f7786912e5' ) ;
116+ expect ( secretLockTransaction . recipient ) . to . be . equal ( recipient ) ;
117+ } ) ;
118+
119+ it ( 'should throw exception when the input is not related to HashTyp: Op_Hash_160' , ( ) => {
120+ expect ( ( ) => {
121+ const recipient = Address . createFromRawAddress ( 'SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL' ) ;
122+ const secretLockTransaction = SecretLockTransaction . create (
123+ Deadline . create ( ) ,
124+ XEM . createAbsolute ( 10 ) ,
125+ UInt64 . fromUint ( 100 ) ,
126+ HashType . Op_Hash_160 ,
127+ 'non valid hash' ,
128+ recipient ,
129+ NetworkType . MIJIN_TEST ,
130+ ) ;
131+ } ) . to . throw ( Error ) ;
132+ } ) ;
133+ it ( 'should be created with HashType: Op_Hash_256 secret' , ( ) => {
134+ const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7' ;
135+ const recipient = Address . createFromRawAddress ( 'SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL' ) ;
136+ const secretLockTransaction = SecretLockTransaction . create (
137+ Deadline . create ( ) ,
138+ XEM . createAbsolute ( 10 ) ,
139+ UInt64 . fromUint ( 100 ) ,
140+ HashType . Op_Hash_256 ,
141+ CryptoJS . SHA256 ( CryptoJS . SHA256 ( proof ) . toString ( CryptoJS . enc . Hex ) ) . toString ( CryptoJS . enc . Hex ) ,
142+ recipient ,
143+ NetworkType . MIJIN_TEST ,
144+ ) ;
145+ expect ( secretLockTransaction . mosaic . id ) . to . be . equal ( XEM . MOSAIC_ID ) ;
146+ expect ( secretLockTransaction . mosaic . amount . equals ( UInt64 . fromUint ( 10 ) ) ) . to . be . equal ( true ) ;
147+ expect ( secretLockTransaction . duration . equals ( UInt64 . fromUint ( 100 ) ) ) . to . be . equal ( true ) ;
148+ expect ( secretLockTransaction . hashType ) . to . be . equal ( 3 ) ;
149+ expect ( secretLockTransaction . secret ) . to . be . equal ( 'c346f5ecf5bcfa54ab14fad815c8239bdeb051df8835d212dba2af59f688a00e' ) ;
150+ expect ( secretLockTransaction . recipient ) . to . be . equal ( recipient ) ;
151+ } ) ;
152+
153+ it ( 'should throw exception when the input is not related to HashTyp: Op_Hash_256' , ( ) => {
154+ expect ( ( ) => {
155+ const recipient = Address . createFromRawAddress ( 'SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL' ) ;
156+ const secretLockTransaction = SecretLockTransaction . create (
157+ Deadline . create ( ) ,
158+ XEM . createAbsolute ( 10 ) ,
159+ UInt64 . fromUint ( 100 ) ,
160+ HashType . Op_Hash_256 ,
59161 'non valid hash' ,
60162 recipient ,
61163 NetworkType . MIJIN_TEST ,
0 commit comments