Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/compressed-token/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const rolls = (fmt, env) => ({
drop_console: false,
drop_debugger: true,
passes: 3,
booleans_as_integers: true,
booleans_as_integers: false,
keep_fargs: false,
keep_fnames: false,
keep_infinity: true,
Expand Down
2 changes: 1 addition & 1 deletion js/stateless.js/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const rolls = (fmt, env) => ({
drop_console: false,
drop_debugger: true,
passes: 3,
booleans_as_integers: true,
booleans_as_integers: false,
keep_fargs: false,
keep_fnames: false,
keep_infinity: true,
Expand Down
26 changes: 21 additions & 5 deletions js/stateless.js/src/utils/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { AccountMeta, PublicKey, SystemProgram } from '@solana/web3.js';
import { defaultStaticAccountsStruct, featureFlags } from '../constants';
import { LightSystemProgram } from '../programs';

const toStrictBool = (value: unknown): boolean =>
value === true || value === 1;

export class PackedAccounts {
private preAccounts: AccountMeta[] = [];
private systemAccounts: AccountMeta[] = [];
Expand Down Expand Up @@ -40,7 +43,11 @@ export class PackedAccounts {
}

addPreAccountsMeta(accountMeta: AccountMeta): void {
this.preAccounts.push(accountMeta);
this.preAccounts.push({
pubkey: accountMeta.pubkey,
isSigner: toStrictBool(accountMeta.isSigner),
isWritable: toStrictBool(accountMeta.isWritable),
});
}

/**
Expand Down Expand Up @@ -81,7 +88,11 @@ export class PackedAccounts {
return entry[0];
}
const index = this.nextIndex++;
const meta: AccountMeta = { pubkey, isSigner, isWritable };
const meta: AccountMeta = {
pubkey,
isSigner: toStrictBool(isSigner),
isWritable: toStrictBool(isWritable),
};
this.map.set(pubkey, [index, meta]);
return index;
}
Expand All @@ -105,11 +116,16 @@ export class PackedAccounts {
} {
const packed = this.hashSetAccountsToMetas();
const [systemStart, packedStart] = this.getOffsets();
const normalize = (meta: AccountMeta): AccountMeta => ({
pubkey: meta.pubkey,
isSigner: toStrictBool(meta.isSigner),
isWritable: toStrictBool(meta.isWritable),
});
return {
remainingAccounts: [
...this.preAccounts,
...this.systemAccounts,
...packed,
...this.preAccounts.map(normalize),
...this.systemAccounts.map(normalize),
...packed.map(normalize),
],
systemStart,
packedStart,
Expand Down
39 changes: 39 additions & 0 deletions js/stateless.js/tests/unit/utils/packed-accounts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { describe, expect, it } from 'vitest';
import { PublicKey } from '@solana/web3.js';
import { PackedAccounts } from '../../../src/utils/instruction';

describe('PackedAccounts runtime boolean normalization', () => {
it('normalizes numeric AccountMeta flags from addPreAccountsMeta', () => {
const packedAccounts = new PackedAccounts();
const pubkey = PublicKey.unique();

packedAccounts.addPreAccountsMeta({
pubkey,
isSigner: 0 as unknown as boolean,
isWritable: 1 as unknown as boolean,
});

const [meta] = packedAccounts.toAccountMetas().remainingAccounts;
expect(typeof meta.isSigner).toBe('boolean');
expect(typeof meta.isWritable).toBe('boolean');
expect(meta.isSigner).toBe(false);
expect(meta.isWritable).toBe(true);
});

it('normalizes numeric flags from insertOrGetConfig', () => {
const packedAccounts = new PackedAccounts();
const pubkey = PublicKey.unique();

packedAccounts.insertOrGetConfig(
pubkey,
1 as unknown as boolean,
0 as unknown as boolean,
);

const [meta] = packedAccounts.toAccountMetas().remainingAccounts;
expect(typeof meta.isSigner).toBe('boolean');
expect(typeof meta.isWritable).toBe('boolean');
expect(meta.isSigner).toBe(true);
expect(meta.isWritable).toBe(false);
});
});
Loading