mock-factory.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { QueryEventBlock, IQueryEvent } from "../../src";
  2. import { Phase, Event, EventRecord } from '@polkadot/types/interfaces';
  3. import { BlockPayload } from "../../src/model";
  4. import { withTs } from "../../src/utils/stringify";
  5. export function blockPayload(height: number): BlockPayload {
  6. return withTs({
  7. height
  8. }) as unknown as BlockPayload
  9. }
  10. export function queryEventBlock(block = 0): QueryEventBlock {
  11. const gen = queryEvent(block);
  12. return {
  13. block_number: block,
  14. query_events: [gen.next().value as IQueryEvent,
  15. gen.next().value as IQueryEvent,
  16. gen.next().value as IQueryEvent]
  17. }
  18. }
  19. export function * queryEvent(block = 0): Generator<IQueryEvent, void, IQueryEvent> {
  20. // TODO: use faker
  21. let i = 0;
  22. do {
  23. yield {
  24. eventRecord: {
  25. phase: {
  26. toJSON: () => { return {} }
  27. } as unknown as Phase,
  28. event: {
  29. method: 'fake.method',
  30. section: 'fake.section',
  31. data: []
  32. } as unknown as Event
  33. } as unknown as EventRecord,
  34. blockNumber: block,
  35. indexInBlock: i,
  36. eventName: 'fake.event',
  37. eventMethod: 'fake.method',
  38. eventParams: {},
  39. index: i
  40. }
  41. i++;
  42. } while (i < 100)
  43. }