generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from blockiosaurus/main
Adding benchmarking suite
- Loading branch information
Showing
9 changed files
with
528 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Benchmark | ||
on: | ||
workflow_call: | ||
|
||
permissions: | ||
# deployments permission to deploy GitHub pages website | ||
deployments: write | ||
# contents permission to update benchmark contents in gh-pages branch | ||
contents: write | ||
|
||
env: | ||
CACHE: true | ||
|
||
jobs: | ||
benchmark: | ||
name: Performance regression check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Load environment variables | ||
run: cat .github/.env >> $GITHUB_ENV | ||
|
||
- name: Start validator | ||
uses: metaplex-foundation/actions/start-validator@v1 | ||
with: | ||
node: 18.x | ||
solana: ${{ env.SOLANA_VERSION }} | ||
cache: ${{ env.CACHE }} | ||
|
||
- name: Install dependencies | ||
uses: metaplex-foundation/actions/install-node-dependencies@v1 | ||
with: | ||
folder: ./clients/js | ||
cache: ${{ env.CACHE }} | ||
key: clients-js | ||
|
||
- name: Build | ||
working-directory: ./clients/js | ||
run: pnpm build | ||
|
||
- name: Test | ||
working-directory: ./clients/js | ||
run: pnpm bench | ||
|
||
# Download previous benchmark result from cache (if exists) | ||
- name: Download previous benchmark data | ||
uses: actions/cache@v4 | ||
with: | ||
path: ./cache | ||
key: ${{ runner.os }}-benchmark | ||
|
||
# Run `github-action-benchmark` action | ||
- name: Store benchmark result | ||
uses: benchmark-action/github-action-benchmark@v1 | ||
with: | ||
# What benchmark tool the output.json came from | ||
tool: "customSmallerIsBetter" | ||
# Where the output from the benchmark tool is stored | ||
output-file-path: ./clients/js/output.json | ||
# Where the previous data file is stored | ||
# external-data-json-path: ./cache/benchmark-data.json | ||
# Workflow will fail when an alert happens | ||
fail-on-alert: true | ||
# Access token to deploy GitHub Pages branch | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
# Push and deploy GitHub pages branch automatically | ||
auto-push: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import { createUmi as basecreateUmi } from '@metaplex-foundation/umi-bundle-tests'; | ||
import { | ||
mplCore, | ||
} from '../src'; | ||
|
||
export const createUmi = async () => (await basecreateUmi()).use(mplCore()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
import { generateSigner, TransactionBuilder } from "@metaplex-foundation/umi"; | ||
import test from "ava"; | ||
import { existsSync, readFileSync, writeFileSync } from "fs"; | ||
import { createCollectionV1, createV1, pluginAuthorityPair, ruleSet } from "../src"; | ||
import { createUmi } from "./_setup"; | ||
|
||
test('create a new, empty asset', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const assetAddress = generateSigner(umi); | ||
|
||
const tx = await createV1(umi, { | ||
asset: assetAddress, | ||
name: "Test", | ||
uri: "www.test.com", | ||
}).sendAndConfirm(umi); | ||
|
||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(assetAddress.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `CU: ${t.title}`, | ||
unit: "Compute Units", | ||
value: compute, | ||
} | ||
|
||
const spaceResult = { | ||
name: `Space: ${t.title}`, | ||
unit: "Bytes", | ||
value: space, | ||
} | ||
|
||
// Read the results array from output.json | ||
let output = []; | ||
if (existsSync("./output.json")) { | ||
output = JSON.parse(readFileSync("./output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("./output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('create a new, empty asset with empty collection', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const collectionAddress = generateSigner(umi); | ||
const assetAddress = generateSigner(umi); | ||
|
||
let builder = new TransactionBuilder(); | ||
builder = builder.add(createCollectionV1(umi, { | ||
collection: collectionAddress, | ||
name: "Test", | ||
uri: "www.test.com", | ||
})); | ||
builder = builder.add(createV1(umi, { | ||
asset: assetAddress, | ||
collection: collectionAddress.publicKey, | ||
name: "Test", | ||
uri: "www.test.com", | ||
})); | ||
|
||
const tx = await builder.sendAndConfirm(umi); | ||
|
||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(assetAddress.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `CU: ${t.title}`, | ||
unit: "Compute Units", | ||
value: compute, | ||
} | ||
|
||
const spaceResult = { | ||
name: `Space: ${t.title}`, | ||
unit: "Bytes", | ||
value: space, | ||
} | ||
|
||
// Read the results array from output.json | ||
let output = []; | ||
if (existsSync("./output.json")) { | ||
output = JSON.parse(readFileSync("./output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("./output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('create a new asset with plugins', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const assetAddress = generateSigner(umi); | ||
|
||
const tx = await createV1(umi, { | ||
asset: assetAddress, | ||
name: "Test", | ||
uri: "www.test.com", | ||
plugins: [ | ||
pluginAuthorityPair({ | ||
type: 'Royalties', | ||
data: { | ||
basisPoints: 5, | ||
creators: [{ address: umi.identity.publicKey, percentage: 100 }], | ||
ruleSet: ruleSet('None'), | ||
}, | ||
}), | ||
pluginAuthorityPair({ type: 'FreezeDelegate', data: { frozen: true } }), | ||
pluginAuthorityPair({ type: 'TransferDelegate' }), | ||
pluginAuthorityPair({ type: 'BurnDelegate' }), | ||
], | ||
}).sendAndConfirm(umi); | ||
|
||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(assetAddress.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `CU: ${t.title}`, | ||
unit: "Compute Units", | ||
value: compute, | ||
} | ||
|
||
const spaceResult = { | ||
name: `Space: ${t.title}`, | ||
unit: "Bytes", | ||
value: space, | ||
} | ||
|
||
// Read the results array from output.json | ||
let output = []; | ||
if (existsSync("./output.json")) { | ||
output = JSON.parse(readFileSync("./output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("./output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('create a new asset with plugins and empty collection', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const collectionAddress = generateSigner(umi); | ||
const assetAddress = generateSigner(umi); | ||
|
||
let builder = new TransactionBuilder(); | ||
builder = builder.add(createCollectionV1(umi, { | ||
collection: collectionAddress, | ||
name: "Test", | ||
uri: "www.test.com", | ||
})); | ||
builder = builder.add(createV1(umi, { | ||
asset: assetAddress, | ||
name: "Test", | ||
uri: "www.test.com", | ||
plugins: [ | ||
pluginAuthorityPair({ | ||
type: 'Royalties', | ||
data: { | ||
basisPoints: 5, | ||
creators: [{ address: umi.identity.publicKey, percentage: 100 }], | ||
ruleSet: ruleSet('None'), | ||
}, | ||
}), | ||
pluginAuthorityPair({ type: 'FreezeDelegate', data: { frozen: true } }), | ||
pluginAuthorityPair({ type: 'TransferDelegate' }), | ||
pluginAuthorityPair({ type: 'BurnDelegate' }), | ||
], | ||
})); | ||
|
||
const tx = await builder.sendAndConfirm(umi); | ||
|
||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(assetAddress.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `CU: ${t.title}`, | ||
unit: "Compute Units", | ||
value: compute, | ||
} | ||
|
||
const spaceResult = { | ||
name: `Space: ${t.title}`, | ||
unit: "Bytes", | ||
value: space, | ||
} | ||
|
||
// Read the results array from output.json | ||
let output = []; | ||
if (existsSync("./output.json")) { | ||
output = JSON.parse(readFileSync("./output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("./output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); |
Oops, something went wrong.