@coinbase/agentkit
Version:
Coinbase AgentKit core primitives
120 lines (119 loc) • 4.95 kB
JavaScript
;
/**
* Clanker Action Provider tests
*/
Object.defineProperty(exports, "__esModule", { value: true });
const clankerActionProvider_1 = require("./clankerActionProvider");
const schemas_1 = require("./schemas");
const utils_1 = require("./utils");
jest.mock("./utils", () => ({
createClankerClient: jest.fn(),
}));
const createClankerClientMock = utils_1.createClankerClient;
const DEPLOYED_HASH = "0xdeadbeef";
const DEPLOYED_TOKEN_ADDRESS = "0xabc123abc123abc123abc123abc123abc123abc1";
describe("Clanker action provider tests", () => {
const provider = (0, clankerActionProvider_1.clankerActionProvider)();
let mockWalletProvider;
beforeEach(() => {
mockWalletProvider = {
getAddress: jest.fn(),
getBalance: jest.fn(),
getName: jest.fn(),
getNetwork: jest.fn().mockReturnValue({
protocolFamily: "evm",
networkId: "base-mainnet",
}),
nativeTransfer: jest.fn(),
};
const fakeClanker = {
deploy: jest.fn(async (_tokenCfg) => ({
txHash: DEPLOYED_HASH,
waitForTransaction: async () => ({ address: DEPLOYED_TOKEN_ADDRESS }),
})),
};
createClankerClientMock.mockResolvedValue(fakeClanker);
});
describe("network validation", () => {
it("should support the protocol family and network", () => {
expect(provider.supportsNetwork({
protocolFamily: "evm",
networkId: "base-mainnet",
})).toBe(true);
});
it("should not support other protocol families", () => {
expect(provider.supportsNetwork({
protocolFamily: "other-protocol-family",
})).toBe(false);
});
it("should handle invalid network objects", () => {
expect(provider.supportsNetwork({ protocolFamily: "invalid-protocol" })).toBe(false);
expect(provider.supportsNetwork({})).toBe(false);
});
});
describe("schema validation", () => {
it("should validate example action schema", () => {
const validInput = {
tokenName: "testTokenName",
tokenSymbol: "TTN",
image: "https://test.com",
vaultPercentage: 10,
vestingDuration_Days: 30,
lockDuration_Days: 30,
interface: "CDP AgentKit",
id: "test-id",
};
const parseResult = schemas_1.ClankTokenSchema.safeParse(validInput);
expect(parseResult.success).toBe(true);
if (parseResult.success) {
expect(parseResult.data.tokenName).toBe("testTokenName");
expect(parseResult.data.tokenSymbol).toBe("TTN");
expect(parseResult.data.image).toBe("https://test.com");
expect(parseResult.data.vaultPercentage).toBe(10);
expect(parseResult.data.vestingDuration_Days).toBe(30);
expect(parseResult.data.lockDuration_Days).toBe(30);
}
});
it("should reject invalid example action input", () => {
const invalidInput = {
fieldName: "",
amount: "invalid",
};
const parseResult = schemas_1.ClankTokenSchema.safeParse(invalidInput);
expect(parseResult.success).toBe(false);
});
});
describe("clanker action execution", () => {
it("should execute the clanker action with wallet provider", async () => {
const args = {
tokenName: "testTokenName",
tokenSymbol: "TTN",
image: "https://test.com",
vaultPercentage: 10,
vestingDuration_Days: 30,
lockDuration_Days: 30,
interface: "CDP AgentKit",
id: "test-id",
};
const result = await provider.clankToken(mockWalletProvider, args);
expect(result).toContain(`Clanker token deployed at ${DEPLOYED_TOKEN_ADDRESS}`);
expect(result).toContain(`View the transaction at ${DEPLOYED_HASH}`);
expect(mockWalletProvider.getNetwork).toHaveBeenCalled();
expect(createClankerClientMock).toHaveBeenCalledWith(expect.any(Object), expect.any(String));
});
});
describe("supportsNetwork", () => {
it("should return true for base-mainnet with evm protocol", () => {
expect(provider.supportsNetwork({
protocolFamily: "evm",
networkId: "base-mainnet",
})).toBe(true);
});
it("should return false for non-base networks", () => {
expect(provider.supportsNetwork({
protocolFamily: "evm",
networkId: "ethereum-mainnet",
})).toBe(false);
});
});
});