Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No testdouble #681

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 0 additions & 65 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/portalnetwork/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"c8": "^7.12.0",
"eslint": "^8.6.0",
"js-yaml": "^4.1.0",
"testdouble": "^3.16.3",
"tslib": "^2.3.1",
"typedoc": "^0.24.0",
"typedoc-plugin-markdown": "^3.11.3",
Expand Down
8 changes: 6 additions & 2 deletions packages/portalnetwork/src/networks/networkDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ export class NetworkDB {
const _db = this.db as MemoryLevel<string, string>
let size = 0
for await (const [key, value] of _db.iterator()) {
size += hexToBytes('0x' + padToEven(key.slice(2))).length
size += hexToBytes(value).length
try {
size += hexToBytes('0x' + padToEven(key.slice(2))).length
size += hexToBytes(value).length
} catch {
// ignore
}
}
return size
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { readFileSync } from 'fs'
import { createRequire } from 'module'
import { EntryStatus } from '@chainsafe/discv5'
import { ENR } from '@chainsafe/enr'
import { Block, type BlockBytes, BlockHeader } from '@ethereumjs/block'
import * as RLP from '@ethereumjs/rlp'
import { bytesToHex, concatBytes, hexToBytes } from '@ethereumjs/util'
import * as td from 'testdouble'
import { bytesToHex, hexToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import {
BlockHeaderWithProof,
ContentKeyType,
HistoricalRootsBlockProof,
HistoryNetworkContentType,
NetworkId,
Expand All @@ -28,58 +24,6 @@ import type { HistoryNetwork } from '../../../src/index.js'
const require = createRequire(import.meta.url)
const testBlocks = require('../../testData/testBlocksForHistory.json')

describe('history Network FINDCONTENT/FOUNDCONTENT message handlers', async () => {
const block1Rlp = testBlocks.block1.blockRlp
const block1Hash = testBlocks.block1.blockHash
const node = await PortalNetwork.create({
bindAddress: '192.168.0.1',
transport: TransportLayer.WEB,
supportedNetworks: [{ networkId: NetworkId.HistoryNetwork }],
})

const network = node.networks.get(NetworkId.HistoryNetwork) as HistoryNetwork
const remoteEnr =
'enr:-IS4QG_M1lzTXzQQhUcAViqK-WQKtBgES3IEdQIBbH6tlx3Zb-jCFfS1p_c8Xq0Iie_xT9cHluSyZl0TNCWGlUlRyWcFgmlkgnY0gmlwhKRc9EGJc2VjcDI1NmsxoQMo1NBoJfVY367ZHKA-UBgOE--U7sffGf5NBsNSVG629oN1ZHCCF6Q'
const decodedEnr = ENR.decodeTxt(remoteEnr)
network.routingTable.insertOrUpdate(decodedEnr, EntryStatus.Connected)
const key = getContentKey(
HistoryNetworkContentType.BlockBody,
hexToBytes('0x88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6'),
)

const findContentResponse = Uint8Array.from([5, 1, 97, 98, 99])
network.store = td.func<any>()
network.validateHeader = td.func<any>()
// network.sendFindContent = td.func<any>()
network.sendMessage = td.func<any>()

td.when(
network.sendMessage(td.matchers.anything(), td.matchers.anything(), td.matchers.anything()),
).thenResolve(findContentResponse)
const res = await network.sendFindContent(decodedEnr.nodeId, key)
it('should send a FINDCONTENT message', () => {
assert.exists(res!['content'])
assert.deepEqual(
res!['content'],
Uint8Array.from([97, 98, 99]),
'got correct response for content abc',
)
})

// TODO: Write good `handleFindContent` tests

td.reset()
const headerKey = getContentKey(HistoryNetworkContentType.BlockHeader, hexToBytes(block1Hash))
await network.store(headerKey, hexToBytes(block1Rlp))
const contentKey = ContentKeyType.serialize(
concatBytes(Uint8Array.from([HistoryNetworkContentType.BlockHeader]), hexToBytes(block1Hash)),
)
const header = await network.sendFindContent('0xabcd', contentKey)
it('should send a FINDCONTENT message for a block header', () => {
assert.equal(header, undefined, 'received undefined for unknown peer')
})
})

describe('store -- Headers and Epoch Accumulators', async () => {
it('Should store and retrieve block header from DB', async () => {
// const epochKey = '0x035ec1ffb8c3b146f42606c74ced973dc16ec5a107c0345858c343fc94780b4218'
Expand Down
Loading
Loading