Skip to content

Commit

Permalink
lint: comply with rules
Browse files Browse the repository at this point in the history
  • Loading branch information
alexruzenhack committed Feb 8, 2024
1 parent b98b90a commit ffadd25
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
51 changes: 23 additions & 28 deletions __tests__/sagas/nanoContracts/registerNanoContract.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { put } from 'redux-saga/effects';
import { ncApi } from '@hathor/wallet-lib';
import { jest, test, expect, beforeEach, describe } from '@jest/globals';
import { getNanoContractState, registerNanoContract, formatNanoContractRegistryEntry, failureMessage } from '../../../src/sagas/nanoContract';
import { nanoContractRegisterFailure, nanoContractRegisterRequest, types } from '../../../src/actions';
import { STORE } from '../../../src/store';
Expand All @@ -17,12 +18,12 @@ const fixtures = {
nc_id: '3cb032600bdf7db784800e4ea911b10676fa2f67591f82bb62628c234e771595',
blueprint_name: 'Bet',
fields: {
token_uid: {'value': '00'},
total: {'value': 300},
final_result: {'value': '1x0'},
oracle_script: {'value': '76a91441c431ff7ad5d6ce5565991e3dcd5d9106cfd1e288ac'},
'withdrawals.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': {'value': 300},
'address_details.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': {'value': {'1x0': 100}},
token_uid: { value: '00' },
total: { value: 300 },
final_result: { value: '1x0' },
oracle_script: { value: '76a91441c431ff7ad5d6ce5565991e3dcd5d9106cfd1e288ac' },
'withdrawals.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': { value: 300 },
'address_details.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': { value: { '1x0': 100 } },
}
}
}
Expand All @@ -38,12 +39,12 @@ const fixtures = {
nc_id: '3cb032600bdf7db784800e4ea911b10676fa2f67591f82bb62628c234e771595',
blueprint_name: 'Bet',
fields: {
token_uid: {'value': '00'},
total: {'value': 300},
final_result: {'value': '1x0'},
oracle_script: {'value': '76a91441c431ff7ad5d6ce5565991e3dcd5d9106cfd1e288ac'},
'withdrawals.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': {'value': 300},
'address_details.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': {'value': {'1x0': 100}},
token_uid: { value: '00' },
total: { value: 300 },
final_result: { value: '1x0' },
oracle_script: { value: '76a91441c431ff7ad5d6ce5565991e3dcd5d9106cfd1e288ac' },
'withdrawals.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': { value: 300 },
'address_details.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': { value: { '1x0': 100 } },
}
},
}
Expand All @@ -67,20 +68,14 @@ const fixtures = {
beforeEach(() => {
jest.clearAllMocks();
STORE.clearItems();

// need a mocked ncApi
// need ncApi.getNanoContractState
// need a mocked wallet
// need wallet.isReady true
// need wallet.isAddressMine true
// need a state.wallet
});

describe('sagas/nanoContract/getNanoContractState', () => {
test('success', async () => {
// arrange ncApi mock
const mockedNcApi = jest.mocked(ncApi);
mockedNcApi.getNanoContractState.mockReturnValue(fixtures.ncApi.getNanoContractState.successResponse);
mockedNcApi.getNanoContractState
.mockReturnValue(fixtures.ncApi.getNanoContractState.successResponse);

// call getNanoContractState
const result = await getNanoContractState(fixtures.ncId);
Expand Down Expand Up @@ -109,24 +104,25 @@ describe('sagas/nanoContract/getNanoContractState', () => {
describe('sagas/nanoContract/registerNanoContract', () => {
test('contract already registered', async () => {
// arrange Nano Contract registration inputs
const { address, ncId } = fixtures;
const { address, ncId } = fixtures;

// add an entry to registeredContracts
const ncEntry = formatNanoContractRegistryEntry(address, ncId);
STORE.setItem(nanoContractKey.registeredContracts, {[ncEntry]: {}});
STORE.setItem(nanoContractKey.registeredContracts, { [ncEntry]: {} });

// call effect to register nano contract
const gen = registerNanoContract(nanoContractRegisterRequest({ address, ncId }));

// assert failure
expect(gen.next().value).toStrictEqual(put(nanoContractRegisterFailure(failureMessage.alreadyRegistered)))
expect(gen.next().value)
.toStrictEqual(put(nanoContractRegisterFailure(failureMessage.alreadyRegistered)))
// assert termination
expect(gen.next().value).toBeUndefined();
});

test('wallet not ready', async () => {
// arrange Nano Contract registration inputs
const { address, ncId } = fixtures;
const { address, ncId } = fixtures;

// call effect to register nano contract
const gen = registerNanoContract(nanoContractRegisterRequest({ address, ncId }));
Expand All @@ -143,7 +139,7 @@ describe('sagas/nanoContract/registerNanoContract', () => {

test('address not mine', async () => {
// arrange Nano Contract registration inputs
const { address, ncId } = fixtures;
const { address, ncId } = fixtures;

// call effect to register nano contract
const gen = registerNanoContract(nanoContractRegisterRequest({ address, ncId }));
Expand All @@ -162,7 +158,7 @@ describe('sagas/nanoContract/registerNanoContract', () => {

test('getNanoContractState error', async () => {
// arrange Nano Contract registration inputs
const { address, ncId } = fixtures;
const { address, ncId } = fixtures;

// call effect to register nano contract
const gen = registerNanoContract(nanoContractRegisterRequest({ address, ncId }));
Expand All @@ -183,7 +179,7 @@ describe('sagas/nanoContract/registerNanoContract', () => {

test('register with success', async () => {
// arrange Nano Contract registration inputs
const { address, ncId } = fixtures;
const { address, ncId } = fixtures;

// call effect to register nano contract
const gen = registerNanoContract(nanoContractRegisterRequest({ address, ncId }));
Expand Down Expand Up @@ -213,4 +209,3 @@ describe('sagas/nanoContract/registerNanoContract', () => {
expect(actionResult.payload.action.payload.entryKey).toBeDefined();
});
});

1 change: 0 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,4 +1014,3 @@ export const nanoContractRegisterSuccess = (ncEntry) => ({
type: types.NANOCONTRACT_REGISTER_SUCCESS,
payload: ncEntry,
});

3 changes: 1 addition & 2 deletions src/reducers/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const initialState = {
* }} registered Nano Contracts per wallet address with basic information.
* @example
* {
* 'HTeZeYTCv7cZ8u7pBGHkWsPwhZAuoq5j3V.00c30fc8a1b9a326a766ab0351faf3635297d316fd039a0eda01734d9de40185': {
* 'HTeZeYT.00c30fc': {
* address: 'HTeZeYTCv7cZ8u7pBGHkWsPwhZAuoq5j3V',
* ncId: '00c30fc8a1b9a326a766ab0351faf3635297d316fd039a0eda01734d9de40185',
* blueprintId: 0025dadebe337a79006f181c05e4799ce98639aedfbd26335806790bdea4b1d4,
Expand Down Expand Up @@ -1238,4 +1238,3 @@ export const onNanoContractRegisterSuccess = (state, { payload }) => ({
}
},
});

13 changes: 6 additions & 7 deletions src/sagas/nanoContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ export function formatNanoContractRegistryEntry(address, ncId) {
export async function getNanoContractState(ncId) {
try {
const state = await ncApi.getNanoContractState(ncId);
return { ncState: {...state} };
}
catch (err) {
return { error: err };
return { ncState: { ...state } };
} catch (err) {
return { error: err };
}
}

Expand Down Expand Up @@ -91,11 +90,11 @@ export function* registerNanoContract({ payload }) {
yield put(nanoContractRegisterFailure(failureMessage.nanoContractStateFailure));
return;
}

// persist the pair address-nanocontract
const ncEntryValue = {
address: address,
ncId: ncId,
address,
ncId,
blueprintId: ncState.blueprint_id,
blueprintName: ncState.blueprint_name
};
Expand Down

0 comments on commit ffadd25

Please sign in to comment.