Skip to content

Commit

Permalink
Merge pull request #881 from starknet-io/v6/v3-transactions
Browse files Browse the repository at this point in the history
V6/v3 transactions 2
  • Loading branch information
tabaktoni authored Dec 8, 2023
2 parents 9d73582 + 89f8221 commit 2b6d349
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
9 changes: 8 additions & 1 deletion __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
stark,
} from '../src';
import {
TEST_TX_VERSION,
compiledErc20,
compiledHelloSierra,
compiledHelloSierraCasm,
Expand Down Expand Up @@ -137,7 +138,13 @@ describe('deploy and test Wallet', () => {
await account.waitForTransaction(transaction_hash);

// deploy account
const accountOZ = new Account(provider, tobeAccountAddress, priKey);
const accountOZ = new Account(
provider,
tobeAccountAddress,
priKey,
undefined,
TEST_TX_VERSION
);
const deployed = await accountOZ.deploySelf({
classHash: accountClassHash,
constructorCalldata: calldata,
Expand Down
3 changes: 2 additions & 1 deletion __tests__/cairo1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
stark,
} from '../src';
import {
TEST_TX_VERSION,
compiledC1Account,
compiledC1AccountCasm,
compiledComplexSierra,
Expand Down Expand Up @@ -533,7 +534,7 @@ describeIfDevnet('Cairo 1 Devnet', () => {
await account.waitForTransaction(transaction_hash);

// deploy account
accountC1 = new Account(provider, toBeAccountAddress, priKey, '1');
accountC1 = new Account(provider, toBeAccountAddress, priKey, '1', TEST_TX_VERSION);
const deployed = await accountC1.deploySelf({
classHash: accountClassHash,
constructorCalldata: calldata,
Expand Down
3 changes: 2 additions & 1 deletion __tests__/cairo1v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
types,
} from '../src';
import {
TEST_TX_VERSION,
compiledC1Account,
compiledC1AccountCasm,
compiledC1v2,
Expand Down Expand Up @@ -714,7 +715,7 @@ describe('Cairo 1', () => {
await account.waitForTransaction(transaction_hash);

// deploy account
accountC1 = new Account(provider, toBeAccountAddress, priKey, '1');
accountC1 = new Account(provider, toBeAccountAddress, priKey, '1', TEST_TX_VERSION);
const deployed = await accountC1.deploySelf({
classHash: accountClassHash,
constructorCalldata: calldata,
Expand Down
4 changes: 3 additions & 1 deletion __tests__/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ export function getTestProvider(isProvider: boolean = true): ProviderInterface |
return provider;
}

export const TEST_TX_VERSION = process.env.TX_VERSION === 'v3' ? ETransactionVersion.V3 : undefined;

export const getTestAccount = (provider: ProviderInterface) => {
return new Account(
provider,
toHex(process.env.TEST_ACCOUNT_ADDRESS || ''),
process.env.TEST_ACCOUNT_PRIVATE_KEY || '',
undefined,
process.env.TX_VERSION === 'v3' ? ETransactionVersion.V3 : undefined // TODO: enable setup to test diff TX versions, add this to print table
TEST_TX_VERSION
);
};

Expand Down
1 change: 1 addition & 0 deletions __tests__/config/jestGlobalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const verifySetup = (final?: boolean) => {
INITIAL_BALANCE: process.env.INITIAL_BALANCE,
TEST_PROVIDER_BASE_URL: process.env.TEST_PROVIDER_BASE_URL,
TEST_RPC_URL: process.env.TEST_RPC_URL,
TX_VERSION: process.env.TX_VERSION === 'v3' ? 'v3' : 'v2',
});

console.table({
Expand Down
17 changes: 6 additions & 11 deletions src/channel/rpc_0_6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ export class RpcChannel {
invocations: AccountInvocations,
{
blockIdentifier = this.blockIdentifier,
skipValidate = false,
skipValidate = true,
skipFeeCharge = true,
}: getSimulateTransactionOptions = {}
) {
const block_id = new Block(blockIdentifier).identifier;
const simulationFlags = [];
const simulationFlags: RPC.ESimulationFlag[] = [];
if (skipValidate) simulationFlags.push(RPC.ESimulationFlag.SKIP_VALIDATE);
if (skipFeeCharge) simulationFlags.push(RPC.ESimulationFlag.SKIP_FEE_CHARGE);

Expand Down Expand Up @@ -522,7 +522,6 @@ export class RpcChannel {
resource_bounds: details.resourceBounds,
tip: toHex(details.tip),
paymaster_data: details.paymasterData.map((it) => toHex(it)),
account_deployment_data: details.accountDeploymentData.map((it) => toHex(it)),
nonce_data_availability_mode: details.nonceDataAvailabilityMode,
fee_data_availability_mode: details.feeDataAvailabilityMode,
},
Expand Down Expand Up @@ -607,13 +606,7 @@ export class RpcChannel {
paymaster_data: invocation.paymasterData.map((it) => toHex(it)),
nonce_data_availability_mode: invocation.nonceDataAvailabilityMode,
fee_data_availability_mode: invocation.feeDataAvailabilityMode,

// dont add account_deployment_data if invocation.type === TransactionType.DEPLOY_ACCOUNT
...(invocation.type === TransactionType.DEPLOY_ACCOUNT
? {}
: {
account_deployment_data: invocation.accountDeploymentData.map((it) => toHex(it)),
}),
account_deployment_data: invocation.accountDeploymentData.map((it) => toHex(it)),
};
}

Expand Down Expand Up @@ -652,14 +645,16 @@ export class RpcChannel {
} as RPC.SPEC.BROADCASTED_DECLARE_TXN;
}
if (invocation.type === TransactionType.DEPLOY_ACCOUNT) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { account_deployment_data, ...restDetails } = details;
// v1 v3
return {
type: invocation.type,
constructor_calldata: CallData.toHex(invocation.constructorCalldata || []),
class_hash: toHex(invocation.classHash),
contract_address_salt: toHex(invocation.addressSalt || 0),
version: toHex(invocation.version || defaultVersions.v3) as RPC.SPEC.INVOKE_TXN['version'],
...details,
...restDetails,
} as RPC.SPEC.BROADCASTED_DEPLOY_ACCOUNT_TXN;
}
throw Error('RPC buildTransaction received unknown TransactionType');
Expand Down
1 change: 0 additions & 1 deletion src/types/api/rpcspec_0_6/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ export type DEPLOY_ACCOUNT_TXN_V3 = {
resource_bounds: RESOURCE_BOUNDS_MAPPING;
tip: u64;
paymaster_data: FELT[];
account_deployment_data: FELT[];
nonce_data_availability_mode: DA_MODE;
fee_data_availability_mode: DA_MODE;
};
Expand Down

0 comments on commit 2b6d349

Please sign in to comment.