Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
CI PR checks
  • Loading branch information
shunsukew committed Feb 15, 2023
commit dc64816ad1b4a6eb2753c872d4fcae9c679f741c
34 changes: 34 additions & 0 deletions .github/workflows/pr-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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

- name: Check targets are installed correctly
run: rustup target list --installed

- name: Install cargo contract
run: |
rustup component add rust-src
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`)
for path in $manifest_paths; do
cargo contract check --manifest-path $path
done

- name: test
run: cargo contract test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From use-ink/cargo-contract#958, cargo contract test is removed. Better use cargo test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HyunggyuJang This will have to be updated when this repo go to cargo contract 2.0 & ink! 4.0
But right now in cargo contract v2.0.0-rc.1 this is not removed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks for the clarification!

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