Remove hard-coded record types #52
@ -14,11 +14,3 @@ Run following scripts when [proto files](./proto/) are updated.
|
|||||||
```bash
|
```bash
|
||||||
./scripts/proto-gen.sh
|
./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
|
|
||||||
|
@ -23,6 +23,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Removing gRPC references..."
|
echo "Removing gRPC references..."
|
||||||
|
# https://github.com/tharsis/evmosjs/tree/main/packages/proto#note
|
||||||
|
|
||||||
for file in $(find $REPO_ROOT/src/proto -type f)
|
for file in $(find $REPO_ROOT/src/proto -type f)
|
||||||
do
|
do
|
||||||
|
@ -97,17 +97,17 @@ const bondTests = () => {
|
|||||||
|
|
||||||
// Create a new record.
|
// Create a new record.
|
||||||
version1 = await publishNewWatcherVersion(bondId1);
|
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);
|
expect(record1.bondId).toBe(bondId1);
|
||||||
|
|
||||||
// Dissociate record, query and confirm.
|
// Dissociate record, query and confirm.
|
||||||
await registry.dissociateBond({ recordId: record1.id }, privateKey, fee);
|
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('');
|
expect(record1.bondId).toBe('');
|
||||||
|
|
||||||
// Associate record with bond, query and confirm.
|
// Associate record with bond, query and confirm.
|
||||||
await registry.associateBond({ recordId: record1.id, bondId: bondId1 }, privateKey, fee);
|
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);
|
expect(record1.bondId).toBe(bondId1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -117,9 +117,9 @@ const bondTests = () => {
|
|||||||
|
|
||||||
// Check version1, version2 as associated with bondId1.
|
// Check version1, version2 as associated with bondId1.
|
||||||
let records;
|
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);
|
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);
|
expect(records[0].bondId).toBe(bondId1);
|
||||||
|
|
||||||
// Create another bond.
|
// Create another bond.
|
||||||
@ -131,16 +131,16 @@ const bondTests = () => {
|
|||||||
|
|
||||||
// Reassociate records from bondId1 to bondId2, verify change.
|
// Reassociate records from bondId1 to bondId2, verify change.
|
||||||
await registry.reassociateRecords({ oldBondId: bondId1, newBondId: bondId2 }, privateKey, fee);
|
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);
|
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);
|
expect(records[0].bondId).toBe(bondId2);
|
||||||
|
|
||||||
// Dissociate all records from bond, verify change.
|
// Dissociate all records from bond, verify change.
|
||||||
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee);
|
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('');
|
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('');
|
expect(records[0].bondId).toBe('');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@ describe('Querying', () => {
|
|||||||
|
|
||||||
test('Query records by attributes.', async () => {
|
test('Query records by attributes.', async () => {
|
||||||
const { version, url } = watcher.record;
|
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);
|
expect(records.length).toBe(1);
|
||||||
|
|
||||||
[ watcher ] = records;
|
[ watcher ] = records;
|
||||||
|
@ -35,7 +35,11 @@ export class Util {
|
|||||||
static toGQLAttributes(obj: any) {
|
static toGQLAttributes(obj: any) {
|
||||||
const vars: any[] = [];
|
const vars: any[] = [];
|
||||||
Object.keys(obj).forEach(key => {
|
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;
|
return vars;
|
||||||
}
|
}
|
||||||
@ -61,6 +65,8 @@ export class Util {
|
|||||||
return { 'array': obj };
|
return { 'array': obj };
|
||||||
}
|
}
|
||||||
return { 'map': obj };
|
return { 'map': obj };
|
||||||
|
case 'undefined':
|
||||||
|
return undefined;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown object type '${type}': ${obj}`);
|
throw new Error(`Unknown object type '${type}': ${obj}`);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user