Skip to content

Commit

Permalink
Merge pull request #304 from xmtp/cv/test-list-2000-accounts
Browse files Browse the repository at this point in the history
Adds test for listing conversations from env variable account
  • Loading branch information
cameronvoell authored Mar 11, 2024
2 parents 676d227 + 9d500a7 commit aced04a
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 13 deletions.
1 change: 1 addition & 0 deletions example/EXAMPLE.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TEST_PRIVATE_KEY=INSERT_TEST_PRIVATE_KEY_HERE
THIRD_WEB_CLIENT_ID=INSERT_CLIENT_ID_HERE
19 changes: 10 additions & 9 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PODS:
- hermes-engine/Pre-built (= 0.71.14)
- hermes-engine/Pre-built (0.71.14)
- libevent (2.1.12)
- LibXMTP (0.4.2-beta5)
- LibXMTP (0.4.3-beta1)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.3):
Expand Down Expand Up @@ -344,7 +344,8 @@ PODS:
- RCTTypeSafety
- React-Core
- ReactCommon/turbomodule/core
- react-native-webview (12.1.0):
- react-native-webview (13.8.1):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- React-perflogger (0.71.14)
- React-RCTActionSheet (0.71.14):
Expand Down Expand Up @@ -444,16 +445,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.8.16):
- XMTP (0.9.0):
- Connect-Swift (= 0.3.0)
- GzipSwift
- LibXMTP (= 0.4.2-beta5)
- LibXMTP (= 0.4.3-beta1)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.8.16)
- XMTP (= 0.9.0)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -700,7 +701,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: 3cbd1d0dd44ae3648f571a0e81bbe73565759e67
LibXMTP: ddfcde5d4c9b3baa34b038956a7aad46e1da6391
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: f902fb6719da13c2ab0965233d8963a59416f911
Expand Down Expand Up @@ -730,7 +731,7 @@ SPEC CHECKSUMS:
react-native-quick-crypto: 455c1b411db006dba1026a30681ececb19180187
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
react-native-safe-area-context: 39c2d8be3328df5d437ac1700f4f3a4f75716acc
react-native-webview: 13db17f7c7fe8f91c826e9afcc369cbc74507ea0
react-native-webview: bdc091de8cf7f8397653e30182efcd9f772e03b3
React-perflogger: 4987ad83731c23d11813c84263963b0d3028c966
React-RCTActionSheet: 5ad952b2a9740d87a5bd77280c4bc23f6f89ea0c
React-RCTAnimation: d2de22af3f536cc80bb5b3918e1a455114d1b985
Expand All @@ -750,8 +751,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 3de1abbf9cc64d277e8ab5d16509813658524994
XMTPReactNative: 8746d61225e2e521a76cf626058625f1eb417ed9
XMTP: f539ad61202ae67ed813f2dd756875c31ce9a677
XMTPReactNative: 845b4760d768d2971e478c46f80d4302de90b6a4
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2
Expand Down
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"react-native-webview-crypto": "^0.0.25",
"react-query": "^3.39.3",
"stream-browserify": "^3.0.0",
"text-encoding": "^0.7.0"
"text-encoding": "^0.7.0",
"viem": "^2.7.22"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
68 changes: 68 additions & 0 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { FramesClient } from '@xmtp/frames-client'
import { content } from '@xmtp/proto'
import { createHmac } from 'crypto'
import ReactNativeBlobUtil from 'react-native-blob-util'
import Config from 'react-native-config'
import { TextEncoder, TextDecoder } from 'text-encoding'
import { PrivateKeyAccount } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage'

