-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from bobanetwork/wsdt/type-verifier-service
Type verifier service
- Loading branch information
Showing
3 changed files
with
83 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |