Skip to content

Commit

Permalink
fix basin test
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed May 23, 2024
1 parent 8e933f5 commit 419dca7
Showing 1 changed file with 126 additions and 25 deletions.
151 changes: 126 additions & 25 deletions projects/subgraph-basin/tests/Well.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { afterEach, assert, beforeEach, clearStore, describe, logStore, test } from "matchstick-as/assembly/index";
import {
afterEach,
assert,
beforeEach,
clearStore,
describe,
logStore,
test
} from "matchstick-as/assembly/index";
import { BEAN_ERC20, WETH } from "../../subgraph-core/utils/Constants";
import { ZERO_BD, ZERO_BI } from "../../subgraph-core/utils/Decimals";
import { loadWell } from "../src/utils/Well";
Expand Down Expand Up @@ -63,23 +71,41 @@ describe("Well Entity: Single Event Tests", () => {

assert.stringEquals(BEAN_USD_AMOUNT.toString(), endingBalances[0].toString());
assert.stringEquals(WETH_USD_AMOUNT.toString(), endingBalances[1].toString());
assert.stringEquals(WETH_USD_AMOUNT.times(BigDecimal.fromString("2")).toString(), updatedStore.totalLiquidityUSD.toString());
assert.stringEquals(
WETH_USD_AMOUNT.times(BigDecimal.fromString("2")).toString(),
updatedStore.totalLiquidityUSD.toString()
);
});
test("Liquidity Token balance", () => {
createDefaultAddLiquidity();
assert.fieldEquals(WELL_ENTITY_TYPE, WELL.toHexString(), "lpTokenSupply", WELL_LP_AMOUNT.toString());
assert.fieldEquals(
WELL_ENTITY_TYPE,
WELL.toHexString(),
"lpTokenSupply",
WELL_LP_AMOUNT.toString()
);
});
test("Previous day snapshot entity created", () => {
createDefaultAddLiquidity();

let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP, 8 * 60 * 60) - 1;
let daySnapshotID = WELL.concatI32(dayID);

let hourID = hourFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let hourSnapshotID = WELL.concatI32(hourID);

assert.fieldEquals(WELL_DAILY_ENTITY_TYPE, daySnapshotID.toHexString(), "id", daySnapshotID.toHexString());
assert.fieldEquals(WELL_HOURLY_ENTITY_TYPE, hourSnapshotID.toHexString(), "id", hourSnapshotID.toHexString());
assert.fieldEquals(
WELL_DAILY_ENTITY_TYPE,
daySnapshotID.toHexString(),
"id",
daySnapshotID.toHexString()
);
assert.fieldEquals(
WELL_HOURLY_ENTITY_TYPE,
hourSnapshotID.toHexString(),
"id",
hourSnapshotID.toHexString()
);
});
});

Expand All @@ -99,19 +125,34 @@ describe("Well Entity: Single Event Tests", () => {
});
test("Liquidity Token balance", () => {
createDefaultRemoveLiquidity();
assert.fieldEquals(WELL_ENTITY_TYPE, WELL.toHexString(), "lpTokenSupply", ZERO_BI.minus(WELL_LP_AMOUNT).toString());
assert.fieldEquals(
WELL_ENTITY_TYPE,
WELL.toHexString(),
"lpTokenSupply",
ZERO_BI.minus(WELL_LP_AMOUNT).toString()
);
});
test("Previous day snapshot entity created", () => {
createDefaultAddLiquidity();

let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP, 8 * 60 * 60) - 1;
let daySnapshotID = WELL.concatI32(dayID);

let hourID = hourFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let hourSnapshotID = WELL.concatI32(hourID);

assert.fieldEquals(WELL_DAILY_ENTITY_TYPE, daySnapshotID.toHexString(), "id", daySnapshotID.toHexString());
assert.fieldEquals(WELL_HOURLY_ENTITY_TYPE, hourSnapshotID.toHexString(), "id", hourSnapshotID.toHexString());
assert.fieldEquals(
WELL_DAILY_ENTITY_TYPE,
daySnapshotID.toHexString(),
"id",
daySnapshotID.toHexString()
);
assert.fieldEquals(
WELL_HOURLY_ENTITY_TYPE,
hourSnapshotID.toHexString(),
"id",
hourSnapshotID.toHexString()
);
});
});

Expand All @@ -137,19 +178,34 @@ describe("Well Entity: Single Event Tests", () => {
createDefaultAddLiquidity();
createDefaultAddLiquidity();
createRemoveLiquidityOneBean();
assert.fieldEquals(WELL_ENTITY_TYPE, WELL.toHexString(), "lpTokenSupply", WELL_LP_AMOUNT.toString());
assert.fieldEquals(
WELL_ENTITY_TYPE,
WELL.toHexString(),
"lpTokenSupply",
WELL_LP_AMOUNT.toString()
);
});
test("Previous day snapshot entity created", () => {
createDefaultAddLiquidity();

let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP, 8 * 60 * 60) - 1;
let daySnapshotID = WELL.concatI32(dayID);

let hourID = hourFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let hourSnapshotID = WELL.concatI32(hourID);

assert.fieldEquals(WELL_DAILY_ENTITY_TYPE, daySnapshotID.toHexString(), "id", daySnapshotID.toHexString());
assert.fieldEquals(WELL_HOURLY_ENTITY_TYPE, hourSnapshotID.toHexString(), "id", hourSnapshotID.toHexString());
assert.fieldEquals(
WELL_DAILY_ENTITY_TYPE,
daySnapshotID.toHexString(),
"id",
daySnapshotID.toHexString()
);
assert.fieldEquals(
WELL_HOURLY_ENTITY_TYPE,
hourSnapshotID.toHexString(),
"id",
hourSnapshotID.toHexString()
);
});
});

