Skip to content

Commit

Permalink
Cleanup more uses of request() in tests
Browse files Browse the repository at this point in the history
This is a follow up to 98fcad2 and
removes a few more uses of `request()` in tests.
  • Loading branch information
andiflabs committed Apr 8, 2024
1 parent 4b6e17b commit c0d0777
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 60 deletions.
18 changes: 7 additions & 11 deletions ironfish/src/rpc/routes/config/getConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ describe('Route config/getConfig', () => {
})

it('returns value of the requested ConfigOptions', async () => {
const response = await routeTest.client
.request('config/getConfig', {
name: 'minerBatchSize',
})
.waitForEnd()
const response = await routeTest.client.config.getConfig({
name: 'minerBatchSize',
})
expect(response.status).toBe(200)
expect(response.content).toEqual({
minerBatchSize: routeTest.node.config.get('minerBatchSize'),
Expand All @@ -24,12 +22,10 @@ describe('Route config/getConfig', () => {

it('returns nothing when no datadir exists', async () => {
const target = {}
const response = await routeTest.client
.request('config/getConfig', {
name: 'minerBatchSize',
user: true,
})
.waitForEnd()
const response = await routeTest.client.config.getConfig({
name: 'minerBatchSize',
user: true,
})
expect(response.status).toBe(200)
expect(response.content).toEqual(target)
})
Expand Down
69 changes: 26 additions & 43 deletions ironfish/src/rpc/routes/config/setConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,61 @@ describe('Route config/setConfig', () => {

it('should error if the config name does not exist', async () => {
await expect(
routeTest.client
.request('config/setConfig', { name: 'asdf', value: 'asdf' })
.waitForEnd(),
routeTest.client.config.setConfig({ name: 'asdf', value: 'asdf' }),
).rejects.toThrow()
})

describe('Convert string to array', () => {
it('does not special-case brackets', async () => {
const response = await routeTest.client
.request('config/setConfig', {
name: 'bootstrapNodes',
value: '[]',
})
.waitForEnd()
const content = await response.content
const response = await routeTest.client.config.setConfig({
name: 'bootstrapNodes',
value: '[]',
})
expect(response.status).toBe(200)
expect(content).toBeUndefined()
expect(response.content).toBeUndefined()
expect(routeTest.sdk.config.get('bootstrapNodes')).toEqual(['[]'])
})

it('should convert strings to arrays', async () => {
const response = await routeTest.client
.request('config/setConfig', {
name: 'bootstrapNodes',
value: 'test.node.com,test2.node.com',
})
.waitForEnd()
const content = await response.content
const response = await routeTest.client.config.setConfig({
name: 'bootstrapNodes',
value: 'test.node.com,test2.node.com',
})
expect(response.status).toBe(200)
expect(content).toBeUndefined()
expect(response.content).toBeUndefined()
expect(routeTest.sdk.config.get('bootstrapNodes')).toEqual([
'test.node.com',
'test2.node.com',
])
})

it('handles single values', async () => {
const response = await routeTest.client
.request('config/setConfig', {
name: 'bootstrapNodes',
value: 'test.node.com',
})
.waitForEnd()
const content = await response.content
const response = await routeTest.client.config.setConfig({
name: 'bootstrapNodes',
value: 'test.node.com',
})
expect(response.status).toBe(200)
expect(content).toBeUndefined()
expect(response.content).toBeUndefined()
expect(routeTest.sdk.config.get('bootstrapNodes')).toEqual(['test.node.com'])
})

it('should strip leading and trailing whitespace', async () => {
const response = await routeTest.client
.request('config/setConfig', {
name: 'bootstrapNodes',
value: ' node1 , node2 ',
})
.waitForEnd()
const content = await response.content
const response = await routeTest.client.config.setConfig({
name: 'bootstrapNodes',
value: ' node1 , node2 ',
})
expect(response.status).toBe(200)
expect(content).toBeUndefined()
expect(response.content).toBeUndefined()
expect(routeTest.sdk.config.get('bootstrapNodes')).toEqual(['node1', 'node2'])
})

it('should leave quotes', async () => {
const response = await routeTest.client
.request('config/setConfig', {
name: 'bootstrapNodes',
value: ' \' node1 \' , " node2 " ',
})
.waitForEnd()
const content = await response.content
const response = await routeTest.client.config.setConfig({
name: 'bootstrapNodes',
value: ' \' node1 \' , " node2 " ',
})
expect(response.status).toBe(200)
expect(content).toBeUndefined()
expect(response.content).toBeUndefined()
expect(routeTest.sdk.config.get('bootstrapNodes')).toEqual(["' node1 '", '" node2 "'])
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ describe('Route multisig/createTrustedDealerKeyPackage', () => {
identity: multisig.ParticipantSecret.random().toIdentity().serialize().toString('hex'),
}))
const request = { minSigners: 2, participants }
const response = await routeTest.client
.request('wallet/multisig/createTrustedDealerKeyPackage', request)
.waitForEnd()
const response = await routeTest.client.wallet.multisig.createTrustedDealerKeyPackage(
request,
)

expect(response.content).toMatchObject({
publicAddress: expect.any(String),
Expand Down
4 changes: 1 addition & 3 deletions ironfish/src/rpc/routes/worker/getStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ describe('Route worker/getStatus', () => {

it('should get status', async () => {
const request: GetWorkersStatusRequest = { stream: false }
const response = await routeTest.client
.request('worker/getStatus', { request })
.waitForEnd()
const response = await routeTest.client.worker.getWorkersStatus(request)

expect(response.status).toBe(200)

Expand Down

0 comments on commit c0d0777

Please sign in to comment.