forked from stellar/rs-soroban-env
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test
update_contract_wasm
with rollbacks. (stellar#1195)
### What This makes sure the correct events are recorded in case if contract fails after update, and also that contract isn't updated after `try_call` fails. ### Why Improving test coverage. ### Known limitations N/A
- Loading branch information
Showing
3 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.08 KB
(270%)
soroban-test-wasms/wasm-workspace/opt/curr/example_updateable_contract.wasm
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
#![no_std] | ||
use soroban_sdk::{contract, contractimpl, symbol_short, BytesN, Env}; | ||
|
||
use soroban_sdk::{contract, contractimpl, symbol_short, Address, BytesN, Env, Error, IntoVal}; | ||
|
||
#[contract] | ||
pub struct Contract; | ||
|
||
#[contractimpl] | ||
impl Contract { | ||
pub fn update(env: Env, wasm_hash: BytesN<32>) -> i32 { | ||
pub fn update(env: Env, wasm_hash: BytesN<32>, fail: bool) -> i32 { | ||
// Modify instance storage to make sure that both instance storage and | ||
// executable are updated. | ||
env.storage().instance().set(&symbol_short!("foo"), &111); | ||
env.deployer().update_current_contract_wasm(wasm_hash); | ||
env.deployer().update_current_contract_wasm(wasm_hash); | ||
if fail { | ||
panic!(); | ||
} | ||
123 | ||
} | ||
|
||
pub fn try_upd(env: Env, contract: Address, wasm_hash: BytesN<32>, fail: bool) -> Option<i32> { | ||
let res = env.try_invoke_contract::<i32, Error>( | ||
&contract, | ||
&symbol_short!("update"), | ||
(wasm_hash, fail).into_val(&env), | ||
); | ||
if let Ok(v) = res { | ||
Some(v.unwrap()) | ||
} else { | ||
None | ||
} | ||
} | ||
} |