import {
Expand All @@ -13,6 +16,7 @@ import {
StaticAttachmentCodec,
RemoteAttachmentCodec,
RemoteAttachmentContent,
Signer,
} from '../../src/index'

type EncodedContent = content.EncodedContent
Expand Down Expand Up @@ -167,6 +171,70 @@ test('can make a client', async () => {
return client.address.length > 0
})

export function convertPrivateKeyAccountToSigner(
privateKeyAccount: PrivateKeyAccount
): Signer {
if (!privateKeyAccount.address) {
throw new Error('WalletClient is not configured')
}

return {
getAddress: async () => privateKeyAccount.address,
signMessage: async (message: string | Uint8Array) =>
privateKeyAccount.signMessage({
message: typeof message === 'string' ? message : { raw: message },
}),
}
}

test('can load a client from env "2k lens convos" private key', async () => {
if (!Config.TEST_PRIVATE_KEY) {
throw new Error('Add private key to .env file')
}
const privateKeyHex: `0x${string}` = `0x${Config.TEST_PRIVATE_KEY}`

const signer = convertPrivateKeyAccountToSigner(
privateKeyToAccount(privateKeyHex)
)
const xmtpClient = await Client.create(signer, {
env: 'local',
})

assert(
xmtpClient.address === '0x209fAEc92D9B072f3E03d6115002d6652ef563cd',
'Address: ' + xmtpClient.address
)
return true
})

test('can load 1995 conversations from dev network "2k lens convos" account', async () => {
if (!Config.TEST_PRIVATE_KEY) {
throw new Error('Add private key to .env file')
}

const privateKeyHex: `0x${string}` = `0x${Config.TEST_PRIVATE_KEY}`

const signer = convertPrivateKeyAccountToSigner(
privateKeyToAccount(privateKeyHex)
)
const xmtpClient = await Client.create(signer, {
env: 'dev',
})

assert(
xmtpClient.address === '0x209fAEc92D9B072f3E03d6115002d6652ef563cd',
'Address: ' + xmtpClient.address
)

const conversations = await xmtpClient.conversations.list()
assert(
conversations.length === 1995,
'Conversations: ' + conversations.length
)

return true
})

test('can pass a custom filter date and receive message objects with expected dates', async () => {
try {
const bob = await Client.createRandom({ env: 'local' })
Expand Down
1 change: 1 addition & 0 deletions example/src/types/react-native-config.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare module 'react-native-config' {
export interface NativeConfig {
THIRD_WEB_CLIENT_ID?: string
TEST_PRIVATE_KEY?: string
}

export const Config: NativeConfig
Expand Down
59 changes: 57 additions & 2 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
resolved "https://registry.npmjs.org/@account-abstraction/contracts/-/contracts-0.5.0.tgz"
integrity sha512-CKyS9Zh5rcYUM+4B6TlaB9+THHzJ+6TY3tWF5QofqvFpqGNvIhF8ddy6wyCmqZw6TB74/yYv7cYD/RarVudfDg==

"@adraffy/[email protected]":
version "1.10.0"
resolved "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz#d2a39395c587e092d77cbbc80acf956a54f38bf7"
integrity sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==

"@ampproject/remapping@^2.2.0":
version "2.2.1"
resolved "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz"
Expand Down Expand Up @@ -5068,6 +5073,13 @@
dependencies:
"@noble/hashes" "1.3.1"

"@noble/[email protected]", "@noble/curves@~1.2.0":
version "1.2.0"
resolved "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
dependencies:
"@noble/hashes" "1.3.2"

"@noble/curves@^1.2.0":
version "1.3.0"
resolved "https://registry.npmjs.org/@noble/curves/-/curves-1.3.0.tgz"
Expand All @@ -5080,7 +5092,12 @@
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz"
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==

"@noble/[email protected]", "@noble/hashes@^1.3.2", "@noble/hashes@^1.3.3", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1":
"@noble/[email protected]":
version "1.3.2"
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==

"@noble/[email protected]", "@noble/hashes@^1.3.2", "@noble/hashes@^1.3.3", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1", "@noble/hashes@~1.3.2":
version "1.3.3"
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz"
integrity sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==
Expand Down Expand Up @@ -5626,7 +5643,7 @@
"@safe-global/safe-core-sdk-utils" "^1.7.4"
ethers "5.7.2"

"@scure/base@~1.1.0":
"@scure/base@~1.1.0", "@scure/base@~1.1.2":
version "1.1.5"
resolved "https://registry.npmjs.org/@scure/base/-/base-1.1.5.tgz"
integrity sha512-Brj9FiG2W1MRQSTB212YVPRrcbjkv48FoZi/u4l/zds/ieRrqsh7aUf6CLwkAq61oKXr/ZlTzlY66gLIj3TFTQ==
Expand All @@ -5640,6 +5657,15 @@
"@noble/hashes" "~1.3.1"
"@scure/base" "~1.1.0"

"@scure/[email protected]":
version "1.3.2"
resolved "https://registry.npmjs.org/@scure/bip32/-/bip32-1.3.2.tgz#90e78c027d5e30f0b22c1f8d50ff12f3fb7559f8"
integrity sha512-N1ZhksgwD3OBlwTv3R6KFEcPojl/W4ElJOeCZdi+vuI5QmTFwLq3OFf2zd2ROpKvxFdgZ6hUpb0dx9bVNEwYCA==
dependencies:
"@noble/curves" "~1.2.0"
"@noble/hashes" "~1.3.2"
"@scure/base" "~1.1.2"

"@scure/[email protected]":
version "1.2.1"
resolved "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.1.tgz"
Expand Down Expand Up @@ -6825,6 +6851,11 @@ JSONStream@^1.3.5:
jsonparse "^1.2.0"
through ">=2.2.7 <3"

[email protected]:
version "1.0.0"
resolved "https://registry.npmjs.org/abitype/-/abitype-1.0.0.tgz#237176dace81d90d018bebf3a45cb42f2a2d9e97"
integrity sha512-NMeMah//6bJ56H5XRj8QCV4AwuW6hB6zqz2LnhhLdcWVQOsXki6/Pn3APeqxCma62nXIcmZWdu1DlHWS74umVQ==

abitype@^0.2.5:
version "0.2.5"
resolved "https://registry.npmjs.org/abitype/-/abitype-0.2.5.tgz"
Expand Down Expand Up @@ -10859,6 +10890,11 @@ isomorphic-ws@^4.0.1:
resolved "https://registry.npmjs.org/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz"
integrity sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w==

[email protected]:
version "1.0.3"
resolved "https://registry.npmjs.org/isows/-/isows-1.0.3.tgz#93c1cf0575daf56e7120bab5c8c448b0809d0d74"
integrity sha512-2cKei4vlmg2cxEjm3wVSqn8pcoRF/LX/wpifuuNquFO4SQmPwarClT+SUCA2lt+l581tTeZIPIZuIDo2jWN1fg==

iterator.prototype@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.2.tgz"
Expand Down Expand Up @@ -15393,6 +15429,20 @@ vary@~1.1.2:
resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==

viem@^2.7.22:
version "2.7.22"
resolved "https://registry.npmjs.org/viem/-/viem-2.7.22.tgz#b6991b73f348d8e3a151f4acea08fddfdc449805"
integrity sha512-R/d9AkWXkhiNF4Gk4/A389LSO5PGDdHUBFDKIUkhrdLTDpOhKzbNln6qDry3kYUcmH7lErx3C2eA6rajnc0s9A==
dependencies:
"@adraffy/ens-normalize" "1.10.0"
"@noble/curves" "1.2.0"
"@noble/hashes" "1.3.2"
"@scure/bip32" "1.3.2"
"@scure/bip39" "1.2.1"
abitype "1.0.0"
isows "1.0.3"
ws "8.13.0"

vlq@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/vlq/-/vlq-1.0.1.tgz"
Expand Down Expand Up @@ -15825,6 +15875,11 @@ [email protected]:
resolved "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz"
integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==

[email protected]:
version "8.13.0"
resolved "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==

[email protected]:
version "8.9.0"
resolved "https://registry.npmjs.org/ws/-/ws-8.9.0.tgz"
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Pod::Spec.new do |s|
s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.8.17"
s.dependency "XMTP", "= 0.9.0"
end
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export { RemoteAttachmentCodec } from './lib/NativeCodecs/RemoteAttachmentCodec'
export { TextCodec } from './lib/NativeCodecs/TextCodec'
export * from './hooks'
export * from './context'
export * from './lib/Signer'

const EncodedContent = content.EncodedContent

Expand Down

0 comments on commit aced04a

Please sign in to comment.