Skip to content

Commit

Permalink
fix: selfdestruct undeployed CAs
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Nov 20, 2023
1 parent 58739b0 commit 93ae60e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions crates/evm/src/model/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ impl AccountImpl of AccountTrait {
}
} else if self.should_deploy(is_registered) {
// If SELFDESTRUCT, deploy empty SN account
let initial_nonce = if (*self.selfdestruct == true) {
0
let (initial_nonce, initial_code) = if (*self.selfdestruct == true) {
(0, Default::default().span())
} else {
*self.nonce
(*self.nonce, *self.code)
};
ContractAccountTrait::deploy(self.address().evm, *self.nonce, *self.code)?;
ContractAccountTrait::deploy(self.address().evm, initial_nonce, initial_code)?;
Result::Ok(())
//Storage is handled outside of the account and must be commited after all accounts are commited.
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ fn test_exec_selfdestruct_add_transfer_post_selfdestruct() {
'contract'.try_into().unwrap(), 1, array![].span()
)
.expect('failed deploy CA');
fund_account_with_native_token(sender.starknet, native_token, 100);
fund_account_with_native_token(sender.starknet, native_token, 150);
fund_account_with_native_token(ca_address.starknet, native_token, 100);
let mut machine = setup_machine_with_target(ca_address);

Expand All @@ -521,7 +521,7 @@ fn test_exec_selfdestruct_add_transfer_post_selfdestruct() {
machine.stack.push(recipient.evm.into());
machine.exec_selfdestruct().expect('selfdestruct failed');
// Add a transfer from sender to CA - after it was selfdestructed in local state. This transfer should go through.
let transfer = Transfer { sender, recipient: ca_address, amount: 100 };
let transfer = Transfer { sender, recipient: ca_address, amount: 150 };
machine.state.add_transfer(transfer).unwrap();
machine.state.commit_context();
machine.state.commit_state();
Expand All @@ -535,5 +535,5 @@ fn test_exec_selfdestruct_add_transfer_post_selfdestruct() {
//FIXME when addressed in the compiler code, this test should be fixed.
// assert(recipient_balance == 100, 'recipient wrong balance');
assert(sender_balance == 0, 'sender wrong balance');
assert(ca_balance == 100, 'ca wrong balance');
assert(ca_balance == 150, 'ca wrong balance');
}

0 comments on commit 93ae60e

Please sign in to comment.