Skip to content

Commit

Permalink
Validator Rest API refactors causing changes to UI (#249)
Browse files Browse the repository at this point in the history
* removing old widgets and removing base64 middleware

* removing bad test

* optimizing ndjson file
  • Loading branch information
james-prysm authored Nov 27, 2023
1 parent f35c0d4 commit 43662e3
Show file tree
Hide file tree
Showing 35 changed files with 49 additions and 929 deletions.
21 changes: 4 additions & 17 deletions src/app/modules/core/interceptors/mock.interceptor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { TestBed, inject } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { RouterTestingModule } from '@angular/router/testing';

import { MockInterceptor, VALIDATOR_API_PREFIX } from './mock.interceptor';
import { MockInterceptor} from './mock.interceptor';
import { EnvironmenterService } from '../services/environmenter.service';
import { Mocks } from '../mocks';

class MockEnv {
env = { production: false };
Expand All @@ -30,16 +29,4 @@ describe('MockInterceptor', () => {
]
});
});

describe('intercept HTTP requests', () => {
it('should retrieve a mock for the beacon node API calls', inject([HttpClient, HttpTestingController],
(http: HttpClient, mock: HttpTestingController) => {
const endpoint = VALIDATOR_API_PREFIX + '/beacon/participation';
http.get(endpoint).subscribe((res) => {
expect(res).toEqual(Mocks[endpoint]);
});
mock.verify();
})
);
});
});
55 changes: 8 additions & 47 deletions src/app/modules/core/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { hexToBase64 } from 'src/app/modules/core/utils/hex-util';
import {
ChainHead, ValidatorBalances,
ValidatorBalances_Balance, ValidatorParticipationResponse, ValidatorQueue,
ValidatorBalances_Balance,
Validators, ValidatorSummaryResponse, Validators_ValidatorContainer
} from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { Peers } from 'src/app/proto/eth/v1alpha1/node';
import { ValidatorParticipation } from 'src/app/proto/eth/v1alpha1/validator';
import {
Account, BackupAccountsResponse, BeaconStatusResponse, GenerateMnemonicResponse, ImportKeystoresResponse, InitializeAuthResponse, ListAccountsResponse, WalletResponse
} from 'src/app/proto/validator/accounts/v2/web_api';
Expand Down Expand Up @@ -54,30 +52,16 @@ export const mockSlashingProtection = {
};

export const mockPublicKeys: string[] = [
hexToBase64(
'0xaadaf653799229200378369ee7d6d9fdbdcdc2788143ed44f1ad5f2367c735e83a37c5bb80d7fb917de73a61bbcf00c4'
),
hexToBase64(
'0xb9a7565e5daaabf7e5656b64201685c6c0241df7195a64dcfc82f94b39826562208ea663dc8e340994fe5e2eef05967a'
),
hexToBase64(
'0xa74a19ce0c8a7909cb38e6645738c8d3f85821e371ecc273f16d02ec8b279153607953522c61e0d9c16c73e4e106dd31'
),
hexToBase64(
'0x8d4d65e320ebe3f8f45c1941a7f340eef43ff233400253a5532ad40313b4c5b3652ad84915c7ab333d8afb336e1b7407'
),
hexToBase64(
'0x93b283992d2db593c40d0417ccf6302ed5a26180555ec401c858232dc224b7e5c92aca63646bbf4d0d61df1584459d90'
),
'0xaadaf653799229200378369ee7d6d9fdbdcdc2788143ed44f1ad5f2367c735e83a37c5bb80d7fb917de73a61bbcf00c4',
'0xb9a7565e5daaabf7e5656b64201685c6c0241df7195a64dcfc82f94b39826562208ea663dc8e340994fe5e2eef05967a',
'0xa74a19ce0c8a7909cb38e6645738c8d3f85821e371ecc273f16d02ec8b279153607953522c61e0d9c16c73e4e106dd31',
'0x8d4d65e320ebe3f8f45c1941a7f340eef43ff233400253a5532ad40313b4c5b3652ad84915c7ab333d8afb336e1b7407',
'0x93b283992d2db593c40d0417ccf6302ed5a26180555ec401c858232dc224b7e5c92aca63646bbf4d0d61df1584459d90',
];

const mockImportedKeys: string[] = [
hexToBase64(
'0x80027c7b2213480672caf8503b82d41ff9533ba3698c2d70d33fa6c1840b2c115691dfb6de791f415db9df8b0176b9e4'
),
hexToBase64(
'0x800212f3ac97227ac9e4418ce649f386d90bbc1a95c400b6e0dbbe04da2f9b970e85c32ae89c4fdaaba74b5a2934ed5e'
),
'0x80027c7b2213480672caf8503b82d41ff9533ba3698c2d70d33fa6c1840b2c115691dfb6de791f415db9df8b0176b9e4',
'0x800212f3ac97227ac9e4418ce649f386d90bbc1a95c400b6e0dbbe04da2f9b970e85c32ae89c4fdaaba74b5a2934ed5e',
];

