Skip to content

Commit

Permalink
fix for test to run
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Dec 21, 2023
1 parent 8585093 commit 75cf34e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@ import {
Transaction,
} from '@solana/web3.js'
import {
VALIDATOR_BONDS_PROGRAM_ID,
ValidatorBondsProgram,
getConfig,
getProgram,
} from '@marinade.finance/validator-bonds-sdk'
import { initTest } from './utils'

beforeAll(() => {
shellMatchers()
})

describe('Init config account using CLI', () => {
const provider = AnchorProvider.env()
provider.opts.skipPreflight = true
const program = getProgram({
connection: provider,
programId: VALIDATOR_BONDS_PROGRAM_ID,
})
let provider: AnchorProvider
let program: ValidatorBondsProgram

let configPath: string
let configKeypair: Keypair
let configCleanup: () => Promise<void>

beforeAll(async () => {
shellMatchers()
;({ provider, program } = await initTest())
})

beforeEach(async () => {
// eslint-disable-next-line @typescript-eslint/no-extra-semi
;({
Expand Down
21 changes: 11 additions & 10 deletions packages/validator-bonds-cli/__tests__/test-validator/show.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@ import { AnchorProvider } from '@coral-xyz/anchor'
import { shellMatchers } from '@marinade.finance/jest-utils'
import YAML from 'yaml'
import {
getProgram,
initConfigInstruction,
VALIDATOR_BONDS_PROGRAM_ID,
findBondsWithdrawerAuthority,
ValidatorBondsProgram,
} from '@marinade.finance/validator-bonds-sdk'
import { executeTxSimple } from '@marinade.finance/web3js-common'
import { transaction } from '@marinade.finance/anchor-common'
import { Keypair } from '@solana/web3.js'
import { initTest } from './utils'

beforeAll(() => {
shellMatchers()
})

describe('Show command using CLI', () => {
const provider = AnchorProvider.env()
provider.opts.skipPreflight = true
provider.opts.commitment = 'confirmed'
const program = getProgram({
connection: provider.connection,
wallet: provider.wallet,
opts: provider.opts,
programId: VALIDATOR_BONDS_PROGRAM_ID,
let provider: AnchorProvider
let program: ValidatorBondsProgram

beforeAll(async () => {
shellMatchers()
;({ provider, program } = await initTest())
})

it('show config', async () => {
Expand Down Expand Up @@ -74,6 +72,7 @@ describe('Show command using CLI', () => {
operatorAuthority: operatorAuthority.toBase58(),
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
minimumStakeLamports: 1000000000,
bondsWithdrawerAuthorityBump,
reserved: [512],
},
Expand Down Expand Up @@ -111,6 +110,7 @@ describe('Show command using CLI', () => {
operatorAuthority: operatorAuthority.toBase58(),
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
minimumStakeLamports: 1000000000,
bondsWithdrawerAuthorityBump,
reserved: [512],
},
Expand Down Expand Up @@ -175,6 +175,7 @@ describe('Show command using CLI', () => {
operatorAuthority: operatorAuthority.toBase58(),
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
minimumStakeLamports: 1000000000,
bondsWithdrawerAuthorityBump,
reserved: [512],
},
Expand Down
19 changes: 19 additions & 0 deletions packages/validator-bonds-cli/__tests__/test-validator/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as anchor from '@coral-xyz/anchor'
import { AnchorProvider } from '@coral-xyz/anchor'
import {
ValidatorBondsProgram,
getProgram,
} from '@marinade.finance/validator-bonds-sdk'

export async function initTest(): Promise<{
program: ValidatorBondsProgram
provider: AnchorProvider
}> {
if (process.env.ANCHOR_PROVIDER_URL?.includes('localhost')) {
// workaround to: https://github.com/coral-xyz/anchor/pull/2725
process.env.ANCHOR_PROVIDER_URL = 'http://127.0.0.1:8899'
}
const provider = AnchorProvider.env() as anchor.AnchorProvider
provider.opts.skipPreflight = true
return { program: getProgram(provider), provider }
}
3 changes: 2 additions & 1 deletion packages/validator-bonds-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ program
.allowExcessArguments(false)
.option(
'-u, --cluster <cluster>',
'solana cluster URL, accepts shortcuts (d/devnet, m/mainnet) (default: http://localhost:8899)'
'solana cluster URL, accepts shortcuts (d/devnet, m/mainnet)',
'http://127.0.0.1:8899'
)
.option('-c <cluster>', 'alias for "-u, --cluster"')
.option('--commitment <commitment>', 'Commitment', 'confirmed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ export async function initTest(): Promise<{
program: ValidatorBondsProgram
provider: AnchorProvider
}> {
anchor.setProvider(anchor.AnchorProvider.env())
const provider = anchor.getProvider() as anchor.AnchorProvider
if (process.env.ANCHOR_PROVIDER_URL?.includes('localhost')) {
// workaround to: https://github.com/coral-xyz/anchor/pull/2725
process.env.ANCHOR_PROVIDER_URL = 'http://127.0.0.1:8899'
}
const provider = AnchorProvider.env() as anchor.AnchorProvider
provider.opts.skipPreflight = true
return { program: getProgram(provider), provider }
}

0 comments on commit 75cf34e

Please sign in to comment.