diff --git a/cmd/soroban-cli/src/commands/contract/bump.rs b/cmd/soroban-cli/src/commands/contract/bump.rs index 1a3aefe350..863917db6d 100644 --- a/cmd/soroban-cli/src/commands/contract/bump.rs +++ b/cmd/soroban-cli/src/commands/contract/bump.rs @@ -65,6 +65,10 @@ pub struct Cmd { #[arg(long, required = true)] ledgers_to_expire: u32, + /// Only print the new expiration ledger sequence after the bump + #[arg(long)] + ledger_expiration_only: bool, + #[command(flatten)] config: config::Args, #[command(flatten)] @@ -121,8 +125,11 @@ impl Cmd { } else { self.run_against_rpc_server().await? }; - - println!("New expiration ledger: {expiration_ledger_seq}"); + if self.ledger_expiration_only { + println!("{expiration_ledger_seq}"); + } else { + println!("New expiration ledger: {expiration_ledger_seq}"); + } Ok(()) } diff --git a/cmd/soroban-rpc/internal/test/cli_test.go b/cmd/soroban-rpc/internal/test/cli_test.go index 264a108591..414eada98d 100644 --- a/cmd/soroban-rpc/internal/test/cli_test.go +++ b/cmd/soroban-rpc/internal/test/cli_test.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "fmt" "os" + "strconv" "strings" "testing" "time" @@ -68,10 +69,14 @@ func TestCLIContractDeployAndInvoke(t *testing.T) { func TestCLISimulateTransactionBumpAndRestoreFootprint(t *testing.T) { test := NewCLITest(t) - contractID := deploy(t, helloWorldContractPath, 0) + output := runSuccessfulCLICmd(t, "contract deploy --salt=0 --wasm "+helloWorldContractPath) + contractID := strings.TrimSpace(output) count := runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id %s -- inc", contractID)) + initialExpiration := bumpSym(t, contractID, "COUNTER", "--durability persistent --ledgers-to-expire 0") + newExpiration := bumpSym(t, contractID, "COUNTER", "--durability persistent --ledgers-to-expire 20") + require.Equal(t, initialExpiration+20, newExpiration) require.Equal(t, "1", count) - waitForKey(t, test, testContractID(t, 0), symToScVal(xdr.ScSymbol("COUNTER"))) + waitForKeyToExpire(t, test, getTestContractIDFromAccountAndSalt(t, 0), symToScVal(xdr.ScSymbol("COUNTER"))) count = runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id %s -- inc", contractID)) require.Equal(t, "2", count) } @@ -152,9 +157,20 @@ func deploy(t *testing.T, wasmPath string, id uint32) string { return contractID } -// func bump(t *testing.T, contractID string, keyBase64 string) string { -// return runSuccessfulCLICmd(t, fmt.Sprintf("contract bump --id=%s, --key-xdr=%s", contractID, keyBase64)) -// } +func bumpBase64(t *testing.T, contractID string, keyBase64 string, args string) uint64 { + return parseInt(t, runSuccessfulCLICmd(t, fmt.Sprintf("contract bump --id=%s --ledger_expiration_only --key-xdr=%s %s", contractID, keyBase64, args))) +} + +func bumpSym(t *testing.T, contractID string, sym string, args string) uint64 { + return parseInt(t, runSuccessfulCLICmd(t, fmt.Sprintf("contract bump --id=%s --ledger_expiration_only --key=%s %s", contractID, sym, args))) + +} + +func parseInt(t *testing.T, s string) uint64 { + i, err := strconv.ParseUint(strings.TrimSpace(s), 10, 64) + require.NoError(t, err) + return i +} // func invoke(t *testing.T, contractID string, testAccountID uint32, args string) string { // return runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --hd-path %d --id %s -- %s", testAccountID, contractID, args)) @@ -189,14 +205,14 @@ func getAccountFromID(t *testing.T, id uint32) string { } func getTestContractIDFromAccountAndSalt(t *testing.T, id uint32) [32]byte { - return getContractID(t, testAccount(t, id), testSalt, StandaloneNetworkPassphrase) + return getContractID(t, getAccountFromID(t, id), testSalt, StandaloneNetworkPassphrase) } const MILLION string = "1000000" func NewCLITest(t *testing.T) *Test { test := NewTest(t) - fundAccount(t, test, testAccount(t, 0), MILLION) + fundAccount(t, test, getAccountFromID(t, 0), MILLION) return test } diff --git a/docs/soroban-cli-full-docs.md b/docs/soroban-cli-full-docs.md index ea17a2183d..526e02c962 100644 --- a/docs/soroban-cli-full-docs.md +++ b/docs/soroban-cli-full-docs.md @@ -248,6 +248,7 @@ If no keys are specified the contract itself is bumped. Temporary * `--ledgers-to-expire ` — Number of ledgers to extend the entries +* `--ledger-expiration-only` — Only print the new expiration ledger sequence after the bump * `--rpc-url ` — RPC server endpoint * `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config