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

[#40] Consistent column order for MBCUSTOMQUERY #50

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2584826
Change defatul number of fileters
daenamkim Nov 26, 2020
dd8442c
Add MBCUSTOMEQUERY test with no filter
daenamkim Nov 26, 2020
6442a65
Add a reference for validators
daenamkim Nov 27, 2020
0116d8b
Update validators
daenamkim Nov 27, 2020
f728067
Change a field name from rule to fieldType
daenamkim Nov 27, 2020
7df1255
Fix regex based on field types
daenamkim Nov 27, 2020
d9176bc
Update MBCUSTOMQUERY tests
daenamkim Nov 27, 2020
5419935
Revert "Add a reference for validators"
daenamkim Nov 27, 2020
478cc01
Add a comment
daenamkim Nov 27, 2020
b7517dd
Change texts
daenamkim Nov 27, 2020
5c1b460
Merge branch 'master' into 30-fix-event-queries-filters
daenamkim Dec 1, 2020
94c243f
Exit when an error happens during tests
daenamkim Dec 4, 2020
773be3a
Add headers preset
daenamkim Dec 11, 2020
15bfb63
Change a test
daenamkim Dec 11, 2020
e29fe41
Merge branch 'master' into 30-fix-event-queries-filters
daenamkim Dec 15, 2020
7cc7360
[#30] Improve event query filter (#35)
daenamkim Dec 25, 2020
e68529a
Remove a wrong valid operand
daenamkim Dec 25, 2020
ddb7a4f
Add formatInts to return number values as integer as is (#55)
daenamkim Dec 25, 2020
99968b9
Merge branch 'master' into 40-consistent-column-order
daenamkim Dec 25, 2020
402f50d
Merge branch '30-fix-event-queries-filters' into 40-consistent-column…
daenamkim Dec 25, 2020
cb1dde6
Merge branch 'master' into 40-consistent-column-order
daenamkim Dec 25, 2020
54088a3
Fix tests
daenamkim Dec 25, 2020
a9d7e17
Update gitignore
daenamkim Jan 12, 2021
ef71cfe
Merge branch 'master' into 40-consistent-column-order
daenamkim Jan 12, 2021
64e3843
Fix headers order
daenamkim Jan 12, 2021
e26397d
Fix variable init
daenamkim Jan 12, 2021
8faf50a
Remove a unused test
daenamkim Jan 12, 2021
821dd6e
Add MBCUSTOMQUERY test with multiple events and filters
daenamkim Jan 12, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ yarn-error.log
.*.json
.vscode
.env
.DS_Store

# Version file: this file will be used only in Apps Script project
# after running "yarn push" command. See package.json
Expand Down
20 changes: 18 additions & 2 deletions src/Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,25 @@ function MBCUSTOMQUERY(events, groupBy, orderBy, limit, offset) {
}
console.log(`Results: ${JSON.stringify(results)}`);

// turn the array of objects into a flat array
const headers = [];
let numEmptyColumns = 0;
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (let col = 0; numEmptyColumns < payload.events.length; col++) {
numEmptyColumns = 0;
// eslint-disable-next-line no-restricted-syntax
for (const event of payload.events) {
if (event.select[col]) {
headers.push(event.select[col].alias);
} else {
numEmptyColumns++;
}
}
}

const objArr = results.result.rows;
return objectArrayToArray(objArr);

// turn the array of objects into a flat array
return objectArrayToArray(objArr, headers);
}

/**
Expand Down
108 changes: 86 additions & 22 deletions src/Code.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ function testRunner(testSheetURL) {
0,
],
expected: [
['amount', 'sender'],
[1e+27, '0x89d048be68575f2b56a999ba24faacabd1b919fb'],
['sender', 'amount'],
['0x89d048be68575f2b56a999ba24faacabd1b919fb', 1e+27],
],
},
{
Expand All @@ -495,10 +495,10 @@ function testRunner(testSheetURL) {
0,
],
expected: [
['amount', 'sender'],
[1e+27, '0x89d048be68575f2b56a999ba24faacabd1b919fb'],
[1000000000000000000, '0xa616eed6ad7a0cf5d2388301a710c273ca955e05'],
[1000000000000000000, '0xbac1cd4051c378bf900087ccc445d7e7d02ad745'],
['sender', 'amount'],
['0x89d048be68575f2b56a999ba24faacabd1b919fb', 1e+27],
['0xa616eed6ad7a0cf5d2388301a710c273ca955e05', 1000000000000000000],
['0xbac1cd4051c378bf900087ccc445d7e7d02ad745', 1000000000000000000],
],
},
{
Expand All @@ -515,12 +515,12 @@ function testRunner(testSheetURL) {
],
],
expected: [
['amount', 'sender'],
[1000000000000000000, '0xa616eed6ad7a0cf5d2388301a710c273ca955e05'],
[1000000000000000000, '0xbac1cd4051c378bf900087ccc445d7e7d02ad745'],
[50, '0x0d6c3707a98bce1a56247555c8b74242705b8acf'],
[50000000000000000000, '0x0d6c3707a98bce1a56247555c8b74242705b8acf'],
[50000000000000000000, '0x005080f78567f8001115f1eee835dd0151bea476'],
['sender', 'amount'],
['0xa616eed6ad7a0cf5d2388301a710c273ca955e05', 1000000000000000000],
['0xbac1cd4051c378bf900087ccc445d7e7d02ad745', 1000000000000000000],
['0x0d6c3707a98bce1a56247555c8b74242705b8acf', 50],
['0x0d6c3707a98bce1a56247555c8b74242705b8acf', 50000000000000000000],
['0x005080f78567f8001115f1eee835dd0151bea476', 50000000000000000000],
],
},
{
Expand All @@ -541,29 +541,93 @@ function testRunner(testSheetURL) {
1,
],
expected: [
['amount', 'sender'],
[1000000000000000000, '0xa616eed6ad7a0cf5d2388301a710c273ca955e05'],
['sender', 'amount'],
['0xa616eed6ad7a0cf5d2388301a710c273ca955e05', 1000000000000000000],
],
},
// TODO: try after https://github.com/curvegrid/multibaas-for-google-sheets/issues/53
{
name: 'TestMBCUSTOMQUERY with wrong selected range',
skip: true,
name: 'TestMBCUSTOMQUERY with multiple events and filters',
skip: false,
only: false,
debug: false,
func: MBCUSTOMQUERY,
isTemplate: false,
args: [
[
['eventName', 'alias', 'index', 'aggregator', 'alias', 'index', 'aggregator', undefined],
['LogDeposited(address,uint256)', 'sender', 0, '', 'amount', 1, '', undefined],
[
'eventName',
'alias',
'index',
'aggregator',
'alias',
'index',
'aggregator',
'rule',
'operand',
'operator',
'value',
'rule',
'operand',
'operator',
'value',
'rule',
'operand',
'operator',
'value',
],
[
'LogDeposited(address,uint256)',
'sender4',
0,
'',
'amount4',
1,
'',
'and',
'input0',
'equal',
'0x89d048be68575f2b56a999ba24faacabd1b919fb',
'and',
'input1',
'greaterthan',
1,
'and:and',
'block_number',
'greaterthan',
1,
],
[
'LogSent(address,uint256)',
'receiver2',
0,
'',
'amount2',
1,
'',
'and',
'input0',
'equal',
'0x0d6c3707a98bce1a56247555c8b74242705b8acf',
'and',
'input1',
'greaterthan',
1,
'and:and',
'block_number',
'greaterthan',
1,
],
],
'',
'',
1,
1,
3,
0,
],
expected: [
['sender4', 'receiver2', 'amount4', 'amount2'],
['0x89d048be68575f2b56a999ba24faacabd1b919fb', '', 1e+27, ''],
['', '0x0d6c3707a98bce1a56247555c8b74242705b8acf', '', 1e+18],
],
expected: ['#ERROR!'],
},
{
name: 'TestMBCUSTOMQUERYTEMPLATE with 2 filters',
Expand Down
9 changes: 7 additions & 2 deletions src/library/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,20 @@ function eventsToArray(entries) {
return rows;
}

function objectArrayToArray(objArr) {
function objectArrayToArray(objArr, headersPreset) {
const rows = [];

if (!Array.isArray(objArr) || objArr.length < 1) {
return '';
}

// header row: just take the keys from the first row
const headers = keysFromObj(objArr[0], true);
let headers;
if (!Array.isArray(headersPreset)) {
headers = keysFromObj(objArr[0], false);
} else {
headers = headersPreset;
}
rows.push(headers);

// body rows
Expand Down