Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: script to reproduce bug T-11895 #431

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/node/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WALLET_PRIVATE_KEY=272b8d63faac40bfc342bacc4cb9af6f146bdf8c45e2accadeb43846d9fce965
114 changes: 114 additions & 0 deletions examples/node/scripts/paginationBug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import {
LensClient,
isCreateDataAvailabilityPublicationResult,
isPostPublication,
} from "@lens-protocol/client";
import { setupWallet } from "./shared/setupWallet";
import { getAuthenticatedClient } from "./shared/getAuthenticatedClient";
import { getActiveProfile } from "./shared/getActiveProfile";
import { buildPublicationMetadata } from "./shared/buildPublicationMetadata";
import { uploadWithBundlr } from "./shared/uploadWithBundlr";
import { Wallet } from "ethers";

async function addMoreRecentPost(lensClient: LensClient, wallet: Wallet, profileId: string) {
// prepare metadata
const metadata = buildPublicationMetadata({
content: "Data Availability Post created with LensClient SDK",
name: "Data Availability Post created with LensClient SDK",
});

// validate metadata
const validateResult = await lensClient.publication.validateMetadata(metadata);

if (!validateResult.valid) {
throw new Error(`Metadata is not valid.`);
}

// upload metadata to
const contentURI = await uploadWithBundlr(metadata);

// fetch a create DA post typed data
const createPostTypedDataResult =
await lensClient.publication.createDataAvailabilityPostTypedData({
from: profileId,
contentURI,
});

const createPostTypedDataValue = createPostTypedDataResult.unwrap();

// sign with the wallet
const signedTypedData = await wallet._signTypedData(
createPostTypedDataValue.typedData.domain,
createPostTypedDataValue.typedData.types,
createPostTypedDataValue.typedData.value
);

const broadcastResult = await lensClient.transaction.broadcastDataAvailability({
id: createPostTypedDataValue.id,
signature: signedTypedData,
});

// broadcastResult is a Result object
const broadcastValue = broadcastResult.unwrap();

if (!isCreateDataAvailabilityPublicationResult(broadcastValue)) {
return false;
}

console.log("New post created with id:", broadcastValue.id);
return true;
}

async function main() {
const wallet = setupWallet();
const address = await wallet.getAddress();
const lensClient = await getAuthenticatedClient(wallet);
const profile = await getActiveProfile(lensClient, address);
const profileId = profile.id;

const publications = await lensClient.publication.fetchAll({
profileId,
limit: 1,
});

console.log(
`Posts fetched:`,
JSON.stringify(
publications.items.map((i) => ({
id: i.id,
})),
null,
2
)
);

await addMoreRecentPost(lensClient, wallet, profileId);

const previous = await publications.prev();

console.log(
`First call to more recent posts with prev=${previous.pageInfo.prev}:\n`,
JSON.stringify(
previous.items.map((i) => ({
id: i.id,
})),
null,
2
)
);

const secondTry = await publications.prev();

console.log(
`Second call to more recent posts with prev=${previous.pageInfo.prev}:\n`,
JSON.stringify(
secondTry.items.map((i) => ({
id: i.id,
})),
null,
2
)
);
}

main();
Loading