-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathaccounts.test.ts
More file actions
93 lines (84 loc) · 2.58 KB
/
Copy pathaccounts.test.ts
File metadata and controls
93 lines (84 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { AdapterRequest } from '@chainlink/ea-bootstrap'
import { server as startServer } from '../../src'
import '@solana/web3.js'
import { mockAccountsInfo } from './fixtures'
import { setupExternalAdapterTest } from '@chainlink/ea-test-helpers'
import type { SuiteContext } from '@chainlink/ea-test-helpers'
import { SuperTest, Test } from 'supertest'
jest.mock('@solana/web3.js', () => ({
...jest.requireActual('@solana/web3.js'),
Connection: class {
getMultipleAccountsInfo() {
return mockAccountsInfo
}
},
}))
describe('accounts', () => {
const context: SuiteContext = {
req: null,
server: startServer,
}
const envVariables = {
RPC_URL: 'https://api.devnet.solana.com',
}
setupExternalAdapterTest(envVariables, context)
describe('successful calls', () => {
const jobID = '1'
it('returns success when fetching the account information', async () => {
const data: AdapterRequest = {
id: jobID,
data: {
addresses: [
'EMtjYGwPnXdtqK5SGL8CWGv4wgdBQN79UPoy53x9bBTJ',
'BSGfVnE6q6KemspkugEERU8x7WbQwSKwvHT1cZZ4ACVN',
'3FMBoeddUhtqxepzkrxPrMUV3CL4bZM5QmMoLJfEpirz',
],
},
}
const response = await (context.req as SuperTest<Test>)
.post('/')
.send(data)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
expect(response.body).toMatchSnapshot()
})
})
describe('errored calls', () => {
const jobID = '1'
it('returns an error when there are no addresses passed to the EA', async () => {
const data: AdapterRequest = {
id: jobID,
data: {
addresses: [],
},
}
const response = await (context.req as SuperTest<Test>)
.post('/')
.send(data)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
expect(response.body).toMatchSnapshot()
})
it('returns an error when there is no rpc url is set', async () => {
delete process.env.RPC_URL
const data: AdapterRequest = {
id: jobID,
data: {
addresses: ['EMtjYGwPnXdtqK5SGL8CWGv4wgdBQN79UPoy53x9bBTJ'],
},
}
const response = await (context.req as SuperTest<Test>)
.post('/')
.send(data)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(500)
expect(response.body).toMatchSnapshot()
})
})
})