Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Querying events endpoint with topic, senderAddress and transactionID does not work #1878

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
Binary file added framework/dist/lisk-service-framework-1.6.1.tgz
Binary file not shown.
4 changes: 2 additions & 2 deletions framework/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisk-service-framework",
"version": "1.6.0",
"version": "1.6.1",
"description": "Lisk Service Framework",
"keywords": [
"lisk",
Expand All @@ -25,7 +25,7 @@
"scripts": {
"release:github": "npm pack && mv lisk-service-framework-$npm_package_version.tgz ./dist/lisk-service-framework-$npm_package_version.tgz",
"test:unit": "./node_modules/.bin/jest --config=tests/unit.config.js --detectOpenHandles --forceExit",
"test:functional": "./node_modules/.bin/jest --config=tests/functional.config.js --detectOpenHandles --forceExit"
"test:functional": "./node_modules/.bin/jest --config=tests/functional.config.js --detectOpenHandles --runInBand --forceExit"
},
"bin": {
"moleculer_client": "./bin/moleculer_client.js"
Expand Down
6 changes: 5 additions & 1 deletion framework/src/database/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const resolveQueryParams = params => {
'sort', 'limit', 'offset', 'propBetweens', 'andWhere', 'orWhere', 'orWhereWith', 'whereNot',
'whereIn', 'whereNotIn', 'orWhereIn', 'whereBetween', 'whereJsonSupersetOf', 'search', 'aggregate',
'distinct', 'order', 'orSearch', 'whereNull', 'whereNotNull', 'leftOuterJoin', 'rightOuterJoin',
'innerJoin', 'groupBy', 'orderByRaw',
'innerJoin', 'groupBy', 'orderByRaw', 'havingRaw',
];
const queryParams = Object.keys(params)
.filter(key => !KNOWN_QUERY_PARAMS.includes(key))
Expand Down Expand Up @@ -199,6 +199,10 @@ const getTableInstance = (tableConfig, knex) => {
});
}

if (params.havingRaw) {
query.having(knex.raw(params.havingRaw));
}

if (params.aggregate) {
query.sum(`${params.aggregate} as total`);
}
Expand Down
105 changes: 97 additions & 8 deletions framework/tests/functional/database/mysql/mysql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ describe('Test MySQL', () => {
});

