Skip to content

Commit

Permalink
fix lint issues, export b2 plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
odilitime committed Jan 14, 2025
1 parent dec9e93 commit 43f9e62
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-b2/src/actions/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
composeContext,
ModelClass,
} from "@elizaos/core";
import { getTxReceipt, sendNativeAsset, sendToken, depositBTC } from "../utils";
import { Address, Hash } from "viem";
import { getTxReceipt, depositBTC } from "../utils";
import { Hash } from "viem";
import { validateB2NetworkConfig } from "../environment";
import { stakeTemplate } from "../templates";
import { WalletProvider } from "../providers";
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-b2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { unstakeAction } from "./actions/unstake";
import { withdrawAction } from "./actions/withdraw";
import { walletProvider } from "./providers";

const b2Plugin: Plugin = {
export const b2Plugin: Plugin = {
name: "b2",
description: "B2 Network Plugin for Eliza",
actions: [transferAction, stakeAction, unstakeAction, withdrawAction],
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-b2/src/tests/stake.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { describe, it, expect, beforeEach } from "vitest";
import { generatePrivateKey } from "viem/accounts";
import { getEnvVariable } from "@elizaos/core";

import { StakeAction } from "../actions/stake";
import { WalletProvider } from "../providers";
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-b2/src/tests/unstake.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { describe, it, expect, beforeEach } from "vitest";
import { generatePrivateKey } from "viem/accounts";
import { getEnvVariable } from "@elizaos/core";

import { UnstakeAction } from "../actions/unstake";
import { WalletProvider } from "../providers";
import { TransferParams, UnstakeParams } from "../types";
import { UnstakeParams } from "../types";

describe("Unstake Action", () => {
let wp: WalletProvider;
Expand Down
7 changes: 3 additions & 4 deletions packages/plugin-b2/src/tests/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { initWalletProvider, WalletProvider } from "../providers";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { Memory, State } from "@elizaos/core";
import { generatePrivateKey } from "viem/accounts";

describe("B2 Network Wallet Provider", () => {
let walletProvider: WalletProvider;
//let walletProvider: WalletProvider;
let mockRuntime;

beforeEach(() => {
vi.clearAllMocks();
const pk = generatePrivateKey();
walletProvider = new WalletProvider(pk);
//walletProvider = new WalletProvider(pk);
mockRuntime = {
getSetting: vi.fn(),
};
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-b2/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Token } from "@lifi/types";
//import type { Token } from "@lifi/types";
import type {
Address,
Hash,
Expand Down Expand Up @@ -26,5 +26,5 @@ export interface UnstakeParams {
amount: string | number;
}

export interface WithdrawParams {
}
//export interface WithdrawParams {
//}
3 changes: 1 addition & 2 deletions packages/plugin-b2/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { IAgentRuntime, elizaLogger } from "@elizaos/core";
import { elizaLogger } from "@elizaos/core";
import {
Hash,
Address,
parseUnits,
encodeFunctionData,
SendTransactionParameters,
} from "viem";
import { b2Network } from "./chains";
import { WalletProvider } from "../providers";
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-squid-router/src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IAgentRuntime } from "@elizaos/core";
import { z } from 'zod';
import { ethers } from 'ethers';
import { bech32 } from 'bech32';
import bs58 from 'bs58';
//import { bech32 } from 'bech32';
//import bs58 from 'bs58';
import {SquidToken, XChainSwapContent} from "../types";

export function convertToWei(amount: string | number, token: SquidToken): string {
Expand Down Expand Up @@ -55,6 +55,7 @@ const isValidEvmPrivateKey = (key: string): boolean => {
return /^[0-9a-fA-F]{64}$/.test(cleanedKey);
};

/*
const isValidSolanaAddress = (address: string): boolean => {
try {
const decoded = bs58.decode(address);
Expand All @@ -80,6 +81,7 @@ const isValidCosmosAddress = (address: string): boolean => {
const isValidCosmosPrivateKey = (key: string): boolean => {
return /^[0-9a-fA-F]{64}$/.test(key);
};
*/

export const squidRouterEnvSchema = z
.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-squid-router/src/providers/squidRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const squidRouterProvider: Provider = {
_state?: State
): Promise<string | null> => {
try {
const provider = initSquidRouterProvider(runtime);
/* const provider = */ initSquidRouterProvider(runtime);
return "Squid Router provider setup successful."
} catch (error) {
console.error("Error in Squid Router provider:", error);
Expand Down
20 changes: 10 additions & 10 deletions packages/plugin-whatsapp/__tests__/handlers/message.handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ import { WhatsAppClient } from '../../src/client';
import { WhatsAppMessage } from '../../src/types';

describe('MessageHandler', () => {
let messageHandler: MessageHandler;
let mockClient: WhatsAppClient;
let messageHandler;
let mockClient;

beforeEach(() => {
mockClient = {
sendMessage: vi.fn(),
} as any as WhatsAppClient;
};

messageHandler = new MessageHandler(mockClient);
});

it('should successfully send a message', async () => {
const mockMessage: WhatsAppMessage = {
const mockMessage = {
type: 'text',
to: '1234567890',
content: 'Test message'
};

const mockResponse = {
const mockResponse = {
messaging_product: 'whatsapp',
contacts: [{ input: '1234567890', wa_id: 'WHATSAPP_ID' }],
messages: [{ id: 'MESSAGE_ID' }]
};

(mockClient.sendMessage as any).mockResolvedValue({ data: mockResponse });
mockClient.sendMessage.mockResolvedValue({ data: mockResponse });

const result = await messageHandler.send(mockMessage);

Expand All @@ -37,28 +37,28 @@ describe('MessageHandler', () => {
});

it('should handle client errors with error message', async () => {
const mockMessage: WhatsAppMessage = {
const mockMessage = {
type: 'text',
to: '1234567890',
content: 'Test message'
};

const errorMessage = 'API Error';
(mockClient.sendMessage as any).mockRejectedValue(new Error(errorMessage));
mockClient.sendMessage.mockRejectedValue(new Error(errorMessage));

await expect(messageHandler.send(mockMessage))
.rejects
.toThrow(`Failed to send WhatsApp message: ${errorMessage}`);
});

it('should handle unknown errors', async () => {
const mockMessage: WhatsAppMessage = {
const mockMessage = {
type: 'text',
to: '1234567890',
content: 'Test message'
};

(mockClient.sendMessage as any).mockRejectedValue('Unknown error');
mockClient.sendMessage.mockRejectedValue('Unknown error');

await expect(messageHandler.send(mockMessage))
.rejects
Expand Down

0 comments on commit 43f9e62

Please sign in to comment.