Skip to content

Commit

Permalink
[transactional-test-runner] read-only shared inputs (MystenLabs#15268)
Browse files Browse the repository at this point in the history
## Description

Add the ability to specify a transction input that is a read-only shared
object (So I can test what transaction effects look like when a
transaction includes one of these).

## Test Plan

Tested in a follow-up PR that uses this in one of its tests.
  • Loading branch information
amnn authored Dec 8, 2023
1 parent d013d3b commit dc72e1d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions crates/sui-transactional-test-runner/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub enum SuiExtraValueArgs {
Object(FakeID, Option<SequenceNumber>),
Digest(String),
Receiving(FakeID, Option<SequenceNumber>),
ImmShared(FakeID, Option<SequenceNumber>),
}

pub enum SuiValue {
Expand All @@ -215,6 +216,7 @@ pub enum SuiValue {
ObjVec(Vec<(FakeID, Option<SequenceNumber>)>),
Digest(String),
Receiving(FakeID, Option<SequenceNumber>),
ImmShared(FakeID, Option<SequenceNumber>),
}

impl SuiExtraValueArgs {
Expand All @@ -232,6 +234,13 @@ impl SuiExtraValueArgs {
Ok(SuiExtraValueArgs::Receiving(fake_id, version))
}

fn parse_read_shared_value<'a, I: Iterator<Item = (ValueToken, &'a str)>>(
parser: &mut MoveCLParser<'a, ValueToken, I>,
) -> anyhow::Result<Self> {
let (fake_id, version) = Self::parse_receiving_or_object_value(parser, "immshared")?;
Ok(SuiExtraValueArgs::ImmShared(fake_id, version))
}

fn parse_digest_value<'a, I: Iterator<Item = (ValueToken, &'a str)>>(
parser: &mut MoveCLParser<'a, ValueToken, I>,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -287,6 +296,7 @@ impl SuiValue {
SuiValue::ObjVec(_) => panic!("unexpected nested Sui object vector in args"),
SuiValue::Digest(_) => panic!("unexpected nested Sui package digest in args"),
SuiValue::Receiving(_, _) => panic!("unexpected nested Sui receiving object in args"),
SuiValue::ImmShared(_, _) => panic!("unexpected nested Sui shared object in args"),
}
}

Expand All @@ -297,6 +307,7 @@ impl SuiValue {
SuiValue::ObjVec(_) => panic!("unexpected nested Sui object vector in args"),
SuiValue::Digest(_) => panic!("unexpected nested Sui package digest in args"),
SuiValue::Receiving(_, _) => panic!("unexpected nested Sui receiving object in args"),
SuiValue::ImmShared(_, _) => panic!("unexpected nested Sui shared object in args"),
}
}

Expand Down Expand Up @@ -330,6 +341,27 @@ impl SuiValue {
Ok(ObjectArg::Receiving(obj.compute_object_reference()))
}

fn read_shared_arg(
fake_id: FakeID,
version: Option<SequenceNumber>,
test_adapter: &SuiTestAdapter,
) -> anyhow::Result<ObjectArg> {
let obj = Self::resolve_object(fake_id, version, test_adapter)?;
let id = obj.id();
if let Owner::Shared {
initial_shared_version,
} = obj.owner
{
Ok(ObjectArg::SharedObject {
id,
initial_shared_version,
mutable: false,
})
} else {
bail!("{fake_id} is not a shared object.")
}
}

fn object_arg(
fake_id: FakeID,
version: Option<SequenceNumber>,
Expand Down Expand Up @@ -361,6 +393,9 @@ impl SuiValue {
SuiValue::Receiving(fake_id, version) => {
CallArg::Object(Self::receiving_arg(fake_id, version, test_adapter)?)
}
SuiValue::ImmShared(fake_id, version) => {
CallArg::Object(Self::read_shared_arg(fake_id, version, test_adapter)?)
}
SuiValue::ObjVec(_) => bail!("obj vec is not supported as an input"),
SuiValue::Digest(pkg) => {
let pkg = Symbol::from(pkg);
Expand Down Expand Up @@ -401,6 +436,7 @@ impl ParsableValue for SuiExtraValueArgs {
(ValueToken::Ident, "object") => Some(Self::parse_object_value(parser)),
(ValueToken::Ident, "digest") => Some(Self::parse_digest_value(parser)),
(ValueToken::Ident, "receiving") => Some(Self::parse_receiving_value(parser)),
(ValueToken::Ident, "immshared") => Some(Self::parse_read_shared_value(parser)),
_ => None,
}
}
Expand Down Expand Up @@ -435,6 +471,7 @@ impl ParsableValue for SuiExtraValueArgs {
SuiExtraValueArgs::Object(id, version) => Ok(SuiValue::Object(id, version)),
SuiExtraValueArgs::Digest(pkg) => Ok(SuiValue::Digest(pkg)),
SuiExtraValueArgs::Receiving(id, version) => Ok(SuiValue::Receiving(id, version)),
SuiExtraValueArgs::ImmShared(id, version) => Ok(SuiValue::ImmShared(id, version)),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/sui-transactional-test-runner/src/test_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,9 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter<'a> {
SuiValue::Digest(_) => bail!("digest is not supported as an input"),
SuiValue::ObjVec(_) => bail!("obj vec is not supported as an input"),
SuiValue::Receiving(_, _) => bail!("receiving is not supported as an input"),
SuiValue::ImmShared(_, _) => {
bail!("read-only shared object is not supported as an input")
}
};
let value = NumericalAddress::new(value.into_bytes(), NumberFormat::Hex);
self.compiled_state
Expand Down

0 comments on commit dc72e1d

Please sign in to comment.