Skip to content

Commit

Permalink
fix: some unit tests, env and fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi committed Feb 6, 2025
1 parent 60cb3b8 commit 6a574ee
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PRIVATE_KEY=<private_key>
TEST_ACCOUNT=<lens_account_owned_by_private_key>
TEST_APP=<a_lens_app>
TEST_APP=0x6F6AC764c218C57a509De5E05013EEdA8c9264E0
8 changes: 2 additions & 6 deletions packages/client/src/actions/account.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
29 changes: 7 additions & 22 deletions packages/client/src/actions/post.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
8 changes: 2 additions & 6 deletions packages/client/src/actions/posts.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
32 changes: 9 additions & 23 deletions packages/client/src/ethers/ethers.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 9 additions & 23 deletions packages/client/src/viem/viem.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
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),
chain: chains.testnet,
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);
});
Expand Down
7 changes: 1 addition & 6 deletions packages/graphql/src/fragments/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,7 @@ export const NamespaceOperationValidationFailedFragment = graphql(
`fragment NamespaceOperationValidationFailed on NamespaceOperationValidationFailed {
__typename
unsatisfiedRules {
required {
...NamespaceUnsatisfiedRules
}
anyOf {
...NamespaceUnsatisfiedRules
}
...NamespaceUnsatisfiedRules
}
reason
}`,
Expand Down

0 comments on commit 6a574ee

Please sign in to comment.