Fix tests for querying records with undefined filter value

This commit is contained in:
Nabarun 2024-01-11 08:58:05 +05:30
parent 18cb09669a
commit 17b21c4750
5 changed files with 18 additions and 19 deletions

View File

@ -14,11 +14,3 @@ Run following scripts when [proto files](./proto/) are updated.
```bash
./scripts/proto-gen.sh
```
3. Remove GRPC code from generated code
```bash
./scripts/remove-grpc.sh
```
Reference: https://github.com/tharsis/evmosjs/tree/main/packages/proto#note

View File

@ -23,6 +23,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
fi
echo "Removing gRPC references..."
# https://github.com/tharsis/evmosjs/tree/main/packages/proto#note
for file in $(find $REPO_ROOT/src/proto -type f)
do

View File

@ -97,17 +97,17 @@ const bondTests = () => {
// Create a new record.
version1 = await publishNewWatcherVersion(bondId1);
let [record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
let [record1] = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
expect(record1.bondId).toBe(bondId1);
// Dissociate record, query and confirm.
await registry.dissociateBond({ recordId: record1.id }, privateKey, fee);
[record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
[record1] = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
expect(record1.bondId).toBe('');
// Associate record with bond, query and confirm.
await registry.associateBond({ recordId: record1.id, bondId: bondId1 }, privateKey, fee);
[record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
[record1] = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
expect(record1.bondId).toBe(bondId1);
});
@ -117,9 +117,9 @@ const bondTests = () => {
// Check version1, version2 as associated with bondId1.
let records;
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
records = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
expect(records[0].bondId).toBe(bondId1);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
records = await registry.queryRecords({ type: watcher.record.type, version: version2 }, true);
expect(records[0].bondId).toBe(bondId1);
// Create another bond.
@ -131,16 +131,16 @@ const bondTests = () => {
// Reassociate records from bondId1 to bondId2, verify change.
await registry.reassociateRecords({ oldBondId: bondId1, newBondId: bondId2 }, privateKey, fee);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
records = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
expect(records[0].bondId).toBe(bondId2);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
records = await registry.queryRecords({ type: watcher.record.type, version: version2 }, true);
expect(records[0].bondId).toBe(bondId2);
// Dissociate all records from bond, verify change.
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
records = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
expect(records[0].bondId).toBe('');
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
records = await registry.queryRecords({ type: watcher.record.type, version: version2 }, true);
expect(records[0].bondId).toBe('');
});
};

View File

@ -55,7 +55,7 @@ describe('Querying', () => {
test('Query records by attributes.', async () => {
const { version, url } = watcher.record;
const records = await registry.queryRecords({ version, url }, true);
const records = await registry.queryRecords({ version, url, type: undefined }, true);
expect(records.length).toBe(1);
[ watcher ] = records;

View File

@ -35,7 +35,11 @@ export class Util {
static toGQLAttributes(obj: any) {
const vars: any[] = [];
Object.keys(obj).forEach(key => {
vars.push({ key, value: this.toGQLValue(obj[key]) });
const value = this.toGQLValue(obj[key]);
if (value !== undefined) {
vars.push({ key, value });
}
});
return vars;
}
@ -61,6 +65,8 @@ export class Util {
return { 'array': obj };
}
return { 'map': obj };
case 'undefined':
return undefined;
default:
throw new Error(`Unknown object type '${type}': ${obj}`);
}