Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 12, 2024
1 parent 01bb399 commit b8d72f7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion example/src/tests/conversationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test('can find a dm by address', async () => {
const alixDm = await alixClient.conversations.findOrCreateDm(boClient.address)

await boClient.conversations.sync()
const boDm = await boClient.conversations.findDm(alixClient.address)
const boDm = await boClient.conversations.findDmByAddress(alixClient.address)

assert(
boDm?.id === alixDm.id,
Expand Down
8 changes: 4 additions & 4 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1482,16 +1482,16 @@ test('only streams groups that can be decrypted', async () => {

await alixClient.conversations.stream(async (group: Conversation<any>) => {
alixGroups.push(group)
}, 'groups')
})
await boClient.conversations.stream(async (group: Conversation<any>) => {
boGroups.push(group)
}, 'groups')
})
await caroClient.conversations.stream(async (group: Conversation<any>) => {
caroGroups.push(group)
}, 'groups')
})

await alixClient.conversations.newGroup([boClient.address])

await delayToPropogate()
assert(
alixGroups.length === 1,
`alix group length should be 1 but was ${alixGroups.length}`
Expand Down
36 changes: 24 additions & 12 deletions example/src/types/typeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {
Client,
ContentTypeId,
ConversationVersion,
Dm,
EncodedContent,
JSContentCodec,
ReactionCodec,
ReplyCodec,
sendMessage,
TextCodec,
} from 'xmtp-react-native-sdk'

Expand Down Expand Up @@ -52,7 +54,14 @@ class NumberCodec implements JSContentCodec<NumberRef> {
}

export const typeTests = async () => {
const textClient = await Client.createRandom<[TextCodec]>({ env: 'local' })
const keyBytes = new Uint8Array([
233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64,
166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145,
])
const textClient = await Client.createRandom<[TextCodec]>({
env: 'local',
dbEncryptionKey: keyBytes,
})
const textConvo = (await textClient.conversations.list())[0]
await textConvo.send({ text: 'hello' })
await textConvo.send('hello')
Expand All @@ -63,6 +72,7 @@ export const typeTests = async () => {

const textConvo2 = new Dm(textClient, {
createdAt: 123,
// @ts-expect-error
topic: 'sdf',
peerAddress: 'sdf',
version: 'sdf',
Expand All @@ -73,15 +83,14 @@ export const typeTests = async () => {
await textConvo2.send(12312312)
// @ts-expect-error
await textConvo2.send({ wrong: 'hello' })
await sendMessage<[TextCodec]>('0x1234', 'topic', { text: 'hello' })
await sendMessage<[TextCodec]>('0x1234', 'topic', 'hello')
// @ts-expect-error
await sendMessage<[TextCodec]>('0x1234', 'topic', 12314)

const supportedCodecs = [new ReactionCodec()]
const reactionClient = await Client.createRandom<typeof supportedCodecs>({
codecs: supportedCodecs,
env: 'local',
dbEncryptionKey: keyBytes,
})
const reactionConvo = (await reactionClient.conversations.list())[0]
await reactionConvo.send({
Expand Down Expand Up @@ -111,13 +120,14 @@ export const typeTests = async () => {
await reactionConvo.send({
text: 'text',
})
const keyBundle = await reactionClient.exportKeyBundle()
const keyBundleReactionClient = await Client.createFromKeyBundle<
typeof supportedCodecs
>(keyBundle, {
codecs: supportedCodecs,
env: 'local',
})
const keyBundleReactionClient = await Client.build<typeof supportedCodecs>(
reactionClient.address,
{
codecs: supportedCodecs,
env: 'local',
dbEncryptionKey: keyBytes,
}
)
const reactionKeyBundleConvo = (
await keyBundleReactionClient.conversations.list()
)[0]
Expand Down Expand Up @@ -150,6 +160,7 @@ export const typeTests = async () => {
const customContentClient = await Client.createRandom({
env: 'local',
codecs: [new NumberCodec()],
dbEncryptionKey: keyBytes,
})
const customContentConvo = (await customContentClient.conversations.list())[0]

Expand Down Expand Up @@ -183,6 +194,7 @@ export const typeTests = async () => {
const replyClient = await Client.createRandom<typeof supportedReplyCodecs>({
codecs: supportedReplyCodecs,
env: 'local',
dbEncryptionKey: keyBytes,
})

const replyConvo = (await replyClient.conversations.list())[0]
Expand Down Expand Up @@ -240,8 +252,9 @@ export const typeTests = async () => {
const convoClient = await Client.createRandom({
env: 'local',
codecs: [new NumberCodec()],
dbEncryptionKey: keyBytes,
})
const convos = await convoClient.conversations.listConversations()
const convos = await convoClient.conversations.list()
const firstConvo = convos[0]
if (firstConvo.version === ConversationVersion.GROUP) {
const groupName = firstConvo.name
Expand All @@ -252,7 +265,6 @@ export const typeTests = async () => {
// @ts-expect-error
const groupName = firstConvo.name
} else {
const peerAddress = firstConvo.peerAddress
// @ts-expect-error
const peerAddress2 = firstConvo.peerInboxId()
}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/Conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ export default class Conversations<
*
* @returns {Promise<Dm>} A Promise that resolves to a Dm or undefined if not found.
*/
async findDm(address: Address): Promise<Dm<ContentTypes> | undefined> {
return await XMTPModule.findDm(this.client, address)
async findDmByAddress(
address: Address
): Promise<Dm<ContentTypes> | undefined> {
return await XMTPModule.findDmByAddress(this.client, address)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Dm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Dm<ContentTypes extends DefaultContentTypes = DefaultContentTypes>
* @returns {Promise<InboxId>} A Promise that resolves to a InboxId.
*/
async peerInboxId(): Promise<InboxId> {
return XMTP.listPeerInboxId(this.client, this.id)
return XMTP.dmPeerInboxId(this.client, this.id)
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ export class Group<
content = { text: content }
}

return await XMTP.sendMessage(
this.client.inboxId,
this.id,
content
)
return await XMTP.sendMessage(this.client.inboxId, this.id, content)
} catch (e) {
console.info('ERROR in send()', e.message)
throw e
Expand Down
2 changes: 0 additions & 2 deletions src/lib/Signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export function getSigner(wallet: Signer | WalletClient | null): Signer | null {
if (!wallet) {
return null
}
console.log("Lopi444")

if (isWalletClient(wallet)) {
return convertWalletClientToSigner(wallet)
}
Expand Down

0 comments on commit b8d72f7

Please sign in to comment.