This directory contains utility modules that power the XMTP testing framework. These helpers provide the foundation for creating test scenarios, managing test personas, collecting metrics, and validating test results.
Module | Purpose |
---|---|
client.ts | Creates signers and manages keys for test personas |
datadog.ts | Sends performance metrics to Datadog |
factory.ts | Creates and manages test personas with workers |
group.ts | Creates test groups with specified participants |
logger.ts | Logging utilities for test output |
main.ts | Worker client implementation for multi-threaded testing |
reflect.ts | Integration with Reflect testing platform |
thread.ts | Worker thread implementation for background processing |
types.ts | Type definitions used throughout the testing framework |
verify.ts | Validation utilities for testing message delivery |
Handles XMTP client creation and key management:
// Create a signer for a private key
const signer = createSigner(privateKey);
// Generate a path for the client database
const dbPath = getDbPath(personaName, accountAddress, testName);
// Generate random encryption keys
const encryptionKey = generateEncryptionKeyHex();
Sends performance metrics to Datadog for monitoring:
// Initialize Datadog metrics
initDataDog(testName, envValue, geolocation, apiKey);
// Send delivery rate metrics
sendDeliveryMetric(deliveryRate, testName, libxmtpVersion);
// Send performance metrics
sendPerformanceMetric(durationMs, testName, libxmtpVersion);
// Measure network performance
const networkStats = await getNetworkStats();
Creates and manages test personas:
// Get a collection of test personas
const personas = await getWorkers(["alice", "bob", "randomguy"], testName);
// Create persona objects with appropriate keys and clients
const personaFactory = new PersonaFactory(testName, typeofStream);
const personas = await personaFactory.createPersonas(descriptors);
const bob = personas.get("bob");
// Clear worker cache when tests are complete
await clearWorkerCache();
To see more about the factory, check the workers section file
Utilities for creating and managing test groups:
// Create a group with a specific number of participants
const result = await createGroupWithBatch(
creator,
allPersonas,
batchSize,
installationsPerUser,
);
// Create multiple groups with increasing batch sizes
const results = await createGroupsWithIncrementalBatches(
creator,
allPersonas,
startBatchSize,
batchIncrement,
maxParticipants,
installationsPerUser,
);
Provides logging capabilities for tests:
// Create a logger for a specific test
const logger = createLogger(testName);
// Override console methods to use the logger
overrideConsole(logger);
// Flush logs to disk when test completes
flushLogger(testName);
Worker client implementation for multi-threaded testing:
// Create a worker client for a persona
const worker = new WorkerClient(persona, typeofStream);
// Initialize the worker with an XMTP client
const { client, dbPath, version } = await worker.initialize();
// Collect messages from a conversation
const messages = await worker.collectMessages(groupId, contentType, count);
// Collect conversation events
const conversations = await worker.collectConversations(peerAddress, count);
// Clean up when done
await worker.terminate();
Integration with the Reflect testing platform:
// Create a Reflect test suite
const reflectTestSuite = new ReflectTestSuite();
// Run GM sending test
const result = await reflectTestSuite.runSendingGmTest();
// Monitor test execution status
await reflectTestSuite.pollExecutionStatus(reflectTestSuite, executionId);
Worker thread implementation for background processing:
// Listen for messages from parent thread
parentPort.on("message", (message) => {
// Handle initialization and other commands
});
// Error handling for worker threads
process.on("unhandledRejection", (reason) => {
console.error("[Worker] Unhandled Rejection:", reason);
});
Type definitions used throughout the testing framework:
// Core types for personas and clients
interface Persona {
name: string;
installationId: string;
version: string;
dbPath: string;
worker: WorkerClient | null;
client: Client | null;
}
// Message and conversation stream types
type WorkerStreamMessage = {
type: "stream_message";
message: DecodedMessage;
};
// Verification result types
type VerifyStreamResult = {
allReceived: boolean;
messages: string[][];
};
Validation utilities for testing message delivery:
// Verify that all participants in a group receive messages
const result = await verifyStreamAll(group, personas, messageCount);
// Verify message delivery with custom settings
const result = await verifyStream(
group,
participants,
contentType,
messageCount,
messageGenerator,
messageSender,
);
// Verify conversation events are received by participants
const result = await verifyConversationStream(initiator, participants);
// Calculate statistics about message delivery
const stats = calculateMessageStats(
messagesByPersona,
messagePrefix,
messageCount,
suffix,
);
The generated-inboxes.json
file contains pre-generated wallet addresses and inbox IDs for testing. This is used to quickly set up test scenarios without having to create new wallets each time.
-
Test Setup:
factory.ts
creates test personas with appropriate keysclient.ts
handles signer creation and database pathslogger.ts
provides logging capabilities
-
Test Execution:
main.ts
andthread.ts
handle multi-threaded message processinggroup.ts
creates test groups with specific participantsverify.ts
validates message delivery
-
Metrics Collection:
datadog.ts
sends performance and reliability metrics to Datadog- Performance metrics include operation duration and network stats
- Delivery metrics track message reception rates
The helpers provide tools for performance testing:
- Use
createGroupsWithIncrementalBatches
to test group creation with increasing sizes - Use
sendPerformanceMetric
to track operation duration - Use
getNetworkStats
to measure network performance - Analyze results in Datadog dashboards
For testing message delivery reliability:
- Use
verifyStream
orverifyStreamAll
to send test messages - Use
calculateMessageStats
to analyze message reception rates - Track delivery metrics with
sendDeliveryMetric
These helpers form the foundation of XMTP's continuous testing infrastructure, ensuring reliable performance and message delivery across different environments.