diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml new file mode 100644 index 0000000..72994bf --- /dev/null +++ b/.github/workflows/pr-checks.yaml @@ -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 diff --git a/uniswap-v2/contracts/factory/lib.rs b/uniswap-v2/contracts/factory/lib.rs index 91b82c1..5ca62f3 100644 --- a/uniswap-v2/contracts/factory/lib.rs +++ b/uniswap-v2/contracts/factory/lib.rs @@ -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::(); + let accounts = default_accounts::(); let factory = FactoryContract::new(accounts.alice, Hash::default()); assert!(factory.factory.fee_to.is_zero()); } diff --git a/uniswap-v2/contracts/pair/lib.rs b/uniswap-v2/contracts/pair/lib.rs index e6ff047..cc882ca 100644 --- a/uniswap-v2/contracts/pair/lib.rs +++ b/uniswap-v2/contracts/pair/lib.rs @@ -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]); diff --git a/uniswap-v2/contracts/router/lib.rs b/uniswap-v2/contracts/router/lib.rs index 209e075..3ec9b09 100755 --- a/uniswap-v2/contracts/router/lib.rs +++ b/uniswap-v2/contracts/router/lib.rs @@ -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]); diff --git a/uniswap-v2/contracts/wnative/lib.rs b/uniswap-v2/contracts/wnative/lib.rs index 60d7e24..8e5640e 100644 --- a/uniswap-v2/contracts/wnative/lib.rs +++ b/uniswap-v2/contracts/wnative/lib.rs @@ -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!( @@ -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); @@ -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); @@ -135,16 +135,16 @@ pub mod wnative { assert_eq!(wnative_balance, 200, "balance not correct!"); } - fn default_accounts() -> ink_env::test::DefaultAccounts { - ink_env::test::default_accounts() + fn default_accounts() -> ink::env::test::DefaultAccounts { + ink::env::test::default_accounts() } fn set_next_caller(caller: AccountId) { - ink_env::test::set_caller::(caller); + ink::env::test::set_caller::(caller); } fn set_balance(account_id: AccountId, balance: Balance) { - ink_env::test::set_account_balance::(account_id, balance) + ink::env::test::set_account_balance::(account_id, balance) } /// Creates a new instance of `WnativeContract` with `initial_balance`. @@ -158,16 +158,16 @@ pub mod wnative { } fn contract_id() -> AccountId { - ink_env::test::callee::() + ink::env::test::callee::() } fn get_balance(account_id: AccountId) -> Balance { - ink_env::test::get_account_balance::(account_id) + ink::env::test::get_account_balance::(account_id) .expect("Cannot get account balance") } fn deposit(contract: &mut WnativeContract, amount: Balance) -> Result<(), PSP22Error> { - let sender = ink_env::caller::(); + let sender = ink::env::caller::(); let contract_id = contract.env().account_id(); let sender_balance = get_balance(sender); let contract_balance = get_balance(contract_id); @@ -182,7 +182,7 @@ pub mod wnative { }, ); set_balance(contract_id, contract_balance + amount); - ink_env::test::set_value_transferred::(amount); + ink::env::test::set_value_transferred::(amount); contract.deposit() } } diff --git a/uniswap-v2/logics/impls/pair/pair.rs b/uniswap-v2/logics/impls/pair/pair.rs index e3dd2c5..332fb45 100644 --- a/uniswap-v2/logics/impls/pair/pair.rs +++ b/uniswap-v2/logics/impls/pair/pair.rs @@ -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!(