Skip to content

Commit

Permalink
piecrust: add root_equal_on_err
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Leegwater Simões committed Nov 21, 2023
1 parent f2709cc commit 8f62a37
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions piecrust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ name = "crossover"
path = "tests/crossover.rs"
required-features = ["debug"]

[[test]]
name = "commit"
path = "tests/commit.rs"
required-features = ["debug"]

[[test]]
name = "debugger"
path = "tests/debugger.rs"
Expand Down
60 changes: 60 additions & 0 deletions piecrust/tests/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,66 @@ fn multiple_commits() -> Result<(), Error> {
Ok(())
}

#[test]
fn root_equal_on_err() -> Result<(), Error> {
let vm = VM::ephemeral()?;

let mut session = vm.session(SessionData::builder())?;

let callcenter_id = session.deploy(
contract_bytecode!("callcenter"),
ContractData::builder(OWNER),
LIMIT,
)?;
let counter_id = session.deploy(
contract_bytecode!("counter"),
ContractData::builder(OWNER),
LIMIT,
)?;

let root = session.commit()?;

let mut session = vm.session(SessionData::builder().base(root))?;
let mut session_alt = vm.session(SessionData::builder().base(root))?;

assert_eq!(
session.root(),
session_alt.root(),
"Roots should be equal at the beginning"
);

session
.call::<_, ()>(callcenter_id, "panik", &counter_id, LIMIT)
.expect_err("Calling with too little gas should error");

assert_eq!(
session.root(),
session_alt.root(),
"Roots should be equal immediately after erroring call"
);

session.call::<_, ()>(
callcenter_id,
"increment_counter",
&counter_id,
LIMIT,
)?;
session_alt.call::<_, ()>(
callcenter_id,
"increment_counter",
&counter_id,
LIMIT,
)?;

assert_eq!(
session.root(),
session_alt.root(),
"Roots should be equal after call"
);

Ok(())
}

fn increment_counter_and_commit(
mut session: Session,
id: ContractId,
Expand Down

0 comments on commit 8f62a37

Please sign in to comment.