Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/plugin-misc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@solanafm/explorer-kit-idls": "^1.1.4",
"@sqds/multisig": "^2.1.3",
"@switchboard-xyz/common": "^2.5.17",
"bn.js": "^5.2.1",
"bs58": "^6.0.0",
"redaxios": "^0.5.1",
"rpc-websockets": "^10.0.0",
Expand All @@ -54,5 +55,8 @@
"peerDependencies": {
"@solana/web3.js": "^1.98.2",
"solana-agent-kit": "2.0.5"
},
"devDependencies": {
"@types/bn.js": "^5.1.6"
}
}
44 changes: 44 additions & 0 deletions packages/plugin-misc/src/ottersec/test/import_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { create_verification_pda } from "../tools";
import * as anchor from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";

async function test_create_verification_pda() {
console.log("Running OtterSec create_verification_pda unit test...");

const mockAgent = {
connection: {},
wallet: {
publicKey: new PublicKey("8417BhZzzmGgPzDE1b43PK7n5zAy5rjYEEuSinSFZUWq"),
toBuffer: () => Buffer.from("mock-wallet-buffer"),
},
};

const mockVerifyParams = {
repository: "https://github.com/example/repo",
commit_hash: "abcdef123456",
deploySlot: 12345678,
};

const programId = "C6v9u8Xo7t4Y3e...mock-program-id"; // Just a string for now

// To test this we need to mock "solana-agent-kit"'s sendTx too.
// This is harder because it's imported at the top of the file.

// Actually, I just want to see if the file LOADS and RUNS without SyntaxError now.
console.log("File loaded successfully. Attempting to run with mocks...");

try {
// This will fail on AnchorProvider initialization because connection is mock
// but we want to see if it gets past the imports.
await create_verification_pda(mockAgent as any, "8417BhZzzmGgPzDE1b43PK7n5zAy5rjYEEuSinSFZUWq", mockVerifyParams as any);
} catch (error: any) {
console.log("Caught expected error or actual error:", error.message);
if (error.message.includes("does not provide an export named 'BN'")) {
console.error("❌ Test Failed: BN import issue still persists.");
process.exit(1);
}
console.log("✅ Import check passed (no SyntaxError).");
}
}

test_create_verification_pda();
47 changes: 47 additions & 0 deletions packages/plugin-misc/src/ottersec/test/unit_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { verify_program } from "../tools";
import { OSEC_ENDPOINT_URI, OSEC_ROUTER } from "../constants";

async function test_verify_program() {
console.log("Running OtterSec verify_program unit test...");

// Mock global fetch
const mockResponse = {
status: "success",
jobId: "mock-job-123",
};

// @ts-ignore
global.fetch = async (url: string, options: any) => {
console.log(`Mock fetch called with URL: ${url}`);
if (url === OSEC_ENDPOINT_URI + OSEC_ROUTER.VERIFY_PROGRAM) {
return {
ok: true,
json: async () => mockResponse,
};
}
return { ok: false };
};

const params = {
program_id: "8417BhZzzmGgPzDE1b43PK7n5zAy5rjYEEuSinSFZUWq", // Example wallet/program ID
repository: "https://github.com/example/repo",
commit_hash: "abcdef123456",
};

try {
const result = await verify_program(params as any);
console.log("Result:", result);

if (result && result.jobId === "mock-job-123") {
console.log("✅ Test Passed: verify_program returns correct mock response.");
} else {
console.error("❌ Test Failed: verify_program returned unexpected result.");
process.exit(1);
}
} catch (error) {
console.error("❌ Test Failed with error:", error);
process.exit(1);
}
}

test_verify_program();
9 changes: 9 additions & 0 deletions packages/plugin-misc/src/ottersec/test/verifyProgram.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { verify_program } from "../tools";

describe("OtterSec verify_program", () => {
it("should handle verification request (mock test structure)", async () => {
// This is a placeholder for the actual integration/unit test logic
// We will refine this once we confirm the mock environment for fetch
console.log("Starting OtterSec test...");
});
});
15 changes: 4 additions & 11 deletions packages/plugin-misc/src/ottersec/tools/create_verification_pda.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import { sendTx, SolanaAgentKit } from "solana-agent-kit";
import { AnchorProvider, Program, BN, Idl } from "@coral-xyz/anchor";
import * as anchor from "@coral-xyz/anchor";
import { BN } from "bn.js";
import { OTTER_SEC_PROGRAM_ID, PDA_INITIALIZE_SEED } from "../constants";
import { PublicKey, SystemProgram } from "@solana/web3.js";
import { CreateVerifyPdaParam } from "../types";
import OTTER_SEC_IDL from "../constants/idl.json";

/**
* @name create_verification_pda
* @description Generate a PDA for program verification
* @param agent
* @param programId
* @param verifyParams
*/

export async function create_verification_pda(
agent: SolanaAgentKit,
programId: string,
verifyParams: CreateVerifyPdaParam
) {
try {
const provider = new AnchorProvider(agent.connection, agent.wallet, {});
const program = new Program(OTTER_SEC_IDL as Idl, provider);
const provider = new anchor.AnchorProvider(agent.connection, agent.wallet, {});
const program = new anchor.Program(OTTER_SEC_IDL as anchor.Idl, provider);
const [pda, _] = PublicKey.findProgramAddressSync(
[
Buffer.from(PDA_INITIALIZE_SEED),
Expand Down
Loading