11import * as assert from 'assert' ;
22import * as sinon from 'sinon' ;
33import 'should' ;
4- import { Wallet } from '../../../../src/bitgo/wallet/wallet' ;
5-
6- describe ( 'Wallet - getAccountResources' , function ( ) {
7- let wallet : Wallet ;
4+ import { BaseCoin } from '../../../../src/bitgo/baseCoin/baseCoin' ;
5+ import { BitGoBase } from '../../../../src/bitgo/bitgoBase' ;
6+
7+ // Create a concrete test implementation of BaseCoin
8+ class TestBaseCoin extends BaseCoin {
9+ getChain ( ) : string {
10+ return 'test' ;
11+ }
12+ getFamily ( ) : string {
13+ return 'test' ;
14+ }
15+ getFullName ( ) : string {
16+ return 'Test Coin' ;
17+ }
18+ getBaseFactor ( ) : string | number {
19+ return 1e8 ;
20+ }
21+ isValidAddress ( address : string ) : boolean {
22+ return true ;
23+ }
24+ static createInstance ( bitgo : BitGoBase ) : BaseCoin {
25+ return new TestBaseCoin ( bitgo ) ;
26+ }
27+ }
28+
29+ describe ( 'BaseCoin - getAccountResources' , function ( ) {
30+ let baseCoin : BaseCoin ;
831 let mockBitGo : any ;
9- let mockBaseCoin : any ;
10- let mockWalletData : any ;
1132
1233 beforeEach ( function ( ) {
1334 mockBitGo = {
1435 get : sinon . stub ( ) ,
36+ url : sinon . stub ( ) . returns ( '/api/v2/' ) ,
1537 } ;
1638
17- mockBaseCoin = {
18- url : sinon . stub ( ) . returns ( '/test/coin' ) ,
19- } ;
20-
21- mockWalletData = {
22- id : 'test-wallet-id' ,
23- keys : [ 'user-key' , 'backup-key' , 'bitgo-key' ] ,
24- } ;
25-
26- wallet = new Wallet ( mockBitGo , mockBaseCoin , mockWalletData ) ;
39+ baseCoin = TestBaseCoin . createInstance ( mockBitGo ) ;
2740 } ) ;
2841
2942 afterEach ( function ( ) {
@@ -46,18 +59,18 @@ describe('Wallet - getAccountResources', function () {
4659 } ) ;
4760
4861 const addresses = [ 'address1' , 'address2' ] ;
49- const result = await wallet . getAccountResources ( addresses ) ;
62+ const result = await baseCoin . getAccountResources ( addresses ) ;
5063
5164 result . should . deepEqual ( mockResponse ) ;
5265 mockBitGo . get . should . have . been . calledOnce ;
5366 const queryStub = mockBitGo . get . returnValues [ 0 ] . query ;
5467 queryStub . should . have . been . calledWith ( { addresses } ) ;
5568 } ) ;
5669
57- it ( 'should call WP API with addresses and tokenName parameters' , async function ( ) {
70+ it ( 'should call WP API with addresses and assetName parameters' , async function ( ) {
5871 const mockResponse = {
5972 resources : [
60- { address : 'address1' , balance : 100 , token : 'USDT' } ,
73+ { address : 'address1' , balance : 100 , asset : 'USDT' } ,
6174 ] ,
6275 } ;
6376
@@ -68,18 +81,18 @@ describe('Wallet - getAccountResources', function () {
6881 } ) ;
6982
7083 const addresses = [ 'address1' ] ;
71- const tokenName = 'USDT' ;
72- const result = await wallet . getAccountResources ( addresses , tokenName ) ;
84+ const assetName = 'USDT' ;
85+ const result = await baseCoin . getAccountResources ( addresses , assetName ) ;
7386
7487 result . should . deepEqual ( mockResponse ) ;
7588 mockBitGo . get . should . have . been . calledOnce ;
7689 const queryStub = mockBitGo . get . returnValues [ 0 ] . query ;
77- queryStub . should . have . been . calledWith ( { addresses, tokenName } ) ;
90+ queryStub . should . have . been . calledWith ( { addresses, assetName } ) ;
7891 } ) ;
7992
8093 it ( 'should throw error if addresses is not an array' , async function ( ) {
8194 try {
82- await wallet . getAccountResources ( 'not-an-array' as any ) ;
95+ await baseCoin . getAccountResources ( 'not-an-array' as any ) ;
8396 assert . fail ( 'Should have thrown error' ) ;
8497 } catch ( error ) {
8598 error . message . should . equal ( 'addresses must be an array' ) ;
@@ -88,14 +101,14 @@ describe('Wallet - getAccountResources', function () {
88101
89102 it ( 'should throw error if addresses array is empty' , async function ( ) {
90103 try {
91- await wallet . getAccountResources ( [ ] ) ;
104+ await baseCoin . getAccountResources ( [ ] ) ;
92105 assert . fail ( 'Should have thrown error' ) ;
93106 } catch ( error ) {
94107 error . message . should . equal ( 'addresses array cannot be empty' ) ;
95108 }
96109 } ) ;
97110
98- it ( 'should not include tokenName in query if not provided' , async function ( ) {
111+ it ( 'should not include assetName in query if not provided' , async function ( ) {
99112 const mockResponse = { resources : [ ] } ;
100113
101114 mockBitGo . get . returns ( {
@@ -105,12 +118,12 @@ describe('Wallet - getAccountResources', function () {
105118 } ) ;
106119
107120 const addresses = [ 'address1' ] ;
108- await wallet . getAccountResources ( addresses ) ;
121+ await baseCoin . getAccountResources ( addresses ) ;
109122
110123 const queryStub = mockBitGo . get . returnValues [ 0 ] . query ;
111124 const queryArg = queryStub . firstCall . args [ 0 ] ;
112125 queryArg . should . deepEqual ( { addresses } ) ;
113- queryArg . should . not . have . property ( 'tokenName ' ) ;
126+ queryArg . should . not . have . property ( 'assetName ' ) ;
114127 } ) ;
115128 } ) ;
116129} ) ;
0 commit comments