Skip to content

Commit

Permalink
chore: accepting the param values for examples (#279)
Browse files Browse the repository at this point in the history
Co-authored-by: Satyajeet Kolhapure <[email protected]>
  • Loading branch information
satyajeetkolhapure and kolhapuresatyajeet authored Oct 13, 2023
1 parent 0964794 commit 346a981
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 73 deletions.
48 changes: 48 additions & 0 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,54 @@ console.log(result);
//
```

## CLI examples

You can use command lines to test all the implemented SDK methods. Here are some examples.

Note: if your don't pass any parameter (e.g. `pnpm portal findBy`)`, some default values will be used.

### Portal examples

```shell
pnpm portal findby '{\"ownerName\": \"Tester\"}'

pnpm portal findonebyid '0x34798a866f52949208e67fb57ad36244024c50c0'

pnpm portal simulateattest '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayload\" : { \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": \"1693583329\", \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": \"true\" }]}, \"validationPayloads\": []}'

pnpm portal attest '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationPayload\" : { \"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"expirationDate\": \"1693583329\", \"subject\": \"0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47\", \"attestationData\": [{ \"isBuidler\": \"true\" }]}, \"validationPayloads\": []}'

pnpm portal simulaterevoke '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationId\" : \"0x000000000000000000000000000000000000000000000000000000000000109b\" }'

pnpm portal revoke '{\"portalAddress\": \"0x34798a866f52949208e67fb57ad36244024c50c0\", \"attestationId\" : \"0x000000000000000000000000000000000000000000000000000000000000109b\" }'
```

### Attestation examples

```shell
pnpm attestation findonebyid "0x000000000000000000000000000000000000000000000000000000000000109b"

pnpm attestation findby '{\"portal\": \"0x34798a866f52949208e67fb57ad36244024c50c0\"}'

pnpm attestation getRelatedAttestations "0x000000000000000000000000000000000000000000000000000000000000109b"
```

### Module examples

```shell
pnpm module findonebyid "0x4bb8769e18f1518c35be8405d43d7cc07ecf501c"

pnpm module findby '{\"name\": \"Msg Sender Module\"}'
```

### Schema examples

```shell
pnpm schema findonebyid "0xce2647ed39aa89e6d1528a56deb6c30667ed2aae1ec2378ec3140c0c5d98a61e"

pnpm schema findby '{\"description\": \"Gitcoin Passport Score\"}'
```

## Other operations

[Work in progress] The class `veraxSdk.utils` extends the capabilities:
Expand Down
29 changes: 13 additions & 16 deletions sdk/examples/attestation/attestationExamples.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import VeraxSdk from "../../src/VeraxSdk";
import { Attestation } from "../../src/types";

export default class AttestationExamples {
private veraxSdk: VeraxSdk;
Expand All @@ -7,29 +8,25 @@ export default class AttestationExamples {
this.veraxSdk = _veraxSdk;
}

async run(methodName: string = "") {
async run(methodName: string = "", argv: string) {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "") {
console.log(
await this.veraxSdk.attestation.findOneById(
"0x00000000000000000000000000000000000000000000000000000000000007b5",
),
);
const attestationId: string =
argv === "" ? "0x00000000000000000000000000000000000000000000000000000000000007b5" : argv;
console.log(await this.veraxSdk.attestation.findOneById(attestationId));
}

if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "") {
console.log(
await this.veraxSdk.attestation.findBy({
schemaId: "0xd1664d97bd195df77e3d5fe78c1737ab3adaa38bbe52a680d1aa30fa51f186ba",
}),
);
const params: Partial<Attestation> =
argv === ""
? { schemaId: "0xd1664d97bd195df77e3d5fe78c1737ab3adaa38bbe52a680d1aa30fa51f186ba" }
: JSON.parse(argv);
console.log(await this.veraxSdk.attestation.findBy(params));
}

if (methodName.toLowerCase() == "getRelatedAttestations".toLowerCase() || methodName == "") {
console.log(
await this.veraxSdk.attestation.getRelatedAttestations(
"0x0000000000000000000000000000000000000000000000000000000000000001",
),
);
const attestationId: string =
argv === "" ? "0x0000000000000000000000000000000000000000000000000000000000000001" : argv;
console.log(await this.veraxSdk.attestation.getRelatedAttestations(attestationId));
}
}
}
5 changes: 4 additions & 1 deletion sdk/examples/attestation/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import VeraxSdk from "../../src/VeraxSdk";
import AttestationExamples from "./attestationExamples";

