Skip to content

Commit

Permalink
Merge pull request #2 from samwise2/update-with-working-tests
Browse files Browse the repository at this point in the history
Update with working tests
  • Loading branch information
samwise2 authored Aug 29, 2023
2 parents e9ef4f7 + f89ef44 commit 04ce25b
Show file tree
Hide file tree
Showing 46 changed files with 3,798 additions and 1,097 deletions.
2 changes: 0 additions & 2 deletions clients/js-solita/.prettierignore

This file was deleted.

2 changes: 0 additions & 2 deletions clients/js-solita/.prettierrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion clients/js-solita/.solitarc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
const path = require('path');
const programDir = path.join(__dirname, '..', '..', 'programs', 'mpl-bubblegum');
const programDir = path.join(__dirname, '..', '..', 'programs', 'bubblegum', 'program');
const idlDir = path.join(__dirname, '..', '..', 'idls');
const sdkDir = path.join(__dirname, 'src', 'generated');
const binaryInstallDir = path.join(__dirname, '.crates');
Expand Down
7 changes: 4 additions & 3 deletions clients/js-solita/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"postpublish": "git push origin && git push origin --tags",
"build:docs": "typedoc",
"build": "rimraf dist && tsc -p tsconfig.json",
"start-validator": "solana-test-validator -ud --quiet --reset -c cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK -c 4VTQredsAmr1yzRJugLV6Mt6eu6XMeCwdkZ73wwVMWHv -c noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV -c 3RHkdjCwWyK2firrwFQGvXCxbUpBky1GTmb9EDK9hUnX -c metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s -c PwDiXFxQsGra4sFFTT8r1QWRMd4vfumiWC1jfWNfdYT -c TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA -c ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL --bpf-program BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY ../../programs/.bin/mpl_bubblegum.so",
"start-validator": "solana-test-validator -ud --reset -c cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK -c 4VTQredsAmr1yzRJugLV6Mt6eu6XMeCwdkZ73wwVMWHv -c noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV -c 3RHkdjCwWyK2firrwFQGvXCxbUpBky1GTmb9EDK9hUnX -c metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s -c PwDiXFxQsGra4sFFTT8r1QWRMd4vfumiWC1jfWNfdYT -c TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA -c ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL --bpf-program BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY ../../programs/.bin/mpl_bubblegum.so",
"run-tests": "jest tests --detectOpenHandles",
"test": "start-server-and-test start-validator http://localhost:8899/health run-tests",
"api:gen": "DEBUG='(solita|rustbin):(info|error)' solita",
Expand Down Expand Up @@ -52,14 +52,15 @@
},
"devDependencies": {
"@metaplex-foundation/amman": "0.12.0",
"@metaplex-foundation/js": "^0.19.4",
"@metaplex-foundation/rustbin": "^0.3.1",
"@metaplex-foundation/solita": "0.19.1",
"@solana/spl-account-compression": "^0.1.4",
"@types/bn.js": "^5.1.1",
"@types/chai": "^4.3.0",
"@types/jest": "^29.1.1",
"@types/mocha": "^9.0.0",
"@types/tape": "^4.13.2",
"@types/bn.js": "^5.1.1",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"chai": "^4.3.4",
Expand All @@ -80,4 +81,4 @@
"typescript": "^4.3.5",
"typescript-collections": "^1.3.3"
}
}
}
89 changes: 50 additions & 39 deletions clients/js-solita/src/generated/accounts/TreeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
* See: https://github.com/metaplex-foundation/solita
*/

import * as web3 from '@solana/web3.js';
import * as beet from '@metaplex-foundation/beet';
import * as beetSolana from '@metaplex-foundation/beet-solana';
import * as web3 from '@solana/web3.js'
import * as beet from '@metaplex-foundation/beet'
import * as beetSolana from '@metaplex-foundation/beet-solana'

/**
* Arguments used to create {@link TreeConfig}
* @category Accounts
* @category generated
*/
export type TreeConfigArgs = {
treeCreator: web3.PublicKey;
treeDelegate: web3.PublicKey;
totalMintCapacity: beet.bignum;
numMinted: beet.bignum;
isPublic: boolean;
};
treeCreator: web3.PublicKey
treeDelegate: web3.PublicKey
totalMintCapacity: beet.bignum
numMinted: beet.bignum
isPublic: boolean
}

