Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): run sdk tests with devnet #456

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
44 changes: 44 additions & 0 deletions .env.devnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Starknet RPC URL
STARKNET_RPC_URL=http://0.0.0.0:5050

## starknet-devnet-rs 0.2.0 account --seed 0
# Starknet accounts
STARKNET_ADMIN_ADDRESS_DEV=0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691
STARKNET_ADMIN_PRIVATE_KEY_DEV=0x0000000000000000000000000000000071d7bb07b9a64f6f78ac4c816aff4da9

STARKNET_ACCOUNT1_ADDRESS=0x78662e7352d062084b0010068b99288486c2d8b914f6e2a55ce945f8792c8b1
STARKNET_ACCOUNT1_PRIVATE_KEY=0x000000000000000000000000000000000e1406455b7d66b1690803be066cbe5e
STARKNET_ACCOUNT1_PUBLIC_KEY=0x007a1bb2744a7dd29bffd44341dbd78008adb4bc11733601e7eddff322ada9cb

STARKNET_ACCOUNT2_ADDRESS=0x49dfb8ce986e21d354ac93ea65e6a11f639c1934ea253e5ff14ca62eca0f38e
STARKNET_ACCOUNT2_PRIVATE_KEY=0x00000000000000000000000000000000a20a02f0ac53692d144b20cb371a60d7
STARKNET_ACCOUNT2_PUBLIC_KEY=0x00b8fd4ddd415902d96f61b7ad201022d495997c2dff8eb9e0eb86253e30fabc

STARKNET_ARK_RECEIVER_ADDRESS=0x4f348398f859a55a0c80b1446c5fdc37edb3a8478a32f10764659fc241027d3
STARKNET_ARK_RECEIVER_PRIVATE_KEY=0x00000000000000000000000000000000a641611c17d4d92bd0790074e34beeb7

STARKNET_ARK_COLLECTION_RECEIVER_ADDRESS=0xd513de92c16aa42418cf7e5b60f8022dbee1b4dfd81bcf03ebee079cfb5cb5
STARKNET_ARK_COLLECTION_RECEIVER_PRIVATE_KEY=0x000000000000000000000000000000005b4ac23628a5749277bcabbf4726b025

STARKNET_ARK_COLLECTION_2981_RECEIVER_ADDRESS=0x1e8c6c17efa3a047506c0b1610bd188aa3e3dd6c5d9227549b65428de24de78
STARKNET_ARK_COLLECTION_2981_RECEIVER_PRIVATE_KEY=0x00000000000000000000000000000000836203aceb0e9b0066138c321dda5ae6

STARKNET_LISTING_BROKER_ACCOUNT_ADDRESS=0x557ba9ef60b52dad611d79b60563901458f2476a5c1002a8b4869fcb6654c7e
STARKNET_LISTING_BROKER_ACCOUNT_PRIVATE_KEY=0x0000000000000000000000000000000015b5e3013d752c909988204714f1ff35

STARKNET_SALE_BROKER_ACCOUNT_ADDRESS=0x3736286f1050d4ba816b4d56d15d80ca74c1752c4e847243f1da726c36e06f
STARKNET_SALE_BROKER_ACCOUNT_PRIVATE_KEY=0x00000000000000000000000000000000a56597ba3378fa9e6440ea9ae0cf2865

SOLIS_ADMIN_ADDRESS_DEV=0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca
SOLIS_ADMIN_PRIVATE_KEY_DEV=0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a
SOLIS_ADMIN_PUBLIC_KEY_DEV=0x640466ebd2ce505209d3e5c4494b4276ed8f1cde764d757eb48831961f7cdea

SOLIS_ADMIN_ADDRESS=0x6b86e40118f29ebe393a75469b4d926c7a44c2e2681b6d319520b7c1156d114
SOLIS_ADMIN_PRIVATE_KEY=0x1c9053c053edf324aec366a34c6901b1095b07af69495bffec7d7fe21effb1b

# Starknet network
STARKNET_NETWORK_ID=dev
# Solis network
SOLIS_NETWORK_ID=dev