export const mockDepositDataJSON = [
Expand Down Expand Up @@ -499,22 +483,6 @@ export const Mocks: IMocks = {
},
],
} as Peers,
'/v2/validator/beacon/participation': {
epoch: 32,
finalized: true,
participation: {
current_epoch_active_gwei: '1446418000000000',
current_epoch_attesting_gwei: '102777000000000',
current_epoch_target_attesting_gwei: '101552000000000',
eligible_ether: '1446290000000000',
global_participation_rate: 0.7861,
previous_epoch_active_gwei: '1446290000000000',
previous_epoch_attesting_gwei: '1143101000000000',
previous_epoch_head_attesting_gwei: '1089546000000000',
previous_epoch_target_attesting_gwei: '1136975000000000',
voted_ether: '1136975000000000',
} as ValidatorParticipation,
} as ValidatorParticipationResponse,
'/v2/validator/beacon/summary': {
current_effective_balances: ['31000000000', '31000000000', '31000000000'],
correctly_voted_head: [true, true, false],
Expand All @@ -530,13 +498,6 @@ export const Mocks: IMocks = {
public_keys: mockPublicKeys,
missing_validators: [],
} as ValidatorSummaryResponse,
'/v2/validator/beacon/queue': {
churn_limit: 4,
activation_public_keys: [mockPublicKeys[0], mockPublicKeys[1]],
activation_validator_indices: [0, 1],
exit_public_keys: [mockPublicKeys[2]],
exit_validator_indices: [2],
} as ValidatorQueue,
'/v2/validator/beacon/validators': {
validator_list: mockPublicKeys.map((key, idx) => {
return {
Expand Down
50 changes: 0 additions & 50 deletions src/app/modules/core/services/chain.service.spec.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/app/modules/core/services/chain.service.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/app/modules/core/services/validator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { VersionResponse } from 'src/app/proto/validator/accounts/v2/web_api';
import { ListFeeRecipientResponse, SetFeeRecipientRequest } from 'src/app/proto/validator/accounts/v2/web_api_keymanager-api';
import { base64ToHex } from '../utils/hex-util';
import { EnvironmenterService } from './environmenter.service';
import { WalletService } from './wallet.service';

Expand Down Expand Up @@ -63,13 +62,13 @@ export class ValidatorService {
}

getFeeRecipient(publicKey:string): Observable< ListFeeRecipientResponse>{
return this.http.get<ListFeeRecipientResponse>(`${this.keymanagerUrl}/validator/${base64ToHex(publicKey)}/feerecipient`).pipe(
return this.http.get<ListFeeRecipientResponse>(`${this.keymanagerUrl}/validator/${publicKey}/feerecipient`).pipe(
catchError((err: HttpErrorResponse) => {
let UNSET_RECIPIENT = "set by beacon node";
// just let the user know it's set by the beacon node if it's not set
return of({
data: {
pubkey: base64ToHex(publicKey),
pubkey: publicKey,
ethaddress: UNSET_RECIPIENT,
}
});
Expand Down
11 changes: 0 additions & 11 deletions src/app/modules/core/utils/hex-util.spec.ts

This file was deleted.

28 changes: 0 additions & 28 deletions src/app/modules/core/utils/hex-util.ts

This file was deleted.

26 changes: 12 additions & 14 deletions src/app/modules/core/utils/ndjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import { from, Observable, Observer, Subject } from 'rxjs';
import { from, Observable, Observer} from 'rxjs';
import { concatMap, filter, map, scan } from 'rxjs/operators';

/*
Expand All @@ -37,15 +37,13 @@ export function stream(url: string): Observable<string> {
const textStream = extractStream(xhr);
const jsonStream = collate(textStream).pipe(
concatMap((lineArray: string) => from(lineArray)),
map((x: string, _) => JSON.parse(x)),
map((x: string) => JSON.parse(x)),
);

if (options.beforeOpen) {
options.beforeOpen(xhr);
}
options.beforeOpen?.(xhr);

xhr.open(options.method ? options.method : 'GET', url);
xhr.send(options.postData ? options.postData : null);
xhr.open(options.method ?? 'GET', url);
xhr.send(options.postData ?? null);

return jsonStream;
}
Expand Down Expand Up @@ -85,16 +83,18 @@ function collate(chunkStream: Observable<string>): Observable<string> {
* flag "endWithNewline: true" which adds a trailing newline if one did not
* exist in the source.
*/
function extractStream(xhr: XMLHttpRequest): Observable<string> {
const options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
interface ExtractStreamOptions {
endWithNewline?: boolean;
}
function extractStream(xhr: XMLHttpRequest, options: ExtractStreamOptions = {}): Observable<string> {
return new Observable((observer: Observer<string>) => {
let charactersSeen = 0;
const notified = () => {
if (xhr.readyState >= 3 && xhr.responseText.length > charactersSeen) {
if (xhr.readyState >= XMLHttpRequest.LOADING && xhr.responseText.length > charactersSeen) {
observer.next(xhr.responseText.substring(charactersSeen));
charactersSeen = xhr.responseText.length;
}
if (xhr.readyState === 4) {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (options.endWithNewline && xhr.responseText[xhr.responseText.length - 1] !== '\n') {
observer.next('\n');
}
Expand All @@ -103,8 +103,6 @@ function extractStream(xhr: XMLHttpRequest): Observable<string> {
};
xhr.onreadystatechange = notified;
xhr.onprogress = notified;
xhr.onerror = event => {
observer.error(event);
};
xhr.onerror = (event: ProgressEvent) => observer.error(event);
});
}
Loading

0 comments on commit 43662e3

Please sign in to comment.