Skip to content

Commit ef86214

Browse files
leoyvensJannis Pohlmann
authored andcommitted
runtime: Update and re-compile tests with new AS version
Some that were harder to update and also are not so relevant were removed.
1 parent 763c058 commit ef86214

16 files changed

+2
-166
lines changed

runtime/wasm/src/module/test.rs

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -145,142 +145,6 @@ where
145145
}
146146
}
147147

148-
/// Create mock Ethereum data
149-
fn generate_fake_block() -> (EthereumBlock, Transaction, Log) {
150-
let block_hash = H256::random();
151-
let transaction = Transaction {
152-
hash: H256::random(),
153-
nonce: U256::zero(),
154-
block_hash: Some(block_hash),
155-
block_number: Some(5.into()),
156-
transaction_index: Some(0.into()),
157-
from: H160::random(),
158-
to: None,
159-
value: 0.into(),
160-
gas_price: 0.into(),
161-
gas: 0.into(),
162-
input: Bytes::default(),
163-
};
164-
let log = Log {
165-
address: Address::from("22843e74c59580b3eaf6c233fa67d8b7c561a835"),
166-
topics: vec![util::ethereum::string_to_h256("ExampleEvent(string)")],
167-
data: Bytes::default(),
168-
block_hash: Some(block_hash),
169-
block_number: Some(5.into()),
170-
transaction_hash: Some(transaction.hash),
171-
transaction_index: Some(0.into()),
172-
log_index: Some(0.into()),
173-
transaction_log_index: Some(0.into()),
174-
log_type: None,
175-
removed: None,
176-
};
177-
let block = EthereumBlock {
178-
block: Block {
179-
hash: Some(block_hash),
180-
parent_hash: H256::random(),
181-
uncles_hash: H256::zero(),
182-
author: H160::random(),
183-
state_root: H256::random(),
184-
transactions_root: H256::random(),
185-
receipts_root: H256::random(),
186-
number: Some(5.into()),
187-
gas_used: 0.into(),
188-
gas_limit: 0.into(),
189-
extra_data: Bytes::default(),
190-
logs_bloom: H2048::random(),
191-
timestamp: 42.into(),
192-
difficulty: 0.into(),
193-
total_difficulty: 0.into(),
194-
seal_fields: vec![],
195-
uncles: vec![],
196-
transactions: vec![transaction.clone()],
197-
size: None,
198-
},
199-
transaction_receipts: vec![],
200-
};
201-
202-
(block, transaction, log)
203-
}
204-
205-
#[test]
206-
fn call_invalid_event_handler_and_dont_crash() {
207-
// This test passing means the module doesn't crash when an invalid
208-
// event handler is called or when the event handler execution fails.
209-
210-
let mut module = test_module(mock_data_source("wasm_test/example_event_handler.wasm"));
211-
212-
let (block, transaction, log) = generate_fake_block();
213-
214-
let ctx = EventHandlerContext {
215-
logger: Logger::root(slog::Discard, o!()),
216-
block: Arc::new(block),
217-
transaction: Arc::new(transaction),
218-
entity_operations: vec![],
219-
};
220-
221-
// Call a non-existent event handler in the test module
222-
let _result = module.handle_ethereum_event(
223-
ctx,
224-
"handleNonExistentExampleEvent",
225-
Arc::new(log),
226-
vec![LogParam {
227-
name: "exampleParam".to_owned(),
228-
value: Token::String("some data".to_owned()),
229-
}],
230-
);
231-
232-
// If the test hasn't crashed, it means it survives Ethereum event handler errors
233-
}
234-
235-
#[test]
236-
fn call_event_handler_and_receive_store_event() {
237-
// Load the example_event_handler.wasm test module. All this module does
238-
// is implement an `handleExampleEvent` function that calls `store.set()`
239-
// with sample data taken from the event parameters.
240-
//
241-
// This test verifies that the event is delivered and the example data
242-
// is returned to the RuntimeHostEvent stream.
243-
244-
let mut module = test_module(mock_data_source("wasm_test/example_event_handler.wasm"));
245-
246-
let (block, transaction, log) = generate_fake_block();
247-
248-
let ctx = EventHandlerContext {
249-
logger: Logger::root(slog::Discard, o!()),
250-
block: Arc::new(block),
251-
transaction: Arc::new(transaction),
252-
entity_operations: vec![],
253-
};
254-
255-
// Call the event handler in the test module and pass the event to it
256-
let result = module.handle_ethereum_event(
257-
ctx,
258-
"handleExampleEvent",
259-
Arc::new(log),
260-
vec![LogParam {
261-
name: "exampleParam".to_owned(),
262-
value: Token::String("some data".to_owned()),
263-
}],
264-
);
265-
266-
assert_eq!(
267-
result.unwrap(),
268-
vec![EntityOperation::Set {
269-
key: EntityKey {
270-
subgraph_id: SubgraphId::new("testsubgraph").unwrap(),
271-
entity_type: "ExampleEntity".to_owned(),
272-
entity_id: "example id".to_owned(),
273-
},
274-
data: Entity::from(HashMap::from_iter(
275-
vec![
276-
("id".to_owned(), "example id".into()),
277-
("exampleAttribute".to_owned(), "some data".into()),
278-
].into_iter()
279-
)),
280-
}]
281-
);
282-
}
283-
284148
#[test]
285149
fn json_conversions() {
286150
let mut module = test_module(mock_data_source("wasm_test/string_to_number.wasm"));
@@ -595,13 +459,3 @@ fn big_int_arithmetic() {
595459
let result: BigInt = module.heap.asc_get(result_ptr);
596460
assert_eq!(result, BigInt::from(1));
597461
}
598-
599-
#[test]
600-
fn abort() {
601-
let mut module = test_module(mock_data_source("wasm_test/abort.wasm"));
602-
let err = module
603-
.module
604-
.invoke_export("abort", &[], &mut module.externals)
605-
.unwrap_err();
606-
assert_eq!(err.to_string(), "Trap: Trap { kind: Host(HostExportError(\"Mapping aborted at abort.ts, line 1, column 1, with message: aborted\")) }");
607-
}

runtime/wasm/wasm_test/abi_classes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ export function concat(bytes1: Bytes, bytes2: FixedBytes): Bytes {
5050
let bytes2_start = load<usize>(changetype<usize>(bytes2)) + array_buffer_header_size;
5151

5252
// Move bytes1.
53-
move_memory(concated_offset, bytes1_start, bytes1.byteLength);
53+
memory.copy(concated_offset, bytes1_start, bytes1.byteLength);
5454
concated_offset += bytes1.byteLength
5555

5656
// Move bytes2.
57-
move_memory(concated_offset, bytes2_start, bytes2.byteLength);
57+
memory.copy(concated_offset, bytes2_start, bytes2.byteLength);
5858

5959
let new_typed_array = new Uint8Array(concated.byteLength);
6060
store<usize>(changetype<usize>(new_typed_array), changetype<usize>(concated));
-217 Bytes
Binary file not shown.
-599 Bytes
Binary file not shown.
2.77 KB
Binary file not shown.

runtime/wasm/wasm_test/abort.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

runtime/wasm/wasm_test/abort.wasm

-435 Bytes
Binary file not shown.
3.02 KB
Binary file not shown.
3.09 KB
Binary file not shown.
3.16 KB
Binary file not shown.

0 commit comments

Comments
 (0)