-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core-state): in-memory storage for last N blocks and transactions
- Loading branch information
1 parent
35b7869
commit 03ddb47
Showing
34 changed files
with
429 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { genesisBlock } from "../../../utils/fixtures/unitnet/block-model"; | ||
|
||
export const state = { | ||
getLastBlock: () => genesisBlock, | ||
forkedBlock: null, | ||
getStore: () => ({ | ||
getLastBlock: () => genesisBlock, | ||
forkedBlock: null, | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export const state = { | ||
cacheTransactions: () => null, | ||
removeCachedTransactionIds: () => null, | ||
getStore: () => ({ | ||
cacheTransactions: () => null, | ||
removeCachedTransactionIds: () => null, | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
import "jest-extended"; | ||
|
||
import { OrderedCappedMap } from "../../../packages/core-utils/src/ordered-capped-map"; | ||
|
||
describe("Ordered Capped Map", () => { | ||
it("should set and get an entry", () => { | ||
const store = new OrderedCappedMap<string, number>(100); | ||
store.set("foo", 1); | ||
store.set("bar", 2); | ||
|
||
expect(store.get("foo")).toBe(1); | ||
expect(store.count()).toBe(2); | ||
}); | ||
|
||
it("should get an entry", () => { | ||
const store = new OrderedCappedMap<string, number>(2); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
|
||
expect(store.get("1")).toBe(1); | ||
expect(store.get("3")).toBeUndefined(); | ||
|
||
store.set("3", 3); | ||
|
||
expect(store.has("1")).toBeFalse(); | ||
expect(store.has("2")).toBeTrue(); | ||
expect(store.has("3")).toBeTrue(); | ||
}); | ||
|
||
it("should set entries and remove ones that exceed the maximum size", () => { | ||
const store = new OrderedCappedMap<string, number>(2); | ||
store.set("foo", 1); | ||
store.set("bar", 2); | ||
|
||
expect(store.get("foo")).toBe(1); | ||
expect(store.get("bar")).toBe(2); | ||
|
||
store.set("baz", 3); | ||
store.set("faz", 4); | ||
|
||
expect(store.has("foo")).toBeFalse(); | ||
expect(store.has("bar")).toBeFalse(); | ||
expect(store.has("baz")).toBeTrue(); | ||
expect(store.has("faz")).toBeTrue(); | ||
expect(store.count()).toBe(2); | ||
}); | ||
|
||
it("should update an entry", () => { | ||
const store = new OrderedCappedMap<string, number>(100); | ||
store.set("foo", 1); | ||
|
||
expect(store.get("foo")).toBe(1); | ||
|
||
store.set("foo", 2); | ||
|
||
expect(store.get("foo")).toBe(2); | ||
expect(store.count()).toBe(1); | ||
}); | ||
|
||
it("should return if an entry exists", () => { | ||
const store = new OrderedCappedMap<string, number>(100); | ||
store.set("1", 1); | ||
|
||
expect(store.has("1")).toBeTrue(); | ||
}); | ||
|
||
it("should remove the specified entrys", () => { | ||
const store = new OrderedCappedMap<string, number>(100); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
|
||
expect(store.delete("1")).toBeTrue(); | ||
expect(store.has("1")).toBeFalse(); | ||
expect(store.has("2")).toBeTrue(); | ||
expect(store.delete("1")).toBeFalse(); | ||
expect(store.count()).toBe(1); | ||
}); | ||
|
||
it("should remove the specified entrys", () => { | ||
const store = new OrderedCappedMap<string, number>(2); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
|
||
expect(store.count()).toBe(2); | ||
expect(store.delete("1")).toBeTrue(); | ||
expect(store.has("1")).toBeFalse(); | ||
expect(store.has("2")).toBeTrue(); | ||
|
||
store.delete("2"); | ||
|
||
expect(store.count()).toBe(0); | ||
}); | ||
|
||
it("should remove all entrys", () => { | ||
const store = new OrderedCappedMap<string, number>(3); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
store.set("3", 3); | ||
|
||
expect(store.count()).toBe(3); | ||
|
||
store.clear(); | ||
|
||
expect(store.count()).toBe(0); | ||
}); | ||
|
||
it("should return the first value", () => { | ||
const store = new OrderedCappedMap<string, number>(2); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
|
||
expect(store.first()).toBe(1); | ||
}); | ||
|
||
it("should return the last value", () => { | ||
const store = new OrderedCappedMap<string, number>(2); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
|
||
expect(store.last()).toBe(2); | ||
}); | ||
|
||
it("should return the keys", () => { | ||
const store = new OrderedCappedMap<string, number>(3); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
store.set("3", 3); | ||
|
||
expect(store.keys()).toEqual(["1", "2", "3"]); | ||
}); | ||
|
||
it("should return the values", () => { | ||
const store = new OrderedCappedMap<string, number>(3); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
store.set("3", 3); | ||
|
||
expect(store.values()).toEqual([1, 2, 3]); | ||
}); | ||
|
||
it("should return the entry count", () => { | ||
const store = new OrderedCappedMap<string, number>(100); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
|
||
expect(store.count()).toBe(2); | ||
|
||
store.delete("1"); | ||
|
||
expect(store.count()).toBe(1); | ||
|
||
store.set("3", 3); | ||
|
||
expect(store.count()).toBe(2); | ||
}); | ||
|
||
it("should resize the map", () => { | ||
const store = new OrderedCappedMap<string, number>(3); | ||
store.set("1", 1); | ||
store.set("2", 2); | ||
store.set("3", 3); | ||
|
||
expect(store.count()).toBe(3); | ||
|
||
store.set("4", 4); | ||
|
||
expect(store.count()).toBe(3); | ||
|
||
store.resize(4); | ||
store.set("5", 5); | ||
|
||
expect(store.count()).toBe(4); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.