Skip to content

Commit d1c0608

Browse files
committed
Fix up tests after merging with latest AssemblyScript
1 parent f71368a commit d1c0608

File tree

4 files changed

+6173
-2332
lines changed

4 files changed

+6173
-2332
lines changed

tests/near-bindgen/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ export function getStringArrayLength(arr: string[]): i32 {
3232
}
3333

3434
export function convertFoobars(foobars: Array<FooBar>): Array<ContainerClass> {
35+
/* TODO: Fix compiler bug https://github.com/AssemblyScript/assemblyscript/issues/539
3536
return foobars.map<ContainerClass>((it: FooBar, i: i32, arr: Array<FooBar>): ContainerClass => {
3637
return { foobar: it};
3738
});
39+
*/
40+
let result: ContainerClass[] = new Array(foobars.length);
41+
for (let i = 0; i < foobars.length; i++) {
42+
result[i] = { foobar: foobars[i] }
43+
}
44+
return result;
3845
}

tests/near-bindgen/model_near.ts.expected

Lines changed: 116 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,47 @@ export function __near_decode_ContainerClass(
403403
return handler.value;
404404
}
405405

406+
export function __near_encode_Array_FooBar(
407+
value: Array<wrapped_FooBar>,
408+
encoder: JSONEncoder
409+
): void {
410+
for (let i = 0; i < value.length; i++) {
411+
if (value[i] != null) {
412+
encoder.pushObject(null);
413+
__near_encode_FooBar(<FooBar>value[i], encoder);
414+
encoder.popObject();
415+
} else {
416+
encoder.setNull(null);
417+
}
418+
}
419+
}
420+
export function __near_encode_Array_Array_FooBar(
421+
value: Array<Array<wrapped_FooBar>>,
422+
encoder: JSONEncoder
423+
): void {
424+
for (let i = 0; i < value.length; i++) {
425+
if (value[i] != null) {
426+
encoder.pushArray(null);
427+
__near_encode_Array_FooBar(<Array<FooBar>>value[i], encoder);
428+
encoder.popArray();
429+
} else {
430+
encoder.setNull(null);
431+
}
432+
}
433+
}
406434
export function __near_encode_AnotherContainerClass(
407435
value: wrapped_AnotherContainerClass,
408436
encoder: JSONEncoder
409437
): void {
410-
if (value.foobar != null) {
411-
encoder.pushObject("foobar");
412-
__near_encode_FooBar(<FooBar>value.foobar, encoder);
413-
encoder.popObject();
438+
if (value.foobars != null) {
439+
encoder.pushArray("foobars");
440+
__near_encode_Array_Array_FooBar(
441+
<Array<Array<FooBar>>>value.foobars,
442+
encoder
443+
);
444+
encoder.popArray();
414445
} else {
415-
encoder.setNull("foobar");
446+
encoder.setNull("foobars");
416447
}
417448
}
418449
export class __near_JSONHandler_AnotherContainerClass extends ThrowingJSONHandler {
@@ -421,8 +452,8 @@ export class __near_JSONHandler_AnotherContainerClass extends ThrowingJSONHandle
421452
handledRoot: boolean = false;
422453
value: wrapped_AnotherContainerClass = new wrapped_AnotherContainerClass();
423454
setNull(name: string): void {
424-
if (name == "foobar") {
425-
this.value.foobar = <wrapped_FooBar>null;
455+
if (name == "foobars") {
456+
this.value.foobars = <Array<Array<wrapped_FooBar>>>null;
426457
return;
427458
}
428459

@@ -437,19 +468,92 @@ export class __near_JSONHandler_AnotherContainerClass extends ThrowingJSONHandle
437468
} else {
438469
assert(name != null);
439470
}
440-
if (name == "foobar") {
441-
this.value.foobar = <FooBar>(
442-
__near_decode_FooBar(this.buffer, this.decoder.state)
471+
472+
return super.pushObject(name);
473+
}
474+
475+
pushArray(name: string): bool {
476+
if (name == "foobars") {
477+
this.value.foobars = <Array<Array<FooBar>>>(
478+
__near_decode_Array_Array_FooBar(this.buffer, this.decoder.state)
443479
);
444480
return false;
445481
}
446482

447-
return super.pushObject(name);
483+
return super.pushArray(name);
448484
}
485+
}
449486

487+
export class __near_JSONHandler_Array_Array_FooBar extends ThrowingJSONHandler {
488+
buffer: Uint8Array;
489+
decoder: JSONDecoder<__near_JSONHandler_Array_Array_FooBar>;
490+
handledRoot: boolean = false;
491+
value: Array<Array<wrapped_FooBar>> = new Array<Array<wrapped_FooBar>>();
492+
pushObject(name: string): bool {
493+
this.value.push(<Array<FooBar>>(
494+
__near_decode_Array_FooBar(this.buffer, this.decoder.state)
495+
));
496+
return false;
497+
}
450498
pushArray(name: string): bool {
451-
return super.pushArray(name);
499+
assert(name == null);
500+
if (!this.handledRoot) {
501+
this.handledRoot = true;
502+
return true;
503+
}
504+
this.value.push(<Array<FooBar>>(
505+
__near_decode_Array_FooBar(this.buffer, this.decoder.state)
506+
));
507+
return false;
508+
}
509+
}
510+
511+
export class __near_JSONHandler_Array_FooBar extends ThrowingJSONHandler {
512+
buffer: Uint8Array;
513+
decoder: JSONDecoder<__near_JSONHandler_Array_FooBar>;
514+
handledRoot: boolean = false;
515+
value: Array<wrapped_FooBar> = new Array<wrapped_FooBar>();
516+
pushObject(name: string): bool {
517+
this.value.push(<FooBar>(
518+
__near_decode_FooBar(this.buffer, this.decoder.state)
519+
));
520+
return false;
452521
}
522+
pushArray(name: string): bool {
523+
assert(name == null);
524+
if (!this.handledRoot) {
525+
this.handledRoot = true;
526+
return true;
527+
}
528+
this.value.push(<FooBar>(
529+
__near_decode_FooBar(this.buffer, this.decoder.state)
530+
));
531+
return false;
532+
}
533+
}
534+
535+
export function __near_decode_Array_FooBar(
536+
buffer: Uint8Array,
537+
state: DecoderState
538+
): Array<wrapped_FooBar> {
539+
let handler = new __near_JSONHandler_Array_FooBar();
540+
handler.buffer = buffer;
541+
handler.decoder = new JSONDecoder<__near_JSONHandler_Array_FooBar>(handler);
542+
handler.decoder.deserialize(buffer, state);
543+
return handler.value;
544+
}
545+
546+
export function __near_decode_Array_Array_FooBar(
547+
buffer: Uint8Array,
548+
state: DecoderState
549+
): Array<Array<wrapped_FooBar>> {
550+
let handler = new __near_JSONHandler_Array_Array_FooBar();
551+
handler.buffer = buffer;
552+
handler.decoder = new JSONDecoder<__near_JSONHandler_Array_Array_FooBar>(
553+
handler
554+
);
555+
handler.decoder.deserialize(buffer, state);
556+
return handler.value;
453557
}
454558

455559
export function __near_decode_AnotherContainerClass(

tests/near-bindgen/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ async function loadModule(path) {
8484
[{ foobar: { foo: 0, bar: 1, u64Val: "64", i64Val: "-64", flag: false, baz: '123', arr: [["1", "2"], ["3"]], u32Arr: null, i32Arr: null }}]);
8585
assert.equal(await module.getStringArrayLength({ arr: ["1", "2", "3"] }), 3);
8686
assert.deepEqual(await module.rewrapFoobar({ container: { foobar: { foo: 123 } } }),
87-
{ foobars: [[{"foo":123,"bar":1,"flag":false,"baz":"123","arr":null}]] });
87+
{"foobars":[[{"foo":123,"bar":1,"u64Val":"64","i64Val":"-64","flag":false,"baz":"123","arr":null,"u32Arr":null,"i32Arr":null}]]});
8888
assert.deepEqual(await module.unwrapFoobar({ container: { foobars: [[{ foo: 123 }]] } }),
89-
{"foo":123,"bar":1,"flag":false,"baz":"123","arr":null} );
89+
{"foo":123,"bar":1,"u64Val":"64","i64Val":"-64","flag":false,"baz":"123","arr":null,"u32Arr":null,"i32Arr":null});
9090
})().catch(e => {
9191
console.error('Error during test execution:', e);
9292
if (e.code == 'ERR_ASSERTION') {

0 commit comments

Comments
 (0)