Skip to content

Commit

Permalink
Merge pull request #13 from swanky-dapps/ci/pr-checks
Browse files Browse the repository at this point in the history
CI - PR checks
  • Loading branch information
shunsukew authored Feb 20, 2023
2 parents 999a278 + a760e9b commit 208b0a2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 25 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/pr-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: PR checks
on:
push:
workflow_dispatch:
jobs:
checks-and-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout the source code
uses: actions/checkout@v3

- name: Install & display rust toolchain
run: |
rustup show
rustup component add rust-src
- name: Check targets are installed correctly
run: rustup target list --installed

- name: Cache Crates
uses: actions/cache@v3
with:
path: ~/.cargo
key: ${{ runner.os }}-rust-${{ hashFiles('rust-toolchain.toml') }}
restore-keys: |
${{ runner.os }}-rust
- name: Check if cargo-contract exists
id: check-cargo-contract
continue-on-error: true
run: cargo contract --version

- name: Install cargo contract
if: ${{ steps.check-cargo-contract.outcome == 'failure' }}
run: |
sudo apt-get install binaryen
cargo install cargo-dylint dylint-link
# Until 2.0.0 official release, we need to specify --version expressly
cargo install --force --locked cargo-contract --version 2.0.0-rc
- name: Compile checks
run: |
manifest_paths=`find uniswap-v2/contracts -type f -name Cargo.toml`
echo $manifest_paths
for manifest_path in $manifest_paths; do
echo $manifest_path
cargo contract check --manifest-path $manifest_path
done
- name: test
run: cargo contract test
10 changes: 4 additions & 6 deletions uniswap-v2/contracts/factory/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,15 @@ pub mod factory {
}
#[cfg(test)]
mod tests {
use ink_env::{
test::default_accounts,
Hash,
};
use ink::env::test::default_accounts;
use ink::primitives::Hash;
use openbrush::traits::AccountIdExt;

use super::*;

#[ink_lang::test]
#[ink::test]
fn initialize_works() {
let accounts = default_accounts::<ink_env::DefaultEnvironment>();
let accounts = default_accounts::<ink::env::DefaultEnvironment>();
let factory = FactoryContract::new(accounts.alice, Hash::default());
assert!(factory.factory.fee_to.is_zero());
}
Expand Down
4 changes: 1 addition & 3 deletions uniswap-v2/contracts/pair/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,9 @@ pub mod pair {
}
#[cfg(test)]
mod tests {
use ink_env::AccountId;

use super::*;

#[ink_lang::test]
#[ink::test]
fn initialize_works() {
let mut pair = PairContract::new();
let token_0 = AccountId::from([0x03; 32]);
Expand Down
4 changes: 1 addition & 3 deletions uniswap-v2/contracts/router/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ pub mod router {
mod tests {
use super::*;

use ink_env::AccountId;

#[ink_lang::test]
#[ink::test]
fn initialize_works() {
let factory = AccountId::from([0x03; 32]);
let wnative = AccountId::from([0x04; 32]);
Expand Down
22 changes: 11 additions & 11 deletions uniswap-v2/contracts/wnative/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub mod wnative {
mod tests {
use super::*;

#[ink_lang::test]
#[ink::test]
fn register_works() {
let wnative_contract = WnativeContract::new();
assert_eq!(
Expand All @@ -100,7 +100,7 @@ pub mod wnative {
);
}

#[ink_lang::test]
#[ink::test]
fn test_deposit() {
let accounts = default_accounts();
let mut wnative_contract = create_contract(0);
Expand All @@ -111,7 +111,7 @@ pub mod wnative {
assert_eq!(native_balance, 1000, "native balance not correct!");
}

#[ink_lang::test]
#[ink::test]
fn test_withdraw() {
let accounts = default_accounts();
let mut wnative_contract = create_contract(1000);
Expand All @@ -135,16 +135,16 @@ pub mod wnative {
assert_eq!(wnative_balance, 200, "balance not correct!");
}

fn default_accounts() -> ink_env::test::DefaultAccounts<ink_env::DefaultEnvironment> {
ink_env::test::default_accounts()
fn default_accounts() -> ink::env::test::DefaultAccounts<ink::env::DefaultEnvironment> {
ink::env::test::default_accounts()
}

fn set_next_caller(caller: AccountId) {
ink_env::test::set_caller::<Environment>(caller);
ink::env::test::set_caller::<Environment>(caller);
}

fn set_balance(account_id: AccountId, balance: Balance) {
ink_env::test::set_account_balance::<ink_env::DefaultEnvironment>(account_id, balance)
ink::env::test::set_account_balance::<ink::env::DefaultEnvironment>(account_id, balance)
}

/// Creates a new instance of `WnativeContract` with `initial_balance`.
Expand All @@ -158,16 +158,16 @@ pub mod wnative {
}

fn contract_id() -> AccountId {
ink_env::test::callee::<ink_env::DefaultEnvironment>()
ink::env::test::callee::<ink::env::DefaultEnvironment>()
}

fn get_balance(account_id: AccountId) -> Balance {
ink_env::test::get_account_balance::<ink_env::DefaultEnvironment>(account_id)
ink::env::test::get_account_balance::<ink::env::DefaultEnvironment>(account_id)
.expect("Cannot get account balance")
}

fn deposit(contract: &mut WnativeContract, amount: Balance) -> Result<(), PSP22Error> {
let sender = ink_env::caller::<ink_env::DefaultEnvironment>();
let sender = ink::env::caller::<ink::env::DefaultEnvironment>();
let contract_id = contract.env().account_id();
let sender_balance = get_balance(sender);
let contract_balance = get_balance(contract_id);
Expand All @@ -182,7 +182,7 @@ pub mod wnative {
},
);
set_balance(contract_id, contract_balance + amount);
ink_env::test::set_value_transferred::<ink_env::DefaultEnvironment>(amount);
ink::env::test::set_value_transferred::<ink::env::DefaultEnvironment>(amount);
contract.deposit()
}
}
Expand Down
4 changes: 2 additions & 2 deletions uniswap-v2/logics/impls/pair/pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,14 @@ mod tests {

use super::update_cumulative;

#[test]
#[ink::test]
fn update_cumulative_from_zero_time_elapsed() {
let (cumulative0, cumulative1) = update_cumulative(0.into(), 0.into(), 0.into(), 10, 10);
assert_eq!(cumulative0, 0.into());
assert_eq!(cumulative1, 0.into());
}

#[test]
#[ink::test]
fn update_cumulative_from_one_time_elapsed() {
let (cumulative0, cumulative1) = update_cumulative(0.into(), 0.into(), 1.into(), 10, 10);
assert_eq!(
Expand Down

0 comments on commit 208b0a2

Please sign in to comment.