describe('With IMPLICIT DB transaction (auto-commit mode)', () => {
afterAll(() => blocksTable.rawQuery(`TRUNCATE ${tableName}`));
afterEach(async () => {
await blocksTable.rawQuery(`TRUNCATE ${tableName}`);
});

it('should insert row', async () => {
await blocksTable.upsert([emptyBlock]);
Expand All @@ -90,6 +92,7 @@ describe('Test MySQL', () => {
});

it('should get rows', async () => {
await blocksTable.upsert([emptyBlock]);
const result = await blocksTable.find({ id: emptyBlock.id }, ['id']);
expect(result).toBeInstanceOf(Array);
expect(result.length).toBe(1);
Expand Down Expand Up @@ -212,6 +215,7 @@ describe('Test MySQL', () => {
});

it('should get row count', async () => {
await blocksTable.upsert([emptyBlock, nonEmptyBlock]);
const count = await blocksTable.count();
expect(count).toBe(2);
});
Expand Down Expand Up @@ -312,6 +316,7 @@ describe('Test MySQL', () => {
});

it('should increment column value', async () => {
await blocksTable.upsert([emptyBlock]);
const [currentBlock] = await blocksTable.find({ id: emptyBlock.id }, ['timestamp']);
const currentTimestamp = currentBlock.timestamp;

Expand All @@ -326,6 +331,7 @@ describe('Test MySQL', () => {
});

it('should decrement column value', async () => {
await blocksTable.upsert([emptyBlock]);
const [currentBlock] = await blocksTable.find({ id: emptyBlock.id }, ['timestamp']);
const currentTimestamp = currentBlock.timestamp;

Expand All @@ -340,6 +346,7 @@ describe('Test MySQL', () => {
});

it('should delete row by primary key', async () => {
await blocksTable.upsert([emptyBlock, nonEmptyBlock]);
const [existingBlock] = await blocksTable.find();
const existingBlockId = existingBlock[`${blocksTableSchema.primaryKey}`];
const count = await blocksTable.deleteByPrimaryKey([existingBlockId]);
Expand Down Expand Up @@ -398,6 +405,7 @@ describe('Test MySQL', () => {
});

it('should execute update method', async () => {
await blocksTable.upsert([emptyBlock]);
const [retrievedBlock] = await blocksTable.find({ id: emptyBlock.id }, ['timestamp']);
expect(retrievedBlock.timestamp).toBe(emptyBlock.timestamp);

Expand Down Expand Up @@ -711,10 +719,38 @@ describe('Test MySQL', () => {
expect(result).toBeInstanceOf(Array);
expect(result.length).toBe(0);
});

it('should apply HAVING clause with havingRaw', async () => {
vardan10 marked this conversation as resolved.
Show resolved Hide resolved
await blocksTable.upsert([emptyBlock, nonEmptyBlock]);

const params = {
groupBy: 'height',
havingRaw: `height < ${Math.max(emptyBlock.height, nonEmptyBlock.height)}`,
};

const result = await blocksTable.find(params, ['id', 'height']);
expect(result).toBeInstanceOf(Array);
expect(result.length).toBe(1);
});

it('should apply complex HAVING clause with havingRaw', async () => {
await blocksTable.upsert([emptyBlock, nonEmptyBlock]);

const params = {
groupBy: 'height',
havingRaw: `SUM(height) < ${Math.max(emptyBlock.height, nonEmptyBlock.height)}`,
};

const result = await blocksTable.find(params, ['id', 'height']);
expect(result).toBeInstanceOf(Array);
expect(result.length).toBe(1);
});
});

describe('With EXPLICIT DB transaction (non-auto commit mode)', () => {
afterAll(() => blocksTable.rawQuery(`TRUNCATE ${tableName}`));
afterEach(async () => {
await blocksTable.rawQuery(`TRUNCATE ${tableName}`);
});

it('should insert row', async () => {
const connection = await getDBConnection();
Expand All @@ -727,6 +763,11 @@ describe('Test MySQL', () => {
});

it('should get rows', async () => {
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([emptyBlock], trx);
await commitDBTransaction(trx);

const result = await blocksTable.find({ id: emptyBlock.id }, ['id']);
expect(result).toBeInstanceOf(Array);
expect(result.length).toBe(1);
Expand Down Expand Up @@ -824,7 +865,7 @@ describe('Test MySQL', () => {
it('should sort the rows in ascending order based on their height', async () => {
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }], trx);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }, nonEmptyBlock], trx);
await commitDBTransaction(trx);

const result = await blocksTable.find({ sort: 'height:asc' });
Expand All @@ -836,7 +877,7 @@ describe('Test MySQL', () => {
it('should sort the rows in descending order based on their height', async () => {
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }], trx);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }, nonEmptyBlock], trx);
await commitDBTransaction(trx);

const result = await blocksTable.find({ sort: 'height:desc' });
Expand All @@ -848,7 +889,7 @@ describe('Test MySQL', () => {
it('should order the rows in ascending order based on their height', async () => {
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }], trx);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }, nonEmptyBlock], trx);
await commitDBTransaction(trx);

const result = await blocksTable.find({ order: 'height:asc' });
Expand All @@ -860,7 +901,7 @@ describe('Test MySQL', () => {
it('should order the rows in descending order based on their height', async () => {
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }], trx);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }, nonEmptyBlock], trx);
await commitDBTransaction(trx);

const result = await blocksTable.find({ order: 'height:desc' });
Expand All @@ -872,7 +913,7 @@ describe('Test MySQL', () => {
it('should order the rows in ascending order based on their height using orderByRaw query', async () => {
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }], trx);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }, nonEmptyBlock], trx);
await commitDBTransaction(trx);

const result = await blocksTable.find({ orderByRaw: ['height asc'] });
Expand All @@ -884,7 +925,7 @@ describe('Test MySQL', () => {
it('should order the rows in descending order based on their height', async () => {
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }], trx);
await blocksTable.upsert([{ ...emptyBlock, size: 50 }, nonEmptyBlock], trx);
await commitDBTransaction(trx);

const result = await blocksTable.find({ orderByRaw: ['height desc'] });
Expand All @@ -894,6 +935,11 @@ describe('Test MySQL', () => {
});

it('should get row count', async () => {
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([emptyBlock, nonEmptyBlock], trx);
await commitDBTransaction(trx);

const count = await blocksTable.count();
expect(count).toBe(2);
});
Expand Down Expand Up @@ -944,6 +990,7 @@ describe('Test MySQL', () => {
});

it('should increment column value', async () => {
await blocksTable.upsert([emptyBlock, nonEmptyBlock]);
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.increment({
Expand All @@ -957,6 +1004,7 @@ describe('Test MySQL', () => {
});

it('should decrement row by primary key', async () => {
await blocksTable.upsert([emptyBlock, nonEmptyBlock]);
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
const [existingBlock] = await blocksTable.find();
Expand Down Expand Up @@ -1065,6 +1113,7 @@ describe('Test MySQL', () => {
});

it('should perform update method', async () => {
await blocksTable.upsert([emptyBlock, nonEmptyBlock]);
const [retrievedBlock] = await blocksTable.find({ id: emptyBlock.id }, ['timestamp']);
expect(retrievedBlock.timestamp).toBe(emptyBlock.timestamp);

Expand Down Expand Up @@ -1319,9 +1368,49 @@ describe('Test MySQL', () => {
expect(firstRow.height).toBe(nonEmptyBlock.height);
expect(firstRow.id).toBe(tokenTransferTransaction.id);
});

it('should apply HAVING clause with havingRaw', async () => {
// Insert a test record.
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([emptyBlock, nonEmptyBlock], trx);
await transactionsTable.upsert([tokenTransferTransaction], trx);

const params = {
groupBy: 'height',
havingRaw: `height < ${Math.max(emptyBlock.height, nonEmptyBlock.height)}`,
};

const result = await blocksTable.find(params, ['id', 'height'], trx);
await commitDBTransaction(trx);
expect(result).toBeInstanceOf(Array);
expect(result.length).toBe(1);
});

it('should apply complex HAVING clause with havingRaw', async () => {
// Insert a test record.
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
await blocksTable.upsert([emptyBlock, nonEmptyBlock], trx);
await transactionsTable.upsert([tokenTransferTransaction], trx);

const params = {
groupBy: 'height',
havingRaw: `SUM(height) < ${Math.max(emptyBlock.height, nonEmptyBlock.height)}`,
};

const result = await blocksTable.find(params, ['id', 'height'], trx);
await commitDBTransaction(trx);
expect(result).toBeInstanceOf(Array);
expect(result.length).toBe(1);
});
});

describe('Transactional atomicity guarantees (non-auto commit mode)', () => {
afterEach(async () => {
await blocksTable.rawQuery(`TRUNCATE ${tableName}`);
});

it('should perform a successful transaction commit', async () => {
const connection = await getDBConnection();
const trx = await startDBTransaction(connection);
Expand Down
2 changes: 1 addition & 1 deletion services/blockchain-app-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"bluebird": "^3.7.2",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/b29df9637584d43ce25b89843637c46ebbcbe628/framework/dist/lisk-service-framework-1.6.0.tgz",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/e72288dc2ee681198097c531aad9ec43edcfd86e/framework/dist/lisk-service-framework-1.6.1.tgz",
"lodash": "^4.17.21",
"octokit": "^2.0.4",
"tar": "^6.1.11"
Expand Down
36 changes: 33 additions & 3 deletions services/blockchain-app-registry/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3084,9 +3084,39 @@ lines-and-columns@^1.1.6:
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==

"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/b29df9637584d43ce25b89843637c46ebbcbe628/framework/dist/lisk-service-framework-1.6.0.tgz":
version "1.6.0"
resolved "https://github.com/LiskHQ/lisk-service/raw/b29df9637584d43ce25b89843637c46ebbcbe628/framework/dist/lisk-service-framework-1.6.0.tgz#22d99e35771f13c9e00d6a36b20dc453e83f799a"
"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/c290db8943b1ad0ad7e6ec913bd43c2a3c36030e/framework/dist/lisk-service-framework-1.6.1.tgz":
version "1.6.1"
resolved "https://github.com/LiskHQ/lisk-service/raw/c290db8943b1ad0ad7e6ec913bd43c2a3c36030e/framework/dist/lisk-service-framework-1.6.1.tgz#bf7089c595b9e1893ac55c64acf2f2163e154695"
dependencies:
"@keyv/redis" "^2.1.2"
"@log4js-node/gelf" "github:MichalTuleja/log4js-node-gelf#89d9933"
axios "^0.21.2"
better-sqlite3 "^8.5.0"
bull "^3.29.3"
debug "^4.3.1"
fastest-validator "^1.10.1"
http-status-codes "^1.4.0"
json-colorizer "^2.2.2"
keyv "^4.0.3"
keyv-lru "^3.0.4"
knex "^2.5.1"
log4js "^6.5.2"
moleculer "^0.14.21"
moleculer-web "^0.10.4"
moment "^2.29.4"
mysql2 "^3.5.2"
nats "^1.4.12"
node-cron "^2.0.3"
prettyjson "^1.2.1"
require-all "^3.0.0"
signals "^1.0.0"
socket.io "^4.4.1"
socket.io-client "^4.0.1"
stack-trace "0.0.10"

"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/e72288dc2ee681198097c531aad9ec43edcfd86e/framework/dist/lisk-service-framework-1.6.1.tgz":
version "1.6.1"
resolved "https://github.com/LiskHQ/lisk-service/raw/e72288dc2ee681198097c531aad9ec43edcfd86e/framework/dist/lisk-service-framework-1.6.1.tgz#730da995d0279f62f94e3285747424511537998d"
dependencies:
"@keyv/redis" "^2.1.2"
"@log4js-node/gelf" "github:MichalTuleja/log4js-node-gelf#89d9933"
Expand Down
2 changes: 1 addition & 1 deletion services/blockchain-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"big-json": "^3.1.0",
"bluebird": "^3.7.2",
"knex": "^2.4.0",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/b29df9637584d43ce25b89843637c46ebbcbe628/framework/dist/lisk-service-framework-1.6.0.tgz",
"lisk-service-framework": "https://github.com/LiskHQ/lisk-service/raw/e72288dc2ee681198097c531aad9ec43edcfd86e/framework/dist/lisk-service-framework-1.6.1.tgz",
"moment": "^2.29.4",
"signals": "^1.0.0",
"tar": "^6.1.11"
Expand Down
36 changes: 33 additions & 3 deletions services/blockchain-connector/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3926,9 +3926,39 @@ lines-and-columns@^1.1.6:
resolved "https://npm.lisk.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==

"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/b29df9637584d43ce25b89843637c46ebbcbe628/framework/dist/lisk-service-framework-1.6.0.tgz":
version "1.6.0"
resolved "https://github.com/LiskHQ/lisk-service/raw/b29df9637584d43ce25b89843637c46ebbcbe628/framework/dist/lisk-service-framework-1.6.0.tgz#22d99e35771f13c9e00d6a36b20dc453e83f799a"
"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/c290db8943b1ad0ad7e6ec913bd43c2a3c36030e/framework/dist/lisk-service-framework-1.6.1.tgz":
version "1.6.1"
resolved "https://github.com/LiskHQ/lisk-service/raw/c290db8943b1ad0ad7e6ec913bd43c2a3c36030e/framework/dist/lisk-service-framework-1.6.1.tgz#bf7089c595b9e1893ac55c64acf2f2163e154695"
dependencies:
"@keyv/redis" "^2.1.2"
"@log4js-node/gelf" "github:MichalTuleja/log4js-node-gelf#89d9933"
axios "^0.21.2"
better-sqlite3 "^8.5.0"
bull "^3.29.3"
debug "^4.3.1"
fastest-validator "^1.10.1"
http-status-codes "^1.4.0"
json-colorizer "^2.2.2"
keyv "^4.0.3"
keyv-lru "^3.0.4"
knex "^2.5.1"
log4js "^6.5.2"
moleculer "^0.14.21"
moleculer-web "^0.10.4"
moment "^2.29.4"
mysql2 "^3.5.2"
nats "^1.4.12"
node-cron "^2.0.3"
prettyjson "^1.2.1"
require-all "^3.0.0"
signals "^1.0.0"
socket.io "^4.4.1"
socket.io-client "^4.0.1"
stack-trace "0.0.10"

"lisk-service-framework@https://github.com/LiskHQ/lisk-service/raw/e72288dc2ee681198097c531aad9ec43edcfd86e/framework/dist/lisk-service-framework-1.6.1.tgz":
version "1.6.1"
resolved "https://github.com/LiskHQ/lisk-service/raw/e72288dc2ee681198097c531aad9ec43edcfd86e/framework/dist/lisk-service-framework-1.6.1.tgz#730da995d0279f62f94e3285747424511537998d"
dependencies:
"@keyv/redis" "^2.1.2"
"@log4js-node/gelf" "github:MichalTuleja/log4js-node-gelf#89d9933"
Expand Down
Loading