@@ -6,8 +6,10 @@ import {
6
6
closestPackableTransactionFee ,
7
7
isTransactionAmountPackable ,
8
8
isTransactionFeePackable ,
9
- TokenSet
9
+ TokenSet ,
10
+ getTxHash
10
11
} from '../src/utils' ;
12
+ import { Transfer , ChangePubKey , Withdraw , ForcedExit } from '../src/types' ;
11
13
import { BigNumber } from 'ethers' ;
12
14
13
15
describe ( 'Packing and unpacking' , function ( ) {
@@ -66,3 +68,79 @@ describe('Token cache resolve', function () {
66
68
expect ( ( ) => tokenCache . resolveTokenId ( 'ERC20-2' ) ) . to . throw ( ) ;
67
69
} ) ;
68
70
} ) ;
71
+
72
+ describe ( 'Test getTxHash' , function ( ) {
73
+ it ( 'Test Transfer' , async function ( ) {
74
+ const transfer = {
75
+ type : 'Transfer' ,
76
+ accountId : 123 ,
77
+ from : '0xdddddddddddddddddddddddddddddddddddddddd' ,
78
+ to : '0xeddddddddddddddddddddddddddddddddddddddd' ,
79
+ token : 0 ,
80
+ amount : 23 ,
81
+ fee : 88 ,
82
+ nonce : 123 ,
83
+ validFrom : 12 ,
84
+ validUntil : 1232321
85
+ } ;
86
+ const transferHash = getTxHash ( transfer as Transfer ) ;
87
+ expect (
88
+ 'sync-tx:9aa2460771722dfc15fc371e11d8412b63acdd0a483b888336234fc4b825b00b' === transferHash ,
89
+ 'Incorrect transfer hash'
90
+ ) . to . be . true ;
91
+ } ) ;
92
+ it ( 'Test Withdraw' , async function ( ) {
93
+ const withdraw = {
94
+ type : 'Withdraw' ,
95
+ accountId : 1 ,
96
+ from : '0xddddddddddddddddddddddddddddddddddddddde' ,
97
+ to : '0xadddddddddddddddddddddddddddddddddddddde' ,
98
+ token : 12 ,
99
+ amount : '123' ,
100
+ fee : '897' ,
101
+ nonce : 1 ,
102
+ validFrom : 90809 ,
103
+ validUntil : 873712938
104
+ } ;
105
+ const withdrawHash = getTxHash ( withdraw as Withdraw ) ;
106
+ expect (
107
+ 'sync-tx:84365ebb70259b8f6d6d9729e660f1ea9ecb2dbeeefd449bed54ac144d80a315' === withdrawHash ,
108
+ 'Incorrect withdrawal hash'
109
+ ) . to . be . true ;
110
+ } ) ;
111
+ it ( 'Test ChangePubKey' , async function ( ) {
112
+ const changePubKey = {
113
+ type : 'ChangePubKey' ,
114
+ accountId : 2 ,
115
+ account : '0xaddddddddddddddddddddddddddddddddddddd0e' ,
116
+ newPkHash : '0xadddddddd1234ddddddddddddddddddddddddd0e' ,
117
+ feeToken : 20 ,
118
+ fee : 98 ,
119
+ nonce : 32 ,
120
+ validFrom : 177 ,
121
+ validUntil : 52443
122
+ } ;
123
+ const changePubKeyHash = getTxHash ( changePubKey as ChangePubKey ) ;
124
+ expect (
125
+ 'sync-tx:486629437f43e9d9383431e2d075ba194d9e549c08b03db234ca4edaebb2200f' === changePubKeyHash ,
126
+ 'Incorrect changePubKey hash'
127
+ ) . to . be . true ;
128
+ } ) ;
129
+ it ( 'Test ForcedExit' , async function ( ) {
130
+ const forcedExit = {
131
+ type : 'ForcedExit' ,
132
+ initiatorAccountId : 776 ,
133
+ target : '0xadddddddd1234ddddd777ddddddddddddddddd0e' ,
134
+ token : 5 ,
135
+ fee : 123 ,
136
+ nonce : 5 ,
137
+ validFrom : 8978 ,
138
+ validUntil : 57382678
139
+ } ;
140
+ const forcedExitHash = getTxHash ( forcedExit as ForcedExit ) ;
141
+ expect (
142
+ 'sync-tx:0f5cba03550d1ab984d6f478c79aeb6f6961873df7a5876c9af4502364163d03' === forcedExitHash ,
143
+ 'Incorrect forcedExit hash'
144
+ ) . to . be . true ;
145
+ } ) ;
146
+ } ) ;
0 commit comments