Skip to content

Commit

Permalink
fix: c1 acc execute props order, c1 test flag, local testing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed May 15, 2023
1 parent ebdcb43 commit d86057c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions __tests__/cairo1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,13 @@ describeIfDevnetSequencer('Cairo 1 Devnet Sequencer', () => {
const calldata = { publicKey: pubKey };

// declare account
const declareAccount = await account.declare({
const declareAccount = await account.declareIfNot({
contract: compiledC1Account,
casm: compiledC1AccountCasm,
});
await account.waitForTransaction(declareAccount.transaction_hash);
if (declareAccount.transaction_hash) {
await account.waitForTransaction(declareAccount.transaction_hash);
}
const accountClassHash = declareAccount.class_hash;

// fund new account
Expand All @@ -279,7 +281,7 @@ describeIfDevnetSequencer('Cairo 1 Devnet Sequencer', () => {
await account.waitForTransaction(transaction_hash);

// deploy account
accountC1 = new Account(provider, toBeAccountAddress, priKey);
accountC1 = new Account(provider, toBeAccountAddress, priKey, '1');
const deployed = await accountC1.deploySelf({
classHash: accountClassHash,
constructorCalldata: calldata,
Expand Down
4 changes: 3 additions & 1 deletion __tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'path';
import { Account, ProviderInterface, RpcProvider, SequencerProvider, json } from '../src';
import { BaseUrl } from '../src/constants';
import {
CairoVersion,
CompiledSierra,
CompiledSierraCasm,
LegacyCompiledContract,
Expand Down Expand Up @@ -102,8 +103,9 @@ export const getTestAccount = (provider: ProviderInterface) => {
testAccountAddress = DEFAULT_TEST_ACCOUNT_ADDRESS;
testAccountPrivateKey = DEFAULT_TEST_ACCOUNT_PRIVATE_KEY;
}
const cairoVersion = (process.env.ACCOUNT_CAIRO_VERSION as CairoVersion) || '0';

return new Account(provider, toHex(testAccountAddress), testAccountPrivateKey);
return new Account(provider, toHex(testAccountAddress), testAccountPrivateKey, cairoVersion);
};

const describeIf = (condition: boolean) => (condition ? describe : describe.skip);
Expand Down
12 changes: 9 additions & 3 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,21 @@ export const transformCallsToMulticallArrays_cairo1 = (calls: Call[]) => {
return callArray;
};

// TT: Can be removed ?
/**
* Transforms a list of calls in the full flattened calldata expected
* by the __execute__ protocol.
* @param calls
* @returns Calldata
*/
export const fromCallsToExecuteCalldata_cairo1 = (calls: Call[]) => {
return CallData.compile({ calls });
// ensure property order
const orderCalls = calls.map((call) => ({
contractAddress: call.contractAddress,
entrypoint: call.entrypoint,
calldata: call.calldata,
}));

return CallData.compile({ orderCalls });
};

/**
Expand All @@ -78,7 +84,7 @@ export const fromCallsToExecuteCalldata_cairo1 = (calls: Call[]) => {
*/
export const getExecuteCalldata = (calls: Call[], cairoVersion: CairoVersion = '0') => {
if (cairoVersion === '1') {
return CallData.compile({ calls });
return fromCallsToExecuteCalldata_cairo1(calls);
}
return fromCallsToExecuteCalldata(calls);
};

0 comments on commit d86057c

Please sign in to comment.