Skip to content

Commit

Permalink
feat: add flag to bump cmd to parse returned expiration to test bump
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Sep 13, 2023
1 parent 8efbfa6 commit 2e978bf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
11 changes: 9 additions & 2 deletions cmd/soroban-cli/src/commands/contract/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(())
}
Expand Down
30 changes: 23 additions & 7 deletions cmd/soroban-rpc/internal/test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"fmt"
"os"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions docs/soroban-cli-full-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ If no keys are specified the contract itself is bumped.
Temporary

* `--ledgers-to-expire <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_URL>` — RPC server endpoint
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
Expand Down

0 comments on commit 2e978bf

Please sign in to comment.