From f07d439660d82b35102b8bb81ada39aaf1e9cef4 Mon Sep 17 00:00:00 2001 From: dafuga Date: Thu, 6 Jul 2023 15:55:08 -0400 Subject: [PATCH] enhancement: added errors when wrong params are passed to find and where --- src/contract/table.ts | 12 ++++++++ ...e1f53ef4cf6544fe89a0deb7a7d1043f43149.json | 30 +++++++++---------- test/tests/table.ts | 2 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/contract/table.ts b/src/contract/table.ts index 93194f0..88c413f 100644 --- a/src/contract/table.ts +++ b/src/contract/table.ts @@ -96,8 +96,16 @@ export class Table { + if (!query) { + throw new Error('Index value range must be provided') + } + const {from, to} = query + if (!from && !to) { + throw new Error('Index value for "from" or "to" must be provided') + } + const lower_bound = from ? typeof from === 'string' ? Name.from(from) @@ -134,6 +142,10 @@ export class Table} Promise resolving to a single table row. */ async find(query, queryOptions?: QueryOptions): Promise { + if (!query) { + throw new Error('Index value must be provided') + } + const fieldToIndexMapping = await this.getFieldToIndex() const tableRowsParams = { diff --git a/test/data/b5ae1f53ef4cf6544fe89a0deb7a7d1043f43149.json b/test/data/b5ae1f53ef4cf6544fe89a0deb7a7d1043f43149.json index fd8d9f2..967b422 100644 --- a/test/data/b5ae1f53ef4cf6544fe89a0deb7a7d1043f43149.json +++ b/test/data/b5ae1f53ef4cf6544fe89a0deb7a7d1043f43149.json @@ -9,24 +9,24 @@ "json": { "server_version": "905c5cc9", "chain_id": "73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d", - "head_block_num": 84730189, - "last_irreversible_block_num": 84729861, - "last_irreversible_block_id": "050ce00508d12790b8143dcf28e77ecb91ac9a28d1a1bdaab0ec0f46d32e2064", - "head_block_id": "050ce14db85929679c1a40861b7fc834cab8010bd4e8b1c6d2940c3bf6b101bb", - "head_block_time": "2023-06-30T06:27:13.500", - "head_block_producer": "hippopotamus", - "virtual_block_cpu_limit": 200000000, + "head_block_num": 85860485, + "last_irreversible_block_num": 85860156, + "last_irreversible_block_id": "051e1f3c57f975d1d4fe1e93781dd7fccc91dfe4a00e8bad43ef3b24442db211", + "head_block_id": "051e20850b33c65ccd1cc7465d35bc4734101bfa61fa7115d497ac6209a205c2", + "head_block_time": "2023-07-06T20:04:32.500", + "head_block_producer": "batinthedark", + "virtual_block_cpu_limit": 250000000, "virtual_block_net_limit": 1048576000, - "block_cpu_limit": 200000, + "block_cpu_limit": 250000, "block_net_limit": 1048576, "server_version_string": "v3.1.3", - "fork_db_head_block_num": 84730189, - "fork_db_head_block_id": "050ce14db85929679c1a40861b7fc834cab8010bd4e8b1c6d2940c3bf6b101bb", + "fork_db_head_block_num": 85860485, + "fork_db_head_block_id": "051e20850b33c65ccd1cc7465d35bc4734101bfa61fa7115d497ac6209a205c2", "server_full_version_string": "v3.1.3-905c5cc900b4e88aed4ab6912009127bf9f4f140", - "total_cpu_weight": "120605025312211", - "total_net_weight": "117529266276322", - "earliest_available_block_num": 84542790, - "last_irreversible_block_time": "2023-06-30T06:24:29.500" + "total_cpu_weight": "120605033683215", + "total_net_weight": "117529266988326", + "earliest_available_block_num": 85684866, + "last_irreversible_block_time": "2023-07-06T20:01:47.500" }, - "text": "{\"server_version\":\"905c5cc9\",\"chain_id\":\"73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d\",\"head_block_num\":84730189,\"last_irreversible_block_num\":84729861,\"last_irreversible_block_id\":\"050ce00508d12790b8143dcf28e77ecb91ac9a28d1a1bdaab0ec0f46d32e2064\",\"head_block_id\":\"050ce14db85929679c1a40861b7fc834cab8010bd4e8b1c6d2940c3bf6b101bb\",\"head_block_time\":\"2023-06-30T06:27:13.500\",\"head_block_producer\":\"hippopotamus\",\"virtual_block_cpu_limit\":200000000,\"virtual_block_net_limit\":1048576000,\"block_cpu_limit\":200000,\"block_net_limit\":1048576,\"server_version_string\":\"v3.1.3\",\"fork_db_head_block_num\":84730189,\"fork_db_head_block_id\":\"050ce14db85929679c1a40861b7fc834cab8010bd4e8b1c6d2940c3bf6b101bb\",\"server_full_version_string\":\"v3.1.3-905c5cc900b4e88aed4ab6912009127bf9f4f140\",\"total_cpu_weight\":\"120605025312211\",\"total_net_weight\":\"117529266276322\",\"earliest_available_block_num\":84542790,\"last_irreversible_block_time\":\"2023-06-30T06:24:29.500\"}" + "text": "{\"server_version\":\"905c5cc9\",\"chain_id\":\"73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d\",\"head_block_num\":85860485,\"last_irreversible_block_num\":85860156,\"last_irreversible_block_id\":\"051e1f3c57f975d1d4fe1e93781dd7fccc91dfe4a00e8bad43ef3b24442db211\",\"head_block_id\":\"051e20850b33c65ccd1cc7465d35bc4734101bfa61fa7115d497ac6209a205c2\",\"head_block_time\":\"2023-07-06T20:04:32.500\",\"head_block_producer\":\"batinthedark\",\"virtual_block_cpu_limit\":250000000,\"virtual_block_net_limit\":1048576000,\"block_cpu_limit\":250000,\"block_net_limit\":1048576,\"server_version_string\":\"v3.1.3\",\"fork_db_head_block_num\":85860485,\"fork_db_head_block_id\":\"051e20850b33c65ccd1cc7465d35bc4734101bfa61fa7115d497ac6209a205c2\",\"server_full_version_string\":\"v3.1.3-905c5cc900b4e88aed4ab6912009127bf9f4f140\",\"total_cpu_weight\":\"120605033683215\",\"total_net_weight\":\"117529266988326\",\"earliest_available_block_num\":85684866,\"last_irreversible_block_time\":\"2023-07-06T20:01:47.500\"}" } \ No newline at end of file diff --git a/test/tests/table.ts b/test/tests/table.ts index 5f6e5be..11a98f9 100644 --- a/test/tests/table.ts +++ b/test/tests/table.ts @@ -123,7 +123,7 @@ suite('Table', () => { }) test('should fetch table row correctly with default filtering', async () => { // curl http://eos.greymass.com/v1/chain/get_table_rows -d '{"table":"producers","limit":10,"code":"eosio","scope":"eosio","json":true, "lower_bound": "teamgreymass", "upper_bound": "teamgreymass"}' - const row = await producersTable.find({owner: 'teamgreymass'}) + const row = await producersTable.find('teamgreymass') assert.deepEqual(row, { owner: 'teamgreymass',