Skip to content

Add initialize to test-cli - #108

Merged
kaze-cow merged 12 commits into
mainfrom
kaze/sc-331-add-initialize-to-test_cli
Aug 21, 2026
Merged

Add initialize to test-cli#108
kaze-cow merged 12 commits into
mainfrom
kaze/sc-331-add-initialize-to-test_cli

Conversation

@kaze-cow

@kaze-cow kaze-cow commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

We don't currently have any neat way to Initialize a newly deployed settlement program.

Thankfully there is a test-cli which is well suited for just that!

This PR adds cow initialize, which sends the Initialize instruction 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 deploy now runs it right after solana program deploy, so a fresh deployment comes out usable in one step. Two details there: the recipe's programid argument 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 what solana program deploy uses while the CLI would otherwise default to devnet regardless of where we just deployed.

On a plain upgrade the state PDA already exists, so initialize fails 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:

  • Pull --rpc-url from solana config file if it exists. Its easy to forget that it isnt synced otherwise
  • Add a unified print_summary function which can be used by test-cli functions going forward

How to test

Against devnet (or a local validator with --rpc-url):

$ cargo run -p cow-test-cli -- initialize
signature = ...
 statePda = ...

Re-running it should fail, since the state PDA already exists. Then confirm the usual sell/buy/settle flow 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:

solana-keygen new -o /tmp/test-deploy.json
just deploy /tmp/test-deploy.json ~/.config/solana/id.json

Example output:

...
Finished building program
Program Solana version: v4.0.3
Docker image Solana version: v4.0.3
ce1a3b7688bc5867e3669e56997b150bec064f91b96528a36810a80fe4900025
Program Id: 3KcWEL1hhwbWDbX611VhXqG5T54Myi4RE9LqBbRX73jz

Signature: 3ZKhKX72aF5Fg6aifydwYHiNJ6t9BJt4FdKfqfpuVLJ4NQnC6sx4DmWmQeLyKM37C1vxnWihF2sg3tGb6wVY6NHz

   Compiling settlement-interface v0.1.0 (/Users/kaze/code/cowprotocol/solana-programs/interface)
   Compiling settlement-client v0.1.0 (/Users/kaze/code/cowprotocol/solana-programs/client)
   Compiling cow-test-cli v0.1.0 (/Users/kaze/code/cowprotocol/solana-programs/test-cli)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.78s
     Running `target/debug/cow --rpc-url 'https://api.devnet.solana.com' --program-id 3KcWEL1hhwbWDbX611VhXqG5T54Myi4RE9LqBbRX73jz --keypair /Users/kaze/.config/solana/id.json initialize`
signature = 5tjC6LcfxFZa4e3ZmsZsCPNZk5nqmh5trWvEUDnH84eexyV9KnHGVoNY3zAq5r2WuPV5s7VZQf9C7jHbT96Q3i2q
 statePda = ELEzQtvEMFTsoDvdSEnf3jnuLjdPPQ7xwmC5jtrX12k5

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>
@linear-code

linear-code Bot commented Aug 18, 2026

Copy link
Copy Markdown

SC-331

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>
@kaze-cow kaze-cow self-assigned this Aug 18, 2026
@kaze-cow
kaze-cow marked this pull request as ready for review August 18, 2026 07:37
@kaze-cow
kaze-cow requested a review from a team as a code owner August 18, 2026 07:37
@kaze-cow

Copy link
Copy Markdown
Contributor Author

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 fedgiac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The only thing blocking merge for me is the RPC handling.

Comment thread test-cli/src/cmd/initialize.rs Outdated
Comment thread Justfile
Comment thread README.md Outdated
@kaze-cow
kaze-cow requested a review from fedgiac August 21, 2026 06:23

@fedgiac fedgiac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment to address but I expect it to be totally uncontroversial so I'm approving in advance for merging.

Comment thread test-cli/src/main.rs Outdated
#[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)

@fedgiac fedgiac Aug 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmh, no, otherwise it defaults to mainnet? I'd change the default to be devnet instead, it's safer, but your pick.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@kaze-cow
kaze-cow merged commit ac7558c into main Aug 21, 2026
14 checks passed
@kaze-cow
kaze-cow deleted the kaze/sc-331-add-initialize-to-test_cli branch August 21, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants