Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: v1.0.3 #591

Merged
merged 7 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 30 additions & 0 deletions __tests__/api/health.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import MockAdapter from 'axios-mock-adapter';
import axios from 'axios';
import healthApi from '../../src/api/health';

describe('healthApi', () => {
let mock;

beforeEach(() => {
mock = new MockAdapter(axios);
});

afterEach(() => {
mock.restore();
});

it('getHealth should return health data', async () => {
const data = { status: 'pass' };
mock.onGet('version').reply(200, data);

const result = await healthApi.getHealth();

expect(result).toEqual(data);
});

it('getHealth should allow capturing errors in case of network error', async () => {
mock.onGet('version').networkError();

await expect(healthApi.getHealth()).rejects.toThrow();
});
});
147 changes: 147 additions & 0 deletions __tests__/api/txMining.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import MockAdapter from 'axios-mock-adapter';
import axios from 'axios';
import txMiningApi from '../../src/api/txMining';

describe('txMiningApi', () => {
let mock;

beforeEach(() => {
mock = new MockAdapter(axios);
});

afterEach(() => {
mock.restore();
});

describe('getJobStatus', () => {
it('should send the right request', async () => {
const data = { status: 'done' };
mock.onGet('job-status').reply(200, data);

const result = await new Promise((resolve, reject) => {
txMiningApi.getJobStatus('jobId', resolve);
});

expect(result).toEqual(data);

expect(mock.history.get.length).toBe(1);
expect(mock.history.get[0].params).toEqual({ "job-id": 'jobId' });
});

it('should allow capturing errors in case of network error', async () => {
mock.onGet('job-status').networkError();

await expect(txMiningApi.getJobStatus('jobId', () => {})).rejects.toThrow();
});

it('should allow capturing errors in case the server responds with 500', async () => {
mock.onGet('job-status').reply(500);

try {
await txMiningApi.getJobStatus('jobId', () => {});
} catch (e) {
expect(e.message).toEqual('Request failed with status code 500');
expect(e.response.status).toEqual(500);
}
});
});

describe('cancelJob', () => {
it('should send the right request', async () => {
const data = { status: 'cancelled' };
mock.onPost('cancel-job').reply(200, data);

const result = await new Promise((resolve, reject) => {
txMiningApi.cancelJob('jobId', resolve);
});

expect(result).toEqual(data);

expect(mock.history.post.length).toBe(1);
expect(mock.history.post[0].data).toEqual(JSON.stringify({ "job-id": 'jobId' }));
});

it('should allow capturing errors in case of network error', async () => {
mock.onPost('cancel-job').networkError();

await expect(txMiningApi.cancelJob('jobId', () => {})).rejects.toThrow();
});

it('should allow capturing errors in case the server responds with 500', async () => {
mock.onPost('cancel-job').reply(500);

try {
await txMiningApi.cancelJob('jobId', () => {});
} catch (e) {
expect(e.message).toEqual('Request failed with status code 500');
expect(e.response.status).toEqual(500);
}
});
});

describe('getHealth', () => {
it('should send the right request', async () => {
const data = { status: 'pass' };
mock.onGet('health').reply(200, data);

const result = await txMiningApi.getHealth();

expect(result).toEqual(data);
});

it('should allow capturing errors in case of network error', async () => {
mock.onGet('health').networkError();

await expect(txMiningApi.getHealth()).rejects.toThrow();
});

it('should allow capturing errors in case the server responds with 500', async () => {
mock.onGet('health').reply(500);

try {
await txMiningApi.getHealth();
} catch (e) {
expect(e.message).toEqual('Request failed with status code 500');
expect(e.response.status).toEqual(500);
}
});
});

describe('submitJob', () => {
it('should send the right request', async () => {
const data = { job: 'jobId' };
mock.onPost('submit-job').reply(200, data);

const result = await new Promise((resolve, reject) => {
txMiningApi.submitJob('tx', true, true, 10, resolve);
});

expect(result).toEqual(data);

expect(mock.history.post.length).toBe(1);
expect(mock.history.post[0].data).toBe(JSON.stringify({
'tx': 'tx',
'propagate': true,
'add_parents': true,
'timeout': 10
}));
});

it('should allow capturing errors in case of network error', async () => {
mock.onPost('submit-job').networkError();

await expect(txMiningApi.submitJob('tx', true, true, 10, () => {})).rejects.toThrow();
});

it('should allow capturing errors in case the server responds with 500', async () => {
mock.onPost('submit-job').reply(500);

try {
await txMiningApi.submitJob('tx', true, true, 10, () => {});
} catch (e) {
expect(e.message).toEqual('Request failed with status code 500');
expect(e.response.status).toEqual(500);
}
});
});
});
73 changes: 73 additions & 0 deletions __tests__/api/version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import MockAdapter from 'axios-mock-adapter';
import axios from 'axios';
import versionApi from '../../src/api/version';

