@@ -53,8 +53,30 @@ internal StackItem Invoke(string methodName, params object[] args)
53
53
{
54
54
// Compose script
55
55
56
+ TestingSyscall ? dynArgument = null ;
56
57
using ScriptBuilder script = new ( ) ;
57
58
59
+ ConvertArgs ( script , args , ref dynArgument ) ;
60
+
61
+ script . EmitPush ( Engine . CallFlags ) ;
62
+ script . EmitPush ( methodName ) ;
63
+ script . EmitPush ( Hash ) ;
64
+ script . EmitSysCall ( ApplicationEngine . System_Contract_Call ) ;
65
+
66
+ // Execute
67
+
68
+ return Engine . Execute ( script . ToArray ( ) , 0 , dynArgument is null ? null : engine => ConfigureEngine ( engine , dynArgument ) ) ;
69
+ }
70
+
71
+ private void ConfigureEngine ( ApplicationEngine engine , TestingSyscall testingSyscall )
72
+ {
73
+ if ( engine is not TestingApplicationEngine testEngine ) throw new InvalidOperationException ( ) ;
74
+
75
+ testEngine . TestingSyscall = testingSyscall ;
76
+ }
77
+
78
+ private void ConvertArgs ( ScriptBuilder script , object [ ] args , ref TestingSyscall ? testingSyscall )
79
+ {
58
80
if ( args is null || args . Length == 0 )
59
81
script . Emit ( OpCode . NEWARRAY0 ) ;
60
82
else
@@ -63,31 +85,52 @@ internal StackItem Invoke(string methodName, params object[] args)
63
85
{
64
86
var arg = args [ i ] ;
65
87
88
+ if ( arg is object [ ] arg2 )
89
+ {
90
+ ConvertArgs ( script , arg2 , ref testingSyscall ) ;
91
+ continue ;
92
+ }
93
+ else if ( arg is IEnumerable < object > argEnumerable )
94
+ {
95
+ ConvertArgs ( script , argEnumerable . ToArray ( ) , ref testingSyscall ) ;
96
+ continue ;
97
+ }
98
+
66
99
if ( ReferenceEquals ( arg , InvalidTypes . InvalidUInt160 . InvalidLength ) ||
67
- ReferenceEquals ( arg , InvalidTypes . InvalidUInt256 . InvalidLength ) )
100
+ ReferenceEquals ( arg , InvalidTypes . InvalidUInt256 . InvalidLength ) ||
101
+ ReferenceEquals ( arg , InvalidTypes . InvalidECPoint . InvalidLength ) )
68
102
{
69
103
arg = System . Array . Empty < byte > ( ) ;
70
104
}
71
105
else if ( ReferenceEquals ( arg , InvalidTypes . InvalidUInt160 . InvalidType ) ||
72
- ReferenceEquals ( arg , InvalidTypes . InvalidUInt256 . InvalidType ) )
106
+ ReferenceEquals ( arg , InvalidTypes . InvalidUInt256 . InvalidType ) ||
107
+ ReferenceEquals ( arg , InvalidTypes . InvalidECPoint . InvalidType ) )
73
108
{
74
109
arg = BigInteger . Zero ;
75
110
}
111
+ else if ( arg is InteropInterface interop )
112
+ {
113
+ // We can't send the interopInterface by an script
114
+ // We create a syscall in order to detect it and push the item
115
+
116
+ testingSyscall ??= new TestingSyscall ( ) ;
117
+ script . EmitSysCall ( TestingSyscall . Hash , testingSyscall . Add ( ( e ) => e . Push ( interop ) ) ) ;
118
+ continue ;
119
+ }
120
+ else if ( arg is Action < ApplicationEngine > onItem )
121
+ {
122
+ // We create a syscall in order to detect it and push the item
123
+
124
+ testingSyscall ??= new TestingSyscall ( ) ;
125
+ script . EmitSysCall ( TestingSyscall . Hash , testingSyscall . Add ( ( e ) => onItem ( e ) ) ) ;
126
+ continue ;
127
+ }
76
128
77
129
script . EmitPush ( arg ) ;
78
130
}
79
131
script . EmitPush ( args . Length ) ;
80
132
script . Emit ( OpCode . PACK ) ;
81
133
}
82
-
83
- script . EmitPush ( CallFlags . All ) ;
84
- script . EmitPush ( methodName ) ;
85
- script . EmitPush ( Hash ) ;
86
- script . EmitSysCall ( ApplicationEngine . System_Contract_Call ) ;
87
-
88
- // Execute
89
-
90
- return Engine . Execute ( script . ToArray ( ) ) ;
91
134
}
92
135
93
136
/// <summary>
0 commit comments