Skip to content

Commit

Permalink
Fix logic bug/test
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Sep 7, 2023
1 parent 53d10d7 commit 84d500b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/portalnetwork/src/subprotocols/beacon/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class BeaconLightClientNetwork extends BaseProtocol {
key = LightClientFinalityUpdateKey.deserialize(contentKey.slice(1))
if (
this.lightClient !== undefined &&
key.finalizedSlot !== BigInt(this.lightClient.getFinalized().beacon.slot)
key.finalizedSlot === BigInt(this.lightClient.getFinalized().beacon.slot)
) {
// We only store the most recent finality update so only retrieve the optimistic update if the slot
// in the key matches the current finalized slot known to our light client
Expand Down
34 changes: 31 additions & 3 deletions packages/portalnetwork/test/subprotocols/beacon/beacon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { PortalNetwork, ProtocolId, TransportLayer } from '../../../src/index.js
import type { BeaconLightClientNetwork } from '../../../src/subprotocols/beacon/index.js'
import { createBeaconConfig, defaultChainConfig } from '@lodestar/config'
import { genesisData } from '@lodestar/config/networks'
import { hexToBytes } from '@ethereumjs/util'
import { concatBytes, hexToBytes } from '@ethereumjs/util'

const specTestVectors = require('./specTestVectors.json')
const config = createBeaconConfig(
Expand Down Expand Up @@ -177,8 +177,22 @@ describe('API tests', async () => {
finalityUpdate.content_key,
hexToBytes(finalityUpdate.content_value),
)

protocol.lightClient = {
//@ts-ignore
getFinalized: () => {
return {
beacon: {
slot: 6718463,
},
}
},
}
const retrievedFinalityUpdate = await protocol.findContentLocally(
hexToBytes(finalityUpdate.content_key),
concatBytes(
new Uint8Array([BeaconLightClientNetworkContentType.LightClientFinalityUpdate]),
LightClientFinalityUpdateKey.serialize({ finalizedSlot: 6718463n }),
),
)

assert.equal(
Expand All @@ -198,8 +212,22 @@ describe('API tests', async () => {
optimisticUpdate.content_key,
hexToBytes(optimisticUpdate.content_value),
)

protocol.lightClient = {
//@ts-ignore
getHead: () => {
return {
beacon: {
slot: 6718463,
},
}
},
}
const retrievedOptimisticUpdate = await protocol.findContentLocally(
hexToBytes(optimisticUpdate.content_key),
concatBytes(
new Uint8Array([BeaconLightClientNetworkContentType.LightClientOptimisticUpdate]),
LightClientOptimisticUpdateKey.serialize({ optimisticSlot: 6718463n }),
),
)

assert.equal(
Expand Down

0 comments on commit 84d500b

Please sign in to comment.