@@ -29,7 +29,7 @@ public async Task TestSendTransactionSuccessEvent()
2929 failedEventHit = true ;
3030 } ;
3131
32- await wallet . SendTransaction ( Chain . None , null ) ;
32+ await wallet . SendTransaction ( Chain . None , Array . Empty < Transaction > ( ) ) ;
3333
3434 Assert . IsTrue ( successEventHit ) ;
3535 Assert . IsFalse ( failedEventHit ) ;
@@ -52,12 +52,117 @@ public async Task TestSendTransactionFailedEvent()
5252 failedEventHit = true ;
5353 } ;
5454
55- await wallet . SendTransaction ( Chain . None , null ) ;
55+ await wallet . SendTransaction ( Chain . None , Array . Empty < Transaction > ( ) ) ;
5656
5757 Assert . IsFalse ( successEventHit ) ;
5858 Assert . IsTrue ( failedEventHit ) ;
5959 }
6060
61+ private static ( DelayedEncodeData , bool ) [ ] _invalidDelayedEncodeData = new [ ]
62+ {
63+ ( new DelayedEncodeData ( "functionName" , Array . Empty < object > ( ) , "functionName" ) , false ) ,
64+ ( new DelayedEncodeData ( "functionName()" , Array . Empty < object > ( ) , "functionName" ) , true ) ,
65+ ( new DelayedEncodeData ( "functionName()" , Array . Empty < object > ( ) , "functionName()" ) , false ) ,
66+ ( new DelayedEncodeData ( "functionName(" , Array . Empty < object > ( ) , "functionName" ) , false ) ,
67+ ( new DelayedEncodeData ( "functionName)" , Array . Empty < object > ( ) , "functionName" ) , false ) ,
68+ ( new DelayedEncodeData ( "functionName(uint banana)" , new object [ ] { 1 } , "functionName" ) , true ) ,
69+ ( new DelayedEncodeData ( "functionName(uint, uint)" , new object [ ] { 1 , 2 } , "functionName" ) , true ) ,
70+ ( new DelayedEncodeData ( "functionName(uint,uint)" , new object [ ] { 1 , 2 } , "functionName(uint,uint)" ) , false ) ,
71+ ( new DelayedEncodeData ( "functionName(uint banana" , new object [ ] { 1 } , "functionName" ) , false ) ,
72+ ( new DelayedEncodeData ( "functionNameuint, uint)" , new object [ ] { 1 , 2 } , "functionName" ) , false ) ,
73+ ( new DelayedEncodeData ( "functionName(uint,uint" , new object [ ] { 1 , 2 } , "functionName" ) , false )
74+ } ;
75+
76+ [ TestCaseSource ( nameof ( _invalidDelayedEncodeData ) ) ]
77+ public async Task TestSendTransactionEvent_delayedEncodeValidation ( ( DelayedEncodeData , bool ) args )
78+ {
79+ DelayedEncodeData data = args . Item1 ;
80+ bool success = args . Item2 ;
81+ IIntentSender intentSender = new MockIntentSender ( new SuccessfulTransactionReturn ( ) ) ;
82+ SequenceWallet wallet = new SequenceWallet ( address , "" , intentSender ) ;
83+
84+ bool successEventHit = false ;
85+ wallet . OnSendTransactionComplete += ( result ) =>
86+ {
87+ successEventHit = true ;
88+ } ;
89+ bool failedEventHit = false ;
90+ wallet . OnSendTransactionFailed += ( result ) =>
91+ {
92+ failedEventHit = true ;
93+ } ;
94+
95+ await wallet . SendTransaction ( Chain . None , new Transaction [ ]
96+ {
97+ new RawTransaction ( "0xc683a014955b75F5ECF991d4502427c8fa1Aa249" ) ,
98+ new DelayedEncode ( "0xc683a014955b75F5ECF991d4502427c8fa1Aa249" , "0" , data ) ,
99+ new RawTransaction ( "0xc683a014955b75F5ECF991d4502427c8fa1Aa249" )
100+ } , waitForReceipt : false ) ;
101+
102+ if ( ! success )
103+ {
104+ Assert . IsFalse ( successEventHit ) ;
105+ Assert . IsTrue ( failedEventHit ) ;
106+ }
107+ else
108+ {
109+ Assert . IsTrue ( successEventHit ) ;
110+ Assert . IsFalse ( failedEventHit ) ;
111+ }
112+ }
113+
114+ private static ( AbiData , bool ) [ ] _invalidContractCallData = new [ ]
115+ {
116+ ( new AbiData ( "functionName" , Array . Empty < object > ( ) ) , false ) ,
117+ ( new AbiData ( "functionName()" , Array . Empty < object > ( ) ) , true ) ,
118+ ( new AbiData ( "functionName(" , Array . Empty < object > ( ) ) , false ) ,
119+ ( new AbiData ( "functionName)" , Array . Empty < object > ( ) ) , false ) ,
120+ ( new AbiData ( "functionName(uint banana)" , new object [ ] { 1 } ) , true ) ,
121+ ( new AbiData ( "functionName(uint, uint)" , new object [ ] { 1 , 2 } ) , true ) ,
122+ ( new AbiData ( "functionName(uint,uint)" , new object [ ] { 1 , 2 } ) , true ) ,
123+ ( new AbiData ( "functionName(uint banana" , new object [ ] { 1 } ) , false ) ,
124+ ( new AbiData ( "functionNameuint, uint)" , new object [ ] { 1 , 2 } ) , false ) ,
125+ ( new AbiData ( "functionName(uint,uint" , new object [ ] { 1 , 2 } ) , false )
126+ } ;
127+
128+ [ TestCaseSource ( nameof ( _invalidContractCallData ) ) ]
129+ public async Task TestSendTransactionEvent_contractCallValidation ( ( AbiData , bool ) args )
130+ {
131+ AbiData data = args . Item1 ;
132+ bool success = args . Item2 ;
133+ IIntentSender intentSender = new MockIntentSender ( new SuccessfulTransactionReturn ( ) ) ;
134+ SequenceWallet wallet = new SequenceWallet ( address , "" , intentSender ) ;
135+
136+ bool successEventHit = false ;
137+ wallet . OnSendTransactionComplete += ( result ) =>
138+ {
139+ successEventHit = true ;
140+ } ;
141+ bool failedEventHit = false ;
142+ wallet . OnSendTransactionFailed += ( result ) =>
143+ {
144+ failedEventHit = true ;
145+ } ;
146+
147+ await wallet . SendTransaction ( Chain . None , new Transaction [ ]
148+ {
149+ new RawTransaction ( "0xc683a014955b75F5ECF991d4502427c8fa1Aa249" ) ,
150+ new SequenceContractCall ( "0xc683a014955b75F5ECF991d4502427c8fa1Aa249" , data ) ,
151+ new RawTransaction ( "0xc683a014955b75F5ECF991d4502427c8fa1Aa249" )
152+ } , waitForReceipt : false ) ;
153+
154+ if ( ! success )
155+ {
156+ Assert . IsFalse ( successEventHit ) ;
157+ Assert . IsTrue ( failedEventHit ) ;
158+ }
159+ else
160+ {
161+ Assert . IsTrue ( successEventHit ) ;
162+ Assert . IsFalse ( failedEventHit ) ;
163+ }
164+ }
165+
61166 [ Test ]
62167 public async Task TestSendTransactionException ( )
63168 {
@@ -75,7 +180,7 @@ public async Task TestSendTransactionException()
75180 failedEventHit = true ;
76181 } ;
77182
78- await wallet . SendTransaction ( Chain . None , null ) ;
183+ await wallet . SendTransaction ( Chain . None , Array . Empty < Transaction > ( ) ) ;
79184
80185 Assert . IsFalse ( successEventHit ) ;
81186 Assert . IsTrue ( failedEventHit ) ;
@@ -343,7 +448,7 @@ public async Task TestWaitForTransactionReceipt(int numberOfFetches)
343448 failedEventHit = true ;
344449 } ;
345450
346- var result = await wallet . SendTransaction ( Chain . None , null ) ;
451+ var result = await wallet . SendTransaction ( Chain . None , Array . Empty < Transaction > ( ) ) ;
347452
348453 Assert . IsTrue ( successEventHit ) ;
349454 Assert . IsFalse ( failedEventHit ) ;
@@ -392,7 +497,7 @@ public async Task TestWaitForTransactionReceipt_failedToFetch()
392497
393498 LogAssert . Expect ( LogType . Error , "Transaction was successful, but we're unable to obtain the transaction hash. Reason: some random error" ) ;
394499
395- var result = await wallet . SendTransaction ( Chain . None , null ) ;
500+ var result = await wallet . SendTransaction ( Chain . None , Array . Empty < Transaction > ( ) ) ;
396501
397502 Assert . IsTrue ( successEventHit ) ;
398503 Assert . IsFalse ( failedEventHit ) ;
@@ -438,7 +543,7 @@ public async Task TestDontWaitForTransactionReceipt(int numberOfFetches)
438543 failedEventHit = true ;
439544 } ;
440545
441- var result = await wallet . SendTransaction ( Chain . None , null , false ) ;
546+ var result = await wallet . SendTransaction ( Chain . None , Array . Empty < Transaction > ( ) , false ) ;
442547
443548 Assert . IsTrue ( successEventHit ) ;
444549 Assert . IsFalse ( failedEventHit ) ;
0 commit comments