export const treeConfigDiscriminator = [122, 245, 175, 248, 171, 34, 0, 207];
export const treeConfigDiscriminator = [122, 245, 175, 248, 171, 34, 0, 207]
/**
* Holds the data for the {@link TreeConfig} Account and provides de/serialization
* functionality for that data
Expand All @@ -36,7 +36,7 @@ export class TreeConfig implements TreeConfigArgs {
readonly treeDelegate: web3.PublicKey,
readonly totalMintCapacity: beet.bignum,
readonly numMinted: beet.bignum,
readonly isPublic: boolean,
readonly isPublic: boolean
) {}

/**
Expand All @@ -48,16 +48,19 @@ export class TreeConfig implements TreeConfigArgs {
args.treeDelegate,
args.totalMintCapacity,
args.numMinted,
args.isPublic,
);
args.isPublic
)
}

/**
* Deserializes the {@link TreeConfig} from the data of the provided {@link web3.AccountInfo}.
* @returns a tuple of the account data and the offset up to which the buffer was read to obtain it.
*/
static fromAccountInfo(accountInfo: web3.AccountInfo<Buffer>, offset = 0): [TreeConfig, number] {
return TreeConfig.deserialize(accountInfo.data, offset);
static fromAccountInfo(
accountInfo: web3.AccountInfo<Buffer>,
offset = 0
): [TreeConfig, number] {
return TreeConfig.deserialize(accountInfo.data, offset)
}

/**
Expand All @@ -69,13 +72,16 @@ export class TreeConfig implements TreeConfigArgs {
static async fromAccountAddress(
connection: web3.Connection,
address: web3.PublicKey,
commitmentOrConfig?: web3.Commitment | web3.GetAccountInfoConfig,
commitmentOrConfig?: web3.Commitment | web3.GetAccountInfoConfig
): Promise<TreeConfig> {
const accountInfo = await connection.getAccountInfo(address, commitmentOrConfig);
const accountInfo = await connection.getAccountInfo(
address,
commitmentOrConfig
)
if (accountInfo == null) {
throw new Error(`Unable to find TreeConfig account at ${address}`);
throw new Error(`Unable to find TreeConfig account at ${address}`)
}
return TreeConfig.fromAccountInfo(accountInfo, 0)[0];
return TreeConfig.fromAccountInfo(accountInfo, 0)[0]
}

/**
Expand All @@ -85,17 +91,19 @@ export class TreeConfig implements TreeConfigArgs {
* @param programId - the program that owns the accounts we are filtering
*/
static gpaBuilder(
programId: web3.PublicKey = new web3.PublicKey('BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY'),
programId: web3.PublicKey = new web3.PublicKey(
'BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY'
)
) {
return beetSolana.GpaBuilder.fromStruct(programId, treeConfigBeet);
return beetSolana.GpaBuilder.fromStruct(programId, treeConfigBeet)
}

/**
* Deserializes the {@link TreeConfig} from the provided data Buffer.
* @returns a tuple of the account data and the offset up to which the buffer was read to obtain it.
*/
static deserialize(buf: Buffer, offset = 0): [TreeConfig, number] {
return treeConfigBeet.deserialize(buf, offset);
return treeConfigBeet.deserialize(buf, offset)
}

/**
Expand All @@ -106,15 +114,15 @@ export class TreeConfig implements TreeConfigArgs {
return treeConfigBeet.serialize({
accountDiscriminator: treeConfigDiscriminator,
...this,
});
})
}

/**
* Returns the byteSize of a {@link Buffer} holding the serialized data of
* {@link TreeConfig}
*/
static get byteSize() {
return treeConfigBeet.byteSize;
return treeConfigBeet.byteSize
}

/**
Expand All @@ -125,17 +133,20 @@ export class TreeConfig implements TreeConfigArgs {
*/
static async getMinimumBalanceForRentExemption(
connection: web3.Connection,
commitment?: web3.Commitment,
commitment?: web3.Commitment
): Promise<number> {
return connection.getMinimumBalanceForRentExemption(TreeConfig.byteSize, commitment);
return connection.getMinimumBalanceForRentExemption(
TreeConfig.byteSize,
commitment
)
}

/**
* Determines if the provided {@link Buffer} has the correct byte size to
* hold {@link TreeConfig} data.
*/
static hasCorrectByteSize(buf: Buffer, offset = 0) {
return buf.byteLength - offset === TreeConfig.byteSize;
return buf.byteLength - offset === TreeConfig.byteSize
}

/**
Expand All @@ -147,29 +158,29 @@ export class TreeConfig implements TreeConfigArgs {
treeCreator: this.treeCreator.toBase58(),
treeDelegate: this.treeDelegate.toBase58(),
totalMintCapacity: (() => {
const x = <{ toNumber: () => number }>this.totalMintCapacity;
const x = <{ toNumber: () => number }>this.totalMintCapacity
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
return x.toNumber()
} catch (_) {
return x;
return x
}
}
return x;
return x
})(),
numMinted: (() => {
const x = <{ toNumber: () => number }>this.numMinted;
const x = <{ toNumber: () => number }>this.numMinted
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
return x.toNumber()
} catch (_) {
return x;
return x
}
}
return x;
return x
})(),
isPublic: this.isPublic,
};
}
}
}

Expand All @@ -180,7 +191,7 @@ export class TreeConfig implements TreeConfigArgs {
export const treeConfigBeet = new beet.BeetStruct<
TreeConfig,
TreeConfigArgs & {
accountDiscriminator: number[] /* size: 8 */;
accountDiscriminator: number[] /* size: 8 */
}
>(
[
Expand All @@ -192,5 +203,5 @@ export const treeConfigBeet = new beet.BeetStruct<
['isPublic', beet.bool],
],
TreeConfig.fromArgs,
'TreeConfig',
);
'TreeConfig'
)
Loading

0 comments on commit 04ce25b

Please sign in to comment.