Skip to content

Commit 0530ce1

Browse files
committed
tests: refactor FDS runner tests
1 parent 375c423 commit 0530ce1

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

tests/runner-tests/file-data-sources/src/mapping.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -107,45 +107,41 @@ export function handleTestEvent(event: TestEvent): void {
107107
}
108108

109109
export function handleFile(data: Bytes): void {
110-
log.info("handleFile {}", [dataSource.stringParam()]);
110+
log.info('handleFile {}', [dataSource.stringParam()]);
111111
let context = dataSource.context();
112112

113-
if (context.isSet("command")) {
114-
let contextCommand = context.getString("command");
115-
116-
if (contextCommand == SPAWN_FDS_FROM_OFFCHAIN_HANDLER) {
117-
let hash = context.getString("hash");
118-
log.info("Creating file data source from handleFile: {}", [hash]);
119-
dataSource.createWithContext("File", [hash], new DataSourceContext());
120-
}
121-
122-
if (contextCommand == ONCHAIN_FROM_OFFCHAIN) {
123-
log.info("Creating onchain data source from offchain handler", []);
124-
let address = context.getString("address");
125-
dataSource.create("OnChainDataSource", [address]);
126-
}
127-
128-
if (contextCommand == CREATE_UNDEFINED_ENTITY) {
129-
log.info("Creating undefined entity", []);
130-
let entity = new Foo(dataSource.stringParam());
131-
entity.save();
132-
}
133-
134-
if (contextCommand == CREATE_FOO) {
135-
log.info("Creating FileEntity with relation to Foo", []);
136-
let entity = new FileEntity(dataSource.stringParam());
137-
entity.foo = dataSource.stringParam();
138-
entity.content = data.toString();
139-
entity.save();
140-
}
141-
} else {
142-
log.info("Creating FileEntity from handleFile: {} , content : {}", [
113+
if (!context.isSet('command')) {
114+
log.info('Creating FileEntity from handleFile: {} , content : {}', [
143115
dataSource.stringParam(),
144116
data.toString(),
145117
]);
146118

147119
let entity = new FileEntity(dataSource.stringParam());
148120
entity.content = data.toString();
149121
entity.save();
122+
123+
return;
150124
}
151-
}
125+
126+
let contextCommand = context.getString('command');
127+
128+
if (contextCommand == SPAWN_FDS_FROM_OFFCHAIN_HANDLER) {
129+
let hash = context.getString('hash');
130+
log.info('Creating file data source from handleFile: {}', [hash]);
131+
dataSource.createWithContext('File', [hash], new DataSourceContext());
132+
} else if (contextCommand == ONCHAIN_FROM_OFFCHAIN) {
133+
log.info('Creating onchain data source from offchain handler', []);
134+
let address = context.getString('address');
135+
dataSource.create('OnChainDataSource', [address]);
136+
} else if (contextCommand == CREATE_UNDEFINED_ENTITY) {
137+
log.info('Creating undefined entity', []);
138+
let entity = new Foo(dataSource.stringParam());
139+
entity.save();
140+
} else if (contextCommand == CREATE_FOO) {
141+
log.info('Creating FileEntity with relation to Foo', []);
142+
let entity = new FileEntity(dataSource.stringParam());
143+
entity.foo = dataSource.stringParam();
144+
entity.content = data.toString();
145+
entity.save();
146+
}
147+
}

tests/tests/runner_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ async fn file_data_sources() {
877877

878878
chain.set_block_stream(blocks);
879879

880-
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)";
880+
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)";
881881

882882
let err = ctx.start_and_sync_to_error(block_5.ptr()).await;
883883

0 commit comments

Comments
 (0)