From 0530ce13796bde0259910f96c15cecb3696650b4 Mon Sep 17 00:00:00 2001 From: incrypto32 Date: Tue, 9 Jul 2024 14:45:15 +0530 Subject: [PATCH] tests: refactor FDS runner tests --- .../file-data-sources/src/mapping.ts | 60 +++++++++---------- tests/tests/runner_tests.rs | 2 +- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/tests/runner-tests/file-data-sources/src/mapping.ts b/tests/runner-tests/file-data-sources/src/mapping.ts index 0adf0d7ecd4..19716ce4503 100644 --- a/tests/runner-tests/file-data-sources/src/mapping.ts +++ b/tests/runner-tests/file-data-sources/src/mapping.ts @@ -107,39 +107,11 @@ export function handleTestEvent(event: TestEvent): void { } export function handleFile(data: Bytes): void { - log.info("handleFile {}", [dataSource.stringParam()]); + log.info('handleFile {}', [dataSource.stringParam()]); let context = dataSource.context(); - if (context.isSet("command")) { - let contextCommand = context.getString("command"); - - if (contextCommand == SPAWN_FDS_FROM_OFFCHAIN_HANDLER) { - let hash = context.getString("hash"); - log.info("Creating file data source from handleFile: {}", [hash]); - dataSource.createWithContext("File", [hash], new DataSourceContext()); - } - - if (contextCommand == ONCHAIN_FROM_OFFCHAIN) { - log.info("Creating onchain data source from offchain handler", []); - let address = context.getString("address"); - dataSource.create("OnChainDataSource", [address]); - } - - if (contextCommand == CREATE_UNDEFINED_ENTITY) { - log.info("Creating undefined entity", []); - let entity = new Foo(dataSource.stringParam()); - entity.save(); - } - - if (contextCommand == CREATE_FOO) { - log.info("Creating FileEntity with relation to Foo", []); - let entity = new FileEntity(dataSource.stringParam()); - entity.foo = dataSource.stringParam(); - entity.content = data.toString(); - entity.save(); - } - } else { - log.info("Creating FileEntity from handleFile: {} , content : {}", [ + if (!context.isSet('command')) { + log.info('Creating FileEntity from handleFile: {} , content : {}', [ dataSource.stringParam(), data.toString(), ]); @@ -147,5 +119,29 @@ export function handleFile(data: Bytes): void { let entity = new FileEntity(dataSource.stringParam()); entity.content = data.toString(); entity.save(); + + return; } -} + + let contextCommand = context.getString('command'); + + if (contextCommand == SPAWN_FDS_FROM_OFFCHAIN_HANDLER) { + let hash = context.getString('hash'); + log.info('Creating file data source from handleFile: {}', [hash]); + dataSource.createWithContext('File', [hash], new DataSourceContext()); + } else if (contextCommand == ONCHAIN_FROM_OFFCHAIN) { + log.info('Creating onchain data source from offchain handler', []); + let address = context.getString('address'); + dataSource.create('OnChainDataSource', [address]); + } else if (contextCommand == CREATE_UNDEFINED_ENTITY) { + log.info('Creating undefined entity', []); + let entity = new Foo(dataSource.stringParam()); + entity.save(); + } else if (contextCommand == CREATE_FOO) { + log.info('Creating FileEntity with relation to Foo', []); + let entity = new FileEntity(dataSource.stringParam()); + entity.foo = dataSource.stringParam(); + entity.content = data.toString(); + entity.save(); + } +} \ No newline at end of file diff --git a/tests/tests/runner_tests.rs b/tests/tests/runner_tests.rs index 00673a4326b..7da707ac7cd 100644 --- a/tests/tests/runner_tests.rs +++ b/tests/tests/runner_tests.rs @@ -877,7 +877,7 @@ async fn file_data_sources() { chain.set_block_stream(blocks); - let message = "error while executing at wasm backtrace:\t 0: 0x3490 - !generated/schema/Foo#save\t 1: 0x3e1c - !src/mapping/handleFile: entity type `Foo` is not on the 'entities' list for data source `File`. Hint: Add `Foo` to the 'entities' list, which currently is: `FileEntity`. in handler `handleFile` at block #5 () at block #5 (0000000000000000000000000000000000000000000000000000000000000005)"; + let message = "error while executing at wasm backtrace:\t 0: 0x3490 - !generated/schema/Foo#save\t 1: 0x3eb2 - !src/mapping/handleFile: entity type `Foo` is not on the 'entities' list for data source `File`. Hint: Add `Foo` to the 'entities' list, which currently is: `FileEntity`. in handler `handleFile` at block #5 () at block #5 (0000000000000000000000000000000000000000000000000000000000000005)"; let err = ctx.start_and_sync_to_error(block_5.ptr()).await;