@@ -151,6 +151,98 @@ describe('NEAR:', function () {
151151 } ) ;
152152 } ) ;
153153
154+ describe ( 'Address verification' , ( ) => {
155+ const addressVerificationData = {
156+ commonKeychain :
157+ '43d3f6a94d7e3faf4dd390a7e26f554eaa98c8f0813e3f0ae959d61d8acd012e0504e552a5c311260f2fbaef3a817dfa5b85b984cd43b161bebad9ded25764cc' ,
158+ rootAddress : '98908af363d3e99d87b1d6dce4f80a28bbfe64fee22dbb8a36dada25ba30d027' ,
159+ receiveAddress : '6aa21569736f6ebaf925fef8ece219c2b703098cc358ce34a97f2c2a2e099659' ,
160+ receiveAddressIndex : 2 ,
161+ } ;
162+
163+ let keychains ;
164+
165+ before ( function ( ) {
166+ keychains = [
167+ { commonKeychain : addressVerificationData . commonKeychain } ,
168+ { commonKeychain : addressVerificationData . commonKeychain } ,
169+ { commonKeychain : addressVerificationData . commonKeychain } ,
170+ ] ;
171+ } ) ;
172+
173+ it ( 'should verify a valid TSS root address (index 0)' , async function ( ) {
174+ const params = {
175+ address : addressVerificationData . rootAddress ,
176+ rootAddress : addressVerificationData . rootAddress ,
177+ keychains : keychains ,
178+ index : 0 ,
179+ } ;
180+ const result = await basecoin . isWalletAddress ( params ) ;
181+ result . should . equal ( true ) ;
182+ } ) ;
183+
184+ it ( 'should verify a valid TSS receive address (index > 0)' , async function ( ) {
185+ const params = {
186+ address : addressVerificationData . receiveAddress ,
187+ rootAddress : addressVerificationData . rootAddress ,
188+ keychains : keychains ,
189+ index : addressVerificationData . receiveAddressIndex ,
190+ } ;
191+ const result = await basecoin . isWalletAddress ( params ) ;
192+ result . should . equal ( true ) ;
193+ } ) ;
194+
195+ it ( 'should throw error for invalid address format' , async function ( ) {
196+ const invalidAddress = 'invalid-address' ;
197+ const params = {
198+ address : invalidAddress ,
199+ keychains : keychains ,
200+ index : 0 ,
201+ } ;
202+ await basecoin . isWalletAddress ( params ) . should . be . rejectedWith ( 'address validation failure' ) ;
203+ } ) ;
204+
205+ it ( 'should throw error when verifying root address with wrong index' , async function ( ) {
206+ const params = {
207+ address : addressVerificationData . rootAddress ,
208+ rootAddress : addressVerificationData . rootAddress ,
209+ keychains : keychains ,
210+ index : 1 ,
211+ } ;
212+ await basecoin . isWalletAddress ( params ) . should . be . rejectedWith ( 'address validation failure' ) ;
213+ } ) ;
214+
215+ it ( 'should throw error when keychains is missing' , async function ( ) {
216+ const params = {
217+ address : addressVerificationData . rootAddress ,
218+ keychains : [ ] ,
219+ index : 0 ,
220+ } ;
221+ await basecoin . isWalletAddress ( params ) . should . be . rejectedWith ( 'missing required param keychains' ) ;
222+ } ) ;
223+
224+ it ( 'should throw error for address that does not match derivation' , async function ( ) {
225+ const wrongAddress = '0000000000000000000000000000000000000000000000000000000000000000' ;
226+ const params = {
227+ address : wrongAddress ,
228+ keychains : keychains ,
229+ index : 0 ,
230+ } ;
231+ await basecoin . isWalletAddress ( params ) . should . be . rejectedWith ( 'address validation failure' ) ;
232+ } ) ;
233+
234+ it ( 'should handle string index' , async function ( ) {
235+ const params = {
236+ address : addressVerificationData . rootAddress ,
237+ rootAddress : addressVerificationData . rootAddress ,
238+ keychains : keychains ,
239+ index : '0' ,
240+ } ;
241+ const result = await basecoin . isWalletAddress ( params ) ;
242+ result . should . equal ( true ) ;
243+ } ) ;
244+ } ) ;
245+
154246 describe ( 'Verify transaction: ' , ( ) => {
155247 const amount = '1000000' ;
156248 const gas = '125000000000000' ;
0 commit comments