Skip to content

Commit

Permalink
fix: update to remove expire and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Oct 19, 2023
1 parent 153ed5c commit 6fa68ec
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 80 deletions.
4 changes: 2 additions & 2 deletions cmd/crates/soroban-test/tests/it/integration/custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde_json::json;
use soroban_cli::commands;
use soroban_test::TestEnv;

use crate::integration::util::{bump_contract, deploy_custom, CUSTOM_TYPES};
use crate::integration::util::{deploy_custom, extend_contract, CUSTOM_TYPES};

use super::util::invoke_with_roundtrip;

Expand All @@ -17,7 +17,7 @@ fn invoke_custom(e: &TestEnv, id: &str, func: &str) -> assert_cmd::Command {
async fn parse() {
let sandbox = &TestEnv::default();
let id = &deploy_custom(sandbox);
bump_contract(sandbox, id, CUSTOM_TYPES).await;
extend_contract(sandbox, id, CUSTOM_TYPES).await;
symbol(sandbox, id);
string_with_quotes(sandbox, id).await;
symbol_with_quotes(sandbox, id).await;
Expand Down
8 changes: 4 additions & 4 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use soroban_cli::commands::{
};
use soroban_test::TestEnv;

use crate::{integration::util::bump_contract, util::DEFAULT_SEED_PHRASE};
use crate::{integration::util::extend_contract, util::DEFAULT_SEED_PHRASE};

use super::util::{
add_test_seed, bump, deploy_hello, network_passphrase, network_passphrase_arg, rpc_url,
add_test_seed, deploy_hello, extend, network_passphrase, network_passphrase_arg, rpc_url,
rpc_url_arg, DEFAULT_PUB_KEY, DEFAULT_PUB_KEY_1, DEFAULT_SECRET_KEY, HELLO_WORLD,
};

Expand All @@ -16,7 +16,7 @@ use super::util::{
async fn invoke() {
let sandbox = &TestEnv::default();
let id = &deploy_hello(sandbox);
bump_contract(sandbox, id, HELLO_WORLD).await;
extend_contract(sandbox, id, HELLO_WORLD).await;
// Note that all functions tested here have no state
invoke_hello_world(sandbox, id);
invoke_hello_world_with_lib(sandbox, id).await;
Expand Down Expand Up @@ -193,7 +193,7 @@ async fn contract_data_read() {
let id = &deploy_hello(sandbox);
let res = sandbox.invoke(&["--id", id, "--", "inc"]).await.unwrap();
assert_eq!(res.trim(), "1");
bump(sandbox, id, Some(KEY)).await;
extend(sandbox, id, Some(KEY)).await;

sandbox
.new_assert_cmd("contract")
Expand Down
14 changes: 7 additions & 7 deletions cmd/crates/soroban-test/tests/it/integration/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,32 @@ pub fn deploy_contract(sandbox: &TestEnv, wasm: &Wasm) -> String {
TEST_CONTRACT_ID.to_string()
}

pub async fn bump_contract(sandbox: &TestEnv, id: &str, wasm: &Wasm<'_>) {
bump(sandbox, id, None).await;
let cmd: contract::bump::Cmd = sandbox.cmd_arr(&[
pub async fn extend_contract(sandbox: &TestEnv, id: &str, wasm: &Wasm<'_>) {
extend(sandbox, id, None).await;
let cmd: contract::extend::Cmd = sandbox.cmd_arr(&[
"--wasm-hash",
wasm.hash().unwrap().to_string().as_str(),
"--durability",
"persistent",
"--ledgers-to-expire",
"--ledgers-to-extend",
"100000",
]);
cmd.run().await.unwrap();
}

pub async fn bump(sandbox: &TestEnv, id: &str, value: Option<&str>) {
pub async fn extend(sandbox: &TestEnv, id: &str, value: Option<&str>) {
let mut args = vec![
"--id",
id,
"--durability",
"persistent",
"--ledgers-to-expire",
"--ledgers-to-extend",
"100000",
];
if let Some(value) = value {
args.push("--key");
args.push(value);
}
let cmd: contract::bump::Cmd = sandbox.cmd_arr(&args);
let cmd: contract::extend::Cmd = sandbox.cmd_arr(&args);
cmd.run().await.unwrap();
}
2 changes: 1 addition & 1 deletion cmd/crates/soroban-test/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod arg_parsing;
mod config;
mod help;
#[cfg(feature = "integration")]
// #[cfg(feature = "integration")]
mod integration;
mod lab;
mod plugin;
Expand Down
57 changes: 4 additions & 53 deletions cmd/soroban-cli/src/commands/contract/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ pub struct Cmd {
/// Number of ledgers to extend the entries
#[arg(long, required = true)]
pub ledgers_to_extend: u32,

/// Only print the new expiration ledger
/// Only print the new TTL ledger
#[arg(long)]
pub expiration_ledger_only: bool,

pub extension_ledger_only: bool,
#[command(flatten)]
pub key: key::Args,

#[command(flatten)]
pub config: config::Args,
#[command(flatten)]
Expand Down Expand Up @@ -83,12 +80,8 @@ pub enum Error {
impl Cmd {
#[allow(clippy::too_many_lines)]
pub async fn run(&self) -> Result<(), Error> {
let expiration_ledger_seq = if self.config.is_no_network() {
self.run_in_sandbox()?
} else {
self.run_against_rpc_server().await?
};
if self.expiration_ledger_only {
let expiration_ledger_seq = self.run_against_rpc_server().await?;
if self.extension_ledger_only {
println!("{expiration_ledger_seq}");
} else {
println!("New ttl ledger: {expiration_ledger_seq}");
Expand Down Expand Up @@ -196,46 +189,4 @@ impl Cmd {
_ => Err(Error::LedgerEntryNotFound),
}
}

fn run_in_sandbox(&self) -> Result<u32, Error> {
let keys = self.key.parse_keys()?;

// Initialize storage and host
// TODO: allow option to separate input and output file
let mut state = self.config.get_state()?;

// Update all matching entries
let mut expiration_ledger_seq = None;
state.ledger_entries = state
.ledger_entries
.iter()
.map(|(k, v)| {
let new_k = k.as_ref().clone();
let new_v = v.0.as_ref().clone();
let new_e = v.1;
(
Box::new(new_k.clone()),
(
Box::new(new_v),
if keys.contains(&new_k) {
// It must have an expiration since it's a contract data entry
let old_expiration = v.1.unwrap();
expiration_ledger_seq = Some(old_expiration + self.ledgers_to_extend);
expiration_ledger_seq
} else {
new_e
},
),
)
})
.collect::<Vec<_>>();

self.config.set_state(&state)?;

let Some(new_expiration_ledger_seq) = expiration_ledger_seq else {
return Err(Error::LedgerEntryNotFound);
};

Ok(new_expiration_ledger_seq)
}
}
8 changes: 4 additions & 4 deletions cmd/soroban-cli/src/commands/contract/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Cmd {
for FullLedgerEntry {
key,
val,
live_until_ledger_seq: expiration_ledger_seq,
live_until_ledger_seq,
last_modified_ledger,
} in &entries.entries
{
Expand All @@ -134,7 +134,7 @@ impl Cmd {
error: e,
})?,
last_modified_ledger.to_string(),
expiration_ledger_seq.to_string(),
live_until_ledger_seq.to_string(),
],
Output::Json => [
serde_json::to_string_pretty(&key).map_err(|error| {
Expand All @@ -155,7 +155,7 @@ impl Cmd {
error,
}
})?,
serde_json::to_string_pretty(&expiration_ledger_seq).map_err(|error| {
serde_json::to_string_pretty(&live_until_ledger_seq).map_err(|error| {
Error::CannotPrintJsonResult {
result: val.clone(),
error,
Expand All @@ -166,7 +166,7 @@ impl Cmd {
key.to_xdr_base64()?,
val.to_xdr_base64()?,
last_modified_ledger.to_xdr_base64()?,
expiration_ledger_seq.to_xdr_base64()?,
live_until_ledger_seq.to_xdr_base64()?,
],
};
out.write_record(output)
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Cmd {
ledgers_to_extend,
config: self.config.clone(),
fee: self.fee.clone(),
expiration_ledger_only: false,
extension_ledger_only: false,
}
.run()
.await?;
Expand Down
2 changes: 0 additions & 2 deletions cmd/soroban-cli/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ pub enum Error {
SpecBase64(#[from] soroban_spec::read::ParseSpecBase64Error),
#[error("Fee was too large {0}")]
LargeFee(u64),
#[error("Failed to parse LedgerEntryData\nkey:{0:?}\nvalue:{1:?}\nexpiration:{2:?}")]
FailedParseLedgerEntryData(LedgerKey, LedgerEntryData, LedgerEntryData),
}

#[derive(serde::Deserialize, serde::Serialize, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func extend(t *testing.T, contractId string, amount string, rest string) uint64
res := runSuccessfulCLICmd(
t,
fmt.Sprintf(
"contract extend --expiration-ledger-only --id=%s --durability persistent --ledgers-to-extend=%s %s",
"contract extend --extension-ledger-only --id=%s --durability persistent --ledgers-to-extend=%s %s",
contractId,
amount,
rest,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stellar/go v0.0.0-20231018140335-d50c63e68acc
github.com/stellar/go v0.0.0-20231016174715-c7d3a47ee7a2
github.com/stretchr/testify v1.8.4
golang.org/x/mod v0.13.0
gotest.tools/v3 v3.5.0
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ github.com/gobuffalo/logger v1.0.6 h1:nnZNpxYo0zx+Aj9RfMPBm+x9zAU2OayFh/xrAWi34H
github.com/gobuffalo/logger v1.0.6/go.mod h1:J31TBEHR1QLV2683OXTAItYIg8pv2JMHnF/quuAbMjs=
github.com/gobuffalo/packd v1.0.2 h1:Yg523YqnOxGIWCp69W12yYBKsoChwI7mtu6ceM9Bwfw=
github.com/gobuffalo/packd v1.0.2/go.mod h1:sUc61tDqGMXON80zpKGp92lDb86Km28jfvX7IAyxFT8=
github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg=
github.com/gobuffalo/packr/v2 v2.8.3 h1:xE1yzvnO56cUC0sTpKR3DIbxZgB54AftTFMhB2XEWlY=
github.com/gobuffalo/packr/v2 v2.8.3/go.mod h1:0SahksCVcx4IMnigTjiFuyldmTrdTctXsOdiU5KwbKc=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down Expand Up @@ -203,8 +204,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY=
github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand Down Expand Up @@ -332,8 +333,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI=
github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI=
github.com/stellar/go v0.0.0-20231018140335-d50c63e68acc h1:FlT7AjN+0tVm8NpFwhQzAaBSfAIzm1vduOwQ0rin7m0=
github.com/stellar/go v0.0.0-20231018140335-d50c63e68acc/go.mod h1:Xkzo5tTJI31Y9VIR5FjviXZWYsHXZKChm+Ii8uHaG30=
github.com/stellar/go v0.0.0-20231016174715-c7d3a47ee7a2 h1:IOOHd1yrwmK0wiAuNDmoHUPTucO0oGkkKa3CE1pgn2E=
github.com/stellar/go v0.0.0-20231016174715-c7d3a47ee7a2/go.mod h1:g78pyZyDFnKMJUaBIXxH7xyQ7PdDrvrJTFCxdGMMb3c=
github.com/stellar/go-xdr v0.0.0-20230919160922-6c7b68458206 h1:UFuvvpbWL8+jqO1QmKYWSVhiMp4MRiIFd8/zQlUINH0=
github.com/stellar/go-xdr v0.0.0-20230919160922-6c7b68458206/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit 6fa68ec

Please sign in to comment.