@@ -120,11 +120,10 @@ describe('deploy and test Wallet', () => {
120120 const calldata = { publicKey : pubKey } ;
121121
122122 // declare account
123- const declareAccount = await account . declare ( {
123+ const declareAccount = await account . declareIfNot ( {
124124 contract : compiledOpenZeppelinAccount ,
125125 } ) ;
126126 const accountClassHash = declareAccount . class_hash ;
127- await account . waitForTransaction ( declareAccount . transaction_hash ) ;
128127
129128 // fund new account
130129 const tobeAccountAddress = hash . calculateContractAddressFromHash (
@@ -193,6 +192,9 @@ describe('deploy and test Wallet', () => {
193192 } ) ;
194193
195194 describe ( 'simulate transaction - single transaction S0.11.2' , ( ) => {
195+ test ( 'simulate empty invocations' , async ( ) => {
196+ await expect ( account . simulateTransaction ( [ ] ) ) . rejects . toThrow ( TypeError ) ;
197+ } ) ;
196198 test ( 'simulate INVOKE Cairo 0' , async ( ) => {
197199 const res = await account . simulateTransaction ( [
198200 {
@@ -245,37 +247,30 @@ describe('deploy and test Wallet', () => {
245247
246248 describeIfDevnet ( 'declare tests only on devnet' , ( ) => {
247249 test ( 'simulate DECLARE - Cairo 0 Contract' , async ( ) => {
248- const res = await account . simulateTransaction ( [
250+ const invocation = await provider . prepareInvocations ( [
249251 {
250252 type : TransactionType . DECLARE ,
251253 contract : compiledErc20 ,
252254 } ,
253255 ] ) ;
254- expect ( res ) . toMatchSchemaRef ( 'SimulateTransactionResponse' ) ;
256+ if ( invocation . length ) {
257+ const res = await account . simulateTransaction ( invocation ) ;
258+ expect ( res ) . toMatchSchemaRef ( 'SimulateTransactionResponse' ) ;
259+ }
255260 } ) ;
256261 } ) ;
257262
258263 test ( 'simulate DECLARE - Cairo 1 Contract - test if not already declared' , async ( ) => {
259- const declareContractPayload = extractContractHashes ( {
260- contract : compiledHelloSierra ,
261- casm : compiledHelloSierraCasm ,
262- } ) ;
263- let skip = false ;
264- try {
265- await account . getClassByHash ( declareContractPayload . classHash ) ;
266- skip = true ;
267- } catch ( error ) {
268- /* empty */
269- }
264+ const invocation = await provider . prepareInvocations ( [
265+ {
266+ type : TransactionType . DECLARE ,
267+ contract : compiledHelloSierra ,
268+ casm : compiledHelloSierraCasm ,
269+ } ,
270+ ] ) ;
270271
271- if ( ! skip ) {
272- const res = await account . simulateTransaction ( [
273- {
274- type : TransactionType . DECLARE ,
275- contract : compiledHelloSierra ,
276- casm : compiledHelloSierraCasm ,
277- } ,
278- ] ) ;
272+ if ( invocation . length ) {
273+ const res = await account . simulateTransaction ( invocation ) ;
279274 expect ( res ) . toMatchSchemaRef ( 'SimulateTransactionResponse' ) ;
280275 }
281276 } ) ;
@@ -625,6 +620,10 @@ describe('deploy and test Wallet', () => {
625620 expect ( result ) . toMatchSchemaRef ( 'EstimateFee' ) ;
626621 } ) ;
627622
623+ test ( 'estimate fee bulk on empty invocations' , async ( ) => {
624+ await expect ( account . estimateFeeBulk ( [ ] ) ) . rejects . toThrow ( TypeError ) ;
625+ } ) ;
626+
628627 test ( 'estimate fee bulk invoke functions' , async ( ) => {
629628 // TODO @dhruvkelawala check expectation for feeTransactionVersion
630629 // const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction');
@@ -696,22 +695,80 @@ describe('deploy and test Wallet', () => {
696695 } ) ;
697696
698697 describeIfDevnet ( 'declare tests only on devnet' , ( ) => {
699- test ( 'declare, deploy & multi invoke functions' , async ( ) => {
700- const res = await account . estimateFeeBulk ( [
701- /* {
702- // Cairo 1.1.0, if declared estimate error with can't redeclare same contract
703- type: TransactionType.DECLARE,
704- contract: compiledHelloSierra,
705- casm: compiledHelloSierraCasm,
706- }, */
698+ test ( 'Manual: declare, deploy & multi invoke functions' , async ( ) => {
699+ /*
700+ * For Cairo0 and Cairo1 contracts re-declaration of the class throw an errors
701+ * as soo We first need to test is class is already declared
702+ */
703+ const isDeclaredCairo0 = await account . isClassDeclared ( {
704+ classHash : '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a' ,
705+ } ) ;
706+
707+ const hashes = extractContractHashes ( {
708+ contract : compiledHelloSierra ,
709+ casm : compiledHelloSierraCasm ,
710+ } ) ;
711+
712+ const isDeclaredCairo1 = await account . isClassDeclared ( { classHash : hashes . classHash } ) ;
713+
714+ const invocations = [
707715 {
708- // Cairo 0
709- type : TransactionType . DECLARE ,
716+ type : TransactionType . INVOKE ,
717+ payload : [
718+ {
719+ contractAddress : erc20Address ,
720+ entrypoint : 'approve' ,
721+ calldata : {
722+ address : erc20Address ,
723+ amount : uint256 ( 10 ) ,
724+ } ,
725+ } ,
726+ {
727+ contractAddress : erc20Address ,
728+ entrypoint : 'transfer' ,
729+ calldata : [ erc20 . address , '10' , '0' ] ,
730+ } ,
731+ ] ,
732+ } ,
733+ {
734+ type : TransactionType . DEPLOY ,
710735 payload : {
711- contract : compiledErc20 ,
712736 classHash : '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a' ,
737+ constructorCalldata : [ 'Token' , 'ERC20' , account . address ] ,
713738 } ,
714739 } ,
740+ ...( ! isDeclaredCairo0
741+ ? [
742+ {
743+ // Cairo 0
744+ type : TransactionType . DECLARE ,
745+ payload : {
746+ contract : compiledErc20 ,
747+ classHash : '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a' ,
748+ } ,
749+ } ,
750+ ]
751+ : [ ] ) ,
752+ ...( ! isDeclaredCairo1
753+ ? [
754+ {
755+ // Cairo 1.1.0, if declared estimate error with can't redeclare same contract
756+ type : TransactionType . DECLARE ,
757+ contract : compiledHelloSierra ,
758+ casm : compiledHelloSierraCasm ,
759+ } ,
760+ ]
761+ : [ ] ) ,
762+ ] ;
763+
764+ const res = await account . estimateFeeBulk ( invocations ) ;
765+ res . forEach ( ( value ) => {
766+ expect ( value ) . toMatchSchemaRef ( 'EstimateFee' ) ;
767+ } ) ;
768+ } ) ;
769+
770+ test ( 'prepareInvocations: unordered declare, deploy & multi invoke' , async ( ) => {
771+ const invocations = await provider . prepareInvocations ( [
715772 {
716773 type : TransactionType . DEPLOY ,
717774 payload : {
@@ -737,8 +794,23 @@ describe('deploy and test Wallet', () => {
737794 } ,
738795 ] ,
739796 } ,
797+ {
798+ // Cairo 0
799+ type : TransactionType . DECLARE ,
800+ payload : {
801+ contract : compiledErc20 ,
802+ classHash : '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a' ,
803+ } ,
804+ } ,
805+ {
806+ // Cairo 1.1.0, if declared estimate error with can't redeclare same contract
807+ type : TransactionType . DECLARE ,
808+ contract : compiledHelloSierra ,
809+ casm : compiledHelloSierraCasm ,
810+ } ,
740811 ] ) ;
741- expect ( res ) . toHaveLength ( 3 ) ;
812+
813+ const res = await account . estimateFeeBulk ( invocations ) ;
742814 res . forEach ( ( value ) => {
743815 expect ( value ) . toMatchSchemaRef ( 'EstimateFee' ) ;
744816 } ) ;
0 commit comments