Skip to content

Commit

Permalink
fix: undercollateralize emit filter on cycling nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Namaskar-1F64F committed Aug 23, 2024
1 parent 67606d4 commit ae20f79
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 36 deletions.
55 changes: 19 additions & 36 deletions src/actions-local/minipool.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { config } from "dotenv";
import { TestRuntime } from "@tenderly/actions-test";

import { beforeAll, describe, test } from "vitest";
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";

import { minipoolStatusChange, minipoolUndercollateralized } from "../actions/minipool";
import { minipoolStatusChange } from "../actions/minipool";
import { undercollateralized } from "../actions/minipoolEjection";
import { emitter } from "../actions/emitter";

config();

Expand All @@ -22,43 +24,24 @@ describe("Minipool", () => {
}
});
describe("Undercollateralized", () => {
test.concurrent("0 [undercollateralized].", async () => {
test.concurrent("emits for recordStakingEnd", async () => {
const emitSpy = vi.spyOn(emitter, "emit");
await testRuntime.execute(
minipoolUndercollateralized,
undercollateralized,
require("./payload/payload-minipool-undercollateralized.json")
);
expect(emitSpy).toHaveBeenCalled();
});
});
describe("Statuses", () => {
test.concurrent("0 [prelaunch].", async () => {
await testRuntime.execute(
minipoolStatusChange,
require("./payload/payload-prelaunch-minipool.json")
);
});
test.concurrent("1 [launched].", async () => {
await testRuntime.execute(
minipoolStatusChange,
require("./payload/payload-launched-minipool.json")
);
});
test.concurrent("2 [staking].", async () => {
await testRuntime.execute(
minipoolStatusChange,
require("./payload/payload-staking-minipool.json")
);
});
test.concurrent("3 [withdrawable].", async () => {
await testRuntime.execute(
minipoolStatusChange,
require("./payload/payload-withdrawable-minipool.json")
);
});
test.concurrent("[streamlined].", async () => {
await testRuntime.execute(
minipoolStatusChange,
require("./payload/payload-streamline-minipool.json")
);
});
test.concurrent(
"[negative] recordStakingEndThenMaybeCycle shouoldn't emit",
async () => {
const emitSpy = vi.spyOn(emitter, "emit");
await testRuntime.execute(
undercollateralized,
require("./payload/payload-minipool-undercollateralized-negative.json")
);
expect(emitSpy).not.toHaveBeenCalled();
}
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"network": "43114",
"blockHash": "0xb89a7fa63c0ae070c93306f5bda7b102c15cb2883c2482bbca113ab89776e202",
"blockNumber": 49567953,
"hash": "0xb14107b0a485eb834d5d85c28b9ef7e9bdbdef23306502a41e7af8133beefe4e",
"from": "0xB486738fa5859d08C841c7EB20b5Ef2B5502F38b",
"to": "0xc300Bc9B4b690BA7A182126299a0618eCe268Ee7",
"logs": [
{
"address": "0xd45Cb6F5AcA41AfAAAeBdBE4EFBA49c1bC41E6BA",
"topics": [
"0xd4502e0d4f9dc8fb9302d686a2b2bff55a6ed89cc5549f55b64490dff5d3e559",
"0xdc9f46fd71d4bf9bb05b835608e68c9394b627d9f45ac7ee85b2772e827e321e"
],
"data": "0x000000000000000000000000000000000000000000000036c1cb9a08eaeda200"
},
{
"address": "0xA25EaF2906FA1a3a13EdAc9B9657108Af7B703e3",
"topics": [
"0xc427d2d659d7dba18f3b7dc230a5b3eeaf5775bdda96b5018efceed241e06e0e",
"0x000000000000000000000000c300bc9b4b690ba7a182126299a0618ece268ee7"
],
"data": "0x0000000000000000000000000000000000000000000000369eca5a040a1d120000000000000000000000000000000000000000000000000023014004e0d09000"
},
{
"address": "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
"topics": [
"0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c",
"0x000000000000000000000000a25eaf2906fa1a3a13edac9b9657108af7b703e3"
],
"data": "0x000000000000000000000000000000000000000000000036c1cb9a08eaeda200"
},
{
"address": "0xc300Bc9B4b690BA7A182126299a0618eCe268Ee7",
"topics": [
"0xc9c043637725967252aedd2704cc65fee962e7b8a1e3cf8098587a66601e50c5",
"0x000000000000000000000000d56e82e834ee51223576db873d1cd93c27bd726d",
"0x0000000000000000000000000000000000000000000000000000000000000003"
],
"data": "0x"
}
],
"input": "0xc339d857000000000000000000000000d56e82e834ee51223576db873d1cd93c27bd726d0000000000000000000000000000000000000000000000000000000066c7109a00000000000000000000000000000000000000000000000046028009c1a12000",
"value": "0x6d83973411d5db4400",
"nonce": "0x8182",
"gas": "0x5c6ae",
"gasUsed": "0x5b683",
"cumulativeGasUsed": "0xd04ac",
"gasPrice": "0x5d21dba00",
"gasTipCap": "0x0",
"gasFeeCap": "0xba43b7400",
"alertId": null
}
13 changes: 13 additions & 0 deletions src/actions/minipoolEjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ import { getHardwareProviderName } from "./minipoolLaunch";
import { SLACK_UNDERCOLLATERALIZED_TEMPLATE } from "./templates";
import { initServices, nodeHexToID } from "./utils";
import { getMinipoolFromEvent } from "./minipool";
import { decodeFunctionData } from "viem";
import MinipoolManager from "./generated/contracts/MinipoolManager";

export const undercollateralized = async (context: Context, event: Event) => {
console.info("Starting minipoolUndercollateralized function");
await initServices(context);
const transactionEvent = event as TransactionEvent;

const { functionName } = decodeFunctionData({
abi: MinipoolManager,
data: transactionEvent.input as `0x${string}`,
});

if (functionName !== "recordStakingEnd") {
console.log(`functionName ${functionName} !== recordStakingEnd`);
return;
}

const { minipool } = await getMinipoolFromEvent(
transactionEvent,
context.metadata.getNetwork()
Expand Down

0 comments on commit ae20f79

Please sign in to comment.