Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
- name: Check Svelte
run: yarn svelte-check
working-directory: packages/ui
- name: Run linter
run: yarn lint
- name: Run tests
run: yarn test
working-directory: packages/core/${{matrix.package}}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules

.env
.env.local
.vscode/
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"arrowParens": "avoid",
"trailingComma": "all",
"printWidth": 120,
"bracketSpacing": true
}
49 changes: 49 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// @ts-check

import eslint from '@eslint/js';
import prettierPluginRecommended from 'eslint-plugin-prettier/recommended';
import unicornPlugin from 'eslint-plugin-unicorn';
import typescriptEslint from 'typescript-eslint';

export default typescriptEslint.config(
eslint.configs.recommended,
typescriptEslint.configs.strict,
prettierPluginRecommended,
{
plugins: {
unicorn: unicornPlugin,
},
rules: {
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/consistent-type-imports': 'error',
'prettier/prettier': [
'error',
{ singleQuote: true, arrowParens: 'avoid', trailingComma: 'all', printWidth: 120, bracketSpacing: true },
],
},
},
{
ignores: ['node_modules/', '*.sol', 'packages/*/node_modules/', 'packages/**/dist/', 'packages/**/build/'],
},
{
files: ['**/*.config.js'],
languageOptions: {
sourceType: 'commonjs',
},
},
{
files: ['**/*.mjs', '**/*.js'],
languageOptions: {
sourceType: 'commonjs',
globals: {
process: 'readonly',
global: 'readonly',
console: 'readonly',
},
},
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
);
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "root",
"private": true,
"scripts": {
"prepare": "wsrun -m prepare"
"prepare": "wsrun -m prepare",
"lint": "eslint"
},
"workspaces": {
"packages": [
Expand All @@ -15,6 +16,14 @@
]
},
"devDependencies": {
"@eslint/js": "^9.20.0",
"eslint": "^9.20.1",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-unicorn": "^57.0.0",
"prettier": "^3.5.1",
"typescript": "^5.7.3",
"typescript-eslint": "^8.24.1",
"wsrun": "^5.2.4"
}
}
6 changes: 1 addition & 5 deletions packages/core/cairo/ava.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ module.exports = {
extensions: ['ts'],
require: ['ts-node/register'],
watchmode: {
ignoreChanges: [
'contracts',
'artifacts',
'cache',
],
ignoreChanges: ['contracts', 'artifacts', 'cache'],
},
timeout: '10m',
workerThreads: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/cairo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"typescript": "^5.0.0",
"semver": "^7.6.0"
}
}
}
42 changes: 24 additions & 18 deletions packages/core/cairo/src/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from 'ava';

import { buildAccount, AccountOptions } from './account';
import type { AccountOptions } from './account';
import { buildAccount } from './account';
import { printContract } from './print';

