-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tsx to node SDK dev deps * Add performance testing scripts to node SDK * Use || to ensure string values * Optimize safe conversation conversion * Ensure URL values in Browser SDK * Create late-tips-pump.md
- Loading branch information
Showing
10 changed files
with
493 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@xmtp/browser-sdk": patch | ||
"@xmtp/node-sdk": patch | ||
--- | ||
|
||
SDK optimizations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
scripts/accounts.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { writeFile } from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; | ||
|
||
type Account = [key: string, address: string]; | ||
type AccountsMap = Record<string, string>; | ||
|
||
const createRandomAccount = (): Account => { | ||
const privateKey = generatePrivateKey(); | ||
const account = privateKeyToAccount(privateKey); | ||
return [privateKey, account.address]; | ||
}; | ||
|
||
const writeAccountsJson = async (accounts: AccountsMap) => { | ||
console.log("Writing accounts to file..."); | ||
const accountsJsonPath = path.join(import.meta.dirname, "accounts.json"); | ||
await writeFile(accountsJsonPath, JSON.stringify(accounts, null, 2)); | ||
console.log(`Accounts data written to '${accountsJsonPath}'`); | ||
}; | ||
|
||
const main = async () => { | ||
console.log("Creating 1000 accounts..."); | ||
const accounts = Object.fromEntries( | ||
Array.from({ length: 1000 }, () => createRandomAccount()), | ||
); | ||
await writeAccountsJson(accounts); | ||
}; | ||
|
||
await main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { randomBytes } from "node:crypto"; | ||
import { readFile } from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { createWalletClient, http, toBytes } from "viem"; | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
import { sepolia } from "viem/chains"; | ||
import { Client } from "@/Client"; | ||
|
||
export const createUser = (key: string) => { | ||
const account = privateKeyToAccount(key as `0x${string}`); | ||
return { | ||
key, | ||
account, | ||
wallet: createWalletClient({ | ||
account, | ||
chain: sepolia, | ||
transport: http(), | ||
}), | ||
}; | ||
}; | ||
|
||
type User = ReturnType<typeof createUser>; | ||
|
||
export const createSigner = (user: User) => { | ||
return { | ||
getAddress: () => user.account.address, | ||
signMessage: async (message: string) => { | ||
const signature = await user.wallet.signMessage({ | ||
message, | ||
}); | ||
return toBytes(signature); | ||
}, | ||
}; | ||
}; | ||
|
||
export const createRegisteredClient = async (user: User, dbPath?: string) => { | ||
return Client.create(createSigner(user), randomBytes(32), { | ||
env: "local", | ||
dbPath, | ||
}); | ||
}; | ||
|
||
const accountsJsonPath = path.join(import.meta.dirname, "accounts.json"); | ||
const parsedAccounts = JSON.parse( | ||
await readFile(accountsJsonPath, "utf-8"), | ||
) as Record<string, string>; | ||
|
||
type Account = { key: string; address: string }; | ||
const accounts: Account[] = Object.entries(parsedAccounts).map( | ||
([key, address]) => ({ key, address }), | ||
); | ||
|
||
const primaryAccount = accounts.shift() as Account; | ||
|
||
const primaryAccountClient = await createRegisteredClient( | ||
createUser(primaryAccount.key), | ||
"./test.db3", | ||
); | ||
|
||
console.log("Registering accounts..."); | ||
|
||
for (const a of accounts) { | ||
await createRegisteredClient(createUser(a.key)); | ||
} | ||
|
||
const groups = []; | ||
|
||
console.log("Creating groups..."); | ||
|
||
// create a bunch of groups | ||
while (accounts.length > 200) { | ||
const groupsAccounts = accounts.splice(0, 4); | ||
const group = await primaryAccountClient.conversations.newGroup( | ||
groupsAccounts.map((a) => a.address), | ||
); | ||
groups.push(group); | ||
} | ||
|
||
console.log(`Created ${groups.length} groups`); | ||
|
||
console.log(`Sending "gm" message into each group...`); | ||
|
||
for (const group of groups) { | ||
await group.send("gm"); | ||
} | ||
|
||
console.log("Creating DM groups..."); | ||
|
||
const dmGroups = []; | ||
|
||
while (accounts.length > 0) { | ||
const dmGroup = await primaryAccountClient.conversations.newDm( | ||
(accounts.pop() as Account).address, | ||
); | ||
dmGroups.push(dmGroup); | ||
} | ||
|
||
console.log(`Created ${dmGroups.length} DM groups`); | ||
|
||
console.log("Sending 'gm' message into each DM group..."); | ||
|
||
for (const dmGroup of dmGroups) { | ||
await dmGroup.send("gm"); | ||
} | ||
|
||
console.log("Syncing all conversations..."); | ||
|
||
await primaryAccountClient.conversations.syncAll(); | ||
|
||
console.log("Querying DM groups..."); | ||
|
||
const groupConvos = primaryAccountClient.conversations.listGroups(); | ||
const dmConvos = primaryAccountClient.conversations.listDms(); | ||
|
||
console.log(`Found ${dmConvos.length} DM conversations`); | ||
console.log(`Found ${groupConvos.length} group conversations`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.