chore: test

This commit is contained in:
aryan
2024-12-19 18:38:31 +05:30
parent 00c626c79b
commit 1cd8fc0927
6 changed files with 7 additions and 142 deletions

View File

@@ -104,8 +104,6 @@ export class SolanaDeployTokenTool extends Tool {
try {
const parsedInput = JSON.parse(input);
console.log(parsedInput);
const result = await this.solanaKit.deployToken(
parsedInput.name,
parsedInput.uri,
@@ -137,8 +135,7 @@ export class SolanaDeployCollectionTool extends Tool {
Inputs (input is a JSON string):
name: string, eg "My Collection" (required)
uri: string, eg "https://example.com/collection.json" (required)
royaltyBasisPoints?: number, eg 500 for 5% (optional)
creators?: Array<{address: string, percentage: number}>, eg [{address: "abc123...", percentage: 100}] (optional)`;
royaltyBasisPoints?: number, eg 500 for 5% (optional)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
@@ -173,9 +170,8 @@ export class SolanaMintNFTTool extends Tool {
Inputs (input is a JSON string):
collectionMint: string, eg "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w" (required) - The address of the collection to mint into
name: string, eg "My NFT" (required)
symbol: string, eg "NFT" (required)
uri: string, eg "https://example.com/nft.json" (required)
recipient?: string, eg "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u" (optional) - The wallet to receive the NFT, defaults to agent's wallet`;
recipient?: string, eg "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u" (optional) - The wallet to receive the NFT, defaults to agent's wallet which is ${this.solanaKit.wallet_address.toString()}`;
constructor(private solanaKit: SolanaAgentKit) {
super();
@@ -185,14 +181,16 @@ export class SolanaMintNFTTool extends Tool {
try {
const parsedInput = JSON.parse(input);
const result = await this.solanaKit.mintNFT(
new PublicKey(parsedInput.collectionMint),
{
name: parsedInput.name,
symbol: parsedInput.symbol,
uri: parsedInput.uri,
},
parsedInput.recipient ? new PublicKey(parsedInput.recipient) : undefined
parsedInput.recipient
? new PublicKey(parsedInput.recipient)
: this.solanaKit.wallet_address
);
return JSON.stringify({

View File

@@ -8,10 +8,10 @@ import { fromWeb3JsKeypair, fromWeb3JsPublicKey, toWeb3JsPublicKey } from "@meta
/**
* Deploy a new SPL token
* @param agent SolanaAgentKit instance
* @param decimals Number of decimals for the token (default: 9)
* @param name Name of the token
* @param uri URI for the token metadata
* @param symbol Symbol of the token
* @param decimals Number of decimals for the token (default: 9)
* @param initialSupply Initial supply to mint (optional)
* @returns Object containing token mint address and initial account (if supply was minted)
*/

View File

@@ -1,30 +0,0 @@
import { SolanaAgentKit } from "../src";
import { deploy_collection } from "../src/tools";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { fromWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
import assert from "assert";
import { fetchCollection, mplCore } from "@metaplex-foundation/mpl-core";
export async function test_deploy_collection() {
console.log("<<< Test Deploy Collection");
const solanaKit = new SolanaAgentKit(
process.env.SOLANA_PRIVATE_KEY!,
process.env.RPC_URL,
process.env.OPENAI_API_KEY!
);
const umi = createUmi(solanaKit.connection.rpcEndpoint).use(mplCore());
const collectionAddress = fromWeb3JsPublicKey((await deploy_collection(solanaKit, {
name: "test",
uri: "www.example.com",
})).collectionAddress);
const collection = await fetchCollection(umi, collectionAddress, { commitment: 'processed' });
assert(collection.name === "test");
assert(collection.uri === "www.example.com");
assert(collection.publicKey === collectionAddress);
assert(collection.numMinted === 0);
console.log(">>> Test Deploy Collection Passed");
}

View File

@@ -1,32 +0,0 @@
import { fetchDigitalAsset, mplTokenMetadata } from "@metaplex-foundation/mpl-token-metadata";
import { SolanaAgentKit } from "../src";
import { deploy_token } from "../src/tools";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { fromWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
import assert from "assert";
export async function test_deploy_token() {
console.log("<<< Test Deploy Token");
const solanaKit = new SolanaAgentKit(
process.env.SOLANA_PRIVATE_KEY!,
process.env.RPC_URL,
process.env.OPENAI_API_KEY!
);
const umi = createUmi(solanaKit.connection.rpcEndpoint).use(mplTokenMetadata());
const mint = fromWeb3JsPublicKey((await deploy_token(solanaKit, 6, "test", "www.example.com", "TEST")).mint);
// Delay for 5 seconds
await new Promise(resolve => setTimeout(resolve, 5000));
const asset = await fetchDigitalAsset(umi, mint, { commitment: 'processed' });
assert(asset.metadata.name === "test");
assert(asset.metadata.uri === "www.example.com");
assert(asset.metadata.symbol === 'TEST');
assert(asset.metadata.sellerFeeBasisPoints === 0);
assert(asset.metadata.mint === mint);
assert(asset.metadata.sellerFeeBasisPoints === 0);
console.log(">>> Test Deploy Token Passed");
}

View File

@@ -1,42 +0,0 @@
import { SolanaAgentKit } from "../src";
import { deploy_collection, mintCollectionNFT } from "../src/tools";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { fromWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
import assert from "assert";
import { fetchAsset, fetchCollection, mplCore } from "@metaplex-foundation/mpl-core";
export async function test_mint_nft() {
console.log("<<< Test Mint NFT");
const solanaKit = new SolanaAgentKit(
process.env.SOLANA_PRIVATE_KEY!,
process.env.RPC_URL,
process.env.OPENAI_API_KEY!
);
const umi = createUmi(solanaKit.connection.rpcEndpoint).use(mplCore());
const { collectionAddress } = await deploy_collection(solanaKit, {
name: "test",
uri: "www.example.com",
});
const assetAddress = fromWeb3JsPublicKey(((await mintCollectionNFT(solanaKit, collectionAddress, {
name: "test",
uri: "www.example.com"
})).mint));
// Delay for 5 seconds
await new Promise(resolve => setTimeout(resolve, 5000));
const asset = await fetchAsset(umi, assetAddress, { commitment: 'processed' });
assert(asset.name === "test");
assert(asset.uri === "www.example.com");
assert(asset.publicKey === assetAddress);
assert(asset.updateAuthority.address === fromWeb3JsPublicKey(collectionAddress));
const collection = await fetchCollection(umi, fromWeb3JsPublicKey(collectionAddress), { commitment: 'processed' });
assert(collection.numMinted === 1);
console.log(">>> Test Mint NFT Passed");
}

View File

@@ -1,29 +0,0 @@
import * as dotenv from "dotenv";
import { test_deploy_token } from "./deployToken";
import { test_deploy_collection } from "./deployCollection";
import { test_mint_nft } from "./mintNft";
dotenv.config();
async function main() {
try {
console.log("Starting Agent...");
// Test Tools
await test_deploy_token();
await test_deploy_collection();
await test_mint_nft();
} catch (error) {
if (error instanceof Error) {
console.error("Error:", error.message);
}
process.exit(1);
}
}
if (require.main === module) {
main().catch(error => {
console.error("Fatal error:", error);
process.exit(1);
});
}