@@ -866,6 +866,132 @@ func TestClient_GetAccountTransactions(t *testing.T) {
866866 }
867867}
868868
869+ func TestClient_GetGatewayBalances (t * testing.T ) {
870+ tests := []struct {
871+ name string
872+ mockResponse string
873+ mockStatus int
874+ request * account.GatewayBalancesRequest
875+ expected account.GatewayBalancesResponse
876+ expectedError string
877+ }{
878+ {
879+ name : "successful response" ,
880+ mockResponse : `{
881+ "result": {
882+ "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q",
883+ "assets": {
884+ "r9F6wk8HkXrgYWoJ7fsv4VrUBVoqDVtzkH": [
885+ {
886+ "currency": "BTC",
887+ "value": "5444166510000000e-26"
888+ }
889+ ]
890+ },
891+ "balances": {
892+ "rKm4uWpg9tfwbVSeATv4KxDe6mpE9yPkgJ": [
893+ {
894+ "currency": "EUR",
895+ "value": "29826.1965999999"
896+ }
897+ ],
898+ "ra7JkEzrgeKHdzKgo4EUUVBnxggY4z37kt": [
899+ {
900+ "currency": "USD",
901+ "value": "13857.70416"
902+ }
903+ ]
904+ },
905+ "ledger_hash": "61DDBF304AF6E8101576BF161D447CA8E4F0170DDFBEAFFD993DC9383D443388",
906+ "ledger_index": 14483212,
907+ "obligations": {
908+ "EUR": "5599.716599999999",
909+ "USD": "12345.9"
910+ },
911+ "status": "success"
912+ }
913+ }` ,
914+ mockStatus : 200 ,
915+ request : & account.GatewayBalancesRequest {
916+ Account : "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q" ,
917+ },
918+ expected : account.GatewayBalancesResponse {
919+ Account : "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q" ,
920+ Assets : map [string ][]account.GatewayBalance {
921+ "r9F6wk8HkXrgYWoJ7fsv4VrUBVoqDVtzkH" : {
922+ {
923+ Currency : "BTC" ,
924+ Value : "5444166510000000e-26" ,
925+ },
926+ },
927+ },
928+ Balances : map [string ][]account.GatewayBalance {
929+ "rKm4uWpg9tfwbVSeATv4KxDe6mpE9yPkgJ" : {
930+ {
931+ Currency : "EUR" ,
932+ Value : "29826.1965999999" ,
933+ },
934+ },
935+ "ra7JkEzrgeKHdzKgo4EUUVBnxggY4z37kt" : {
936+ {
937+ Currency : "USD" ,
938+ Value : "13857.70416" ,
939+ },
940+ },
941+ },
942+ LedgerHash : "61DDBF304AF6E8101576BF161D447CA8E4F0170DDFBEAFFD993DC9383D443388" ,
943+ LedgerIndex : 14483212 ,
944+ Obligations : map [string ]string {
945+ "EUR" : "5599.716599999999" ,
946+ "USD" : "12345.9" ,
947+ },
948+ },
949+ },
950+ {
951+ name : "error response" ,
952+ mockResponse : `{
953+ "result": {
954+ "error": "actNotFound",
955+ "status": "error"
956+ }
957+ }` ,
958+ mockStatus : 200 ,
959+ request : & account.GatewayBalancesRequest {
960+ Account : "rInvalidAccount" ,
961+ },
962+ expectedError : "actNotFound" ,
963+ },
964+ }
965+
966+ for _ , tt := range tests {
967+ t .Run (tt .name , func (t * testing.T ) {
968+ mc := testutil.JSONRPCMockClient {}
969+ mc .DoFunc = testutil .MockResponse (tt .mockResponse , tt .mockStatus , & mc )
970+
971+ cfg , err := NewClientConfig ("http://testnode/" , WithHTTPClient (& mc ))
972+ require .NoError (t , err )
973+
974+ client := NewClient (cfg )
975+
976+ resp , err := client .Request (tt .request )
977+
978+ if tt .expectedError != "" {
979+ require .Error (t , err )
980+ require .Contains (t , err .Error (), tt .expectedError )
981+ return
982+ }
983+
984+ require .NoError (t , err )
985+
986+ var gatewayBalancesResp account.GatewayBalancesResponse
987+ err = resp .GetResult (& gatewayBalancesResp )
988+ require .NoError (t , err )
989+
990+ require .Equal (t , tt .expected , gatewayBalancesResp )
991+ })
992+ }
993+ }
994+
869995func TestClient_GetChannelVerify (t * testing.T ) {
870996 tests := []struct {
871997 name string
0 commit comments