let argv: string | null | undefined = process.argv[3] as string;
argv !== null && argv !== undefined ? (argv = argv.replaceAll("\\", "")) : (argv = "");

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);

await new AttestationExamples(veraxSdk).run(process.argv[2]);
await new AttestationExamples(veraxSdk).run(process.argv[2], argv);
5 changes: 4 additions & 1 deletion sdk/examples/module/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import VeraxSdk from "../../src/VeraxSdk";
import ModuleExamples from "./moduleExamples";

let argv: string | null | undefined = process.argv[3] as string;
argv !== null && argv !== undefined ? (argv = argv.replaceAll("\\", "")) : (argv = "");

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);

await new ModuleExamples(veraxSdk).run(process.argv[2]);
await new ModuleExamples(veraxSdk).run(process.argv[2], argv);
15 changes: 10 additions & 5 deletions sdk/examples/module/moduleExamples.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import VeraxSdk from "../../src/VeraxSdk";
import { Module } from "../../src/types";

export default class ModuleExamples {
private veraxSdk: VeraxSdk;
constructor(_veraxSdk: VeraxSdk) {
this.veraxSdk = _veraxSdk;
}
async run(methodName: string = "") {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.module.findOneById("0xf75be6f9418710fd516fa82afb3aad07e11a0f1b"));
async run(methodName: string = "", argv: string) {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "") {
const moduleId: string = argv === "" ? "0xf75be6f9418710fd516fa82afb3aad07e11a0f1b" : argv;
console.log(await this.veraxSdk.module.findOneById(moduleId));
}

if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.module.findBy({ name: "SchemaCheckerModule" }));
if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "") {
const params: Partial<Module> = argv === "" ? { name: "SchemaCheckerModule" } : JSON.parse(argv);
console.log(await this.veraxSdk.module.findBy(params));
}

if (methodName.toLowerCase() == "register" || methodName == "") console.log(await this.veraxSdk.module.register());
}
Expand Down
5 changes: 4 additions & 1 deletion sdk/examples/portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import VeraxSdk from "../../src/VeraxSdk";
import PortalExamples from "./portalExamples";

let argv: string | null | undefined = process.argv[3] as string;
argv !== null && argv !== undefined ? (argv = argv.replaceAll("\\", "")) : (argv = "");

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);

await new PortalExamples(veraxSdk).run(process.argv[2]);
await new PortalExamples(veraxSdk).run(process.argv[2], argv);
94 changes: 53 additions & 41 deletions sdk/examples/portal/portalExamples.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Address } from "viem";
import VeraxSdk from "../../src/VeraxSdk";
import { Portal } from "../../src/types";

export default class PortalExamples {
private veraxSdk: VeraxSdk;
Expand All @@ -7,41 +9,47 @@ export default class PortalExamples {
this.veraxSdk = _veraxSdk;
}

async run(methodName: string = "") {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.findOneById("0x1495341ab1019798dd08976f4a3e5ab0e095510b"));
async run(methodName: string = "", argv: string) {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "") {
const portalId: string = argv === "" ? "0x1495341ab1019798dd08976f4a3e5ab0e095510b" : argv;
console.log(await this.veraxSdk.portal.findOneById(portalId));
}

if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.findBy({ ownerName: "Clique" }));
if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "") {
const params: Partial<Portal> = argv === "" ? { ownerName: "Clique" } : JSON.parse(argv);
console.log(await this.veraxSdk.portal.findBy(params));
}

if (methodName.toLowerCase() == "simulateAttest".toLowerCase() || methodName == "") {
console.log(
await this.veraxSdk.portal.simulateAttest(
"0xeea25bc2ec56cae601df33b8fc676673285e12cc",
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
[],
),
);
let params;
if (argv !== "") params = JSON.parse(argv);
const portalAddress = params?.portalAddress
? (params.portalAddress as Address)
: "0xeea25bc2ec56cae601df33b8fc676673285e12cc";
const attestationData = params?.attestationData ?? {
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
};
const validationPayloads = params?.validationPayloads ?? [];
console.log(await this.veraxSdk.portal.simulateAttest(portalAddress, attestationData, validationPayloads));
}

