Skip to content

Commit

Permalink
Merge pull request #206 from enviodev/feature/add-superchain-factorie…
Browse files Browse the repository at this point in the history
…s-testing

Feature: Adds Superchain Factories Tests.
  • Loading branch information
jfarid27 authored Nov 25, 2024
2 parents 8d26a79 + a4d0019 commit 9f0a8fd
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/EventHandlers/SuperchainCLFactory/RootPoolCreated.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect } from "chai";
import { MockDb, SuperchainCLFactory } from "../../../generated/src/TestHelpers.gen";

describe("SuperchainCLFactory RootPoolCreated Event", () => {
const token0Address = "0x1111111111111111111111111111111111111111";
const token1Address = "0x2222222222222222222222222222222222222222";
const poolAddress = "0x3333333333333333333333333333333333333333";
const chainId = 10;
const mockPoolChainId = 5;

let mockDb: ReturnType<typeof MockDb.createMockDb>;

beforeEach(() => {
mockDb = MockDb.createMockDb();
});

it("should create a new RootPoolCreated entity", async () => {
const mockEvent = SuperchainCLFactory.RootPoolCreated.createMockEvent({
token0: token0Address,
token1: token1Address,
pool: poolAddress,
chainid: BigInt(mockPoolChainId),
tickSpacing: 10n,
mockEventData: {
block: {
timestamp: 1000000,
number: 123456,
hash: "0x1234567890123456789012345678901234567890123456789012345678901234"
},
chainId,
logIndex: 1,
}
});

const result = await SuperchainCLFactory.RootPoolCreated.processEvent({
event: mockEvent,
mockDb
});

const createdEvent = result.entities.SuperchainCLFactory_RootPoolCreated.get(`${mockPoolChainId}_123456_1`);
expect(createdEvent).to.not.be.undefined;
expect(createdEvent?.token0).to.equal(token0Address);
expect(createdEvent?.token1).to.equal(token1Address);
expect(createdEvent?.pool).to.equal(poolAddress);
expect(createdEvent?.poolChainId).to.equal(mockPoolChainId);
expect(createdEvent?.tickSpacing).to.equal(10n);
expect(createdEvent?.timestamp).to.deep.equal(new Date(1000000 * 1000));
});
});
50 changes: 50 additions & 0 deletions test/EventHandlers/SuperchainPoolFactory/RootPoolCreated.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect } from "chai";
import { MockDb, SuperchainPoolFactory } from "../../../generated/src/TestHelpers.gen";

describe("SuperchainPoolFactory RootPoolCreated Event", () => {
const token0Address = "0x1111111111111111111111111111111111111111";
const token1Address = "0x2222222222222222222222222222222222222222";
const poolAddress = "0xb01234713d278d0ae3039d5930102956861d144b"; // Using real pool address.
const chainId = 10;
const mockPoolChainId = 252;

let mockDb: ReturnType<typeof MockDb.createMockDb>;

beforeEach(() => {
mockDb = MockDb.createMockDb();
});

xit("should create a new RootPoolCreated entity with chain ID from Web3 call", async () => {
const mockEvent = SuperchainPoolFactory.RootPoolCreated.createMockEvent({
token0: token0Address,
token1: token1Address,
pool: poolAddress,
stable: false,
length: 2n,
mockEventData: {
block: {
timestamp: 1000000,
number: 123456,
hash: "0x1234567890123456789012345678901234567890123456789012345678901234"
},
chainId,
logIndex: 1,
}
});

const result = await SuperchainPoolFactory.RootPoolCreated.processEvent({
event: mockEvent,
mockDb
});

const createdEvent = result.entities.SuperchainPoolFactory_RootPoolCreated.get(`${chainId}_123456_1`);
expect(createdEvent).to.not.be.undefined;
expect(createdEvent?.token0).to.equal(token0Address);
expect(createdEvent?.token1).to.equal(token1Address);
expect(createdEvent?.pool).to.equal(poolAddress);
expect(createdEvent?.stable).to.be.false;
expect(createdEvent?.poolChainId).to.equal(mockPoolChainId);
expect(createdEvent?.length).to.equal(2n);
expect(createdEvent?.timestamp).to.deep.equal(new Date(1000000 * 1000));
});
});

0 comments on commit 9f0a8fd

Please sign in to comment.