expectEvent.js 623 B

123456789101112131415161718192021222324252627282930313233
  1. const should = require('chai').should();
  2. function inLogs (logs, eventName, eventArgs = {}) {
  3. const event = logs.find(function (e) {
  4. if (e.event === eventName) {
  5. let matches = true;
  6. for (const [k, v] of Object.entries(eventArgs)) {
  7. if (e.args[k] !== v) {
  8. matches = false;
  9. }
  10. }
  11. if (matches) {
  12. return true;
  13. }
  14. }
  15. });
  16. should.exist(event);
  17. return event;
  18. }
  19. async function inTransaction (tx, eventName, eventArgs = {}) {
  20. const { logs } = await tx;
  21. return inLogs(logs, eventName, eventArgs);
  22. }
  23. module.exports = {
  24. inLogs,
  25. inTransaction,
  26. };