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

chore: add CI/CD basics for Cairo and Solidity contracts #122

Merged
Merged
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
20 changes: 20 additions & 0 deletions .github/workflows/eth-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: ETH YABTransfer Tests

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
test-ETH:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Run tests
run: make ethereum-test
37 changes: 37 additions & 0 deletions .github/workflows/sn-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: SN Escrow Tests

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
test-SN:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.3.1"

- name: Install starkliup
run: |
curl https://get.starkli.sh | sh

- name: Install Starkli
run: |
/home/runner/.config/.starkli/bin/starkliup --version 0.1.20
sudo mv /home/runner/.config/.starkli/bin/starkli /usr/local/bin/

- name: Install snFoundry
uses: foundry-rs/setup-snfoundry@v2
with:
starknet-foundry-version: 0.12.0

- name: Run make starknet-test
run: |
make starknet-test
2 changes: 1 addition & 1 deletion contracts/cairo/src/escrow.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod Escrow {
use openzeppelin::{
access::ownable::OwnableComponent,
upgrades::{UpgradeableComponent, interface::IUpgradeable},
security::PausableComponent
security::PausableComponent,
};
use starknet::{
ContractAddress, EthAddress, ClassHash, get_caller_address, get_contract_address,
Expand Down
1 change: 0 additions & 1 deletion contracts/cairo/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ mod mocks {
#[cfg(test)]
mod tests {
mod test_escrow_allowance;
mod test_escrow_cancel;
mod test_escrow_pause;
mod test_escrow_upgrade;
mod test_escrow_ownable;
Expand Down
145 changes: 0 additions & 145 deletions contracts/cairo/src/tests/test_escrow_cancel.cairo

This file was deleted.

51 changes: 38 additions & 13 deletions contracts/cairo/src/tests/test_escrow_pause.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ mod Escrow {
use openzeppelin::{
upgrades::{
UpgradeableComponent,
interface::{IUpgradeable, IUpgradeableDispatcher, IUpgradeableDispatcherTrait}
interface::{IUpgradeable, IUpgradeableDispatcher, IUpgradeableDispatcherTrait},
},
security::{
PausableComponent,
interface::{IPausable, IPausableDispatcher, IPausableDispatcherTrait},
},
};

Expand Down Expand Up @@ -94,38 +98,46 @@ mod Escrow {
#[test]
fn test_start_unpaused() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), OWNER());
assert(escrow.pause_state() == false, 'Should start unpaused');
assert(pausable.is_paused() == false, 'Should start unpaused');
stop_prank(CheatTarget::One(escrow.contract_address));
}

#[test]
fn test_pause() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), OWNER());
escrow.pause();
assert(escrow.pause_state() == true, 'Should be paused');
assert(pausable.is_paused() == true, 'Should be paused');
stop_prank(CheatTarget::One(escrow.contract_address));
}

#[test]
fn test_pause_unpause() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), OWNER());
assert(escrow.pause_state() == false, 'Should start unpaused');
assert(pausable.is_paused() == false, 'Should start unpaused');
escrow.pause();
assert(escrow.pause_state() == true, 'Should be paused');
assert(pausable.is_paused() == true, 'Should be paused');
escrow.unpause();
assert(escrow.pause_state() == false, 'Should be unpaused');
assert(pausable.is_paused() == false, 'Should be unpaused');
stop_prank(CheatTarget::One(escrow.contract_address));
}

#[test]
#[should_panic(expected: ('Caller is not the owner',))]
fn test_fail_pause_not_owner() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), USER());
assert(escrow.pause_state() == false, 'Should start unpaused');
assert(pausable.is_paused() == false, 'Should start unpaused');
escrow.pause();
stop_prank(CheatTarget::One(escrow.contract_address));
}
Expand All @@ -134,10 +146,12 @@ mod Escrow {
#[should_panic(expected: ('Caller is not the owner',))]
fn test_fail_unpause_not_owner() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), OWNER());
assert(escrow.pause_state() == false, 'Should start unpaused');
assert(pausable.is_paused() == false, 'Should start unpaused');
escrow.pause();
assert(escrow.pause_state() == true, 'Should be paused');
assert(pausable.is_paused() == true, 'Should be paused');
stop_prank(CheatTarget::One(escrow.contract_address));

start_prank(CheatTarget::One(escrow.contract_address), USER());
Expand All @@ -149,10 +163,12 @@ mod Escrow {
#[should_panic(expected: ('Pausable: paused',))]
fn test_fail_pause_while_paused() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), OWNER());
assert(escrow.pause_state() == false, 'Should start unpaused');
assert(pausable.is_paused() == false, 'Should start unpaused');
escrow.pause();
assert(escrow.pause_state() == true, 'Should be paused');
assert(pausable.is_paused() == true, 'Should be paused');
escrow.pause();
stop_prank(CheatTarget::One(escrow.contract_address));
}
Expand All @@ -161,10 +177,12 @@ mod Escrow {
#[should_panic(expected: ('Pausable: not paused',))]
fn test_fail_unpause_while_unpaused() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), OWNER());
assert(escrow.pause_state() == false, 'Should start unpaused');
assert(pausable.is_paused() == false, 'Should start unpaused');
escrow.unpause();
assert(escrow.pause_state() == false, 'Should be unpaused');
assert(pausable.is_paused() == false, 'Should be unpaused');
escrow.unpause();
stop_prank(CheatTarget::One(escrow.contract_address));
}
Expand All @@ -173,6 +191,8 @@ mod Escrow {
#[should_panic(expected: ('Pausable: paused',))]
fn test_fail_set_order_when_paused() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), OWNER());
escrow.pause();
stop_prank(CheatTarget::One(escrow.contract_address));
Expand All @@ -186,6 +206,8 @@ mod Escrow {
#[test]
fn test_set_order_when_unpaused_after_prev_pause() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };


start_prank(CheatTarget::One(escrow.contract_address), USER());
let order = Order { recipient_address: 12345.try_into().unwrap(), amount: 500, fee: 0 };
Expand All @@ -206,6 +228,7 @@ mod Escrow {
#[test]
fn test_upgrade_when_paused() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };
let upgradeable = IUpgradeableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), OWNER());
Expand All @@ -221,6 +244,8 @@ mod Escrow {
#[test]
fn test_fail_call_l1_handler_while_paused() {
let (escrow, _) = setup();
let pausable = IPausableDispatcher { contract_address: escrow.contract_address };

start_prank(CheatTarget::One(escrow.contract_address), OWNER());
escrow.pause();
stop_prank(CheatTarget::One(escrow.contract_address));
Expand Down
Loading