Skip to content

Commit

Permalink
Merge pull request #75 from kafeikui/add-get-next-initialized-tick-test
Browse files Browse the repository at this point in the history
add `getNextInitializedTick` test in TickManager
  • Loading branch information
kafeikui authored Jun 10, 2022
2 parents e1962f9 + f9ea249 commit b23ee78
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bella-defintech/uniswap-v3-simulator",
"version": "0.1.4",
"version": "0.1.5",
"description": "the 'Tuner', a Uniswap V3 Simulator",
"keywords": [
"uniswap",
Expand Down
2 changes: 1 addition & 1 deletion test/TestSubgraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ chai.use(chaiAsPromised);
describe("Test Uniswap v3 Subgraph", function () {
const APIURL = "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3";

it.only("can download events", async function () {
it("can download events", async function () {
const query = gql`
query {
pool(id: "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8") {
Expand Down
104 changes: 104 additions & 0 deletions test/TickManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Tick } from "../src/model/Tick";
import { TickMath } from "../src/util/TickMath";
import { expect } from "./shared/expect";
import { TickManager } from "../src/manager/TickManager";

describe("TickManager", () => {
describe("#getNextInitializedTick", () => {
let highTick: Tick;
let lowTick: Tick;
let midTick: Tick;
let ticks: Tick[];
let tickManager: TickManager = new TickManager();

beforeEach(() => {
lowTick = new Tick(TickMath.MIN_TICK + 1);
midTick = new Tick(0);
highTick = new Tick(TickMath.MAX_TICK - 1);

ticks = [lowTick, midTick, highTick];

for (let tick of ticks) {
tickManager.set(tick);
}
});

it("lte = true", () => {
expect(tickManager.getNextInitializedTick(-257, 1, true)).to.eql({
nextTick: -512,
initialized: false,
});
expect(tickManager.getNextInitializedTick(-256, 1, true)).to.eql({
nextTick: -256,
initialized: false,
});
expect(tickManager.getNextInitializedTick(-1, 1, true)).to.eql({
nextTick: -256,
initialized: false,
});
expect(tickManager.getNextInitializedTick(0, 1, true)).to.eql({
nextTick: 0,
initialized: true,
});
expect(tickManager.getNextInitializedTick(1, 1, true)).to.eql({
nextTick: 0,
initialized: true,
});
expect(tickManager.getNextInitializedTick(255, 1, true)).to.eql({
nextTick: 0,
initialized: true,
});
expect(tickManager.getNextInitializedTick(256, 1, true)).to.eql({
nextTick: 256,
initialized: false,
});
expect(tickManager.getNextInitializedTick(257, 1, true)).to.eql({
nextTick: 256,
initialized: false,
});
});

it("lte = false", () => {
expect(tickManager.getNextInitializedTick(-215041, 60, false)).to.eql({
nextTick: -199740,
initialized: false,
});
expect(tickManager.getNextInitializedTick(-257, 1, false)).to.eql({
nextTick: -1,
initialized: false,
});
expect(tickManager.getNextInitializedTick(-256, 1, false)).to.eql({
nextTick: -1,
initialized: false,
});
expect(tickManager.getNextInitializedTick(-2, 1, false)).to.eql({
nextTick: -1,
initialized: false,
});
expect(tickManager.getNextInitializedTick(-1, 1, false)).to.eql({
nextTick: 0,
initialized: true,
});
expect(tickManager.getNextInitializedTick(0, 1, false)).to.eql({
nextTick: 255,
initialized: false,
});
expect(tickManager.getNextInitializedTick(1, 1, false)).to.eql({
nextTick: 255,
initialized: false,
});
expect(tickManager.getNextInitializedTick(254, 1, false)).to.eql({
nextTick: 255,
initialized: false,
});
expect(tickManager.getNextInitializedTick(255, 1, false)).to.eql({
nextTick: 511,
initialized: false,
});
expect(tickManager.getNextInitializedTick(256, 1, false)).to.eql({
nextTick: 511,
initialized: false,
});
});
});
});

0 comments on commit b23ee78

Please sign in to comment.