Skip to content

Commit

Permalink
[cli] fix error on compilation after upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Jan 22, 2025
1 parent 0eb5234 commit 49df53b
Show file tree
Hide file tree
Showing 55 changed files with 410 additions and 406 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"license": "ISC",
"author": "Marinade.Finance",
"scripts": {
"compile": "npx tsc -b -verbose",
"compile": "tsc --project tsconfig.build.json",
"_copy-readme": "cp packages/lib/anchor-common/*.md build/packages/lib/anchor-common/ && cp packages/lib/cli-common/*.md build/packages/lib/cli-common/ && cp packages/lib/jest-utils/*.md build/packages/lib/jest-utils/ && cp packages/lib/spl-gov-utils/*.md build/packages/lib/spl-gov-utils/ && cp packages/lib/web3js-common/*.md build/packages/lib/web3js-common/ && cp packages/lib/umi-utils/*.md build/packages/lib/umi-utils/ && cp packages/lib/bankrun-utils/*.md build/packages/lib/bankrun-utils/ && cp packages/marinade-ts-cli/*.md build/packages/marinade-ts-cli/",
"build": "pnpm compile && pnpm _copy-readme",
"marinade": "pnpm cli",
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/anchor-common/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function verifyError(
idl: Idl | Map<number, string>,
errCode: number,
errMessage?: string,
logger: LoggerPlaceholder | undefined = undefined
logger: LoggerPlaceholder | undefined = undefined,
) {
let anchorErrorMap: Map<number, string>
if (idl instanceof Map) {
Expand All @@ -32,7 +32,7 @@ export function verifyError(
if (errMessage !== undefined && !anchorErrorMsg.includes(errMessage)) {
throw new Error(
`Error code ${errCode} belongs to Anchor error message '${anchorErrorMsg}' ` +
`which does not match expected text '${errMessage}'`
`which does not match expected text '${errMessage}'`,
)
}
let decNum: number
Expand Down
25 changes: 12 additions & 13 deletions packages/lib/anchor-common/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getStakeActivation } from '@anza-xyz/solana-rpc-get-stake-activation'

export async function getAnchorValidatorInfo(
connection: Connection,
identityKeypairPath?: string
identityKeypairPath?: string,
): Promise<{
votePubkey: PublicKey
validatorIdentity: Keypair
Expand All @@ -21,7 +21,7 @@ export async function getAnchorValidatorInfo(
process.cwd() + '/.anchor/test-ledger/validator-keypair.json'
if (!fs.existsSync(identityKeypairPath)) {
throw new Error(
`Expected test validator identity key pair at ${identityKeypairPath} but file not found`
`Expected test validator identity key pair at ${identityKeypairPath} but file not found`,
)
}
const validatorIdentityPath = identityKeypairPath
Expand All @@ -30,32 +30,32 @@ export async function getAnchorValidatorInfo(
// let's verify the leader schedule matches the validator identity
const leaderSchedule = await connection.getLeaderSchedule()
const isScheduledOnlyTestValidator = Object.keys(leaderSchedule).every(
address => address === validatorIdentity.publicKey.toBase58()
address => address === validatorIdentity.publicKey.toBase58(),
)
if (!isScheduledOnlyTestValidator) {
throw new Error(
'Error on global setup: expected only test validator being run and scheduled as leader'
'Error on global setup: expected only test validator being run and scheduled as leader',
)
}

const voteAccounts = await connection.getVoteAccounts()
// expecting run on localhost and only one voting vote account is available
// i.e., one validator solana-test-validator is voting and the validator identity is the same
const anchorValidatorVoteAccounts = voteAccounts.current.filter(
v => v.nodePubkey === validatorIdentity.publicKey.toBase58()
v => v.nodePubkey === validatorIdentity.publicKey.toBase58(),
)
if (anchorValidatorVoteAccounts.length <= 0) {
throw new Error(
'Expected solana-test-validator to be voting. Cannot continue in global local test setup. ' +
`No one with "nodePubkey" of validator ${validatorIdentity.publicKey.toBase58()}. ` +
`Number of all vote accounts found: ${voteAccounts.current.length}`
`Number of all vote accounts found: ${voteAccounts.current.length}`,
)
}
if (anchorValidatorVoteAccounts.length > 1) {
throw new Error(
'Expected one vote account of solana-test-validator. Cannot continue in global local test setup.' +
`More vote accounts of "nodePubkey" of validator ${validatorIdentity.publicKey.toBase58()}. ` +
` Number of solana-test-validator vote accounts found: ${anchorValidatorVoteAccounts.length}`
` Number of solana-test-validator vote accounts found: ${anchorValidatorVoteAccounts.length}`,
)
}
const votePubkey = new PublicKey(anchorValidatorVoteAccounts[0].votePubkey)
Expand Down Expand Up @@ -94,20 +94,19 @@ export async function waitForStakeAccountActivation({
stakeStatus = await getStakeActivation(connection, stakeAccount)
if (Date.now() - startTime > timeoutSeconds * 1000) {
throw new Error(
`Stake account ${stakeAccount.toBase58()} was not activated in timeout of ${timeoutSeconds} seconds`
`Stake account ${stakeAccount.toBase58()} was not activated in timeout of ${timeoutSeconds} seconds`,
)
}
}

// 2. the stake account is active, but it needs to be active for at least waitForEpochs epochs
if (activatedAtLeastFor > 0) {
connection.getParsedAccountInfo(stakeAccount)
const stakeAccountData = await getStakeAccount(connection, stakeAccount)
const stakeAccountActivationEpoch = stakeAccountData.activationEpoch
if (stakeAccountActivationEpoch === null) {
throw new Error(
'Expected stake account to be already activated. Unexpected setup error stake account:' +
stakeAccountData
stakeAccountData,
)
}

Expand All @@ -120,21 +119,21 @@ export async function waitForStakeAccountActivation({
`Waiting for the stake account ${stakeAccount.toBase58()} to be active at least for ${activatedAtLeastFor} epochs ` +
`currently active for ${
currentEpoch - stakeAccountActivationEpoch.toNumber()
} epoch(s)`
} epoch(s)`,
)
try {
await waitForEpoch(
connection,
stakeAccountActivationEpoch.toNumber() + activatedAtLeastFor,
timeoutSeconds
timeoutSeconds,
)
} catch (err) {
console.error(
`Stake account ${stakeAccount.toBase58()} was activated but timeout ${timeoutSeconds} elapsed when waiting ` +
`for ${activatedAtLeastFor} epochs the account to be activated, it's activated only for ` +
`${
currentEpoch - stakeAccountActivationEpoch.toNumber()
} epochs at this time`
} epochs at this time`,
)
throw err
}
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/anchor-common/src/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Idl, Program } from '@coral-xyz/anchor'

export function anchorProgramWalletPubkey<IDL extends Idl = Idl>(
program: Program<IDL>
program: Program<IDL>,
) {
const pubkey = program.provider.publicKey
if (pubkey === undefined) {
throw new Error(
'Cannot get wallet pubkey from Anchor Program ' + program.programId
'Cannot get wallet pubkey from Anchor Program ' + program.programId,
)
}
return pubkey
Expand Down
7 changes: 3 additions & 4 deletions packages/lib/bankrun-utils/src/bankrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BankrunProvider } from 'anchor-bankrun'

export async function assertNotExist(
provider: BankrunProvider,
account: PublicKey
account: PublicKey,
) {
const accountInfo = await provider.context.banksClient.getAccount(account)
expect(accountInfo).toBeNull()
Expand Down Expand Up @@ -33,7 +33,7 @@ export async function currentEpoch(provider: BankrunProvider): Promise<bigint> {

export async function warpOffsetEpoch(
provider: BankrunProvider,
plusEpochs: number | bigint
plusEpochs: number | bigint,
) {
const nextEpoch = (await currentEpoch(provider)) + BigInt(plusEpochs)
warpToEpoch(provider, nextEpoch)
Expand All @@ -49,10 +49,9 @@ export async function currentSlot(provider: BankrunProvider): Promise<bigint> {

export async function warpOffsetSlot(
provider: BankrunProvider,
plusSlots: number | bigint
plusSlots: number | bigint,
) {
const nextSlot = (await currentSlot(provider)) + BigInt(plusSlots)
warpOffsetSlot(provider, nextSlot)
provider.context.warpToSlot(nextSlot)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/lib/bankrun-utils/src/extendedProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class BankrunExtendedProvider
}

export async function bankrunTransaction(
provider: BankrunProvider
provider: BankrunProvider,
): Promise<Transaction> {
const bh = await provider.context.banksClient.getLatestBlockhash()
const lastValidBlockHeight = (
Expand Down Expand Up @@ -67,7 +67,7 @@ export async function bankrunExecuteIx(
export async function bankrunExecute(
provider: BankrunProvider,
signers: (Wallet | Signer | Keypair)[],
tx: Transaction
tx: Transaction,
): Promise<BanksTransactionMeta> {
for (const signer of signers) {
if (instanceOfWallet(signer)) {
Expand All @@ -76,7 +76,7 @@ export async function bankrunExecute(
tx.partialSign(signer)
} else {
throw new Error(
'bankrunExecute: provided signer parameter is not a signer: ' + signer
'bankrunExecute: provided signer parameter is not a signer: ' + signer,
)
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/lib/bankrun-utils/src/testInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,26 @@ export function loadPrograms(programs: ProgramInputData[]): AddedProgram[] {
hookDeleteDir = true
}
for (const { pubkey, path, name } of programs.filter(
p => p.path !== undefined
p => p.path !== undefined,
)) {
const programPath = path!
if (!existsSync(programPath)) {
console.error(
`bankrun startup: program ${pubkey.toBase58()} at path ${programPath} does not exist cannot be loaded`
`bankrun startup: program ${pubkey.toBase58()} at path ${programPath} does not exist cannot be loaded`,
)
continue
}
const fixturesProgramSoPath = join(fixturesPath, `${name}.so`)
if (existsSync(fixturesProgramSoPath)) {
console.log(
`bankrun startup: skipping to upload the program ${pubkey.toBase58()} from path ${path} to ${fixturesProgramSoPath} as it already exists`
`bankrun startup: skipping to upload the program ${pubkey.toBase58()} from path ${path} to ${fixturesProgramSoPath} as it already exists`,
)
} else {
console.debug(
'bankrun startup: copying program',
fixturesProgramSoPath,
'to',
fixturesProgramSoPath
fixturesProgramSoPath,
)
cpSync(programPath, fixturesProgramSoPath)
hookDeleteProgramNames.push(fixturesProgramSoPath)
Expand Down Expand Up @@ -167,7 +167,7 @@ export function loadPrograms(programs: ProgramInputData[]): AddedProgram[] {

function registerCleanup(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
exitHandler: (options: any, exitCode: any) => void
exitHandler: (options: any, exitCode: any) => void,
): void {
// do something when app is closing
process.on('exit', exitHandler.bind(null, { cleanup: true }))
Expand Down Expand Up @@ -239,7 +239,7 @@ export async function testInit({
accountData.address = acc.pubkey
}
return accountData
})
}),
)
}
if (programs !== undefined) {
Expand All @@ -249,7 +249,7 @@ export async function testInit({
const context = await startAnchor(
'./',
additionalPrograms,
additionalAccounts
additionalAccounts,
)
return new BankrunExtendedProvider(context)
}
2 changes: 1 addition & 1 deletion packages/lib/cli-common/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getContext(): Context {
export function setContext(newContext: Context) {
if (context) {
throw new Error(
'Context already initialized, context can be initialized only once'
'Context already initialized, context can be initialized only once',
)
}
context = newContext
Expand Down
6 changes: 1 addition & 5 deletions packages/lib/cli-common/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { Transaction, VersionedTransaction } from '@solana/web3.js'
import { ExecutionError } from '@marinade.finance/web3js-common'

export class CliCommandError extends ExecutionError {
readonly cause?: Error
readonly logs?: string[]
readonly transaction?: Transaction | VersionedTransaction

constructor({
commandName,
valueName,
Expand Down Expand Up @@ -36,7 +32,7 @@ export class CliCommandError extends ExecutionError {
commandName,
valueName,
value,
msg
msg,
)
} else {
errorMessage = format('%s: %s', commandName, msg)
Expand Down
8 changes: 5 additions & 3 deletions packages/lib/cli-common/src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function print_data(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any,
format: FormatType,
valueName = '--format'
valueName = '--format',
): void {
if (format === 'text') {
console.log(data)
Expand Down Expand Up @@ -111,7 +111,9 @@ export class ChainedKeyNameFormatter extends BaseObjectFormatter {
export function reformat(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any,
formatter: ObjectFormatterFn | BaseObjectFormatter = new BaseObjectFormatter()
formatter:
| ObjectFormatterFn
| BaseObjectFormatter = new BaseObjectFormatter(),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any {
let result: any // eslint-disable-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -149,7 +151,7 @@ export function reformat(
formatterResult.records.forEach(
({ key: formattedKey, value: formattedValue }) => {
result[formattedKey] = formattedValue
}
},
)
break
}
Expand Down
Loading

0 comments on commit 49df53b

Please sign in to comment.