Skip to content

Commit 4507388

Browse files
immrsdericglauPatrick-Ehimen
authored
Add CI checks for Cairo test projects (#499)
Co-authored-by: Eric Lau <[email protected]> Co-authored-by: 0xOse <[email protected]>
1 parent 32a8156 commit 4507388

File tree

14 files changed

+699
-153
lines changed

14 files changed

+699
-153
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Validate Cairo Alpha Test Project
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'packages/core/cairo_alpha/**'
7+
push:
8+
9+
jobs:
10+
validate-cairo-alpha:
11+
runs-on: ubuntu-latest
12+
concurrency:
13+
group: validate-cairo-alpha-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Setup node
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 18.x
24+
cache: 'yarn'
25+
26+
- name: Install dependencies
27+
working-directory: packages/core/cairo_alpha
28+
run: yarn install --network-concurrency 1
29+
30+
- name: Extract Scarb version
31+
working-directory: packages/core/cairo_alpha/test_project
32+
run: |
33+
SCARB_VERSION=$(grep 'scarb-version = ' Scarb.toml | sed 's/scarb-version = "\(.*\)"/\1/')
34+
echo "SCARB_VERSION=$SCARB_VERSION" >> "$GITHUB_ENV"
35+
36+
- name: Setup Scarb
37+
uses: software-mansion/setup-scarb@v1
38+
with:
39+
scarb-version: ${{ env.SCARB_VERSION }}
40+
41+
- name: Generate and compile test project
42+
working-directory: packages/core/cairo_alpha/test_project
43+
run: |
44+
# Exit immediately if a command exits with a non-zero status
45+
set -e
46+
47+
declare -a all_kinds=("ERC20" "ERC721" "ERC1155" "Account" "Vesting" "Governor" "Custom")
48+
declare -a all_royalty_info_options=("disabled" "enabled_default" "enabled_custom")
49+
for kind in "${all_kinds[@]}"; do
50+
scarb clean
51+
52+
if [[ "$kind" == "ERC721" || "$kind" == "ERC1155" ]]; then
53+
for royalty_info_option in "${all_royalty_info_options[@]}"; do
54+
proj_name="'$kind (royalty info: $royalty_info_option)' test project"
55+
echo "Generating $proj_name..."
56+
yarn run update_scarb_project $kind $royalty_info_option
57+
58+
echo "Compiling $proj_name..."
59+
scarb build
60+
61+
echo "✅ Compiled $proj_name!"
62+
echo "---------------------------------"
63+
done
64+
65+
else
66+
proj_name="'$kind' test project"
67+
68+
echo "Generating $proj_name..."
69+
yarn run update_scarb_project $kind
70+
71+
echo "Compiling $proj_name..."
72+
scarb build
73+
74+
echo "✅ Compiled $proj_name!"
75+
echo "---------------------------------"
76+
fi
77+
78+
done
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Validate Cairo Test Project
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'packages/core/cairo/**'
7+
push:
8+
9+
jobs:
10+
validate-cairo:
11+
runs-on: ubuntu-latest
12+
concurrency:
13+
group: validate-cairo-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Setup node
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 18.x
24+
cache: 'yarn'
25+
26+
- name: Install dependencies
27+
working-directory: packages/core/cairo
28+
run: yarn install --network-concurrency 1
29+
30+
- name: Extract Scarb version
31+
working-directory: packages/core/cairo/test_project
32+
run: |
33+
SCARB_VERSION=$(grep 'scarb-version = ' Scarb.toml | sed 's/scarb-version = "\(.*\)"/\1/')
34+
echo "SCARB_VERSION=$SCARB_VERSION" >> "$GITHUB_ENV"
35+
36+
- name: Setup Scarb
37+
uses: software-mansion/setup-scarb@v1
38+
with:
39+
scarb-version: ${{ env.SCARB_VERSION }}
40+
41+
- name: Generate and compile test project
42+
working-directory: packages/core/cairo/test_project
43+
run: |
44+
# Exit immediately if a command exits with a non-zero status
45+
set -e
46+
47+
declare -a all_kinds=("ERC20" "ERC721" "ERC1155" "Account" "Vesting" "Governor" "Custom")
48+
declare -a all_royalty_info_options=("disabled" "enabled_default" "enabled_custom")
49+
for kind in "${all_kinds[@]}"; do
50+
scarb clean
51+
52+
if [[ "$kind" == "ERC721" || "$kind" == "ERC1155" ]]; then
53+
for royalty_info_option in "${all_royalty_info_options[@]}"; do
54+
proj_name="'$kind (royalty info: $royalty_info_option)'' test project"
55+
echo "Generating $proj_name..."
56+
yarn run update_scarb_project $kind $royalty_info_option
57+
58+
echo "Compiling $proj_name..."
59+
scarb build
60+
61+
echo "✅ Compiled $proj_name!"
62+
echo "---------------------------------"
63+
done
64+
65+
else
66+
proj_name="'$kind' test project"
67+
68+
echo "Generating $proj_name..."
69+
yarn run update_scarb_project $kind
70+
71+
echo "Compiling $proj_name..."
72+
scarb build
73+
74+
echo "✅ Compiled $proj_name!"
75+
echo "---------------------------------"
76+
fi
77+
78+
done

packages/core/cairo/src/generate/erc1155.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@ import type { ERC1155Options } from '../erc1155';
22
import { accessOptions } from '../set-access-control';
33
import { infoOptions } from '../set-info';
44
import { upgradeableOptions } from '../set-upgradeable';
5-
import { royaltyInfoOptions } from '../set-royalty-info';
5+
import type { RoyaltyInfoSubset } from '../set-royalty-info';
6+
import { resolveRoyaltyOptionsSubset } from '../set-royalty-info';
67
import { generateAlternatives } from './alternatives';
78

89
const booleans = [true, false];
910

10-
const blueprint = {
11-
name: ['MyToken'],
12-
baseUri: ['https://example.com/'],
13-
burnable: booleans,
14-
pausable: booleans,
15-
mintable: booleans,
16-
updatableUri: booleans,
17-
upgradeable: upgradeableOptions,
18-
royaltyInfo: [royaltyInfoOptions.disabled, royaltyInfoOptions.enabledDefault, royaltyInfoOptions.enabledCustom],
19-
access: accessOptions,
20-
info: infoOptions,
11+
type GeneratorOptions = {
12+
royaltyInfo: RoyaltyInfoSubset;
2113
};
2214

23-
export function* generateERC1155Options(): Generator<Required<ERC1155Options>> {
15+
function prepareBlueprint(opts: GeneratorOptions) {
16+
const royaltyInfo = resolveRoyaltyOptionsSubset(opts.royaltyInfo);
17+
return {
18+
name: ['MyToken'],
19+
baseUri: ['https://example.com/'],
20+
burnable: booleans,
21+
pausable: booleans,
22+
mintable: booleans,
23+
updatableUri: booleans,
24+
upgradeable: upgradeableOptions,
25+
royaltyInfo,
26+
access: accessOptions,
27+
info: infoOptions,
28+
};
29+
}
30+
31+
export function* generateERC1155Options(opts: GeneratorOptions): Generator<Required<ERC1155Options>> {
32+
const blueprint = prepareBlueprint(opts);
2433
yield* generateAlternatives(blueprint);
2534
}
Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
import type { ERC721Options } from '../erc721';
22
import { accessOptions } from '../set-access-control';
3-
import { infoOptions } from '../set-info';
3+
import { defaults as infoDefaults } from '../set-info';
44
import { upgradeableOptions } from '../set-upgradeable';
5-
import { royaltyInfoOptions } from '../set-royalty-info';
5+
import type { RoyaltyInfoSubset } from '../set-royalty-info';
6+
import { resolveRoyaltyOptionsSubset } from '../set-royalty-info';
67
import { generateAlternatives } from './alternatives';
78

89
const booleans = [true, false];
910

10-
const blueprint = {
11-
name: ['MyToken'],
12-
symbol: ['MTK'],
13-
baseUri: ['https://example.com/'],
14-
burnable: booleans,
15-
enumerable: booleans,
16-
votes: booleans,
17-
appName: ['MyApp'],
18-
appVersion: ['v1'],
19-
pausable: booleans,
20-
mintable: booleans,
21-
royaltyInfo: [royaltyInfoOptions.disabled, royaltyInfoOptions.enabledDefault, royaltyInfoOptions.enabledCustom],
22-
access: accessOptions,
23-
upgradeable: upgradeableOptions,
24-
info: infoOptions,
11+
type GeneratorOptions = {
12+
royaltyInfo: RoyaltyInfoSubset;
2513
};
2614

27-
export function* generateERC721Options(): Generator<Required<ERC721Options>> {
15+
function prepareBlueprint(opts: GeneratorOptions) {
16+
const royaltyInfo = resolveRoyaltyOptionsSubset(opts.royaltyInfo);
17+
return {
18+
name: ['MyToken'],
19+
symbol: ['MTK'],
20+
baseUri: ['https://example.com/'],
21+
burnable: booleans,
22+
enumerable: booleans,
23+
votes: booleans,
24+
appName: ['MyApp'],
25+
appVersion: ['v1'],
26+
pausable: booleans,
27+
mintable: booleans,
28+
royaltyInfo,
29+
access: accessOptions,
30+
upgradeable: upgradeableOptions,
31+
info: [infoDefaults],
32+
};
33+
}
34+
35+
export function* generateERC721Options(opts: GeneratorOptions): Generator<Required<ERC721Options>> {
36+
const blueprint = prepareBlueprint(opts);
2837
yield* generateAlternatives(blueprint);
2938
}

0 commit comments

Comments
 (0)