Expand All @@ -169,19 +225,34 @@ describe("Well Entity: Single Event Tests", () => {
});
test("Liquidity Token balance", () => {
createRemoveLiquidityOneWeth();
assert.fieldEquals(WELL_ENTITY_TYPE, WELL.toHexString(), "lpTokenSupply", ZERO_BI.minus(WELL_LP_AMOUNT).toString());
assert.fieldEquals(
WELL_ENTITY_TYPE,
WELL.toHexString(),
"lpTokenSupply",
ZERO_BI.minus(WELL_LP_AMOUNT).toString()
);
});
test("Previous day snapshot entity created", () => {
createDefaultAddLiquidity();

let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP, 8 * 60 * 60) - 1;
let daySnapshotID = WELL.concatI32(dayID);

let hourID = hourFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let hourSnapshotID = WELL.concatI32(hourID);

assert.fieldEquals(WELL_DAILY_ENTITY_TYPE, daySnapshotID.toHexString(), "id", daySnapshotID.toHexString());
assert.fieldEquals(WELL_HOURLY_ENTITY_TYPE, hourSnapshotID.toHexString(), "id", hourSnapshotID.toHexString());
assert.fieldEquals(
WELL_DAILY_ENTITY_TYPE,
daySnapshotID.toHexString(),
"id",
daySnapshotID.toHexString()
);
assert.fieldEquals(
WELL_HOURLY_ENTITY_TYPE,
hourSnapshotID.toHexString(),
"id",
hourSnapshotID.toHexString()
);
});
});

Expand Down Expand Up @@ -227,14 +298,24 @@ describe("Well Entity: Single Event Tests", () => {
test("Previous day snapshot entity created", () => {
createDefaultAddLiquidity();

let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let dayID = dayFromTimestamp(CURRENT_BLOCK_TIMESTAMP, 8 * 60 * 60) - 1;
let daySnapshotID = WELL.concatI32(dayID);

let hourID = hourFromTimestamp(CURRENT_BLOCK_TIMESTAMP) - 1;
let hourSnapshotID = WELL.concatI32(hourID);

assert.fieldEquals(WELL_DAILY_ENTITY_TYPE, daySnapshotID.toHexString(), "id", daySnapshotID.toHexString());
assert.fieldEquals(WELL_HOURLY_ENTITY_TYPE, hourSnapshotID.toHexString(), "id", hourSnapshotID.toHexString());
assert.fieldEquals(
WELL_DAILY_ENTITY_TYPE,
daySnapshotID.toHexString(),
"id",
daySnapshotID.toHexString()
);
assert.fieldEquals(
WELL_HOURLY_ENTITY_TYPE,
hourSnapshotID.toHexString(),
"id",
hourSnapshotID.toHexString()
);
});
});
});
Expand All @@ -254,7 +335,12 @@ describe("Swap Entity", () => {
});
test("Account entity exists", () => {
let id = createDefaultSwap();
assert.fieldEquals(ACCOUNT_ENTITY_TYPE, SWAP_ACCOUNT.toHexString(), "id", SWAP_ACCOUNT.toHexString());
assert.fieldEquals(
ACCOUNT_ENTITY_TYPE,
SWAP_ACCOUNT.toHexString(),
"id",
SWAP_ACCOUNT.toHexString()
);
});
test("Well value", () => {
let id = createDefaultSwap();
Expand Down Expand Up @@ -293,7 +379,12 @@ describe("AddLiquidity => Deposit Entity", () => {
});
test("Account entity exists", () => {
let id = createDefaultAddLiquidity();
assert.fieldEquals(ACCOUNT_ENTITY_TYPE, SWAP_ACCOUNT.toHexString(), "id", SWAP_ACCOUNT.toHexString());
assert.fieldEquals(
ACCOUNT_ENTITY_TYPE,
SWAP_ACCOUNT.toHexString(),
"id",
SWAP_ACCOUNT.toHexString()
);
});
test("Well value", () => {
let id = createDefaultAddLiquidity();
Expand Down Expand Up @@ -338,7 +429,12 @@ describe("RemoveLiquidity => Withdraw Entity", () => {
});
test("Account entity exists", () => {
let id = createDefaultRemoveLiquidity();
assert.fieldEquals(ACCOUNT_ENTITY_TYPE, SWAP_ACCOUNT.toHexString(), "id", SWAP_ACCOUNT.toHexString());
assert.fieldEquals(
ACCOUNT_ENTITY_TYPE,
SWAP_ACCOUNT.toHexString(),
"id",
SWAP_ACCOUNT.toHexString()
);
});
test("Well value", () => {
let id = createDefaultRemoveLiquidity();
Expand Down Expand Up @@ -387,7 +483,12 @@ describe("RemoveLiquidityOneToken => Withdraw Entity", () => {
createDefaultAddLiquidity();
createDefaultAddLiquidity();
let id = createRemoveLiquidityOneBean();
assert.fieldEquals(ACCOUNT_ENTITY_TYPE, SWAP_ACCOUNT.toHexString(), "id", SWAP_ACCOUNT.toHexString());
assert.fieldEquals(
ACCOUNT_ENTITY_TYPE,
SWAP_ACCOUNT.toHexString(),
"id",
SWAP_ACCOUNT.toHexString()
);
});
test("Well value", () => {
createDefaultAddLiquidity();
Expand Down

0 comments on commit 419dca7

Please sign in to comment.