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

Trie: replace static methods #3515

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
trie: update test
  • Loading branch information
ScottyPoi committed Jul 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 81a3ab4b83eb4eb629f351c3a84759b497fe3cd5
36 changes: 18 additions & 18 deletions packages/trie/test/trie/trie.spec.ts
Original file line number Diff line number Diff line change
@@ -43,18 +43,18 @@ for (const { constructor, defaults, title } of [
}

describe(`${title} (Persistence)`, () => {
it('creates an instance via the static constructor `create` function and defaults to `false` with a database', async () => {
it('creates an instance via createTrie and defaults to `false` with a database', async () => {
// TODO: check this test
assert.isUndefined(
((await constructor.create({ ...defaults, db: new MapDB() })) as any)._useRootPersistence
((await createTrie({ ...defaults, db: new MapDB() })) as any)._useRootPersistence
)
})

it('creates an instance via the static constructor `create` function and respects the `useRootPersistence` option with a database', async () => {
it('creates an instance via createTrie and respects the `useRootPersistence` option with a database', async () => {
// TODO: check this test
assert.isUndefined(
(
(await constructor.create({
(await createTrie({
...defaults,
db: new MapDB(),
useRootPersistence: false,
@@ -63,11 +63,11 @@ for (const { constructor, defaults, title } of [
)
})

it('creates an instance via the static constructor `create` function and respects the `useRootPersistence` option with a database', async () => {
it('creates an instance via createTrie and respects the `useRootPersistence` option with a database', async () => {
// TODO: check this test
assert.isUndefined(
(
(await constructor.create({
(await createTrie({
...defaults,
db: new MapDB(),
useRootPersistence: false,
@@ -76,15 +76,15 @@ for (const { constructor, defaults, title } of [
)
})

it('creates an instance via the static constructor `create` function and defaults to `false` without a database', async () => {
it('creates an instance via createTrie and defaults to `false` without a database', async () => {
// TODO: check this test
assert.isUndefined(
((await constructor.create({ ...defaults, db: new MapDB() })) as any)._useRootPersistence
((await createTrie({ ...defaults, db: new MapDB() })) as any)._useRootPersistence
)
})

it('persist the root if the `useRootPersistence` option is `true`', async () => {
const trie = await constructor.create({
const trie = await createTrie({
...defaults,
db: new MapDB(),
useRootPersistence: true,
@@ -98,7 +98,7 @@ for (const { constructor, defaults, title } of [
})

it('persist the root if the `root` option is given', async () => {
const trie = await constructor.create({
const trie = await createTrie({
...defaults,
db: new MapDB(),
root: KECCAK256_RLP,
@@ -113,7 +113,7 @@ for (const { constructor, defaults, title } of [
})

it('does not persist the root if the `useRootPersistence` option is `false`', async () => {
const trie = await constructor.create({
const trie = await createTrie({
...defaults,
db: new MapDB(),
useRootPersistence: false,
@@ -127,7 +127,7 @@ for (const { constructor, defaults, title } of [
})

it('persists the root if the `db` option is not provided', async () => {
const trie = await constructor.create({ ...defaults, useRootPersistence: true })
const trie = await createTrie({ ...defaults, useRootPersistence: true })

assert.equal(await trie['_db'].get(ROOT_DB_KEY), undefined)

@@ -139,17 +139,17 @@ for (const { constructor, defaults, title } of [
it('persist and restore the root', async () => {
const db = new MapDB<string, string>()

const trie = await constructor.create({ ...defaults, db, useRootPersistence: true })
const trie = await createTrie({ ...defaults, db, useRootPersistence: true })
assert.equal(await trie['_db'].get(ROOT_DB_KEY), undefined)
await trie.put(utf8ToBytes('foo'), utf8ToBytes('bar'))
assert.equal(bytesToHex((await trie['_db'].get(ROOT_DB_KEY))!), EXPECTED_ROOTS)

// Using the same database as `trie` so we should have restored the root
const copy = await constructor.create({ ...defaults, db, useRootPersistence: true })
const copy = await createTrie({ ...defaults, db, useRootPersistence: true })
assert.equal(bytesToHex((await copy['_db'].get(ROOT_DB_KEY))!), EXPECTED_ROOTS)

// New trie with a new database so we shouldn't find a root to restore
const empty = await constructor.create({
const empty = await createTrie({
...defaults,
db: new MapDB(),
useRootPersistence: true,
@@ -175,7 +175,7 @@ for (const { constructor, defaults, title } of [
const value = randomBytes(10)
return { key, value }
})
const trie = await constructor.create({
const trie = await createTrie({
...defaults,
db: new MapDB(),
})
@@ -199,7 +199,7 @@ for (const { constructor, defaults, title } of [
}
})
it('should return false for all keys if trie is empty', async () => {
const emptyTrie = await constructor.create({
const emptyTrie = await createTrie({
...defaults,
db: new MapDB(),
})
@@ -220,7 +220,7 @@ for (const { constructor, defaults, title } of [
}
})
it('Should throw on unrelated errors', async () => {
const emptyTrie = await constructor.create({
const emptyTrie = await createTrie({
...defaults,
db: new MapDB(),
useRootPersistence: true,
Loading