import { account } from '.';
Expand Down Expand Up @@ -32,22 +33,27 @@ function testEthAccount(title: string, opts: Partial<AccountOptions>) {
*/
function testAPIEquivalence(title: string, opts?: AccountOptions) {
test(title, t => {
t.is(account.print(opts), printContract(buildAccount({
name: 'MyAccount',
type: 'stark',
declare: true,
deploy: true,
pubkey: true,
outsideExecution: true,
...opts,
})));
t.is(
account.print(opts),
printContract(
buildAccount({
name: 'MyAccount',
type: 'stark',
declare: true,
deploy: true,
pubkey: true,
outsideExecution: true,
...opts,
}),
),
);
});
}

testAccount('default full account, mixin + upgradeable', {});

testAccount('default full account, mixin + non-upgradeable', {
upgradeable: false
upgradeable: false,
});

testAccount('explicit full account, mixin + upgradeable', {
Expand All @@ -57,7 +63,7 @@ testAccount('explicit full account, mixin + upgradeable', {
deploy: true,
pubkey: true,
outsideExecution: true,
upgradeable: true
upgradeable: true,
});

testAccount('explicit full account, mixin + non-upgradeable', {
Expand All @@ -67,7 +73,7 @@ testAccount('explicit full account, mixin + non-upgradeable', {
deploy: true,
pubkey: true,
outsideExecution: true,
upgradeable: false
upgradeable: false,
});

testAccount('basic account, upgradeable', {
Expand All @@ -82,7 +88,7 @@ testAccount('basic account, non-upgradeable', {
deploy: false,
pubkey: false,
outsideExecution: false,
upgradeable: false
upgradeable: false,
});

testAccount('account outside execution', {
Expand Down Expand Up @@ -127,7 +133,7 @@ testAccount('account deployable, public key', {
testEthAccount('default full ethAccount, mixin + upgradeable', {});

testEthAccount('default full ethAccount, mixin + non-upgradeable', {
upgradeable: false
upgradeable: false,
});

testEthAccount('explicit full ethAccount, mixin + upgradeable', {
Expand All @@ -137,7 +143,7 @@ testEthAccount('explicit full ethAccount, mixin + upgradeable', {
deploy: true,
pubkey: true,
outsideExecution: true,
upgradeable: true
upgradeable: true,
});

testEthAccount('explicit full ethAccount, mixin + non-upgradeable', {
Expand All @@ -147,7 +153,7 @@ testEthAccount('explicit full ethAccount, mixin + non-upgradeable', {
deploy: true,
pubkey: true,
outsideExecution: true,
upgradeable: false
upgradeable: false,
});

testEthAccount('basic ethAccount, upgradeable', {
Expand All @@ -162,7 +168,7 @@ testEthAccount('basic ethAccount, non-upgradeable', {
deploy: false,
pubkey: false,
outsideExecution: false,
upgradeable: false
upgradeable: false,
});

testEthAccount('ethAccount outside execution', {
Expand Down
67 changes: 39 additions & 28 deletions packages/core/cairo/src/account.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Contract, ContractBuilder } from './contract';
import { CommonOptions, withCommonDefaults } from './common-options';
import type { Contract } from './contract';
import { ContractBuilder } from './contract';
import type { CommonOptions } from './common-options';
import { withCommonDefaults } from './common-options';
import { defaults as commonDefaults } from './common-options';
import { setAccountUpgradeable } from './set-upgradeable';
import { setInfo } from './set-info';
import { defineComponents } from './utils/define-components';
import { printContract } from './print';
import { addSRC5Component } from './common-components';


export const accountTypes = ['stark', 'eth'] as const;
export type Account = typeof accountTypes[number];
export type Account = (typeof accountTypes)[number];

export const defaults: Required<AccountOptions> = {
name: 'MyAccount',
Expand All @@ -19,7 +20,7 @@ export const defaults: Required<AccountOptions> = {
pubkey: true,
outsideExecution: true,
upgradeable: commonDefaults.upgradeable,
info: commonDefaults.info
info: commonDefaults.info,
} as const;

export function printAccount(opts: AccountOptions = defaults): string {
Expand All @@ -42,8 +43,8 @@ function withDefaults(opts: AccountOptions): Required<AccountOptions> {
declare: opts.declare ?? defaults.declare,
deploy: opts.deploy ?? defaults.deploy,
pubkey: opts.pubkey ?? defaults.pubkey,
outsideExecution: opts.outsideExecution ?? defaults.outsideExecution
}
outsideExecution: opts.outsideExecution ?? defaults.outsideExecution,
};
}

export function buildAccount(opts: AccountOptions): Contract {
Expand Down Expand Up @@ -157,11 +158,14 @@ function addAccountMixin(c: ContractBuilder, accountType: Account) {
}

function getBaseCompAndCompType(accountType: Account): [string, typeof componentType] {
const [baseComponent, componentType] = accountType === 'stark' ? ['AccountComponent', components.AccountComponent] : ['EthAccountComponent', components.EthAccountComponent];
const [baseComponent, componentType] =
accountType === 'stark'
? ['AccountComponent', components.AccountComponent]
: ['EthAccountComponent', components.EthAccountComponent];
return [baseComponent, componentType];
}

const components = defineComponents( {
const components = defineComponents({
AccountComponent: {
path: 'openzeppelin::account',
substorage: {
Expand All @@ -172,11 +176,13 @@ const components = defineComponents( {
name: 'AccountEvent',
type: 'AccountComponent::Event',
},
impls: [{
name: 'AccountInternalImpl',
embed: false,
value: 'AccountComponent::InternalImpl<ContractState>',
}],
impls: [
{
name: 'AccountInternalImpl',
embed: false,
value: 'AccountComponent::InternalImpl<ContractState>',
},
],
},
EthAccountComponent: {
path: 'openzeppelin::account::eth_account',
Expand All @@ -188,11 +194,13 @@ const components = defineComponents( {
name: 'EthAccountEvent',
type: 'EthAccountComponent::Event',
},
impls: [{
name: 'EthAccountInternalImpl',
embed: false,
value: 'EthAccountComponent::InternalImpl<ContractState>',
}]
impls: [
{
name: 'EthAccountInternalImpl',
embed: false,
value: 'EthAccountComponent::InternalImpl<ContractState>',
},
],
},
SRC9Component: {
path: 'openzeppelin::account::extensions',
Expand All @@ -204,13 +212,16 @@ const components = defineComponents( {
name: 'SRC9Event',
type: 'SRC9Component::Event',
},
impls: [{
name: 'OutsideExecutionV2Impl',
value: 'SRC9Component::OutsideExecutionV2Impl<ContractState>',
}, {
name: 'OutsideExecutionInternalImpl',
embed: false,
value: 'SRC9Component::InternalImpl<ContractState>',
}]
}
impls: [
{
name: 'OutsideExecutionV2Impl',
value: 'SRC9Component::OutsideExecutionV2Impl<ContractState>',
},
{
name: 'OutsideExecutionInternalImpl',
embed: false,
value: 'SRC9Component::InternalImpl<ContractState>',
},
],
},
});
Loading
Loading