BROKER_ID=
36 changes: 36 additions & 0 deletions .github/actions/install-snforge/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "Install contract dependencies"
description: "Install dependencies for smart contract"

env:
SCARB_VERSION: 2.7.1
STARKNET_FOUNDRY_VERSION: 0.30.0

runs:
using: "composite"
steps:
- name: Install universal sierra compiler
shell: bash
run: |
curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh
echo "/root/.local/bin" >> ${GITHUB_PATH}

- name: Check universal sierra compiler version
shell: bash
run: universal-sierra-compiler --version

- name: Setup Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}

- name: Setup Starknet Foundry
uses: foundry-rs/setup-snfoundry@v3
with:
starknet-foundry-version: ${{ env.STARKNET_FOUNDRY_VERSION }}

- name: Set Up Stable Rust Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

78 changes: 54 additions & 24 deletions .github/workflows/arkproject-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,77 @@ on:
paths:
- "contracts/**"

env:
SCARB_VERSION: 2.7.1
STARKNET_DEVNET_VERSION: 0.2.0-rc3
DEVNET_DUMP_PATH: /devnet-dump.json
jobs:
fmt:
runs-on: ubuntu-latest
name: Cairo formatting
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install universal sierra compiler
run: curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh
uses: actions/checkout@v4

- name: Setup Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: 2.7.1
scarb-version: ${{ env.SCARB_VERSION }}

- name: Check Scarb Formatting
run: cd contracts && scarb fmt --check
test:

forge-test:
runs-on: ubuntu-latest
name: Cairo starknet foundry tests
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install universal sierra compiler
run: curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh
- name: Setup Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: 2.7.1
uses: actions/checkout@v4

- name: Setup Starknet Foundry
uses: foundry-rs/setup-snfoundry@v2
with:
starknet-foundry-version: 0.28.0
- name: Install starknet foundry & dependencies
uses: ./.github/actions/install-snforge

- name: Test contracts
run: cd contracts && snforge test

devnet-test:
runs-on: ubuntu-latest
name: Running SDK test with starknet-devnet
# needs: forge-test
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install starknet foundry & dependencies
uses: ./.github/actions/install-snforge

- name: Build smart contracts
run: cd contracts && scarb build --workspace

- name: Run starknet-devnet as a background process
run: |
docker run -d --rm --name starknet-devnet \
-p 5050:5050 \
ptisserand/starknet-devnet-rs:${STARKNET_DEVNET_VERSION} \
--seed 0 --dump-path $DEVNET_DUMP_PATH --state-archive-capacity full
sleep 3 # Wait for 3 seconds for the Docker container to initialize

- name: Test ark_common contracts
run: cd contracts/ark_common && snforge test
- name: Install SDK dependencies
uses: ./.github/actions/install-dependencies

- name: Setup environment for devnet
run: cp .env.devnet .env

- name: Deploy smart contract
run: pnpm deploy:starknet:local

- name: Run SDK test
run: |
cp .env.devnet .env
pnpm test

- name: Test ark_orderbook contracts
run: cd contracts/ark_orderbook && snforge test
- name: Stop starknet-devnet container
if: always()
run: docker stop starknet-devnet

- name: Test ark_starknet contracts
run: cd contracts/ark_starknet && snforge test

- name: Test ark_tokens contracts
run: cd contracts/ark_tokens && snforge test
2 changes: 1 addition & 1 deletion contracts/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.7.1
starknet-foundry 0.28.0
starknet-foundry 0.30.0
6 changes: 3 additions & 3 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f
[[package]]
name = "snforge_scarb_plugin"
version = "0.1.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.30.0#196f06b251926697c3d66800f2a93ae595e76496"

[[package]]
name = "snforge_std"
version = "0.28.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea"
version = "0.30.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.30.0#196f06b251926697c3d66800f2a93ae595e76496"
dependencies = [
"snforge_scarb_plugin",
]
Expand Down
2 changes: 1 addition & 1 deletion contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
[workspace.dependencies]
starknet = "2.7.1"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.1" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.30.0" }
assert_macros = "0.1.0"

