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.
fedgiac
left a comment
There was a problem hiding this comment.
One comment to address but I expect it to be totally uncontroversial so I'm approving in advance for merging.
| #[command(name = "cow", about = "CoW Protocol Solana dev/testing CLI")] | ||
| struct Cli { | ||
| /// Solana RPC endpoint | ||
| /// Solana RPC endpoint (defaults to the `solana config` endpoint, or devnet) |
There was a problem hiding this comment.
Mmh, no, otherwise it defaults to mainnet? I'd change the default to be devnet instead, it's safer, but your pick.
There was a problem hiding this comment.
this is how you know that I still make some of my changes by hand 😆
Since the solana cli itself defaults to mainnet, and because one of the largest consumers of this tool is going to be solvers who primarily work on mainnet, this seems like the most sensible choice. sg?
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.As part of the review comments, some additional minor changes were made to the test-cli:
--rpc-urlfrom solana config file if it exists. Its easy to forget that it isnt synced otherwiseprint_summaryfunction which can be used by test-cli functions going forwardHow 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: