|
1 | 1 | import test from 'ava'; |
2 | | -import {invokeParser, signed} from "../../src/messaging/Parsers"; |
| 2 | +import {invokeParser, remoteFunctionResultParser, signed} from "../../src/messaging/Parsers"; |
3 | 3 | import {Exception, Expected, Kind, Message, Step, WASM} from "../../src"; |
| 4 | +import {RemoteFunctionResult} from "../../src/protocol/vendor/debug"; |
4 | 5 | import {Verifier} from "../../src/framework/Verifier"; |
5 | 6 | import Type = WASM.Type; |
6 | 7 | import WasmInt = WASM.WasmInt; |
@@ -112,7 +113,39 @@ test('[invoke parser] : f32 decimal bit pattern with alpha hex equivalent', t => |
112 | 113 | t.is(result.value, -8.881785255792436e-16); |
113 | 114 | }); |
114 | 115 |
|
115 | | -test('[verifier] : numeric mismatch is reported as failure, not missing field', t => { |
| 116 | +test("[protobuf invoke result] : decodes signed i64 boundaries", t => { |
| 117 | + for (const [bits, expected] of [[0n, 0n], [0xffffffffffffffffn, -1n], [0x8000000000000000n, -9223372036854775808n]]) { |
| 118 | + const result = remoteFunctionResultParser(RemoteFunctionResult.encode({success: true, results: [{i64Bits: bits, index: 0}], error: Buffer.alloc(0)}).finish()); |
| 119 | + t.false("text" in result); |
| 120 | + if ("text" in result) return; |
| 121 | + t.is(result.type, WASM.Integer.i64); |
| 122 | + t.is((result.value as WasmInt).toBigInt(), expected); |
| 123 | + } |
| 124 | +}); |
| 125 | + |
| 126 | +test("[protobuf invoke result] : decodes IEEE-754 float bits", t => { |
| 127 | + const f32 = remoteFunctionResultParser(RemoteFunctionResult.encode({success: true, results: [{f32Bits: 0x3fc00000, index: 0}], error: Buffer.alloc(0)}).finish()); |
| 128 | + const f64 = remoteFunctionResultParser(RemoteFunctionResult.encode({success: true, results: [{f64Bits: 0x4004000000000000n, index: 0}], error: Buffer.alloc(0)}).finish()); |
| 129 | + |
| 130 | + t.false("text" in f32); |
| 131 | + t.false("text" in f64); |
| 132 | + if ("text" in f32 || "text" in f64) return; |
| 133 | + t.deepEqual(f32, {type: WASM.Float.f32, value: 1.5}); |
| 134 | + t.deepEqual(f64, {type: WASM.Float.f64, value: 2.5}); |
| 135 | +}); |
| 136 | + |
| 137 | +test("[protobuf invoke result] : maps void, malformed, and failed responses", t => { |
| 138 | + const voidResult = remoteFunctionResultParser(RemoteFunctionResult.encode({success: true, results: [], error: Buffer.alloc(0)}).finish()); |
| 139 | + t.deepEqual(voidResult, WASM.nothing); |
| 140 | + |
| 141 | + const failure = remoteFunctionResultParser(RemoteFunctionResult.encode({success: false, results: [], error: Buffer.from("division by zero")}).finish()); |
| 142 | + t.deepEqual(failure, {text: "division by zero"}); |
| 143 | + |
| 144 | + const malformed = RemoteFunctionResult.encode({success: true, results: [{index: 0}], error: Buffer.alloc(0)}).finish(); |
| 145 | + t.throws(() => remoteFunctionResultParser(malformed), {message: /no supported WASM value/}); |
| 146 | +}); |
| 147 | + |
| 148 | +test("[verifier] : numeric mismatch is reported as failure, not missing field", t => { |
116 | 149 | const step: Step = { |
117 | 150 | title: 'CHECK: numeric mismatch', |
118 | 151 | instruction: { |
|
0 commit comments