generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18eb452
commit 23af1a2
Showing
19 changed files
with
1,674 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[workspace] | ||
members = ["programs/solana-serialization-benchmark"] | ||
resolver = "2" | ||
members = ["programs/solana-serialization-benchmark"] | ||
resolver = "2" |
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,244 @@ | ||
import { generateSigner } from "@metaplex-foundation/umi"; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import test from "ava"; | ||
import { existsSync, readFileSync, writeFileSync } from "fs"; | ||
import { createBasicBincode, createCollectionBincode, updateBasicBincode, updateCollectionBincode } from '../src'; | ||
import { createUmi } from "./_setup"; | ||
|
||
test('Create:Basic:Bincode', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const address = generateSigner(umi); | ||
|
||
// When we create a new account. | ||
const tx = await createBasicBincode(umi, { address }).sendAndConfirm(umi); | ||
|
||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(address.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `Compute:${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("../../docs/output.json")) { | ||
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('Read:Basic:Bincode', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const address = generateSigner(umi); | ||
|
||
// When we create a new account. | ||
const tx = await createBasicBincode(umi, { address }).sendAndConfirm(umi); | ||
|
||
// Then an account was created with the correct data. | ||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(address.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `Compute:${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("../../docs/output.json")) { | ||
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('Update:Basic:Bincode', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const address = generateSigner(umi); | ||
|
||
// When we create a new account. | ||
await createBasicBincode(umi, { address }).sendAndConfirm(umi); | ||
const tx = await updateBasicBincode(umi, { address: address.publicKey }).sendAndConfirm(umi); | ||
|
||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(address.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `Compute:${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("../../docs/output.json")) { | ||
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('Create:Collection:Bincode', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const address = generateSigner(umi); | ||
|
||
// When we create a new account. | ||
const tx = await createCollectionBincode(umi, { address }).sendAndConfirm(umi); | ||
|
||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(address.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `Compute:${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("../../docs/output.json")) { | ||
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('Read:Collection:Bincode', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const address = generateSigner(umi); | ||
|
||
// When we create a new account. | ||
const tx = await createCollectionBincode(umi, { address }).sendAndConfirm(umi); | ||
|
||
// Then an account was created with the correct data. | ||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(address.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `Compute:${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("../../docs/output.json")) { | ||
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('Update:Collection:Bincode', async (t) => { | ||
// Given an Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const address = generateSigner(umi); | ||
|
||
// When we create a new account. | ||
await createCollectionBincode(umi, { address }).sendAndConfirm(umi); | ||
const tx = await updateCollectionBincode(umi, { address: address.publicKey }).sendAndConfirm(umi); | ||
|
||
const compute = Number((await umi.rpc.getTransaction(tx.signature))?.meta.computeUnitsConsumed); | ||
const account = await umi.rpc.getAccount(address.publicKey); | ||
const space = account.exists ? account.data.length : 0; | ||
|
||
const cuResult = { | ||
name: `Compute:${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("../../docs/output.json")) { | ||
output = JSON.parse(readFileSync("../../docs/output.json", 'utf-8')); | ||
} | ||
|
||
// Push the result to the array | ||
output.push(cuResult); | ||
output.push(spaceResult); | ||
// Write the array to output.json | ||
writeFileSync("../../docs/output.json", JSON.stringify(output, null, 2)); | ||
|
||
t.pass(); | ||
}); |
Oops, something went wrong.