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

Typegen generating invalid types with Scripts and Predicates #2832

Closed
petertonysmith94 opened this issue Jul 25, 2024 · 1 comment · Fixed by #2859
Closed

Typegen generating invalid types with Scripts and Predicates #2832

petertonysmith94 opened this issue Jul 25, 2024 · 1 comment · Fixed by #2859
Assignees
Labels
bug Issue is a bug

Comments

@petertonysmith94
Copy link
Contributor

Summary

When building out Scripts and Predicates using configurables, I encountered some issues with the generated types (which can be found below with examples). The following PR has the expanded example that should showcase the issue.

As part of this, we should:

  • Add valid typegen output for Option, Enum and Struct
  • Expand the example from the PR, adding all types used to the inputs of the script and predicate.
  • Add tests around these two script and predicate, ensuring that we can use the typegen'd resuts, pass inputs and update configurables.

Details

Option

configurable {
  configurableOption: Option<u8> = Some(0),
}

Actual

export type AbiConfigurables = Partial<{
  configurableOption: Option;
}>

Expected

export type AbiConfigurables = Partial<{
  configurableOption: Option<BigNumberish>;
}>

Enum

enum GenericEnum<V> {
    Foo: u64,
}

configurable {
  configurableEnumWithGeneric: GenericEnum<u8> = GenericEnum::Foo(0),
}

Actual

// V generic is unused
export type GenericEnumInput<V> = Enum<{ Foo: BigNumberish }>;
export type GenericEnumOutput<V> = Enum<{ Foo: BN }>;

export type AbiConfigurables = Partial<{
  // We don't pass in any generic type to `GenericEnumInput` so TS complains
  configurableEnumWithGeneric: GenericEnumInput;
}>

Expected

// V should extend the given type and default to the that type
export type GenericEnumInput<V extends BigNumberish = BigNumberish> = Enum<{ Foo: V }>;
export type GenericEnumOutput<V extends BigNumberish = BigNumberish> = Enum<{ Foo: V }>;

export type AbiConfigurables = Partial<{
  configurableEnumWithGeneric: GenericEnumInput;
}>

Option

struct GenericStruct<T> {
    Boo: T
}

configurable {
  configurableStructWithGeneric: GenericStruct<u8> = GenericStruct {
      Boo: 0
  },
}

Actual

// T is used, however, we don't enforce a type
export type GenericStructInput<T> = { Boo: T };
export type GenericStructOutput<T> = GenericStructInput<T>;

export type AbiConfigurables = Partial<{
  // We don't pass in any generic type to `GenericStructInput` so TS complains
  configurableStructWithGeneric: GenericStructInput;
}>

Expected

// T should extend the given type and default to the that type
export type GenericStructInput<T extends BigNumberish = BigNumberish> = { Boo: T };
export type GenericStructOutput<T extends BigNumberish = BigNumberish> = GenericStructInput<T>;

export type AbiConfigurables = Partial<{
  configurableStructWithGeneric: GenericStructInput;
}>
@petertonysmith94 petertonysmith94 added bug Issue is a bug p1 labels Jul 25, 2024
@nedsalk

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is a bug
Projects
None yet
2 participants