if (methodName.toLowerCase() == "attest" || methodName == "") {
console.log(
await this.veraxSdk.portal.attest(
"0xeea25bc2ec56cae601df33b8fc676673285e12cc",
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
[],
),
);
let params;
if (argv !== "") params = JSON.parse(argv);
const portalAddress = params?.portalAddress
? (params.portalAddress as Address)
: "0xeea25bc2ec56cae601df33b8fc676673285e12cc";
const attestationData = params?.attestationData ?? {
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
};
const validationPayloads = params?.validationPayloads ?? [];
console.log(await this.veraxSdk.portal.attest(portalAddress, attestationData, validationPayloads));
}

if (methodName.toLowerCase() == "simulateBulkAttest".toLowerCase() || methodName == "") {
Expand Down Expand Up @@ -93,21 +101,25 @@ export default class PortalExamples {
if (methodName.toLowerCase() == "replace" || methodName == "") console.log(await this.veraxSdk.portal.replace());

if (methodName.toLowerCase() == "revoke" || methodName == "") {
console.log(
await this.veraxSdk.portal.revoke(
"0xeea25bc2ec56cae601df33b8fc676673285e12cc",
"0x0000000000000000000000000000000000000000000000000000000000000001",
),
);
let params;
if (argv !== "") params = JSON.parse(argv);
const portalAddress = params?.portalAddress
? (params.portalAddress as Address)
: "0xeea25bc2ec56cae601df33b8fc676673285e12cc";
const attestationId =
params?.attestationId ?? "0x0000000000000000000000000000000000000000000000000000000000000001";
console.log(await this.veraxSdk.portal.revoke(portalAddress, attestationId));
}

if (methodName.toLowerCase() == "simulateRevoke".toLowerCase() || methodName == "") {
console.log(
await this.veraxSdk.portal.simulateRevoke(
"0xeea25bc2ec56cae601df33b8fc676673285e12cc",
"0x0000000000000000000000000000000000000000000000000000000000000001",
),
);
let params;
if (argv !== "") params = JSON.parse(argv);
const portalAddress = params?.portalAddress
? (params.portalAddress as Address)
: "0xeea25bc2ec56cae601df33b8fc676673285e12cc";
const attestationId =
params?.attestationId ?? "0x0000000000000000000000000000000000000000000000000000000000000001";
console.log(await this.veraxSdk.portal.simulateRevoke(portalAddress, attestationId));
}

if (methodName.toLowerCase() == "simulateBulkRevoke".toLowerCase() || methodName == "")
Expand Down
5 changes: 4 additions & 1 deletion sdk/examples/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import VeraxSdk from "../../src/VeraxSdk";
import PortalExamples from "./schemaExamples";

let argv: string | null | undefined = process.argv[3] as string;
argv !== null && argv !== undefined ? (argv = argv.replaceAll("\\", "")) : (argv = "");

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);

await new PortalExamples(veraxSdk).run(process.argv[2]);
await new PortalExamples(veraxSdk).run(process.argv[2], argv);
18 changes: 11 additions & 7 deletions sdk/examples/schema/schemaExamples.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import VeraxSdk from "../../src/VeraxSdk";
import { Schema } from "../../src/types";

export default class SchemaExamples {
private veraxSdk: VeraxSdk;
constructor(_veraxSdk: VeraxSdk) {
this.veraxSdk = _veraxSdk;
}
async run(methodName: string = "") {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "")
console.log(
await this.veraxSdk.schema.findOneById("0x01f031da36192c34057c764239eb77bb6ec8ebfb808f72a7bb172f37a5bec31f"),
);
async run(methodName: string = "", argv: string) {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "") {
const schemaId: string =
argv === "" ? "0x01f031da36192c34057c764239eb77bb6ec8ebfb808f72a7bb172f37a5bec31f" : argv;
console.log(await this.veraxSdk.schema.findOneById(schemaId));
}

if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.schema.findBy({ name: "Relationship" }));
if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "") {
const params: Partial<Schema> = argv === "" ? { name: "Relationship" } : JSON.parse(argv);
console.log(await this.veraxSdk.schema.findBy(params));
}

if (methodName.toLowerCase() == "create" || methodName == "") console.log(await this.veraxSdk.schema.create());
}
Expand Down

0 comments on commit 346a981

Please sign in to comment.