diff --git a/.env.example b/.env.example index b6e6d94eec..080e3274c2 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ PRIVATE_KEY= TEST_ACCOUNT= -TEST_APP= +TEST_APP=0x6F6AC764c218C57a509De5E05013EEdA8c9264E0 diff --git a/packages/client/src/actions/account.test.ts b/packages/client/src/actions/account.test.ts index 34b2477bad..4aecdd926f 100644 --- a/packages/client/src/actions/account.test.ts +++ b/packages/client/src/actions/account.test.ts @@ -1,15 +1,11 @@ -import { testnet } from '@lens-protocol/env'; import { assertOk, evmAddress } from '@lens-protocol/types'; import { describe, it } from 'vitest'; -import { PublicClient } from '../clients'; +import { createPublicClient } from '../test-utils'; import { fetchAccount } from './account'; describe('Given the Account query actions', () => { - const client = PublicClient.create({ - environment: testnet, - origin: 'http://example.com', - }); + const client = createPublicClient(); describe(`When invoking the '${fetchAccount.name}' action`, () => { it('Then it should not fail w/ a GQL BadRequest error', async () => { diff --git a/packages/client/src/actions/post.test.ts b/packages/client/src/actions/post.test.ts index ffa5ae205e..b83400ff7d 100644 --- a/packages/client/src/actions/post.test.ts +++ b/packages/client/src/actions/post.test.ts @@ -1,32 +1,17 @@ -import { testnet } from '@lens-protocol/env'; -import { assertOk, evmAddress, uri } from '@lens-protocol/types'; -import { privateKeyToAccount } from 'viem/accounts'; +import { assertOk, uri } from '@lens-protocol/types'; import { describe, expect, it } from 'vitest'; -import { PublicClient } from '../clients'; +import { loginAsAccountOwner } from '../test-utils'; import { post } from './post'; -const signer = privateKeyToAccount(import.meta.env.PRIVATE_KEY); -const owner = evmAddress(signer.address); -const app = evmAddress(import.meta.env.TEST_APP); -const account = evmAddress(import.meta.env.TEST_ACCOUNT); - -const client = PublicClient.create({ - environment: testnet, - origin: 'http://example.com', -}); - describe(`Given the '${post.name}' action`, () => { describe('When creating a Post', () => { it('Then it should return the expected TransactionRequest', async () => { - const authenticated = await client.login({ - accountOwner: { account, app, owner }, - signMessage: (message) => signer.signMessage({ message }), - }); - - const result = await post(authenticated._unsafeUnwrap(), { - contentUri: uri('https://example.com'), - }); + const result = await loginAsAccountOwner().andThen((sessionClient) => + post(sessionClient, { + contentUri: uri('https://example.com'), + }), + ); assertOk(result); expect(result.value).toMatchObject({ diff --git a/packages/client/src/actions/posts.test.ts b/packages/client/src/actions/posts.test.ts index 3553d64cff..dcc82a2136 100644 --- a/packages/client/src/actions/posts.test.ts +++ b/packages/client/src/actions/posts.test.ts @@ -1,15 +1,11 @@ -import { testnet } from '@lens-protocol/env'; import { assertOk, postId } from '@lens-protocol/types'; import { describe, it } from 'vitest'; -import { PublicClient } from '../clients'; +import { createPublicClient } from '../test-utils'; import { fetchPost } from './posts'; describe('Given the Post query actions', () => { - const client = PublicClient.create({ - environment: testnet, - origin: 'http://example.com', - }); + const client = createPublicClient(); describe(`When invoking the '${fetchPost.name}' action`, () => { it('Then it should not fail w/ a GQL BadRequest error', async () => { diff --git a/packages/client/src/ethers/ethers.test.ts b/packages/client/src/ethers/ethers.test.ts index 03cf70bbcf..569173acca 100644 --- a/packages/client/src/ethers/ethers.test.ts +++ b/packages/client/src/ethers/ethers.test.ts @@ -1,39 +1,25 @@ -import { testnet } from '@lens-protocol/env'; import { describe, it } from 'vitest'; -import { assertOk, evmAddress, uri } from '@lens-protocol/types'; +import { assertOk, uri } from '@lens-protocol/types'; import { post } from '../actions/post'; -import { PublicClient } from '../clients'; import { handleOperationWith } from './signer'; import { Network, Wallet, getDefaultProvider } from '@lens-network/sdk/ethers'; +import { loginAsAccountOwner } from '../test-utils'; // biome-ignore lint/suspicious/noExplicitAny: needs a fix in @lens-network/sdk const wallet = new Wallet(import.meta.env.PRIVATE_KEY, getDefaultProvider(Network.Testnet) as any); -const owner = evmAddress(wallet.address); -const app = evmAddress(import.meta.env.TEST_APP); -const account = evmAddress(import.meta.env.TEST_ACCOUNT); - -const publicClient = PublicClient.create({ - environment: testnet, - origin: 'http://example.com', -}); - describe('Given an integration with ethers.js', () => { describe('When handling transaction actions', () => { it('Then it should be possible to chain them with other helpers', async () => { - const authenticated = await publicClient.login({ - accountOwner: { account, app, owner }, - signMessage: (message: string) => wallet.signMessage(message), - }); - const sessionClient = authenticated._unsafeUnwrap(); - - const result = await post(sessionClient, { - contentUri: uri('https://devnet.irys.xyz/3n3Ujg3jPBHX58MPPqYXBSQtPhTgrcTk4RedJgV1Ejhb'), - }) - .andThen(handleOperationWith(wallet)) - .andThen(sessionClient.waitForTransaction); + const result = await loginAsAccountOwner().andThen((sessionClient) => + post(sessionClient, { + contentUri: uri('https://devnet.irys.xyz/3n3Ujg3jPBHX58MPPqYXBSQtPhTgrcTk4RedJgV1Ejhb'), + }) + .andThen(handleOperationWith(wallet)) + .andThen(sessionClient.waitForTransaction), + ); assertOk(result); }); diff --git a/packages/client/src/test-utils.ts b/packages/client/src/test-utils.ts index 56aadfc6fc..cc1f0bd80c 100644 --- a/packages/client/src/test-utils.ts +++ b/packages/client/src/test-utils.ts @@ -6,7 +6,7 @@ import { evmAddress } from '@lens-protocol/types'; import { http, type Account, type Transport, type WalletClient, createWalletClient } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; -import { GraphQLErrorCode, PublicClient, testnet as apiEnv } from '.'; +import { GraphQLErrorCode, PublicClient, staging as apiEnv } from '.'; const pk = privateKeyToAccount(import.meta.env.PRIVATE_KEY); export const account = evmAddress(import.meta.env.TEST_ACCOUNT); diff --git a/packages/client/src/viem/viem.test.ts b/packages/client/src/viem/viem.test.ts index e58ece3c2b..cfa257b5f5 100644 --- a/packages/client/src/viem/viem.test.ts +++ b/packages/client/src/viem/viem.test.ts @@ -1,13 +1,12 @@ -import { testnet } from '@lens-protocol/env'; import { describe, expect, it } from 'vitest'; import { chains } from '@lens-network/sdk/viem'; -import { evmAddress, uri } from '@lens-protocol/types'; +import { uri } from '@lens-protocol/types'; import { http, createWalletClient } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { handleOperationWith } from '.'; import { post } from '../actions/post'; -import { PublicClient } from '../clients'; +import { loginAsAccountOwner } from '../test-utils'; const walletClient = createWalletClient({ account: privateKeyToAccount(import.meta.env.PRIVATE_KEY), @@ -15,29 +14,16 @@ const walletClient = createWalletClient({ transport: http(), }); -const owner = evmAddress(walletClient.account.address); -const app = evmAddress(import.meta.env.TEST_APP); -const account = evmAddress(import.meta.env.TEST_ACCOUNT); - -const publicClient = PublicClient.create({ - environment: testnet, - origin: 'http://example.com', -}); - describe('Given an integration with viem', { timeout: 10000 }, () => { describe('When handling transaction actions', () => { it('Then it should be possible to chain them with other helpers', async () => { - const authenticated = await publicClient.login({ - accountOwner: { account, app, owner }, - signMessage: (message: string) => walletClient.signMessage({ message }), - }); - const sessionClient = authenticated._unsafeUnwrap(); - - const result = await post(sessionClient, { - contentUri: uri('https://devnet.irys.xyz/3n3Ujg3jPBHX58MPPqYXBSQtPhTgrcTk4RedJgV1Ejhb'), - }) - .andThen(handleOperationWith(walletClient)) - .andThen(sessionClient.waitForTransaction); + const result = await loginAsAccountOwner().andThen((sessionClient) => + post(sessionClient, { + contentUri: uri('https://devnet.irys.xyz/3n3Ujg3jPBHX58MPPqYXBSQtPhTgrcTk4RedJgV1Ejhb'), + }) + .andThen(handleOperationWith(walletClient)) + .andThen(sessionClient.waitForTransaction), + ); expect(result.isOk(), result.isErr() ? result.error.message : undefined).toBe(true); }); diff --git a/packages/graphql/src/fragments/primitives.ts b/packages/graphql/src/fragments/primitives.ts index 9d6d8ca8a1..cd2e90e30c 100644 --- a/packages/graphql/src/fragments/primitives.ts +++ b/packages/graphql/src/fragments/primitives.ts @@ -342,12 +342,7 @@ export const NamespaceOperationValidationFailedFragment = graphql( `fragment NamespaceOperationValidationFailed on NamespaceOperationValidationFailed { __typename unsatisfiedRules { - required { - ...NamespaceUnsatisfiedRules - } - anyOf { - ...NamespaceUnsatisfiedRules - } + ...NamespaceUnsatisfiedRules } reason }`,