diff --git a/packages/neo-one-node-blockchain/package.json b/packages/neo-one-node-blockchain/package.json index 1f54a93d5e..051756ad3a 100644 --- a/packages/neo-one-node-blockchain/package.json +++ b/packages/neo-one-node-blockchain/package.json @@ -33,9 +33,11 @@ "@types/leveldown": "^4.0.0", "@types/lodash": "^4.14.138", "@types/lru-cache": "^5.1.0", + "@types/memdown": "^3.0.0", "leveldown": "^5.1.1", "levelup": "4.1.0", "gulp": "~4.0.2", + "memdown": "^5.0.0", "tslib": "^1.10.0" } } diff --git a/packages/neo-one-node-blockchain/src/HeaderIndexCache.ts b/packages/neo-one-node-blockchain/src/HeaderIndexCache.ts index 67635bd4e6..aab6e69817 100644 --- a/packages/neo-one-node-blockchain/src/HeaderIndexCache.ts +++ b/packages/neo-one-node-blockchain/src/HeaderIndexCache.ts @@ -59,7 +59,7 @@ export class HeaderIndexCache { return this.getHeaderHashIndexFromCurrent(hashListHashIndex); } - const hashListIndex = (index - hashListHashIndex) / 2000; + const hashListIndex = index - hashListHashIndex; const headerHashList = await this.getHeaderHashList(hashListIndex); if (headerHashList === undefined) { return undefined; diff --git a/packages/neo-one-node-blockchain/src/__tests__/headerIndexCache.test.ts b/packages/neo-one-node-blockchain/src/__tests__/headerIndexCache.test.ts new file mode 100644 index 0000000000..20535bdfdb --- /dev/null +++ b/packages/neo-one-node-blockchain/src/__tests__/headerIndexCache.test.ts @@ -0,0 +1,37 @@ +// tslint:disable: readonly-keyword no-object-mutation +import { crypto } from '@neo-one/client-common'; +import { Storage } from '@neo-one/node-core'; +import { storage as levelStorage } from '@neo-one/node-storage-levelup'; +import { randomBytes } from 'crypto'; +import LevelUp from 'levelup'; +import _ from 'lodash'; +import MemDown from 'memdown'; +import { HeaderIndexCache } from '../HeaderIndexCache'; + +const getUInt = () => crypto.hash256(randomBytes(32)); +const getUInts = (n: number) => _.range(n).map(getUInt); + +describe('headerIndexCache tests', () => { + const context = { messageMagic: 1951352142, validatorsCount: 7 }; + + let storage: Storage; + let db: any; + beforeEach(() => { + db = new LevelUp(new MemDown()); + storage = levelStorage({ db, context }); + }); + + test('headerCacheIndex push 2500 hashes -- retrieves something from different headerHashLists', async () => { + const cache = new HeaderIndexCache({ storage, initCurrentHeaderHashes: [], initStorageCount: 0 }); + const testHashes = getUInts(2500); + // tslint:disable-next-line: no-loop-statement + for (const hash of testHashes) { + await cache.push(hash); + } + + const [listZeroHash, listTwoThousandHash] = await Promise.all([cache.get(11), cache.get(2005)]); + + expect(listZeroHash.equals(testHashes[11])).toEqual(true); + expect(listTwoThousandHash.equals(testHashes[2005])).toEqual(true); + }); +}); diff --git a/packages/neo-one-website/docs/4-contributing/1-codebase-overview.md b/packages/neo-one-website/docs/4-contributing/1-codebase-overview.md index 313678f993..02f6174339 100644 --- a/packages/neo-one-website/docs/4-contributing/1-codebase-overview.md +++ b/packages/neo-one-website/docs/4-contributing/1-codebase-overview.md @@ -158,7 +158,7 @@ Creates the environment for compiling smart contracts, which is then used in the ### neo-one-smart-contract-lib -Defines NEP17 tokens and ICOs. +Defines NEP5 tokens and ICOs. ### neo-one-smart-contract-test