Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolution of abi-coder tests #3422

Open
petertonysmith94 opened this issue Nov 25, 2024 · 0 comments
Open

Resolution of abi-coder tests #3422

petertonysmith94 opened this issue Nov 25, 2024 · 0 comments
Labels
chore Issue is a chore

Comments

@petertonysmith94
Copy link
Contributor

Summary

With #3349, we introduced several tests which we skipped at the time for a variety of reasons. It'd be good to resolve all of these to ensure our abi-coder has a full coverage of encoding/decoding.

For types_struct_with_array_of_enums we have an issue with result causing some unexpected behaviour.

For types_struct_with_multiple_struct_params and types_struct_with_complex_nested_struct we encounter issues with the deeply nested types and go unexpected results when returning these for functions:

error: Type "StructD<u32, u32, StructF<Vec<StructG>>>" does not implement AbiEncode or AbiDecode.

types_struct_with_array_of_enums

  • We encountered an issue with the results of this function, and all the details can be found in the following issue.

types_struct_with_multiple_struct_params

  • StructC has not been fully implemented:
    pub struct StructC {
    pub propC1: StructA,
    pub propC2: Vec<StructB>,
    pub propC3: StructD<u8, u8, StructF<str[1]>>,
    // propC4: Vec<StructD<u16, u16, StructF<bool>>>,
    // propC5: Vec<StructD<u32, u32, StructF<Vec<StructG>>>>,
    }
  • Sway function not fully implemented:
    fn types_struct_with_multiple_struct_params(x: StructA, y: StructB, z: StructC) -> bool {
    const STRUCT_A: StructA = StructA { propA1: 10 };
    assert(x == STRUCT_A);
    const STRUCT_B: StructB = StructB {
    propB1: STRUCT_A,
    propB2: 20,
    };
    assert(y == STRUCT_B);
    // PropC2
    let mut propC2 = Vec::new();
    propC2.push(STRUCT_B);
    // PropC3
    const STRUCT_E: StructE<u8> = StructE {
    propE1: STRUCT_A,
    propE2: STRUCT_B,
    propE3: 30,
    };
    let mut propD1 = Vec::new();
    propD1.push(STRUCT_E);
    const STRUCT_F: StructF<str[1]> = StructF {
    propF1: 50,
    propF2: __to_str_array("A"),
    };
    let propC3: StructD<u8, u8, StructF<str[1]>> = StructD {
    propD1: propD1,
    propD2: 40,
    propD3: STRUCT_F,
    };
    let STRUCT_C: StructC = StructC {
    propC1: STRUCT_A,
    propC2: propC2,
    propC3: propC3,
    // propC4: [STRUCT_D],
    // propC5: [STRUCT_D],
    };
    assert(z == STRUCT_C);
    return true;
    // const STRUCT_C4: StructD<u16, u16, StructF<bool>> = StructD<u16, u16, StructF<bool> {
    // propD1: [StructE { propE1: STRUCT_A, propE2: STRUCT_B, propE3: 30 }],
    // propD2: 40,
    // propD3: StructF { propF1: 50, propF2: true },
    // };
    // const STRUCT_C5: StructD<u32, u32, StructF<Vec<StructG>>> = StructD<u32, u32, StructF<Vec<StructG>> {
    // propD1: [StructE { propE1: STRUCT_A, propE2: STRUCT_B, propE3: 30 }],
    // propD2: 40,
    // propD3: StructF { propF1: 50, propF2: [StructG { propG1: 60 }] },
    // };
    // const STRUCT_C: StructC = StructC {
    // propC1: STRUCT_A,
    // propC2: [STRUCT_B],
    // propC3: STRUCT_C3,
    // propC4: [STRUCT_C4],
    // propC5: [STRUCT_C5],
    // };
    // const STRUCT_B: StructB = StructB { propB1: INPUT_X, propB2: 20 };
    // const STRUCT_C: StructC = StructC { propC1: INPUT_X, propC2: [INPUT_Y], propC3: INPUT_D, propC4: [INPUT_D], propC5: [INPUT_D] };
    // const STRUCT_D: StructD = StructD {
    // propD1: [StructE { propE1: INPUT_X, propE2: INPUT_Y, propE3: 30 }],
    // propD2: 40,
    // propD3: StructF { propF1: 50, propF2: __to_str_array("ABC") },
    // };
    // assert(y == INPUT_Y);
    }
  • Implement the associated TS test:
    it.todo('should encode/decode just fine', async () => {
    const STRUCT_A = { propA1: 10 };
    const STRUCT_B = { propB1: STRUCT_A, propB2: 20 };
    const INPUT_X = STRUCT_A;
    const INPUT_Y = STRUCT_B;
    const INPUT_Z: StructCInput = {
    propC1: STRUCT_A,
    propC2: [STRUCT_B],
    propC3: {
    propD1: [{ propE1: STRUCT_A, propE2: STRUCT_B, propE3: 30 }],
    propD2: 40,
    propD3: { propF1: 50, propF2: 'A' },
    },
    };
    const { waitForResult } = await contract.functions
    .types_struct_with_multiple_struct_params(INPUT_X, INPUT_Y, INPUT_Z)
    .call();
    await waitForResult();
    // const { value, logs } = await waitForResult();
    // expect(value).toStrictEqual(expected);
    // expect(logs).toStrictEqual([expected]);
    });

types_struct_with_complex_nested_struct

@petertonysmith94 petertonysmith94 added the chore Issue is a chore label Nov 25, 2024
@petertonysmith94 petertonysmith94 mentioned this issue Dec 9, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Issue is a chore
Projects
None yet
Development

No branches or pull requests

1 participant