Skip to content

Commit 6f784ea

Browse files
feat: skip signatures when skipValidate is true
* feat: don't sign when skipValidate is true * test: adjust tests for skipValidate change --------- Co-authored-by: Petar Penovic <pp@spaceshard.io>
1 parent 0104c59 commit 6f784ea

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

__tests__/account.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import typedDataExample from '../__mocks__/typedData/baseExample.json';
22
import {
33
Account,
4+
AllowArray,
5+
Call,
46
Contract,
57
DeclareDeployUDCResponse,
68
Provider,
@@ -87,17 +89,24 @@ describe('deploy and test Wallet', () => {
8789

8890
test('estimateInvokeFee Cairo 0', async () => {
8991
const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction');
90-
const result = await account.estimateInvokeFee({
92+
93+
const calls: AllowArray<Call> = {
9194
contractAddress: erc20Address,
9295
entrypoint: 'transfer',
9396
calldata: [erc20.address, '10', '0'],
94-
});
97+
};
98+
99+
let result = await account.estimateInvokeFee(calls, { skipValidate: true });
100+
expect(result).toMatchSchemaRef('EstimateFee');
101+
expect(innerInvokeEstFeeSpy).not.toHaveBeenCalled();
102+
innerInvokeEstFeeSpy.mockClear();
95103

104+
result = await account.estimateInvokeFee(calls, { skipValidate: false });
96105
expect(result).toMatchSchemaRef('EstimateFee');
97106
expect([constants.TRANSACTION_VERSION.F1, constants.TRANSACTION_VERSION.F3]).toContain(
98107
innerInvokeEstFeeSpy.mock.calls[0][1].version
99108
);
100-
innerInvokeEstFeeSpy.mockClear();
109+
innerInvokeEstFeeSpy.mockRestore();
101110
});
102111

103112
xtest('estimateDeclareFee Cairo 0 & Cairo 1', async () => {

src/account/default.ts

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ export class Account extends Provider implements AccountInterface {
134134
calls: AllowArray<Call>,
135135
details: UniversalDetails = {}
136136
): Promise<EstimateFee> {
137-
const { nonce: providedNonce, blockIdentifier, version: providedVersion } = details;
137+
const {
138+
nonce: providedNonce,
139+
blockIdentifier,
140+
version: providedVersion,
141+
skipValidate = true,
142+
} = details;
138143

139144
const transactions = Array.isArray(calls) ? calls : [calls];
140145
const nonce = toBigInt(providedNonce ?? (await this.getNonce()));
@@ -152,6 +157,7 @@ export class Account extends Provider implements AccountInterface {
152157
version,
153158
chainId,
154159
cairoVersion: await this.getCairoVersion(),
160+
skipValidate,
155161
};
156162

157163
const invocation = await this.buildInvocation(transactions, signerDetails);
@@ -167,7 +173,12 @@ export class Account extends Provider implements AccountInterface {
167173
payload: DeclareContractPayload,
168174
details: UniversalDetails = {}
169175
): Promise<EstimateFee> {
170-
const { blockIdentifier, nonce: providedNonce, version: providedVersion } = details;
176+
const {
177+
blockIdentifier,
178+
nonce: providedNonce,
179+
version: providedVersion,
180+
skipValidate = true,
181+
} = details;
171182
const nonce = toBigInt(providedNonce ?? (await this.getNonce()));
172183
const version = toTransactionVersion(
173184
!isSierra(payload.contract)
@@ -185,6 +196,7 @@ export class Account extends Provider implements AccountInterface {
185196
walletAddress: this.address,
186197
maxFee: ZERO,
187198
cairoVersion: undefined, // unused parameter
199+
skipValidate,
188200
});
189201

190202
return super.getDeclareEstimateFee(
@@ -204,7 +216,7 @@ export class Account extends Provider implements AccountInterface {
204216
}: DeployAccountContractPayload,
205217
details: UniversalDetails = {}
206218
): Promise<EstimateFee> {
207-
const { blockIdentifier, version: providedVersion } = details;
219+
const { blockIdentifier, version: providedVersion, skipValidate = true } = details;
208220
const version = toTransactionVersion(
209221
this.getPreferredVersion(ETransactionVersion.F1, ETransactionVersion.F3),
210222
toFeeVersion(providedVersion)
@@ -222,6 +234,7 @@ export class Account extends Provider implements AccountInterface {
222234
walletAddress: this.address, // unused parameter
223235
maxFee: ZERO,
224236
cairoVersion: undefined, // unused parameter,
237+
skipValidate,
225238
}
226239
);
227240

@@ -269,7 +282,7 @@ export class Account extends Provider implements AccountInterface {
269282
invocations: Invocations,
270283
details: SimulateTransactionDetails = {}
271284
): Promise<SimulateTransactionResponse> {
272-
const { nonce, blockIdentifier, skipValidate, skipExecute, version } = details;
285+
const { nonce, blockIdentifier, skipValidate = true, skipExecute, version } = details;
273286
const accountInvocations = await this.accountInvocationsFactory(invocations, {
274287
...v3Details(details),
275288
versions: [
@@ -281,6 +294,7 @@ export class Account extends Provider implements AccountInterface {
281294
],
282295
nonce,
283296
blockIdentifier,
297+
skipValidate,
284298
});
285299

286300
return super.getSimulateTransaction(accountInvocations, {
@@ -649,7 +663,7 @@ export class Account extends Provider implements AccountInterface {
649663
details: InvocationsSignerDetails
650664
): Promise<Invocation> {
651665
const calldata = getExecuteCalldata(call, await this.getCairoVersion());
652-
const signature = await this.signer.signTransaction(call, details);
666+
const signature = !details.skipValidate ? await this.signer.signTransaction(call, details) : [];
653667

654668
return {
655669
...v3Details(details),
@@ -673,13 +687,15 @@ export class Account extends Provider implements AccountInterface {
673687
throw Error('V3 Transaction work with Cairo1 Contracts and require compiledClassHash');
674688
}
675689

676-
const signature = await this.signer.signDeclareTransaction({
677-
...details,
678-
...v3Details(details),
679-
classHash,
680-
compiledClassHash: compiledClassHash as string, // TODO: TS Nekuzi da v2 nemora imat a v3 mora i da je throvano ako nije definiran
681-
senderAddress: details.walletAddress,
682-
});
690+
const signature = !details.skipValidate
691+
? await this.signer.signDeclareTransaction({
692+
...details,
693+
...v3Details(details),
694+
classHash,
695+
compiledClassHash: compiledClassHash as string, // TODO: TS Nekuzi da v2 nemora imat a v3 mora i da je throvano ako nije definiran
696+
senderAddress: details.walletAddress,
697+
})
698+
: [];
683699

684700
return {
685701
senderAddress: details.walletAddress,
@@ -703,14 +719,16 @@ export class Account extends Provider implements AccountInterface {
703719
providedContractAddress ??
704720
calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
705721

706-
const signature = await this.signer.signDeployAccountTransaction({
707-
...details,
708-
...v3Details(details),
709-
classHash,
710-
contractAddress,
711-
addressSalt,
712-
constructorCalldata: compiledCalldata,
713-
});
722+
const signature = !details.skipValidate
723+
? await this.signer.signDeployAccountTransaction({
724+
...details,
725+
...v3Details(details),
726+
classHash,
727+
contractAddress,
728+
addressSalt,
729+
constructorCalldata: compiledCalldata,
730+
})
731+
: [];
714732

715733
return {
716734
...v3Details(details),
@@ -752,7 +770,7 @@ export class Account extends Provider implements AccountInterface {
752770
invocations: Invocations,
753771
details: AccountInvocationsFactoryDetails
754772
) {
755-
const { nonce, blockIdentifier } = details;
773+
const { nonce, blockIdentifier, skipValidate = true } = details;
756774
const safeNonce = await this.getNonceSafe(nonce);
757775
const chainId = await this.getChainId();
758776
const versions = details.versions.map((it) => toTransactionVersion(it));
@@ -775,6 +793,7 @@ export class Account extends Provider implements AccountInterface {
775793
chainId,
776794
cairoVersion,
777795
version: '' as ETransactionVersion,
796+
skipValidate,
778797
};
779798
const common = {
780799
type: transaction.type,

src/types/account.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type AccountInvocationsFactoryDetails = {
2121
versions: Array<`${ETransactionVersion}`>;
2222
nonce?: BigNumberish;
2323
blockIdentifier?: BlockIdentifier;
24+
skipValidate?: boolean;
2425
} & Partial<V3TransactionDetails>;
2526

2627
export interface UniversalDetails {

src/types/signer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010

1111
export type InvocationsSignerDetails = (V2InvocationsSignerDetails | V3InvocationsSignerDetails) & {
1212
version: `${ETransactionVersion}`;
13+
skipValidate?: boolean;
1314
};
1415

1516
export type V2InvocationsSignerDetails = {

0 commit comments

Comments
 (0)