Skip to content
Snippets Groups Projects
Commit 1bd780e8 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] #985 Sources of an account must take care of the key case

parent 6b208480
Branches
Tags
No related merge requests found
......@@ -22,7 +22,16 @@ function SQLiteDriver(path) {
logger.debug('Opening SQLite database "%s"...', path);
let sqlite = new sqlite3.Database(path);
yield new Promise((resolve) => sqlite.once('open', resolve));
// Database is opened and ready
// Database is opened
// Force case sensitiveness on LIKE operator
const sql = 'PRAGMA case_sensitive_like=ON;'
yield new Promise((resolve, reject) => sqlite.exec(sql, (err) => {
if (err) return reject(Error('SQL error "' + err.message + '" on INIT queries "' + sql + '"'))
return resolve()
}));
// Database is ready
return sqlite;
}));
}
......
......@@ -69,7 +69,7 @@ function AbstractSQLite(driver) {
this.sqlFindLikeAny = (obj, sort) => co(function *() {
const keys = _.keys(obj);
return that.query('SELECT * FROM ' + that.table + ' WHERE ' + keys.map((k) => '`' + k + '` like ?').join(' or '), keys.map((k) => obj[k].toUpperCase()), sort);
return that.query('SELECT * FROM ' + that.table + ' WHERE ' + keys.map((k) => 'UPPER(`' + k + '`) like ?').join(' or '), keys.map((k) => obj[k].toUpperCase()), sort);
});
this.sqlRemoveWhere = (obj) => co(function *() {
......
"use strict";
const co = require('co');
const _ = require('underscore');
const should = require('should');
const assert = require('assert');
const constants = require('../../app/lib/constants');
const bma = require('duniter-bma').duniter.methods.bma;
const toolbox = require('./tools/toolbox');
const node = require('./tools/node');
const unit = require('./tools/unit');
const http = require('./tools/http');
const now = 1480000000;
const conf = {
dt: 1000,
ud0: 200,
udTime0: now - 1, // So we have a UD right on block#1
medianTimeBlocks: 1 // Easy: medianTime(b) = time(b-1)
};
let s1, cat, tac
describe("Sources property", function() {
before(() => co(function*() {
const res = yield toolbox.simpleNodeWith2Users(conf);
s1 = res.s1;
cat = res.cat;
tac = res.tac;
yield s1.commit({ time: now });
yield s1.commit({ time: now + 1 });
}));
it('it should exist block#1 with UD of 200', () => s1.expect('/blockchain/block/1', (block) => {
should.exists(block);
assert.equal(block.number, 1);
assert.equal(block.dividend, 200);
}));
it('it should exist sources for HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', () => s1.expect('/tx/sources/HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', (res) => {
assert.equal(res.sources.length, 1)
}));
it('it should NOT exist sources if we change one letter to uppercased version', () => s1.expect('/tx/sources/HGTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', (res) => {
assert.equal(res.sources.length, 0)
}));
});
......@@ -39,7 +39,7 @@ describe("Transactions: CLTV", function() {
assert.equal(block.dividend, 200);
}));
it('with SIG and XHX', () => co(function *() {
it('with SIG and CLTV', () => co(function *() {
let tx1 = yield cat.prepareITX(200, tac);
yield unit.shouldNotFail(cat.sendTX(tx1));
yield s1.commit({ time: now + 19 }); // TODO: why not in the same block?
......
......@@ -39,7 +39,7 @@ describe("Transactions: CSV", function() {
assert.equal(block.dividend, 200);
}));
it('with SIG and XHX', () => co(function *() {
it('with SIG and CSV', () => co(function *() {
let tx1 = yield cat.prepareITX(200, tac);
yield unit.shouldNotFail(cat.sendTX(tx1));
yield s1.commit({ time: now + 19 }); // TODO: why not in the same block?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment