mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-31 23:26:50 +00:00
Adding basic tests and fixing issues.
This commit is contained in:
30
test/deployCollection.ts
Normal file
30
test/deployCollection.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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");
|
||||
}
|
||||
|
||||
32
test/deployToken.ts
Normal file
32
test/deployToken.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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");
|
||||
}
|
||||
|
||||
42
test/mintNft.ts
Normal file
42
test/mintNft.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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");
|
||||
}
|
||||
|
||||
29
test/tools.ts
Normal file
29
test/tools.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user