From 048b128d83e30b21d9f1db0e5fa1ffc76b311edd Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Mon, 8 May 2023 12:11:14 -0300 Subject: [PATCH] [Hotfix] Fix tests and adding workflow to run test on CI (#94) (#95) * Fix typo on environment variable and update contract fixed on #91 (#94) * Fix typo on environment variable and update contract fixed on #91 * Adding workflow job to CI * Adding environment variable * Using config on jest * Bump version to 0.1.1 --- .github/workflows/test.yml | 61 +++++++++++++++++++++++++++++ package.json | 2 +- src/constants/config.ts | 2 +- src/data/contracts_rs/psp22_full.rs | 2 + tests/coreApp.test.ts | 14 +++---- 5 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..984dca04 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,61 @@ +name: Test +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + unit-tests: + env: + POLKADOT_CONNECTION_TESTS: false + name: Run tests + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.5.0 + with: + access_token: ${{ github.token }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + registry-url: https://registry.npmjs.org + + - name: Restore yarn cache if available + uses: actions/cache@v3 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: | + node_modules + */*/node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + + - name: Install dependencies + if: steps.yarn-cache.outputs.cache-hit != 'true' + run: | + yarn install --frozen-lockfile + + - name: Run linting check + run: | + yarn lint + env: + CI: true + + - name: Run type check + run: | + yarn ts:check + env: + CI: true + + - name: Run Unit Tests + run: | + yarn jest --config=jest.config.js + env: + CI: true + diff --git a/package.json b/package.json index c85a6ae9..e7a2b77a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "polkadot-contract-wizard", - "version": "0.1.0", + "version": "0.1.1", "private": true, "scripts": { "dev": "next dev", diff --git a/src/constants/config.ts b/src/constants/config.ts index e474c26a..d17c32ec 100644 --- a/src/constants/config.ts +++ b/src/constants/config.ts @@ -9,7 +9,7 @@ export interface DappConfig { export const DAPP_CONFIG: DappConfig = { name: 'Polkadot contract wizard', providerSocket: - process.env.NEXT_PUBLIC_PROVIDER_DEFAUL_SOCKET || + process.env.NEXT_PUBLIC_PROVIDER_DEFAULT_SOCKET || 'wss://rococo-contracts-rpc.polkadot.io' } diff --git a/src/data/contracts_rs/psp22_full.rs b/src/data/contracts_rs/psp22_full.rs index 4800f57c..6f22dd67 100644 --- a/src/data/contracts_rs/psp22_full.rs +++ b/src/data/contracts_rs/psp22_full.rs @@ -6,6 +6,7 @@ pub mod my_psp22 { // imports from openbrush use openbrush::contracts::psp22::Transfer; use openbrush::contracts::psp22::*; + use openbrush::contracts::psp22; use openbrush::traits::String; use openbrush::traits::Storage; use openbrush::contracts::access_control::only_role; @@ -72,6 +73,7 @@ pub mod my_psp22 { #[ink(constructor)] pub fn new(initial_supply: Balance, name: Option, symbol: Option, decimal: u8) -> Self { let mut _instance = Self::default(); + _instance._init_cap(initial_supply).expect("Should init cap"); _instance._mint_to(_instance.env().caller(), initial_supply).expect("Should mint"); _instance._init_with_admin(_instance.env().caller()); _instance.grant_role(MANAGER, _instance.env().caller()).expect("Should grant MANAGER role"); diff --git a/tests/coreApp.test.ts b/tests/coreApp.test.ts index 9fc65741..1e414d02 100644 --- a/tests/coreApp.test.ts +++ b/tests/coreApp.test.ts @@ -1,3 +1,4 @@ +const ASTAR_RPC = 'wss://rpc.astar.network' describe('Environments variables', () => { const ALL_ENV = process.env @@ -5,7 +6,8 @@ describe('Environments variables', () => { jest.resetModules() process.env = { ...ALL_ENV, // Make a copy - NODE_ENV: 'development' + NODE_ENV: 'development', + NEXT_PUBLIC_PROVIDER_DEFAULT_SOCKET: ASTAR_RPC } }) @@ -15,11 +17,9 @@ describe('Environments variables', () => { test('That environment variables exist', () => { expect(process.env.NODE_ENV).toBe('development') - expect(process.env.NEXT_PUBLIC_PROVIDER_SOCKET_PROD).toBe( - 'wss://rococo-contracts-rpc.polkadot.io' - ) - expect(process.env.NEXT_PUBLIC_PROVIDER_SOCKET_DEV).toBe( - 'wss://rococo-contracts-rpc.polkadot.io' - ) + }) + + test('That rpc variables is setted', () => { + expect(process.env.NEXT_PUBLIC_PROVIDER_DEFAULT_SOCKET).toBe(ASTAR_RPC) }) })