import pkg/asynctest import pkg/ethers import pkg/contractabi import ./examples ## Define outside the scope of the suite to allow for exporting ## To use custom distinct types, these procs will generally need ## to be defined in the application code anyway, to support ABI ## encoding/decoding type DistinctAlias = distinct array[32, byte] proc `==`*(x, y: DistinctAlias): bool {.borrow.} func toArray(value: DistinctAlias): array[32, byte] = array[32, byte](value) func encode*(encoder: var AbiEncoder, value: DistinctAlias) = encoder.write(value.toArray) func decode*(decoder: var AbiDecoder, T: type DistinctAlias): ?!T = let d = ?decoder.read(type array[32, byte]) success DistinctAlias(d) suite "Events": type SimpleEvent = object of Event a: UInt256 b: Address DynamicSizeEvent = object of Event a: array[32, byte] b: seq[byte] IndexedEvent = object of Event a: UInt256 b {.indexed.}: Address c: Address d {.indexed.}: UInt256 e {.indexed.}: array[32, byte] ComplexIndexedEvent = object of Event a {.indexed.}: array[42, UInt256] b {.indexed.}: seq[UInt256] c {.indexed.}: string d {.indexed.}: seq[byte] e {.indexed.}: (Address, UInt256) f {.indexed.}: array[33, byte] IndexedWithDistinctType = object of Event a {.indexed.}: DistinctAlias b: DistinctAlias proc example(_: type SimpleEvent): SimpleEvent = SimpleEvent( a: UInt256.example, b: Address.example ) proc example(_: type DynamicSizeEvent): DynamicSizeEvent = DynamicSizeEvent( a: array[32, byte].example, b: seq[byte].example ) proc example(_: type IndexedEvent): IndexedEvent = IndexedEvent( a: UInt256.example, b: Address.example, c: Address.example, d: UInt256.example, e: array[32, byte].example ) proc example(_: type IndexedWithDistinctType): IndexedWithDistinctType = IndexedWithDistinctType( a: DistinctAlias(array[32, byte].example) ) func encode(_: type AbiEncoder, value: DistinctAlias): seq[byte] = @(value.toArray) func encode[T](_: type Topic, value: T): Topic = let encoded = AbiEncoder.encode(value) result[0..