@@ -29,13 +29,14 @@ describe("account", function() {
29
29
} ) ;
30
30
31
31
it ( "getList" , async function ( ) {
32
- expect ( await node . sdk . rpc . account . getList ( ) ) . not . to . be . null ;
32
+ expect ( await node . rpc . account . getList ( ) ) . not . to . be . null ;
33
33
} ) ;
34
34
35
35
it ( "create" , async function ( ) {
36
- expect ( await node . sdk . rpc . account . create ( ) ) . not . to . be . null ;
37
- expect ( await node . sdk . rpc . account . create ( "my-password" ) ) . not . to . be
38
- . null ;
36
+ expect ( await node . rpc . account . create ( { passphrase : "my-password" } ) )
37
+ . not . to . be . null ;
38
+ expect ( await node . rpc . account . create ( { passphrase : "my-password" } ) )
39
+ . not . to . be . null ;
39
40
} ) ;
40
41
41
42
describe ( "importRaw" , function ( ) {
@@ -53,26 +54,38 @@ describe("account", function() {
53
54
{ networkId : "tc" }
54
55
) ;
55
56
expect (
56
- await node . sdk . rpc . account . importRaw ( randomSecret )
57
+ await node . rpc . account . importRaw ( {
58
+ secret : "0x" . concat ( randomSecret ) ,
59
+ passphrase : ""
60
+ } )
57
61
) . to . equal ( address . toString ( ) ) ;
58
62
} ) ;
59
63
60
64
it ( "KeyError" , async function ( ) {
61
65
try {
62
- await node . sdk . rpc . account . importRaw ( invalidSecret ) ;
66
+ await node . rpc . account . importRaw ( {
67
+ secret : "0x" . concat ( invalidSecret ) ,
68
+ passphrase : ""
69
+ } ) ;
63
70
expect . fail ( ) ;
64
71
} catch ( e ) {
65
- expect ( e ) . is . similarTo ( ERROR . KEY_ERROR ) ;
72
+ expect ( e . toString ( ) ) . is . include ( ERROR . KEY_ERROR ) ;
66
73
}
67
74
} ) ;
68
75
69
76
it ( "AlreadyExists" , async function ( ) {
70
77
try {
71
- await node . sdk . rpc . account . importRaw ( randomSecret ) ;
72
- await node . sdk . rpc . account . importRaw ( randomSecret ) ;
78
+ await node . rpc . account . importRaw ( {
79
+ secret : "0x" . concat ( randomSecret ) ,
80
+ passphrase : null
81
+ } ) ;
82
+ await node . rpc . account . importRaw ( {
83
+ secret : "0x" . concat ( randomSecret ) ,
84
+ passphrase : null
85
+ } ) ;
73
86
expect . fail ( ) ;
74
87
} catch ( e ) {
75
- expect ( e ) . is . similarTo ( ERROR . ALREADY_EXISTS ) ;
88
+ expect ( e . toString ( ) ) . is . include ( ERROR . ALREADY_EXISTS ) ;
76
89
}
77
90
} ) ;
78
91
} ) ;
@@ -84,118 +97,137 @@ describe("account", function() {
84
97
let secret : string ;
85
98
beforeEach ( async function ( ) {
86
99
secret = node . sdk . util . generatePrivateKey ( ) ;
87
- address = await node . sdk . rpc . account . importRaw (
88
- secret ,
89
- "my-password"
90
- ) ;
100
+ address = await node . rpc . account . importRaw ( {
101
+ secret : "0x" . concat ( secret ) ,
102
+ passphrase : "my-password"
103
+ } ) ;
91
104
} ) ;
92
105
93
106
it ( "Ok" , async function ( ) {
94
107
const calculatedSignature = node . sdk . util . signEcdsa (
95
108
message ,
96
109
secret
97
110
) ;
98
- const signature = await node . sdk . rpc . account . sign (
99
- message ,
100
- address ,
101
- "my-password"
102
- ) ;
111
+ const signature = await node . rpc . account . sign ( {
112
+ message : `0x ${ message } ` ,
113
+ account : address ,
114
+ passphrase : "my-password"
115
+ } ) ;
103
116
expect ( signature ) . to . equal ( `0x${ calculatedSignature } ` ) ;
104
117
} ) ;
105
118
106
119
it ( "WrongPassword" , async function ( ) {
107
120
try {
108
- await node . sdk . rpc . account . sign (
109
- message ,
110
- address ,
111
- "wrong-password"
112
- ) ;
121
+ await node . rpc . account . sign ( {
122
+ message : `0x ${ message } ` ,
123
+ account : address ,
124
+ passphrase : "wrong-password"
125
+ } ) ;
113
126
expect . fail ( ) ;
114
127
} catch ( e ) {
115
- expect ( e ) . is . similarTo ( ERROR . WRONG_PASSWORD ) ;
128
+ expect ( e . toString ( ) ) . is . include ( ERROR . WRONG_PASSWORD ) ;
116
129
}
117
130
} ) ;
118
131
119
132
it ( "NoSuchAccount" , async function ( ) {
120
133
try {
121
- await node . sdk . rpc . account . sign (
122
- message ,
123
- invalidAddress ,
124
- "my-password"
125
- ) ;
134
+ await node . rpc . account . sign ( {
135
+ message : `0x ${ message } ` ,
136
+ account : invalidAddress ,
137
+ passphrase : "my-password"
138
+ } ) ;
126
139
expect . fail ( ) ;
127
140
} catch ( e ) {
128
- expect ( e ) . is . similarTo ( ERROR . NO_SUCH_ACCOUNT ) ;
141
+ expect ( e . toString ( ) ) . is . include ( ERROR . NO_SUCH_ACCOUNT ) ;
129
142
}
130
143
} ) ;
131
144
} ) ;
132
145
133
146
describe ( "unlock" , function ( ) {
134
147
let address : string ;
135
148
beforeEach ( async function ( ) {
136
- address = await node . sdk . rpc . account . create ( "123" ) ;
149
+ address = await node . rpc . account . create ( { passphrase : "123" } ) ;
137
150
} ) ;
138
151
139
152
it ( "Ok" , async function ( ) {
140
- await node . sdk . rpc . account . unlock ( address , "123" ) ;
141
- await node . sdk . rpc . account . unlock ( address , "123" , 0 ) ;
142
- await node . sdk . rpc . account . unlock ( address , "123" , 300 ) ;
153
+ await node . rpc . account . unlock ( {
154
+ account : address ,
155
+ passphrase : "123"
156
+ } ) ;
157
+ await node . rpc . account . unlock ( {
158
+ account : address ,
159
+ passphrase : "123" ,
160
+ duration : 0
161
+ } ) ;
162
+ await node . rpc . account . unlock ( {
163
+ account : address ,
164
+ passphrase : "123" ,
165
+ duration : 300
166
+ } ) ;
143
167
} ) ;
144
168
145
169
it ( "WrongPassword" , async function ( ) {
146
170
try {
147
- await node . sdk . rpc . account . unlock ( address , "456" ) ;
171
+ await node . rpc . account . unlock ( {
172
+ account : address ,
173
+ passphrase : "456"
174
+ } ) ;
148
175
expect . fail ( ) ;
149
176
} catch ( e ) {
150
- expect ( e ) . is . similarTo ( ERROR . WRONG_PASSWORD ) ;
177
+ expect ( e . toString ( ) ) . is . include ( ERROR . WRONG_PASSWORD ) ;
151
178
}
152
179
} ) ;
153
180
154
181
it ( "NoSuchAccount" , async function ( ) {
155
182
try {
156
- await node . sdk . rpc . account . unlock ( invalidAddress , "456" ) ;
183
+ await node . rpc . account . unlock ( {
184
+ account : invalidAddress . toString ( ) ,
185
+ passphrase : "456"
186
+ } ) ;
157
187
expect . fail ( ) ;
158
188
} catch ( e ) {
159
- expect ( e ) . is . similarTo ( ERROR . NO_SUCH_ACCOUNT ) ;
189
+ expect ( e . toString ( ) ) . is . include ( ERROR . NO_SUCH_ACCOUNT ) ;
160
190
}
161
191
} ) ;
162
192
} ) ;
163
193
164
194
describe ( "changePassword" , function ( ) {
165
195
let address : string ;
166
196
beforeEach ( async function ( ) {
167
- address = await node . sdk . rpc . account . create ( "123" ) ;
197
+ address = await node . rpc . account . create ( { passphrase : "123" } ) ;
168
198
} ) ;
169
199
170
200
it ( "Ok" , async function ( ) {
171
- await node . sdk . rpc . sendRpcRequest ( "account_changePassword" , [
172
- address ,
173
- "123" ,
174
- "456"
175
- ] ) ;
201
+ await node . rpc . account . changePassword ( {
202
+ account : address ,
203
+ oldPassphrase : "123" ,
204
+ newPassphrase : "456"
205
+ } ) ;
176
206
} ) ;
177
207
178
208
it ( "WrongPassword" , async function ( ) {
179
209
try {
180
- await node . sdk . rpc . sendRpcRequest (
181
- "account_changePassword" ,
182
- [ address , "456" , "123" ]
183
- ) ;
210
+ await node . rpc . account . changePassword ( {
211
+ account : address ,
212
+ oldPassphrase : "456" ,
213
+ newPassphrase : "123"
214
+ } ) ;
184
215
expect . fail ( ) ;
185
216
} catch ( e ) {
186
- expect ( e ) . is . similarTo ( ERROR . WRONG_PASSWORD ) ;
217
+ expect ( e . toString ( ) ) . is . include ( ERROR . WRONG_PASSWORD ) ;
187
218
}
188
219
} ) ;
189
220
190
221
it ( "NoSuchAccount" , async function ( ) {
191
222
try {
192
- await node . sdk . rpc . sendRpcRequest (
193
- "account_changePassword" ,
194
- [ invalidAddress , "123" , "345" ]
195
- ) ;
223
+ await node . rpc . account . changePassword ( {
224
+ account : invalidAddress ,
225
+ oldPassphrase : "123" ,
226
+ newPassphrase : "345"
227
+ } ) ;
196
228
expect . fail ( ) ;
197
229
} catch ( e ) {
198
- expect ( e ) . is . similarTo ( ERROR . NO_SUCH_ACCOUNT ) ;
230
+ expect ( e . toString ( ) ) . is . include ( ERROR . NO_SUCH_ACCOUNT ) ;
199
231
}
200
232
} ) ;
201
233
} ) ;
0 commit comments