Skip to content

Commit

Permalink
Merge pull request #913 from lens-protocol/chore/re-enable-gated-tests
Browse files Browse the repository at this point in the history
chore: re-enable skipped test for Amoy release
  • Loading branch information
cesarenaldi authored Apr 17, 2024
2 parents a27d2b4 + 97a4088 commit cccb264
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 130 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ jobs:
- name: Run tests
run: pnpm test
env:
SDK_GATED_TEST_PK: ${{secrets.SDK_GATED_TEST_PK}}
SDK_GATED_TEST_PROFILE_ID: ${{secrets.SDK_GATED_TEST_PROFILE_ID}}
SDK_GATED_TEST_PUBLICATION_ID: ${{secrets.SDK_GATED_TEST_PUBLICATION_ID}}
TESTING_ENV_URL: ${{secrets.TESTING_ENV_URL}}
TESTING_HEADER_KEY: ${{secrets.TESTING_HEADER_KEY}}
TESTING_HEADER_VALUE: ${{secrets.TESTING_HEADER_VALUE}}
TESTING_NO_RATE_LIMIT: ${{secrets.TESTING_NO_RATE_LIMIT}}
TESTING_WHITELISTED: ${{secrets.TESTING_WHITELISTED}}

build:
name: Build
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/__helpers__/buildTestEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ dotenv.config();
export const buildTestEnvironment = (): Environment => {
invariant(process.env.TESTING_ENV_URL, 'TESTING_ENV_URL is not defined in .env file');

return new Environment('testing', process.env.TESTING_ENV_URL, GatedEnvironments.development);
return new Environment('testing', process.env.TESTING_ENV_URL, GatedEnvironments.testing);
};
10 changes: 0 additions & 10 deletions packages/client/src/__helpers__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,3 @@ export async function postOnchainViaLensManager(

return publication;
}

export async function collect(client: LensClient, publicationId: string) {
const result = await client.publication.actions.actOn({
actOn: { simpleCollectOpenAction: true },
for: publicationId,
});
const value = result.unwrap();
invariant(isRelaySuccess(value), `Broadcast failed: ${JSON.stringify(value)}`);
await client.transaction.waitUntilComplete({ forTxId: value.txId });
}
26 changes: 0 additions & 26 deletions packages/client/src/__mocks__/graphql-request.ts

This file was deleted.

11 changes: 11 additions & 0 deletions packages/client/src/gated/__helpers/setup.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { Wallet } from '@ethersproject/wallet';
import { invariant } from '@lens-protocol/shared-kernel';
import * as dotenv from 'dotenv';

import { buildTestEnvironment } from '../../__helpers__';
import { LensClient } from '../LensClient';

dotenv.config();

export function createGatedLensClient(signer: Wallet) {
invariant(process.env.TESTING_NO_RATE_LIMIT, 'TESTING_NO_RATE_LIMIT is not defined in .env file');
invariant(process.env.TESTING_WHITELISTED, 'TESTING_WHITELISTED is not defined in .env file');

return new LensClient({
environment: buildTestEnvironment(),
authentication: {
domain: 'lens.dev',
uri: 'https://lens.dev',
},
headers: {
'x-e2e-lens-no-rl': process.env.TESTING_NO_RATE_LIMIT,
'X-Whitelisted': process.env.TESTING_WHITELISTED,
},
signer,
});
}
85 changes: 6 additions & 79 deletions packages/client/src/gated/__tests__/LensClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { invariant } from '@lens-protocol/shared-kernel';

