3
3
4
4
#![ warn( missing_docs) ]
5
5
6
- mod bundle;
7
6
pub mod errors;
8
- mod mock;
9
7
pub mod runtime;
10
8
pub mod sandbox;
11
9
pub use sandbox:: * ;
12
10
#[ cfg( feature = "session" ) ]
13
11
pub mod session;
14
12
15
- use std:: sync:: { Arc , Mutex } ;
16
-
17
- pub use bundle:: ContractBundle ;
13
+ #[ cfg( feature = "macros" ) ]
18
14
pub use drink_test_macro:: { contract_bundle_provider, test} ;
19
15
pub use errors:: Error ;
20
16
pub use frame_support:: {
21
17
sp_runtime:: { AccountId32 , DispatchError } ,
22
18
weights:: Weight ,
23
19
} ;
24
20
use frame_system:: EventRecord ;
25
- pub use mock:: { mock_message, ContractMock , MessageMock , MockedCallResult , Selector } ;
26
- use pallet_contracts:: { debug:: ExecResult , ExecReturnValue } ;
27
- use pallet_contracts_uapi:: ReturnFlags ;
28
- use parity_scale_codec:: { Decode , Encode } ;
21
+ #[ cfg( feature = "session" ) ]
22
+ pub use session:: mock:: { mock_message, ContractMock , MessageMock , MockedCallResult , Selector } ;
29
23
/// Export pallets that are used in the minimal runtime.
30
24
pub use { frame_support, frame_system, pallet_balances, pallet_contracts, pallet_timestamp} ;
31
25
32
26
pub use crate :: runtime:: minimal:: { self , MinimalRuntime } ;
33
- use crate :: {
34
- errors:: MessageResult , mock:: MockRegistry ,
35
- runtime:: pallet_contracts_debugging:: InterceptingExtT ,
36
- } ;
37
27
38
28
/// Alias for `frame-system`'s `RuntimeCall` type.
39
29
pub type RuntimeCall < R > = <R as frame_system:: Config >:: RuntimeCall ;
@@ -50,63 +40,3 @@ pub type EventRecordOf<T> =
50
40
51
41
/// Default gas limit.
52
42
pub const DEFAULT_GAS_LIMIT : Weight = Weight :: from_parts ( 100_000_000_000 , 3 * 1024 * 1024 ) ;
53
-
54
- /// Runtime extension enabling contract call interception.
55
- struct MockingExtension < AccountId : Ord > {
56
- /// Mock registry, shared with the sandbox.
57
- ///
58
- /// Potentially the runtime is executed in parallel and thus we need to wrap the registry in
59
- /// `Arc<Mutex>` instead of `Rc<RefCell>`.
60
- mock_registry : Arc < Mutex < MockRegistry < AccountId > > > ,
61
- }
62
-
63
- impl < AccountId : Ord + Decode > InterceptingExtT for MockingExtension < AccountId > {
64
- fn intercept_call (
65
- & self ,
66
- contract_address : Vec < u8 > ,
67
- _is_call : bool ,
68
- input_data : Vec < u8 > ,
69
- ) -> Vec < u8 > {
70
- let contract_address = Decode :: decode ( & mut & contract_address[ ..] )
71
- . expect ( "Contract address should be decodable" ) ;
72
-
73
- match self
74
- . mock_registry
75
- . lock ( )
76
- . expect ( "Should be able to acquire registry" )
77
- . get ( & contract_address)
78
- {
79
- // There is no mock registered for this address, so we return `None` to indicate that
80
- // the call should be executed normally.
81
- None => None :: < ( ) > . encode ( ) ,
82
- // We intercept the call and return the result of the mock.
83
- Some ( mock) => {
84
- let ( selector, call_data) = input_data. split_at ( 4 ) ;
85
- let selector: Selector = selector
86
- . try_into ( )
87
- . expect ( "Input data should contain at least selector bytes" ) ;
88
-
89
- let result = mock
90
- . call ( selector, call_data. to_vec ( ) )
91
- . expect ( "TODO: let the user define the fallback mechanism" ) ;
92
-
93
- // Although we don't know the exact type, thanks to the SCALE encoding we know
94
- // that `()` will always succeed (we only care about the `Ok`/`Err` distinction).
95
- let decoded_result: MessageResult < ( ) > =
96
- Decode :: decode ( & mut & result[ ..] ) . expect ( "Mock result should be decodable" ) ;
97
-
98
- let flags = match decoded_result {
99
- Ok ( _) => ReturnFlags :: empty ( ) ,
100
- Err ( _) => ReturnFlags :: REVERT ,
101
- } ;
102
-
103
- let result: ExecResult = Ok ( ExecReturnValue {
104
- flags,
105
- data : result,
106
- } ) ;
107
-
108
- Some ( result) . encode ( )
109
- }
110
- }
111
- }
112
- }
0 commit comments