Skip to content

Commit

Permalink
[Hotfix] Fix tests and adding workflow to run test on CI (#94) (#95)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
henrypalacios authored May 8, 2023
1 parent 9059d96 commit 048b128
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 9 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkadot-contract-wizard",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
2 changes: 2 additions & 0 deletions src/data/contracts_rs/psp22_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,6 +73,7 @@ pub mod my_psp22 {
#[ink(constructor)]
pub fn new(initial_supply: Balance, name: Option<String>, symbol: Option<String>, 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");
Expand Down
14 changes: 7 additions & 7 deletions tests/coreApp.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const ASTAR_RPC = 'wss://rpc.astar.network'
describe('Environments variables', () => {
const ALL_ENV = process.env

beforeEach(() => {
jest.resetModules()
process.env = {
...ALL_ENV, // Make a copy
NODE_ENV: 'development'
NODE_ENV: 'development',
NEXT_PUBLIC_PROVIDER_DEFAULT_SOCKET: ASTAR_RPC
}
})

Expand All @@ -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)
})
})

1 comment on commit 048b128

@vercel
Copy link

@vercel vercel bot commented on 048b128 May 8, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.