Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding chain labels + update chain to SDk #181

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ The Orchestrate library provides convenient access to the Orchestrate API from a

| SDK versions | Orchestrate versions |
| ------------------- | ----------------------------- |
| master/HEAD | Orchestrate v21.1.0 or higher |
| master/HEAD | Orchestrate v21.1.5 or higher |
| SDK v4.1.x | Orchestrate v21.1.5 or higher |
| SDK v4.0.x | Orchestrate v21.1.0 or higher |
| SDK v3.1.1 | Orchestrate v2.4 or higher |
| SDK v3.1.x | Orchestrate v2.3 or higher |
Expand Down
3 changes: 3 additions & 0 deletions examples/register-chain/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export const start = async () => {
urls: ['http://validator2:8545'],
listener: {
fromBlock: 'latest'
},
labels: {
my_label: 'testing labels'
}
})

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pegasys-orchestrate",
"version": "4.0.1",
"version": "4.1.0",
"description": "The PegaSys Orchestrate library provides convenient access to the Codefi Orchestrate API from applications written in server-side JavaScript",
"main": "lib/index.js",
"files": [
Expand Down
76 changes: 74 additions & 2 deletions src/client/OrchestrateClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const mockChain: types.IChain = {
tenantID: 'tenantID',
urls: ['endpoint:8545'],
uuid: 'uuid',
labels: {
label: 'value'
},
createdAt: new Date(),
updatedAt: new Date()
}
Expand Down Expand Up @@ -392,7 +395,10 @@ describe('OrchestrateClient', () => {
it('should register a new chain successfully', async () => {
const chain: types.IRegisterChainRequest = {
name: 'chainName',
urls: ['localhost:8545']
urls: ['localhost:8545'],
labels: {
label: 'value'
}
}

try {
Expand All @@ -410,7 +416,10 @@ describe('OrchestrateClient', () => {
it('should register a new chain with jwt successfully', async () => {
const chain: types.IRegisterChainRequest = {
name: 'chainName',
urls: ['localhost:8545']
urls: ['localhost:8545'],
labels: {
label: 'value'
}
}

mockHTTPClient.post.mockResolvedValueOnce(mockChain)
Expand Down Expand Up @@ -466,6 +475,69 @@ describe('OrchestrateClient', () => {
})
})

describe('updateChain', () => {
it('should update a new chain successfully', async () => {
const chain: types.IUpdateChainRequest = {
name: 'chainName2',
labels: {
label2: 'value2'
}
}

mockHTTPClient.patch.mockResolvedValueOnce(mockChain)

try {
const res = await client.updateChain(mockChain.uuid, chain)
expect(res).toEqual(mockChain)
} catch (e) {
fail(e)
}

expect(mockHTTPClient.patch).toHaveBeenCalledWith(`/chains/${mockChain.uuid}`, chain, undefined)
})

it('should update a new chain with jwt successfully', async () => {
const chain: types.IUpdateChainRequest = {
name: 'chainName3',
labels: {
label3: 'value3'
}
}

mockHTTPClient.patch.mockResolvedValueOnce(mockChain)

try {
const res = await client.updateChain(mockChain.uuid, chain, authToken)
expect(res).toEqual(mockChain)
} catch (e) {
fail(e)
}

expect(mockHTTPClient.patch).toHaveBeenCalledWith(`/chains/${mockChain.uuid}`, chain, authToken)
})

it('should to register a new chain and return and error', async () => {
const chain: types.IUpdateChainRequest = {
name: 'chainName'
}

const err = new Error('fail message')
try {
mockHTTPClient.patch.mockRejectedValueOnce({
data: err,
status: 500,
headers: {}
})
await client.updateChain(mockChain.uuid, chain)
fail(`expected to fail`)
} catch (e) {
expect(e.data).toEqual(err)
}

expect(mockHTTPClient.patch).toHaveBeenCalledWith(`/chains/${mockChain.uuid}`, chain, undefined)
})
})

describe('searchFaucets', () => {
it('should fetch faucets successfully', async () => {
const req: IHttpPOSTRequest = {
Expand Down
18 changes: 18 additions & 0 deletions src/client/OrchestrateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ export class OrchestrateClient {
}
}

/**
* Update a registered chain
* @param chainUUID uuid of registered chain
* @param chainRequest register chain request data
* @param authToken Bearer token. Required when multi-tenancy is enabled
*/
public async updateChain(
chainUUID: string,
chainRequest: types.IUpdateChainRequest,
authToken?: string
): Promise<types.IChain> {
try {
return await this.client.patch(`/chains/${chainUUID}`, chainRequest, authToken)
} catch (e) {
throw e
}
}

/**
* Fetch list of registered faucets
* @param authToken Bearer token. Required when multi-tenancy is enabled
Expand Down
17 changes: 17 additions & 0 deletions src/client/types/IChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ export interface IRegisterChainRequest {
url: string
type: string
}
labels?: object
}

export interface IUpdateChainRequest {
name: string
listener?: {
depth?: number
currentBlock?: string
backoffDuration?: string
externalTxEnabled?: boolean
}
privateTxManager?: {
url: string
type: string
}
labels?: object
}

export interface IChain {
Expand All @@ -24,6 +40,7 @@ export interface IChain {
listenerBackOffDuration?: string
ListenerExternalTxEnabled?: boolean
privateTxManagers?: IPrivateTxManager[]
labels?: object
createdAt: Date
updatedAt: Date
}
Expand Down