Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug loading contract spec in sandbox when not deployed #745

Merged
merged 18 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl TestEnv {
/// to be the internal `temp_dir`.
pub fn new_assert_cmd(&self, subcommand: &str) -> Command {
let mut this = Command::cargo_bin("soroban").unwrap_or_else(|_| Command::new("soroban"));
this.arg("-q");
this.arg(subcommand);
this.current_dir(&self.temp_dir);
this
Expand Down
14 changes: 0 additions & 14 deletions cmd/crates/soroban-test/tests/it/custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ fn map_help() {
.stdout(predicates::str::contains("Map<u32, bool>"));
}

#[test]
fn set() {
invoke_with_roundtrip("set", json!([0, 1]));
}

#[test]
fn set_help() {
invoke(&TestEnv::default(), "set")
.arg("--help")
.assert()
.success()
.stdout(predicates::str::contains("Set<u32>"));
}

#[test]
fn vec_() {
invoke_with_roundtrip("vec", json!([0, 1]));
Expand Down
3 changes: 3 additions & 0 deletions cmd/crates/soroban-test/tests/it/invoke_sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ fn handles_kebab_case() {

#[tokio::test]
async fn fetch() {
// TODO: Currently this test fetches a live contract from futurenet. This obviously depends on
// futurenet for the test to work, which is not great. But also means that if we are upgrading
// the XDR ahead of a futurenet upgrade, this test will pass. Oof. :(
let e = TestEnv::default();
let f = e.dir().join("contract.wasm");
let cmd = e.cmd_arr::<fetch::Cmd>(&[
Expand Down
24 changes: 12 additions & 12 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use soroban_env_host::{
events::HostEvent,
storage::Storage,
xdr::{
self, AccountId, Error as XdrError, HostFunction, InvokeHostFunctionOp, LedgerEntryData,
LedgerFootprint, LedgerKey, LedgerKeyAccount, Memo, MuxedAccount, Operation, OperationBody,
Preconditions, PublicKey, ScBytes, ScSpecEntry, ScSpecFunctionV0, ScSpecTypeDef, ScVal,
ScVec, SequenceNumber, SorobanAddressCredentials, SorobanAuthorizationEntry,
SorobanCredentials, Transaction, TransactionExt, Uint256, VecM,
self, AccountId, Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp,
LedgerEntryData, LedgerFootprint, LedgerKey, LedgerKeyAccount, Memo, MuxedAccount,
Operation, OperationBody, Preconditions, PublicKey, ScAddress, ScSpecEntry,
ScSpecFunctionV0, ScSpecTypeDef, ScVal, ScVec, SequenceNumber, SorobanAddressCredentials,
SorobanAuthorizationEntry, SorobanCredentials, Transaction, TransactionExt, Uint256, VecM,
},
DiagnosticLevel, Host, HostError,
};
Expand Down Expand Up @@ -211,7 +211,7 @@ impl Cmd {

// Add the contract ID and the function name to the arguments
let mut complete_args = vec![
ScVal::Bytes(ScBytes(contract_id.try_into().unwrap())),
ScVal::Address(ScAddress::Contract(Hash(contract_id))),
ScVal::Symbol(
function
.try_into()
Expand Down Expand Up @@ -322,12 +322,12 @@ impl Cmd {

let snap = Rc::new(state.clone());
let mut storage = Storage::with_recording_footprint(snap);
let spec_entries = utils::get_contract_spec_from_storage(
&mut storage,
&state.sequence_number,
contract_id,
)
.map_err(Error::CannotParseContractSpec)?;
let spec_entries = if let Some(spec) = self.spec_entries()? {
spec
} else {
utils::get_contract_spec_from_storage(&mut storage, &state.sequence_number, contract_id)
.map_err(Error::CannotParseContractSpec)?
};
let budget = Budget::default();
if self.unlimited_budget {
budget.reset_unlimited();
Expand Down
7 changes: 7 additions & 0 deletions cmd/soroban-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ pub fn ledger_snapshot_read_or_default(
Err(soroban_ledger_snapshot::Error::Io(e)) if e.kind() == ErrorKind::NotFound => {
Ok(LedgerSnapshot {
network_id: sandbox_network_id(),
// These three "defaults" are not part of the actual default definition in
// rs-soroban-sdk, but if we don't have them the sandbox doesn't work right.
// Oof.
// TODO: Remove this hacky workaround.
min_persistent_entry_expiration: 4096,
min_temp_entry_expiration: 16,
max_entry_expiration: 6_312_000,
..Default::default()
})
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/soroban-rpc/lib/preflight/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ use soroban_env_host::fees::{
};
use soroban_env_host::storage::{AccessType, Footprint, Storage, StorageMap};
use soroban_env_host::xdr::{
ConfigSettingEntry, ConfigSettingId, DecoratedSignature, DiagnosticEvent, ExtensionPoint,
self, ConfigSettingEntry, ConfigSettingId, DecoratedSignature, DiagnosticEvent, ExtensionPoint,
InvokeHostFunctionOp, LedgerEntry, LedgerEntryData, LedgerFootprint, LedgerKey,
LedgerKeyConfigSetting, Memo, MuxedAccount, MuxedAccountMed25519, Operation, OperationBody,
Preconditions, SequenceNumber, Signature, SignatureHint, SorobanResources,
SorobanTransactionData, Transaction, TransactionExt, TransactionV1Envelope, Uint256, WriteXdr,
};
use soroban_env_host::{xdr, Env};
use std::cmp::max;
use std::convert::{TryFrom, TryInto};
use std::error;
Expand Down