Skip to content

Commit

Permalink
Merge pull request #178 from bobanetwork/wsdt/type-verifier-service
Browse files Browse the repository at this point in the history
Type verifier service
  • Loading branch information
wsdt authored Nov 15, 2023
2 parents c14290f + 4564f38 commit 76d56b8
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 37 deletions.
37 changes: 0 additions & 37 deletions src/services/verifier.service.js

This file was deleted.

48 changes: 48 additions & 0 deletions src/services/verifier.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import verifierService from './verifier.service'
import networkService from './networkService'

jest.mock('./networkService', () => {
return {
networkConfig: {
L1: {
chainId: 1,
},
},
}
})

describe('VerifierService', () => {
const vsInstance = verifierService
let spyLog: any
afterEach(() => {
jest.restoreAllMocks()
})
afterAll(() => {
jest.restoreAllMocks()
})

beforeEach(() => {
spyLog = jest.spyOn(console, 'log').mockImplementation(() => {
return
})
})

test('fetch verifier status when watcher instance undefined', async () => {
// test
const status = await vsInstance.getVerifierStatus()
expect(status).toBeFalsy()
})

test('fetch verifier status when watcher instance defined', async () => {
// prep
networkService.networkConfig.VERIFIER_WATCHER_URL =
'https://api-verifier.mainnet.boba.network/'

// test
const status = await vsInstance.getVerifierStatus()
expect(status?.isOK).toBeTruthy()
expect(status?.matchedBlock).toBeGreaterThan(0)
expect(status?.matchedRoot).toBeDefined()
expect(status?.timestamp).toBeGreaterThan(0)
})
})
35 changes: 35 additions & 0 deletions src/services/verifier.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import verifierWatcherAxiosInstance from 'api/verifierWatcherAxios'
import networkService from './networkService'

class VerifierService {
/**
* @getVerifierStatus
*/

async getVerifierStatus() {
const watcherInstance = verifierWatcherAxiosInstance(
networkService.networkConfig
)

if (!watcherInstance) {
return false
}

const response = await watcherInstance.post('/', {
jsonrpc: '2.0',
method: 'status',
id: 1,
})

if (response.status === 200) {
return response.data.result
} else {
console.warn('VS: Bad verifier response')
return false
}
}
}

const verifierService = new VerifierService()

export default verifierService

0 comments on commit 76d56b8

Please sign in to comment.