Skip to content

Commit

Permalink
test: update silo test
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Jul 22, 2024
1 parent d8ee4a2 commit 36cfc6b
Showing 1 changed file with 19 additions and 41 deletions.
60 changes: 19 additions & 41 deletions projects/sdk/src/lib/silo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const account2 = "0x0000000000000000000000000000000000000000"; // zero addy
/// Setup
const { sdk, account, utils } = getTestUtils();


/// Tests
beforeAll(async () => {
await utils.resetFork();
Expand All @@ -39,29 +40,19 @@ beforeAll(async () => {
describe("Silo Balance loading", () => {
describe("getBalance", function () {
it("returns an empty object", async () => {
const balance = await sdk.silo.getBalance(sdk.tokens.BEAN, account2, {
source: DataSource.LEDGER
});
const balance = await sdk.silo.getBalance(sdk.tokens.BEAN, account2, { source: DataSource.LEDGER });
chaiExpect(balance.amount.eq(0)).to.be.true;
});
it("loads an account with deposits (fuzzy)", async () => {
const balance = await sdk.silo.getBalance(sdk.tokens.BEAN, account, {
source: DataSource.LEDGER
});
const balance = await sdk.silo.getBalance(sdk.tokens.BEAN, account, { source: DataSource.LEDGER });
chaiExpect(balance.amount.toHuman()).to.eq("100000");
});

// FIX: discrepancy in graph results
it.skip("source: ledger === subgraph", async function () {
const [ledger, subgraph]: TokenSiloBalance[] = await Promise.all([
timer(
sdk.silo.getBalance(sdk.tokens.BEAN, account, { source: DataSource.LEDGER }),
"Ledger result time"
),
timer(
sdk.silo.getBalance(sdk.tokens.BEAN, account, { source: DataSource.SUBGRAPH }),
"Subgraph result time"
)
timer(sdk.silo.getBalance(sdk.tokens.BEAN, account, { source: DataSource.LEDGER }), "Ledger result time"),
timer(sdk.silo.getBalance(sdk.tokens.BEAN, account, { source: DataSource.SUBGRAPH }), "Subgraph result time")
]);

// We cannot compare .deposited.bdv as the ledger results come from prod
Expand All @@ -78,12 +69,12 @@ describe("Silo Balance loading", () => {
// Pulled an account with some large positions for testing
// @todo pick several accounts and loop
// beforeAll(async () => {
// [ledger, subgraph] = await Promise.all([
// timer(sdk.silo.getBalances(account, { source: DataSource.LEDGER }), "Ledger result time"),
// timer(sdk.silo.getBalances(account, { source: DataSource.SUBGRAPH }), "Subgraph result time")
// ]);
// [ledger, subgraph] = await Promise.all([
// timer(sdk.silo.getBalances(account, { source: DataSource.LEDGER }), "Ledger result time"),
// timer(sdk.silo.getBalances(account, { source: DataSource.SUBGRAPH }), "Subgraph result time")
// ]);
// });

// FIX: Discrepancy in graph results.
it.skip("source: ledger === subgraph", async function () {
for (let [token, value] of ledger.entries()) {
Expand All @@ -105,9 +96,7 @@ describe("Silo Balance loading", () => {
describe("stalk calculations for each crate", () => {
let balance: TokenSiloBalance;
beforeAll(async () => {
balance = await sdk.silo.getBalance(sdk.tokens.BEAN, BF_MULTISIG, {
source: DataSource.SUBGRAPH
});
balance = await sdk.silo.getBalance(sdk.tokens.BEAN, BF_MULTISIG, { source: DataSource.SUBGRAPH });
});

it("stalk = baseStalk + grownStalk", () => {
Expand Down Expand Up @@ -195,9 +184,7 @@ describe("Silo mowMultiple", () => {
const whitelistedToken = sdk.tokens.BEAN;
const whitelistedToken2 = sdk.tokens.BEAN_CRV3_LP;
const nonWhitelistedToken = sdk.tokens.DAI;
const whitelistedTokenAddresses = Array.from(sdk.tokens.siloWhitelist.values()).map(
(token) => token.address
);
const whitelistedTokenAddresses = Array.from(sdk.tokens.siloWhitelist.values()).map((token) => token.address);

beforeEach(() => {
// We mock the methods used in mowMultiple
Expand All @@ -216,44 +203,35 @@ describe("Silo mowMultiple", () => {
});

it("throws when non-whitelisted token provided", async () => {
await expect(sdk.silo.mowMultiple(account, [nonWhitelistedToken])).rejects.toThrow(
`${nonWhitelistedToken.symbol} is not whitelisted`
);
await expect(sdk.silo.mowMultiple(account, [nonWhitelistedToken])).rejects.toThrow(`${nonWhitelistedToken.symbol} is not whitelisted`);
});

it.skip("warns when single token provided", async () => {
const consoleSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
await sdk.silo.mowMultiple(account, [whitelistedToken]);
expect(consoleSpy).toHaveBeenCalledWith(
"Optimization: use `mow()` instead of `mowMultiple()` for a single token"
);
expect(consoleSpy).toHaveBeenCalledWith("Optimization: use `mow()` instead of `mowMultiple()` for a single token");
consoleSpy.mockRestore();
});

it.skip("mows multiple tokens", async () => {
const transaction = await sdk.silo.mowMultiple(account, [whitelistedToken, whitelistedToken2]);
expect(transaction).toBe("mockedTransaction");
expect(Silo.sdk.contracts.beanstalk.mowMultiple).toHaveBeenCalledWith(account, [
whitelistedToken.address,
whitelistedToken2.address
]);
expect(Silo.sdk.contracts.beanstalk.mowMultiple).toHaveBeenCalledWith(account, [whitelistedToken.address, whitelistedToken2.address]);
});

it.skip("mows all whitelisted tokens when no specific tokens provided", async () => {
const transaction = await sdk.silo.mowMultiple(account);
expect(transaction).toBe("mockedTransaction");
expect(Silo.sdk.contracts.beanstalk.mowMultiple).toHaveBeenCalledWith(
account,
whitelistedTokenAddresses
);
expect(Silo.sdk.contracts.beanstalk.mowMultiple).toHaveBeenCalledWith(account, whitelistedTokenAddresses);
});

it.todo("throws when there are duplicate tokens provided");
});


const setTokenRewards = () => {
sdk.tokens.BEAN.rewards = {
seeds: sdk.tokens.SEEDS.amount(1),
stalk: sdk.tokens.STALK.amount(3)
};
};
}
}

0 comments on commit 36cfc6b

Please sign in to comment.