import {
authenticate,
collect,
createOrGetProfile,
enableLensProfileManager,
postOnchainViaLensManager,
Expand All @@ -19,14 +18,7 @@ jest.retryTimes(3, { logErrorsBeforeRetry: true });

const signer = new Wallet('0xd6e6257e8cf0f321ad0f798dd0b121a7eb4fe9c7c51994e843c0a1ed05867a5f');

const signerWithNoProfile = new Wallet(
'dc377a505ab51735b73656ddfd5abc01fb9d26544b71d9188ecd74c70a22cb6d',
);

/**
* Disabled until Lit team comes back with a solution for Amoy testnet
*/
xdescribe(`Given an instance of "gated.${LensClient.name}"`, () => {
describe(`Given an instance of "gated.${LensClient.name}"`, () => {
const initialPostMetadata = metadata.image({
image: {
item: faker.internet.url(),
Expand All @@ -48,8 +40,8 @@ xdescribe(`Given an instance of "gated.${LensClient.name}"`, () => {

await enableLensProfileManager(signer, client, profile);

const condition = metadata.profileOwnershipCondition({
profileId: profile.id,
const condition = metadata.eoaOwnershipCondition({
address: signer.address,
});

const encrypted = await client.gated.encryptPublicationMetadata(
Expand All @@ -60,34 +52,7 @@ xdescribe(`Given an instance of "gated.${LensClient.name}"`, () => {
post = await postOnchainViaLensManager(signer, client, encrypted.unwrap());
}, 60_000);

describe('when decrypted by the publication author', () => {
it('should return the decrypted metadata', async () => {
const client = createGatedLensClient(signer);
const profile = await createOrGetProfile(signer, client, publicationAuthorHandle);

await authenticate(signer, client, profile);

invariant(
isEncryptedPublicationMetadata(post.metadata),
'Metadata is not encrypted. This is likely an API issue.',
);

const decrypted = await client.gated.decryptPublicationMetadataFragment(post.metadata);

expect(decrypted.unwrap()).toMatchObject({
asset: {
image: {
raw: {
uri: initialPostMetadata.lens.image.item,
},
},
},
content: initialPostMetadata.lens.content,
});
}, 60_000);
});

describe('when decrypted by just a wallet that meets the token-gated conditions', () => {
describe('when decrypted by a wallet that meets the token-gated conditions', () => {
it('should return the decrypted metadata', async () => {
const authenticatedWithOnlyWalletClient = createGatedLensClient(signer);

Expand Down Expand Up @@ -116,9 +81,9 @@ xdescribe(`Given an instance of "gated.${LensClient.name}"`, () => {
});
});

describe('when decrypted by just a wallet that does not meet the token-gated conditions', () => {
describe('when decrypted by a wallet that does NOT meet the token-gated conditions', () => {
it(`should throw a ${CannotDecryptError.name} error`, async () => {
const authenticatedWithOnlyWalletClient = createGatedLensClient(signerWithNoProfile);
const authenticatedWithOnlyWalletClient = createGatedLensClient(Wallet.createRandom());

await authenticate(signer, authenticatedWithOnlyWalletClient);

Expand All @@ -140,42 +105,4 @@ xdescribe(`Given an instance of "gated.${LensClient.name}"`, () => {
});
});
});

describe('and a token-gated post with collect conditions', () => {
// TODO complete once collect is fixed at the API level
it.skip('should be decryptable via the collect condition', async () => {
const client = createGatedLensClient(signer);
const profile = await createOrGetProfile(signer, client, publicationAuthorHandle);

const condition = metadata.collectCondition({
publicationId: await client.publication.predictNextOnChainPublicationId({
from: profile.id,
}),
thisPublication: true,
});
const encrypted = await client.gated.encryptPublicationMetadata(
initialPostMetadata,
condition,
);

const post = await postOnchainViaLensManager(signer, client, encrypted.unwrap());

const collector = await createOrGetProfile(signer, client, 'bobthebuilder2');

await authenticate(signer, client, collector);
await enableLensProfileManager(signer, client, collector);
await collect(client, post.id);

// invariant(
// isEncryptedPublicationMetadata(post.metadata),
// 'Metadata is not encrypted. This is likely an API issue.',
// );

// const decrypted = await client.gated.decryptPublicationMetadataFragment(post.metadata);

// expect(decrypted.unwrap()).toMatchObject({
// content: initial.lens.content,
// });
}, 60_000);
});
});
5 changes: 3 additions & 2 deletions packages/gated-content/src/GatedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ export class GatedClient {
case 'TransactionMetadataV3':
case 'VideoMetadataV3':
return new PublicationMetadataDecryptor(cipher).decrypt(encryptedMetadata);
}

assertNever(encryptedMetadata, `Not supported metadata type`);
default:
assertNever(encryptedMetadata, `Not supported metadata type`);
}
}

private async getOrCreateAuthSig(): Promise<JsonAuthSig> {
Expand Down
10 changes: 4 additions & 6 deletions packages/gated-content/src/__tests__/GatedClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
mockProfileOwnershipCondition,
mockPublicationMetadata,
} from '../__helpers__/mocks';
import { development } from '../environments';
import { testing } from '../environments';
import { EncryptedFragmentOfAnyPublicationMetadata } from '../graphql';
import * as gql from '../graphql/__helpers__/mocks';
import { webCryptoProvider } from '../web';
Expand All @@ -34,24 +34,22 @@ function setupTestScenario() {
uri: 'https://localhost/login',
},
signer,
environment: development,
environment: testing,
storageProvider: new InMemoryStorageProvider(),
encryptionProvider: webCryptoProvider(),
});

return { client };
}

const rawAccessCondition: raw.AccessCondition = raw.orCondition([
mockProfileOwnershipCondition({ profileId: ownerId }),
mockEoaOwnershipCondition({
address: knownAddress,
}),
]);

/**
* Disabled until Lit team comes back with a solution for Amoy testnet
*/
xdescribe(`Given an instance of the ${GatedClient.name}`, () => {
describe(`Given an instance of the ${GatedClient.name}`, () => {
describe(`when calling the "${GatedClient.prototype.encryptPublicationMetadata.name}" method`, () => {
it(`should return the expected raw PublicationMetadata`, async () => {
const { client } = setupTestScenario();
Expand Down
2 changes: 1 addition & 1 deletion packages/gated-content/src/conditions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ function toRawSimpleCondition(gqlCondition: gql.ThirdTierCondition): raw.SimpleC
default:
assertNever(gqlCondition.contractType, 'Unknown NFT contract type');
}
break;

// eslint-disable-next-line no-fallthrough
case 'CollectCondition':
return raw.collectCondition({
publicationId: gqlCondition.publicationId,
Expand Down
6 changes: 6 additions & 0 deletions packages/gated-content/src/conditions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export enum LitContractType {
export enum SupportedChains {
ETHEREUM = 'ethereum',
POLYGON = 'polygon',
/**
* @deprecated Mumbai is no longer supported.
*/
MUMBAI = 'mumbai',
AMOY = 'amoy',
LINEA_GOERLI = 'lineaGoerli',
Expand All @@ -54,6 +57,9 @@ export enum SupportedChains {
export enum SupportedChainId {
ETHEREUM = 1,
POLYGON = 137,
/**
* @deprecated Mumbai is no longer supported.
*/
MUMBAI = 80001,
AMOY = 80002,
LINEA_GOERLI = 59140,
Expand Down
14 changes: 14 additions & 0 deletions packages/gated-content/src/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ export const development: EnvironmentConfig = {
chainId: SupportedChainId.AMOY,
},
};

/**
* We are using Polygon since Mumbai is no longer supported.
* This seems to not affect tests automation, but it's worth noting.
*/
export const testing: EnvironmentConfig = {
name: 'development',
chainId: 137,
chainName: SupportedChains.POLYGON,
accessControlContract: {
address: '0x98a6C31E43b158198da95Ef1242faCA868424187',
chainId: SupportedChainId.POLYGON,
},
};

0 comments on commit cccb264

Please sign in to comment.