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
67 changes: 38 additions & 29 deletions agentkit-core/src/actions/disperseAction_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ let gaslessCallsCount = 0;
const mockSendTransaction = async (wallet: any, tx: any) => {
mockTransactions.push(tx);
gaslessCallsCount++; // Count each call to sendTransaction (which is gasless)

console.log(`📤 Gasless Transaction ${gaslessCallsCount}:`);
console.log(` To: ${tx.to}`);
console.log(` Value: ${tx.value?.toString() || "0"}`);
console.log(` Data: ${tx.data.slice(0, 10)}... (${tx.data.length} chars)`);

return {
success: true,
txHash: `0x${Math.random().toString(16).slice(2, 10)}`,
Expand All @@ -45,7 +45,7 @@ async function runTests() {
recipients: [{ address: "invalid", amount: "1.0" }],
tokenAddress: "eth",
});

if (result1.includes("Invalid address format")) {
console.log("✅ PASS: Invalid address correctly rejected");
} else {
Expand All @@ -59,7 +59,7 @@ async function runTests() {
recipients: [{ address: "0x1234567890123456789012345678901234567890", amount: "-1" }],
tokenAddress: "eth",
});

if (result2.includes("Invalid amount")) {
console.log("✅ PASS: Invalid amount correctly rejected");
} else {
Expand All @@ -71,23 +71,27 @@ async function runTests() {
console.log("\nTest 3: Valid ETH batch transfer (🔥 GASLESS TEST)");
mockTransactions = []; // Reset
gaslessCallsCount = 0;

const result3 = await disperseTokens(mockWallet, {
recipients: [
{ address: "0x1234567890123456789012345678901234567890", amount: "0.1" },
{ address: "0x0987654321098765432109876543210987654321", amount: "0.2" },
],
tokenAddress: "eth",
});

if (result3.includes("🚀 Gasless Batch Transfer Completed!") &&
result3.includes("Total Recipients: 2") &&
result3.includes("Successful Transfers: 2") &&
mockTransactions.length === 2 &&
gaslessCallsCount === 2) {

if (
result3.includes("🚀 Gasless Batch Transfer Completed!") &&
result3.includes("Total Recipients: 2") &&
result3.includes("Successful Transfers: 2") &&
mockTransactions.length === 2 &&
gaslessCallsCount === 2
) {
console.log("✅ PASS: ETH batch transfer works correctly");
console.log(`🔥 GASLESS CONFIRMED: ${gaslessCallsCount} transactions sent via gasless sendTransaction service`);

console.log(
`🔥 GASLESS CONFIRMED: ${gaslessCallsCount} transactions sent via gasless sendTransaction service`,
);

// Verify transaction structure for gasless
console.log("\n💡 Transaction Structure Verification:");
mockTransactions.forEach((tx, i) => {
Expand All @@ -103,27 +107,33 @@ async function runTests() {
console.log("\nTest 4: Valid ERC20 token batch transfer (🔥 GASLESS TEST)");
mockTransactions = []; // Reset
gaslessCallsCount = 0;

const result4 = await disperseTokens(mockWallet, {
recipients: [
{ address: "0x1234567890123456789012345678901234567890", amount: "100" },
{ address: "0x0987654321098765432109876543210987654321", amount: "200" },
],
tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
});

if (result4.includes("🚀 Gasless Batch Transfer Completed!") &&
result4.includes("Total Recipients: 2") &&
result4.includes("Successful Transfers: 2") &&
mockTransactions.length === 2 &&
gaslessCallsCount === 2) {

if (
result4.includes("🚀 Gasless Batch Transfer Completed!") &&
result4.includes("Total Recipients: 2") &&
result4.includes("Successful Transfers: 2") &&
mockTransactions.length === 2 &&
gaslessCallsCount === 2
) {
console.log("✅ PASS: ERC20 batch transfer works correctly");
console.log(`🔥 GASLESS CONFIRMED: ${gaslessCallsCount} transactions sent via gasless sendTransaction service`);

console.log(
`🔥 GASLESS CONFIRMED: ${gaslessCallsCount} transactions sent via gasless sendTransaction service`,
);

// Verify ERC20 transfer encoding
console.log("\n💡 ERC20 Transfer Verification:");
mockTransactions.forEach((tx, i) => {
console.log(` Tx ${i + 1}: to=${tx.to} (token contract), value=0, data=${tx.data.slice(0, 10)}... (transfer function call)`);
console.log(
` Tx ${i + 1}: to=${tx.to} (token contract), value=0, data=${tx.data.slice(0, 10)}... (transfer function call)`,
);
});
} else {
console.log("❌ FAIL: ERC20 batch transfer failed");
Expand All @@ -140,7 +150,7 @@ async function runTests() {
],
tokenAddress: "eth",
});

if (result5.includes("Total Amount Distributed: 4 ETH")) {
console.log("✅ PASS: Total amount calculated correctly");
} else {
Expand All @@ -155,12 +165,12 @@ async function runTests() {
address: `0x${"1".repeat(39)}${i.toString().padStart(1, "0")}`,
amount: "1.0",
}));

DisperseInput.parse({
recipients: tooManyRecipients,
tokenAddress: "eth",
});

console.log("❌ FAIL: Schema should reject 51 recipients");
} catch (error) {
console.log("✅ PASS: Schema correctly rejects too many recipients");
Expand All @@ -169,15 +179,14 @@ async function runTests() {
console.log("\n🎉 All tests completed!");
console.log("\n📋 Summary:");
console.log("• Address validation: Working ✅");
console.log("• Amount validation: Working ✅");
console.log("• Amount validation: Working ✅");
console.log("• ETH batch transfers: Working ✅");
console.log("• ERC20 batch transfers: Working ✅");
console.log("• Amount calculation: Working ✅");
console.log("• Schema validation: Working ✅");
console.log("• 🔥 GASLESS EXECUTION: Working ✅");
console.log("\n🚀 The Disperse Action is ready for production!");
console.log("💰 Users will pay $0 in gas fees thanks to 0xGasless paymaster!");

} catch (error) {
console.error("❌ Test failed with error:", error);
} finally {
Expand All @@ -191,4 +200,4 @@ if (require.main === module) {
runTests().catch(console.error);
}

export { runTests };
export { runTests };
Loading