diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/hello_world/src/lib.rs b/cmd/crates/soroban-test/tests/fixtures/test-wasms/hello_world/src/lib.rs index 24cb2d8b21..7bdf62194b 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/hello_world/src/lib.rs +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/hello_world/src/lib.rs @@ -30,7 +30,7 @@ impl Contract { addr } - pub fn inc(env: Env) { + pub fn inc(env: Env) -> u32 { let mut count: u32 = env.storage().persistent().get(&COUNTER).unwrap_or(0); // Panic if the value of COUNTER is not u32. log!(&env, "count: {}", count); @@ -39,6 +39,7 @@ impl Contract { // Save the count. env.storage().persistent().set(&COUNTER, &count); + count } #[allow(unused_variables)] diff --git a/cmd/soroban-cli/src/commands/contract/bump.rs b/cmd/soroban-cli/src/commands/contract/bump.rs index 863917db6d..c39a61155e 100644 --- a/cmd/soroban-cli/src/commands/contract/bump.rs +++ b/cmd/soroban-cli/src/commands/contract/bump.rs @@ -181,7 +181,7 @@ impl Cmd { .await?; tracing::trace!(?result); - tracing::trace!(?meta); + tracing::trace!("Meta:\n {meta:#?}"); if !events.is_empty() { tracing::info!("Events:\n {events:#?}"); } diff --git a/cmd/soroban-rpc/internal/test/cli_test.go b/cmd/soroban-rpc/internal/test/cli_test.go index 414eada98d..8b746f3f7e 100644 --- a/cmd/soroban-rpc/internal/test/cli_test.go +++ b/cmd/soroban-rpc/internal/test/cli_test.go @@ -61,24 +61,26 @@ func TestCLIContractDeploy(t *testing.T) { func TestCLIContractDeployAndInvoke(t *testing.T) { NewCLITest(t) - output := runSuccessfulCLICmd(t, "contract deploy --salt=0 --wasm "+helloWorldContractPath) - contractID := strings.TrimSpace(output) - output = runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id %s -- hello --world=world", contractID)) + contractID := runSuccessfulCLICmd(t, "contract deploy --salt=0 --wasm "+helloWorldContractPath) + output := runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id %s -- hello --world=world", contractID)) require.Contains(t, output, `["Hello","world"]`) } func TestCLISimulateTransactionBumpAndRestoreFootprint(t *testing.T) { test := NewCLITest(t) - output := runSuccessfulCLICmd(t, "contract deploy --salt=0 --wasm "+helloWorldContractPath) - contractID := strings.TrimSpace(output) + contractID := runSuccessfulCLICmd(t, "contract deploy --salt=0 --wasm "+helloWorldContractPath) 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) - 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) + key, err := xdr.MarshalBase64(symToScVal(xdr.ScSymbol("COUNTER"))) + require.NoError(t, err) + initialExpiration := bumpBase64(t, contractID, key, "--durability persistent --ledgers-to-expire 1") + newExpiration := bumpSym(t, contractID, "COUNTER", "--durability persistent --ledgers-to-expire 20") + require.Greater(t, newExpiration, initialExpiration) + waitForKeyToExpire(t, test, getTestContractIDFromAccountAndSalt(t, 0), symToScVal(xdr.ScSymbol("COUNTER"))) + count = runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id %s -- inc", contractID)) + require.Equal(t, "3", count) } func symToScVal(s xdr.ScSymbol) xdr.ScVal { @@ -158,12 +160,15 @@ func deploy(t *testing.T, wasmPath string, id uint32) string { } 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))) + return bump(t, contractID, fmt.Sprintf("--key-xdr=%s %s", 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))) + return bump(t, contractID, fmt.Sprintf("--key=%s %s", sym, args)) +} +func bump(t *testing.T, contractID string, args string) uint64 { + return parseInt(t, runSuccessfulCLICmd(t, fmt.Sprintf("contract bump --id=%s --ledger-expiration-only %s", contractID, args))) } func parseInt(t *testing.T, s string) uint64 { @@ -178,9 +183,10 @@ func parseInt(t *testing.T, s string) uint64 { func runSuccessfulCLICmd(t *testing.T, cmd string) string { res := runCLICommand(t, cmd) - require.NoError(t, res.Error, fmt.Sprintf("stderr:\n%s\nstdout:\n%s\n", res.Stderr(), res.Stdout())) - println(fmt.Sprintf("stderr:\n%s\nstdout:\n-------\n%s\n-----\n", res.Stderr(), res.Stdout())) - return res.Stdout() + stdout, stderr := res.Stdout(), res.Stderr() + require.NoError(t, res.Error, fmt.Sprintf("stderr:\n%s\nstdout:\n%s\n", stderr, stdout)) + println(fmt.Sprintf("stderr:\n%s\nstdout:\n-------\n%s\n-----\n", stderr, stdout)) + return strings.TrimSpace(stdout) } func cliCmd(t *testing.T, cmd string) icmd.Cmd {