diff --git a/src/transactions/SetStore.ts b/src/transactions/SetStore.ts index 5104e6c..524494a 100644 --- a/src/transactions/SetStore.ts +++ b/src/transactions/SetStore.ts @@ -15,13 +15,10 @@ export interface SetStoreArgs { public: boolean; } -const setStoreStruct = borsh.struct( - [ - ['instruction', 'u8'], - ['public', 'u8'], - ], - [], -); +const setStoreStruct = borsh.struct([ + ['instruction', 'u8'], + ['public', 'u8'], +]); type SetStoreParams = { store: PublicKey; @@ -35,7 +32,9 @@ export class SetStore extends Transaction { const { feePayer } = options; const { admin, store, isPublic } = params; - const data = setStoreStruct.serialize({ instruction: 8, public: isPublic }); + const data = setStoreStruct.serialize( + new setStoreStruct.type({ instruction: 8, public: isPublic }), + ); this.add( new TransactionInstruction({ diff --git a/src/utils/borsh.ts b/src/utils/borsh.ts index bb0180b..7751bb6 100644 --- a/src/utils/borsh.ts +++ b/src/utils/borsh.ts @@ -30,18 +30,25 @@ extendBorsh(); export class Struct { readonly fields; readonly dependencies: Struct[] = []; - readonly type: (args: T) => T; + readonly type: any; //(args: T) => T; readonly schema: Map; constructor(fields: any[][], dependencies: Struct[] = [], parse?: (args: T) => T) { this.fields = fields; this.dependencies = dependencies; - this.type = function (args: T = {} as T) { - // Ensure all args exist as undefined. - for (const [name] of fields) { - if (!(name in args)) (args as any)[name] = undefined; + + this.type = class Type { + constructor(args: T = {} as T) { + for (const [name] of fields) { + if (!(name in args)) { + (args as any)[name] = undefined; + } + } + parse && parse(args); + for (const key of Object.keys(args)) { + this[key] = args[key]; + } } - return parse ? parse(args) : args; }; const entries = [ diff --git a/test/metaplex.test.ts b/test/metaplex.test.ts index 99ca096..8cc4770 100644 --- a/test/metaplex.test.ts +++ b/test/metaplex.test.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { Keypair, sendAndConfirmTransaction } from '@solana/web3.js'; import { Auction, @@ -21,6 +22,8 @@ describe('Metaplex', () => { let connection: Connection; let owner: Keypair; + jest.setTimeout(80000); + beforeAll(() => { connection = new Connection('devnet'); owner = Keypair.generate(); @@ -64,7 +67,7 @@ describe('Metaplex', () => { commitment: 'confirmed', }); - console.log(txid); + // console.log(txid); }); });