events.spec.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import expect from 'expect';
  2. import { gasLimit, createConnection, deploy, transaction, aliceKeypair, } from './index';
  3. import { ContractPromise } from '@polkadot/api-contract';
  4. import { ApiPromise } from '@polkadot/api';
  5. import { DecodedEvent } from '@polkadot/api-contract/types';
  6. describe('Deploy events contract and test', () => {
  7. let conn: ApiPromise;
  8. before(async function () {
  9. conn = await createConnection();
  10. });
  11. after(async function () {
  12. await conn.disconnect();
  13. });
  14. it('events', async function () {
  15. this.timeout(50000);
  16. const alice = aliceKeypair();
  17. // call the constructors
  18. let deploy_contract = await deploy(conn, alice, 'events.contract', BigInt(0));
  19. let contract = new ContractPromise(conn, deploy_contract.abi, deploy_contract.address);
  20. let tx = contract.tx.emitEvent({ gasLimit });
  21. let res0: any = await transaction(tx, alice);
  22. let events: DecodedEvent[] = res0.contractEvents;
  23. expect(events.length).toEqual(2);
  24. expect(events[0].event.identifier).toBe("foo1");
  25. expect(events[0].event.docs).toEqual(["Ladida tada\n\n"]);
  26. expect(events[0].args.map(a => a.toJSON())).toEqual([254, "hello there"]);
  27. expect(events[1].event.identifier).toBe("foo2");
  28. expect(events[1].event.docs).toEqual(["Event Foo2\n\nJust a test\n\nAuthor: them is me"]);
  29. expect(events[1].args.map(a => a.toJSON())).toEqual(["0x7fffffffffffffff", "minor", deploy_contract.address.toString()]);
  30. });
  31. });