describe('versionApi', () => {
let mock;

beforeEach(() => {
mock = new MockAdapter(axios);
});

afterEach(() => {
mock.restore();
});

describe('getVersion', () => {
it('should return version data', async () => {
const data = { version: '1.0.0' };
mock.onGet('/version').reply(200, data);

const result = await new Promise((resolve, reject) => {
versionApi.getVersion(resolve);
});

expect(result).toEqual(data);
});

it('should allow capturing errors in case of network error', async () => {
mock.onGet('/version').networkError();

await expect(versionApi.getVersion(() => {})).rejects.toThrow();
});

it('should allow capturing errors in case the server responds with 500', async () => {
mock.onGet('/version').reply(500);

try {
await versionApi.getVersion(() => {});
} catch (e) {
expect(e.message).toEqual('Request failed with status code 500');
expect(e.response.status).toEqual(500);
}
});
});

describe('asyncGetVersion', () => {
it('should return version data', async () => {
const data = { version: '1.0.0' };
mock.onGet('/version').reply(200, data);

const result = await versionApi.asyncGetVersion();

expect(result).toEqual(data);
});

it('should allow capturing errors in case of network error', async () => {
mock.onGet('/version').networkError();

await expect(versionApi.asyncGetVersion()).rejects.toThrow();
});

it('should allow capturing errors in case the server responds with 500', async () => {
mock.onGet('/version').reply(500);

try {
await versionApi.asyncGetVersion();
} catch (e) {
expect(e.message).toEqual('Request failed with status code 500');
expect(e.response.status).toEqual(500);
}
});
});
});
6 changes: 3 additions & 3 deletions __tests__/integration/atomic_swap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('partial tx proposal', () => {
const hWallet2 = await generateWalletHelper();

// Injecting funds and creating a new custom token
const txI = await GenesisWalletHelper.injectFunds(await hWallet1.getAddressAtIndex(0), 103);
const txI = await GenesisWalletHelper.injectFunds(hWallet1, await hWallet1.getAddressAtIndex(0), 103);
const { hash: token1Uid } = await createTokenHelper(
hWallet1,
'Token1',
Expand All @@ -33,7 +33,7 @@ describe('partial tx proposal', () => {
);

// Injecting funds and creating a new custom token
await GenesisWalletHelper.injectFunds(await hWallet2.getAddressAtIndex(0), 10);
await GenesisWalletHelper.injectFunds(hWallet2, await hWallet2.getAddressAtIndex(0), 10);
const { hash: token2Uid } = await createTokenHelper(
hWallet2,
'Token2',
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('partial tx proposal', () => {
expect(tx.hash).toBeDefined();

await waitForTxReceived(hWallet1, tx.hash);
await delay(1000); // This transaction seems to take longer than usual to complete
await waitForTxReceived(hWallet2, tx.hash);

// Get the balance states before the exchange
const w1HTRAfter = await hWallet1.getBalance(HATHOR_TOKEN_CONFIG.uid);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/configuration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
"--memory-storage",
]
environment:
HATHOR_CONFIG_FILE: privnet.conf.privnet
HATHOR_CONFIG_YAML: privnet/conf/privnet.yml
ports:
- "8083:8080"
- "40404:40404"
Expand Down
31 changes: 0 additions & 31 deletions __tests__/integration/configuration/privnet.py

This file was deleted.

32 changes: 32 additions & 0 deletions __tests__/integration/configuration/privnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file is the Private Network Configuration for the Fullnode
# It is consumed by the docker-compose.yml file on the integration folder.
# For more information, refer to:
# https://github.com/HathorNetwork/rfcs/blob/master/text/0033-private-network-guide.md

# This genesis adds the funds to the following wallet seed:
# avocado spot town typical traffic vault danger century property shallow divorce festival spend attack anchor afford rotate green audit adjust fade wagon depart level

P2PKH_VERSION_BYTE: x49
MULTISIG_VERSION_BYTE: x87
NETWORK_NAME: privatenet
BOOTSTRAP_DNS: []
ENABLE_PEER_WHITELIST: false

# Genesis stuff
GENESIS_OUTPUT_SCRIPT: 76a91466665b27f7dbc4c8c089d2f686c170c74d66f0b588ac
GENESIS_BLOCK_TIMESTAMP: 1643902665
GENESIS_BLOCK_NONCE: 4784939
GENESIS_BLOCK_HASH: 00000334a21fbb58b4db8d7ff282d018e03e2977abd3004cf378fb1d677c3967
GENESIS_TX1_NONCE: 0
GENESIS_TX1_HASH: 54165cef1fd4cf2240d702b8383c307c822c16ca407f78014bdefa189a7571c2
GENESIS_TX2_NONCE: 0
GENESIS_TX2_HASH: 039906854ce6309b3180945f2a23deb9edff369753f7082e19053f5ac11bfbae

MIN_TX_WEIGHT_K: 0
MIN_TX_WEIGHT_COEFFICIENT: 0
MIN_TX_WEIGHT: 1
REWARD_SPEND_MIN_BLOCKS: 1

CHECKPOINTS: []

extends: mainnet.yml
Loading
Loading