-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unified syntax - ReturnsResultOrError + tests
- Loading branch information
1 parent
06fc066
commit 07207f6
Showing
10 changed files
with
142 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,9 @@ | |
"gasLimit": "70,000,000" | ||
}, | ||
"expect": { | ||
"out": [], | ||
"out": [ | ||
"str:init-result" | ||
], | ||
"status": "0" | ||
} | ||
}, | ||
|
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
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
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
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
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
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
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
89 changes: 89 additions & 0 deletions
89
framework/scenario/src/facade/result_handlers/returns_result_or_err.rs
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::marker::PhantomData; | ||
|
||
use multiversx_sc::{ | ||
tuple_util::NestedTupleFlatten, | ||
types::{ | ||
OriginalResultMarker, RHList, RHListAppendRet, RHListExec, RHListItem, RHListItemExec, | ||
TxEnv, | ||
}, | ||
}; | ||
|
||
use crate::scenario_model::{TxResponse, TxResponseStatus}; | ||
|
||
/// Indicates that a `Result` will be returned, either with the handled result, | ||
/// according to the inner result handlers, or with an error in case of a failed transaction. | ||
pub struct ReturnsResultOrError<Env, Original, Ok> | ||
where | ||
Env: TxEnv, | ||
Ok: RHList<Env>, | ||
{ | ||
_phantom_env: PhantomData<Env>, | ||
_phantom_original: PhantomData<Original>, | ||
pub ok_t: Ok, | ||
} | ||
|
||
impl<Env, Original> Default for ReturnsResultOrError<Env, Original, OriginalResultMarker<Original>> | ||
where | ||
Env: TxEnv, | ||
{ | ||
fn default() -> Self { | ||
ReturnsResultOrError { | ||
_phantom_env: PhantomData, | ||
_phantom_original: PhantomData, | ||
ok_t: OriginalResultMarker::new(), | ||
} | ||
} | ||
} | ||
|
||
impl<Env, Original> ReturnsResultOrError<Env, Original, OriginalResultMarker<Original>> | ||
where | ||
Env: TxEnv, | ||
{ | ||
pub fn new() -> Self { | ||
ReturnsResultOrError::default() | ||
} | ||
} | ||
|
||
impl<Env, Original, Ok> ReturnsResultOrError<Env, Original, Ok> | ||
where | ||
Env: TxEnv, | ||
Ok: RHListExec<TxResponse, Env>, | ||
{ | ||
pub fn returns<RH>(self, item: RH) -> ReturnsResultOrError<Env, Original, Ok::RetOutput> | ||
where | ||
RH: RHListItem<Env, Ok::OriginalResult>, | ||
Ok: RHListAppendRet<Env, RH>, | ||
{ | ||
ReturnsResultOrError { | ||
_phantom_env: PhantomData, | ||
_phantom_original: PhantomData, | ||
ok_t: self.ok_t.append_ret(item), | ||
} | ||
} | ||
} | ||
|
||
impl<Env, Original, Ok> RHListItem<Env, Original> for ReturnsResultOrError<Env, Original, Ok> | ||
where | ||
Env: TxEnv, | ||
Ok: RHListExec<TxResponse, Env>, | ||
Ok::ListReturns: NestedTupleFlatten, | ||
{ | ||
type Returns = Result<<Ok::ListReturns as NestedTupleFlatten>::Unpacked, TxResponseStatus>; | ||
} | ||
|
||
impl<Env, Original, Ok> RHListItemExec<TxResponse, Env, Original> | ||
for ReturnsResultOrError<Env, Original, Ok> | ||
where | ||
Env: TxEnv, | ||
Ok: RHListExec<TxResponse, Env>, | ||
Ok::ListReturns: NestedTupleFlatten, | ||
{ | ||
fn item_process_result(self, raw_result: &TxResponse) -> Self::Returns { | ||
if raw_result.tx_error.is_success() { | ||
let tuple_result = self.ok_t.list_process_result(raw_result); | ||
Ok(tuple_result.flatten_unpack()) | ||
} else { | ||
Err(raw_result.tx_error.clone()) | ||
} | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
framework/scenario/src/scenario/model/transaction/tx_error.rs
This file was deleted.
Oops, something went wrong.