Skip to content

Commit

Permalink
feat: Add support to isProduction flag for private networks (#535)
Browse files Browse the repository at this point in the history
* add support to isProduction flag for private networks

* add example
  • Loading branch information
MCarlomagno authored Sep 2, 2024
1 parent 40c06ed commit 5d79306
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/create-private-network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function main() {
configuration: {
symbol: 'ETH',
},
isProduction: false, // (optional) indicates if it's a testnet
});

console.log(network);
Expand Down
5 changes: 3 additions & 2 deletions packages/network/src/api/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiosInstance } from 'axios';
import { NetworkClient } from '.';
import { TenantNetworkCreateRequest } from '../models/networks';
import { PrivateNetworkCreateRequest, TenantNetworkCreateRequest } from '../models/networks';

jest.mock('@openzeppelin/defender-sdk-base-client');
jest.mock('aws-sdk');
Expand All @@ -24,14 +24,15 @@ const createForkPayload: TenantNetworkCreateRequest = {
networkType: 'fork',
};

const createPrivatePayload: TenantNetworkCreateRequest = {
const createPrivatePayload: PrivateNetworkCreateRequest = {
name: 'mock-fork',
rpcUrl: 'https://localhost:8585',
blockExplorerUrl: 'https://localhost:8585/explorer',
configuration: {
symbol: 'ETH',
},
networkType: 'private',
isProduction: true,
};

describe('NetworkClient', () => {
Expand Down
15 changes: 9 additions & 6 deletions packages/network/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
TenantNetworkResponse,
TenantNetworkUpdateRequest,
ListNetworkRequestOptions,
PrivateNetworkCreateRequest,
PrivateNetworkResponse,
PrivateNetworkUpdateRequest,
} from '../models/networks';

const PATH = '/networks';
Expand Down Expand Up @@ -64,15 +67,15 @@ export class NetworkClient extends BaseApiClient {
});
}

public async listPrivateNetworks(): Promise<TenantNetworkResponse[]> {
public async listPrivateNetworks(): Promise<PrivateNetworkResponse[]> {
return this.apiCall(async (api) => {
return await api.get(`${PATH}/private`);
});
}

public async createPrivateNetwork(
network: Omit<TenantNetworkCreateRequest, 'networkType'>,
): Promise<TenantNetworkResponse> {
network: Omit<PrivateNetworkCreateRequest, 'networkType'>,
): Promise<PrivateNetworkResponse> {
return this.apiCall(async (api) => {
return await api.post(`${PATH}/private`, { ...network, networkType: 'private' });
});
Expand All @@ -84,16 +87,16 @@ export class NetworkClient extends BaseApiClient {
});
}

public async getPrivateNetwork(id: string): Promise<TenantNetworkResponse> {
public async getPrivateNetwork(id: string): Promise<PrivateNetworkResponse> {
return this.apiCall(async (api) => {
return await api.get(`${PATH}/private/${id}`);
});
}

public async updatePrivateNetwork(
id: string,
network: Omit<TenantNetworkUpdateRequest, 'tenantNetworkId'>,
): Promise<TenantNetworkResponse> {
network: Omit<PrivateNetworkUpdateRequest, 'tenantNetworkId'>,
): Promise<PrivateNetworkResponse> {
return this.apiCall(async (api) => {
return await api.put(`${PATH}/private/${id}`, { ...network, tenantNetworkId: id });
});
Expand Down
12 changes: 12 additions & 0 deletions packages/network/src/models/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface TenantNetworkCreateRequest {
stackResourceId?: string;
}

export interface PrivateNetworkCreateRequest extends TenantNetworkCreateRequest {
isProduction?: boolean;
}

export interface TenantNetworkUpdateRequest {
tenantNetworkId: string;
apiKey?: string;
Expand All @@ -27,6 +31,10 @@ export interface TenantNetworkUpdateRequest {
stackResourceId?: string;
}

export interface PrivateNetworkUpdateRequest extends TenantNetworkUpdateRequest {
isProduction?: boolean;
}

export interface TenantNetworkResponse {
tenantNetworkId: string;
name: TenantNetwork;
Expand All @@ -42,6 +50,10 @@ export interface TenantNetworkResponse {
createdBy: string;
}

export interface PrivateNetworkResponse extends TenantNetworkResponse {
isProduction?: boolean;
}

export interface TenantNetworkConfiguration {
symbol: string;
eips?: TenantNetworkEIPConfiguration;
Expand Down

0 comments on commit 5d79306

Please sign in to comment.