Skip to content

Commit

Permalink
tests: refactor FDS runner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
incrypto32 committed Jul 9, 2024
1 parent 375c423 commit 0530ce1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
60 changes: 28 additions & 32 deletions tests/runner-tests/file-data-sources/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,45 +107,41 @@ 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(),
]);

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();
}
}
2 changes: 1 addition & 1 deletion tests/tests/runner_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 - <unknown>!generated/schema/Foo#save\t 1: 0x3e1c - <unknown>!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 - <unknown>!generated/schema/Foo#save\t 1: 0x3eb2 - <unknown>!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;

Expand Down

0 comments on commit 0530ce1

Please sign in to comment.