Skip to content

Commit

Permalink
[cli] fixing issue with not possible to use --keypair arg
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Jan 2, 2024
1 parent 9c38c0f commit 09bd963
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
8 changes: 3 additions & 5 deletions packages/validator-bonds-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ Options:
-u, --cluster <cluster> solana cluster URL, accepts shortcuts (d/devnet, m/mainnet) (default: "http://127.0.0.1:8899")
-c <cluster> alias for "-u, --cluster"
--commitment <commitment> Commitment (default: "confirmed")
-k, --keypair <keypair-or-ledger> Wallet keypair (path or ledger url in format usb://ledger/[<pubkey>][?key=<derivedPath>]) (default: ~/.config/solana/id.json)
-k, --keypair <keypair-or-ledger> Wallet keypair (path or ledger url in format usb://ledger/[<pubkey>][?key=<derivedPath>]). Wallet keypair is used to pay for the transaction fees and as default value for signers. (default: ~/.config/solana/id.json)
--program-id <pubkey> Program id of validator bonds contract (default: vBoNdEvzMrSai7is21XgVYik65mqtaKXuSdMBJ1xkW4)
-s, --simulate Simulate (default: false)
-p, --print-only Print only mode, no execution, instructions are printed in base64 to output. This can be used for placing the admin commands to SPL
Governance UI by hand. (default: false)
--skip-preflight transaction execution flag "skip-preflight", see https://solanacookbook.com/guides/retrying-transactions.html#the-cost-of-skipping-preflight
(default: false)
-p, --print-only Print only mode, no execution, instructions are printed in base64 to output. This can be used for placing the admin commands to SPL Governance UI by hand. (default: false)
--skip-preflight transaction execution flag "skip-preflight", see https://solanacookbook.com/guides/retrying-transactions.html#the-cost-of-skipping-preflight (default: false)
-d, --debug printing more detailed information of the CLI execution (default: false)
-v, --verbose alias for --debug (default: false)
-h, --help display help for command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ describe('Init config account using CLI', () => {
let configPath: string
let configKeypair: Keypair
let configCleanup: () => Promise<void>
let keypairFeePayerPath: string
let keypairFeePayerKeypair: Keypair
let keypairFeePayerCleanup: () => Promise<void>

beforeAll(async () => {
shellMatchers()
Expand All @@ -31,10 +34,16 @@ describe('Init config account using CLI', () => {
keypair: configKeypair,
cleanup: configCleanup,
} = await createTempFileKeypair())
;({
path: keypairFeePayerPath,
keypair: keypairFeePayerKeypair,
cleanup: keypairFeePayerCleanup,
} = await createTempFileKeypair())
})

afterEach(async () => {
await configCleanup()
await keypairFeePayerCleanup()
})

it('inits config account', async () => {
Expand All @@ -44,17 +53,30 @@ describe('Init config account using CLI', () => {
cleanup: cleanupRentPayer,
} = await createTempFileKeypair()
const rentPayerFunds = 10 * LAMPORTS_PER_SOL
const tx = new Transaction().add(
SystemProgram.transfer({
fromPubkey: provider.wallet.publicKey,
toPubkey: rentPayerKeypair.publicKey,
lamports: rentPayerFunds,
})
await provider.sendAndConfirm(
new Transaction().add(
SystemProgram.transfer({
fromPubkey: provider.wallet.publicKey,
toPubkey: rentPayerKeypair.publicKey,
lamports: rentPayerFunds,
})
)
)
await provider.sendAndConfirm!(tx)
await expect(
provider.connection.getBalance(rentPayerKeypair.publicKey)
).resolves.toStrictEqual(rentPayerFunds)
await provider.sendAndConfirm(
new Transaction().add(
SystemProgram.transfer({
fromPubkey: provider.wallet.publicKey,
toPubkey: keypairFeePayerKeypair.publicKey,
lamports: LAMPORTS_PER_SOL,
})
)
)
await expect(
provider.connection.getBalance(keypairFeePayerKeypair.publicKey)
).resolves.toStrictEqual(LAMPORTS_PER_SOL)

const admin = Keypair.generate().publicKey
const operator = Keypair.generate().publicKey
Expand All @@ -66,6 +88,8 @@ describe('Init config account using CLI', () => {
'cli',
'-u',
provider.connection.rpcEndpoint,
'-k',
keypairFeePayerPath,
'--program-id',
program.programId.toBase58(),
'init-config',
Expand Down Expand Up @@ -113,6 +137,8 @@ describe('Init config account using CLI', () => {
'cli',
'-u',
provider.connection.rpcEndpoint,
'-k',
keypairFeePayerPath,
'--program-id',
program.programId.toBase58(),
'init-config',
Expand Down
10 changes: 5 additions & 5 deletions packages/validator-bonds-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
parseKeypair,
parsePubkey,
} from '@marinade.finance/cli-common'
import { Keypair } from '@solana/web3.js'
import { installCommands } from './commands'
import { Logger } from 'pino'
import { setValidatorBondsCliContext } from './context'
Expand All @@ -29,8 +28,9 @@ program
.option('--commitment <commitment>', 'Commitment', 'confirmed')
.option(
'-k, --keypair <keypair-or-ledger>',
'Wallet keypair (path or ledger url in format usb://ledger/[<pubkey>][?key=<derivedPath>]) ' +
` (default: ${DEFAULT_KEYPAIR_PATH})`
'Wallet keypair (path or ledger url in format usb://ledger/[<pubkey>][?key=<derivedPath>]). ' +
'Wallet keypair is used to pay for the transaction fees and as default value for signers. ' +
`(default: ${DEFAULT_KEYPAIR_PATH})`
)
.option(
'--program-id <pubkey>',
Expand Down Expand Up @@ -58,8 +58,8 @@ program
.hook('preAction', async (command: Command, action: Command) => {
const wallet = command.opts().keypair
const walletKeypair = wallet
? ((await wallet) as Keypair)
: await parseKeypair('~/.config/solana/id.json')
? await parseKeypair(wallet)
: await parseKeypair(DEFAULT_KEYPAIR_PATH)
if (command.opts().debug || command.opts().verbose) {
logger.level = 'debug'
}
Expand Down

0 comments on commit 09bd963

Please sign in to comment.