[workspace.scripts]
Expand Down
35 changes: 13 additions & 22 deletions contracts/ark_component/src/orderbook/orderbook.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub mod OrderbookComponent {
/// Events emitted by the Orderbook contract.
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
pub enum Event {
OrderPlaced: OrderPlaced,
OrderExecuted: OrderExecuted,
OrderCancelled: OrderCancelled,
Expand All @@ -51,10 +51,10 @@ pub mod OrderbookComponent {
}

// must be increased when `OrderPlaced` content change
const ORDER_PLACED_EVENT_VERSION: u8 = 1;
pub const ORDER_PLACED_EVENT_VERSION: u8 = 1;
/// Event for when an order is placed.
#[derive(Drop, starknet::Event)]
struct OrderPlaced {
pub struct OrderPlaced {
#[key]
order_hash: felt252,
#[key]
Expand All @@ -70,10 +70,10 @@ pub mod OrderbookComponent {
}

// must be increased when `OrderExecuted` content change
const ORDER_EXECUTED_EVENT_VERSION: u8 = 2;
pub const ORDER_EXECUTED_EVENT_VERSION: u8 = 2;
/// Event for when an order is executed.
#[derive(Drop, starknet::Event)]
struct OrderExecuted {
pub struct OrderExecuted {
#[key]
order_hash: felt252,
#[key]
Expand All @@ -88,10 +88,10 @@ pub mod OrderbookComponent {
}

// must be increased when `OrderPlaced` content change
const ORDER_CANCELLED_EVENT_VERSION: u8 = 1;
pub const ORDER_CANCELLED_EVENT_VERSION: u8 = 1;
/// Event for when an order is cancelled.
#[derive(Drop, starknet::Event)]
struct OrderCancelled {
pub struct OrderCancelled {
#[key]
order_hash: felt252,
#[key]
Expand All @@ -102,10 +102,10 @@ pub mod OrderbookComponent {
}

// must be increased when `RollbackStatus` content change
const ROLLBACK_STATUS_EVENT_VERSION: u8 = 1;
pub const ROLLBACK_STATUS_EVENT_VERSION: u8 = 1;
/// Event for when an order has been rollbacked to placed.
#[derive(Drop, starknet::Event)]
struct RollbackStatus {
pub struct RollbackStatus {
#[key]
order_hash: felt252,
#[key]
Expand All @@ -117,10 +117,10 @@ pub mod OrderbookComponent {
}

// must be increased when `OrderFulfilled` content change
const ORDER_FULFILLED_EVENT_VERSION: u8 = 1;
pub const ORDER_FULFILLED_EVENT_VERSION: u8 = 1;
/// Event for when an order is fulfilled.
#[derive(Drop, starknet::Event)]
struct OrderFulfilled {
pub struct OrderFulfilled {
#[key]
order_hash: felt252,
#[key]
Expand Down Expand Up @@ -265,21 +265,12 @@ pub mod OrderbookComponent {
.validate_order_type()
.expect(orderbook_errors::ORDER_INVALID_DATA);
let order_hash = order.compute_order_hash();
assert(order_status_read(order_hash).is_none(), orderbook_errors::ORDER_ALREADY_EXISTS);
match order_type {
OrderType::Listing => {
assert(
order_status_read(order_hash).is_none(),
orderbook_errors::ORDER_ALREADY_EXISTS
);
let _ = self._create_listing_order(order, order_type, order_hash);
},
OrderType::Auction => {
assert(
order_status_read(order_hash).is_none(),
orderbook_errors::ORDER_ALREADY_EXISTS
);
self._create_auction(order, order_type, order_hash);
},
OrderType::Auction => { self._create_auction(order, order_type, order_hash); },
OrderType::Offer => { self._create_offer(order, order_type, order_hash); },
OrderType::CollectionOffer => {
self._create_collection_offer(order, order_type, order_hash);
Expand Down
2 changes: 1 addition & 1 deletion contracts/ark_oz/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ starknet = "2.7.1"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.1" }

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.30.0" }
assert_macros = "0.1.0"

[tool.fmt]
Expand Down
Loading
Loading