Skip to content

Commit

Permalink
test: add client controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
ALPAC-4 committed Dec 16, 2024
1 parent 4178274 commit 677fa94
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 53 additions & 0 deletions src/db/controller/client.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ClientTable } from 'src/types'
import { DB } from '..'
import { insert } from '../utils'
import { mockServers } from 'src/test/testSetup'
import { ClientController } from './client'

describe('client controller', () => {
mockServers // to set set config file
test('client controller e2e', async () => {
const currentTimestamp = Math.floor(new Date().valueOf() / 1000)
// add clients for test
const testClients: ClientTable[] = [
{
chain_id: 'chain-1',
client_id: 'client-1',
counterparty_chain_id: 'chain-2',
revision_height: 1,
trusting_period: 3000,
last_update_time: currentTimestamp - 2500, // need update
},

{
chain_id: 'chain-1',
client_id: 'client-2',
counterparty_chain_id: 'chain-2',
revision_height: 1,
trusting_period: 3000,
last_update_time: currentTimestamp - 500, // do not need to update
},

{
chain_id: 'chain-1',
client_id: 'client-3',
counterparty_chain_id: 'chain-2',
revision_height: 1,
trusting_period: 3000,
last_update_time: currentTimestamp - 3500, // expired
},
]

testClients.map((client) => {
insert(DB, ClientController.tableName, client)
})

// get clients to update
const clientsToUpdate = ClientController.getClientsToUpdate('chain-1', [
'chain-2',
])

// check clients to update
expect(clientsToUpdate.map((v) => v.client_id)).toEqual(['client-1'])
})
})
2 changes: 1 addition & 1 deletion src/lib/eventParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('event parser', () => {
timeoutTimestamp: 1730467768,
timeoutHeightRaw: '0-0',
timeoutTimestampRaw: '1730467768229000000',
ordering: undefined,
ordering: '',
ack: 'eyJyZXN1bHQiOiJBUT09In0=',
}

Expand Down

0 comments on commit 677fa94

Please sign in to comment.