Skip to content

Commit

Permalink
avoid crash if deployment fail
Browse files Browse the repository at this point in the history
  • Loading branch information
cassc committed Jul 18, 2024
1 parent 091b72f commit 5d75ea7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ hashbrown = "*"
redis = { version= "0.25.4", optional = true}
alloy = { version = "0.1.4", features = ["full"] }
uuid = { version = "1.9.1", features = ["v4"] }
hex-literal = "0.4.1"

[dev-dependencies]
criterion = {version="0.3.6", features=["html_reports"] }
Expand All @@ -63,4 +64,4 @@ name = "function"
harness = false

[profile.bench]
debug = true
debug = true
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,11 @@ impl TinyEVM {
Some(force_address),
)?;

if !resp.success {
// todo return reverted
}

if let Some(balance) = init_value {
let address = Address::from_slice(&resp.data);
self.set_account_balance(address, bigint_to_ruint_u256(&balance)?)?;
if resp.success {
if let Some(balance) = init_value {
let address = Address::from_slice(&resp.data);
self.set_account_balance(address, bigint_to_ruint_u256(&balance)?)?;
}
}

resp
Expand Down
13 changes: 13 additions & 0 deletions tests/revm_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,19 @@ fn test_deterministic_deploy() {
assert_ne!(c1.data, c2.data, "Address of c1 and c2 should not equal");
}

#[test]
fn test_deterministic_deploy_fail() {
use hex_literal::hex;
let constructor_revert_bin = hex!("6080604052348015600f57600080fd5b600080fdfe");
let constructor_revert_bin = constructor_revert_bin.to_vec();
let mut vm = TinyEVM::default();
let c = vm
.deploy_helper(*OWNER, constructor_revert_bin.clone(), UZERO, None, None)
.unwrap();

assert!(!c.success, "Deploy invalid deployment binary should fail",);
}

#[test]
fn test_deterministic_deploy_overwrite() -> Result<()> {
setup();
Expand Down

0 comments on commit 5d75ea7

Please sign in to comment.