Add initialize to test-cli - #108
Conversation
Creating the singleton settlement state PDA previously required hand-rolling the transaction. Expose it as `cow initialize`, with `--reclaim-authority` defaulting to the payer, and print the resulting state PDA. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The state PDA has to exist before the program is usable, and it has to be recreated whenever a minor version bump relocates it. Fold that into the deploy recipe instead of leaving it as a manual follow-up step. The recipe's `programid` is a keypair file on a first deploy and an address on an upgrade, so resolve it to an address for the CLI. The RPC endpoint is read from the Solana config, which is what `solana program deploy` uses -- the CLI otherwise defaults to devnet regardless of where we just deployed. On a plain upgrade the state PDA already exists, so `initialize` fails there. That is expected and shouldn't fail the deploy, so it only warns. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
for general record, though it wasn't merged, we used this branch of the test-cli today as part of the v0.2 release. It worked pretty well once we merged in the version bump and other necessary changes! |
fedgiac
left a comment
There was a problem hiding this comment.
Looks good. The only thing blocking merge for me is the RPC handling.
| println!("signature: {sig}"); | ||
| println!("state PDA: {state_pda}"); |
There was a problem hiding this comment.
Nit: I've seen other commands with the same output, we could move this to a "print transaction" function.
| # A failure here is expected when upgrading a program whose state PDA already | ||
| # exists, so don't fail the deploy over it. | ||
| cargo run -p cow-test-cli -- \ | ||
| --rpc-url "$(solana config get json_rpc_url | awk '{print $NF}')" \ |
There was a problem hiding this comment.
We should definitely change this, the RPC URL of an initialization can easily be inconsistent with that of the program deployment, we would have totally stumbled upon this when we released 2.0.
Also, nit: we should recover the RPC URL in its own line so that if that fails we don't continue execution with a weird URL.
In general, to me it would be great if the CLI itself were to pick up the default URL instead of passing it in.
| ``` | ||
|
|
||
| If the package minor or major has been changed, it is also necessary to run initialize again. | ||
| `just deploy` finishes by running `initialize` to create the program's state PDA. On a plain upgrade that PDA already exists, so the step fails and prints a warning that can be ignored. After a minor or major bump the storage is relocated, so `initialize` creates the new PDA and is expected to succeed. |
There was a problem hiding this comment.
It sounds like on an upgrade you always reuse the same state PDA but this isn't true.
| `just deploy` finishes by running `initialize` to create the program's state PDA. On a plain upgrade that PDA already exists, so the step fails and prints a warning that can be ignored. After a minor or major bump the storage is relocated, so `initialize` creates the new PDA and is expected to succeed. | |
| `just deploy` finishes by running `initialize` to create the program's state PDA.\ | |
| If the deployment upgrades an existing program _and_ there's an either minor or major version bump, then this latter step fails and prints a warning that can be safely ignored. |
In principle we could check if it's already initialized in the CLI, by the way. But I won't push for that, it's fine like this.
We don't currently have any neat way to
Initializea newly deployed settlement program.Thankfully there is a test-cli which is well suited for just that!
This PR adds
cow initialize, which sends theInitializeinstruction and prints the resulting signature and state PDA.By default, all accounts/permissions are initialized to the transaction payer (which also is expected to have to be the current program upgrade authority). These can be overridden with flags.
just deploynow runs it right aftersolana program deploy, so a fresh deployment comes out usable in one step. Two details there: the recipe'sprogramidargument is a keypair file on a first deploy but an address on an upgrade, so it's resolved to an address for the CLI; and the RPC endpoint is read from the Solana config, since that's whatsolana program deployuses while the CLI would otherwise default to devnet regardless of where we just deployed.On a plain upgrade the state PDA already exists, so
initializefails there. That's expected and shouldn't fail an otherwise successful deploy, so it only prints a warning. After a minor or major bump the storage is relocated and it creates the new PDA for real. The README section on upgrading is updated accordingly — it previously described running initialize again as a manual step.How to test
Against devnet (or a local validator with
--rpc-url):Re-running it should fail, since the state PDA already exists. Then confirm the usual
sell/buy/settleflow works against that freshly initialized deployment.The whole deployment process can be tested pretty easily if you only have some testnet funds by cerating a fresh keypair and deploying to it. for example:
Example output: