Socket
Socket
Sign inDemoInstall

truffle-assertions

Package Overview
Dependencies
2
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

test/box-img-lg.png

38

index.js

@@ -30,2 +30,28 @@ const _ = require('lodash');

/* Returns event string in the form of EventType(arg1, arg2, ...) */
getPrettyEventString = (eventType, args) => {
let argString = '';
Object.entries(args).forEach(([key, value]) => {
argString += `, ${key}: ${value}`;
});
argString = argString.replace(', ', '');
return `${eventType}(${argString})`;
}
/* Returns a list of all emitted events in a transaction,
* using the format of getPrettyEventString
*/
getPrettyEmittedEventsString = (result) => {
if (result.logs.length === 0) {
return ` No events emitted in tx ${result.tx}\n`;
}
let string = ` Events emitted in tx ${result.tx}:\n`;
string += ` ----------------------------------------------------------------------------------------\n`;
for (const emittedEvent of result.logs) {
string += ` ${getPrettyEventString(emittedEvent.event, emittedEvent.args)}\n`;
}
string += ` ----------------------------------------------------------------------------------------\n`;
return string;
}
module.exports = {

@@ -37,3 +63,4 @@ eventEmitted: (result, eventType, filter, message) => {

});
assertEventListNotEmpty(events, message, `Event of type ${eventType} was not emitted`);
//TODO: Move the getPrettyEmittedEventsString to the assertion functions
assertEventListNotEmpty(events, message, `Event of type ${eventType} was not emitted\n${getPrettyEmittedEventsString(result)}`);

@@ -50,3 +77,3 @@ /* Return if no filter function was provided */

eventArgs = _.filter(eventArgs, filter);
assertEventListNotEmpty(eventArgs, message, `Event filter for ${eventType} returned no results`);
assertEventListNotEmpty(eventArgs, message, `Event filter for ${eventType} returned no results\n${getPrettyEmittedEventsString(result)}`);
},

@@ -61,3 +88,3 @@ eventNotEmitted: (result, eventType, filter, message) => {

if (filter == undefined || filter === null) {
assertEventListEmpty(events, message, `Event of type ${eventType} was emitted`);
assertEventListEmpty(events, message, `Event of type ${eventType} was emitted\n${getPrettyEmittedEventsString(result)}`);
return;

@@ -71,4 +98,7 @@ }

eventArgs = _.filter(eventArgs, filter);
assertEventListEmpty(eventArgs, message, `Event filter for ${eventType} returned results`);
assertEventListEmpty(eventArgs, message, `Event filter for ${eventType} returned results\n${getPrettyEmittedEventsString(result)}`);
},
prettyPrintEmittedEvents: (result) => {
console.log(getPrettyEmittedEventsString(result));
}
}

4

package.json
{
"name": "truffle-assertions",
"version": "0.2.0",
"description": "Additional assertions for testing Ethereum smart contracts Truffle unit tests",
"version": "0.3.0",
"description": "Additional assertions and utilities for testing Ethereum smart contracts Truffle unit tests",
"main": "index.js",

@@ -6,0 +6,0 @@ "scripts": {},

@@ -21,6 +21,6 @@ # truffle-assertions

## Assertions
## Exported functions
### truffleAssert.eventEmitted(result, eventType, filter, message)
The `eventEmitted` assertion checks that an event with type eventType has been emitted by the transaction with result result. A filter function can be passed along to further specify requirements for the event arguments:
The `eventEmitted` assertion checks that an event with type `eventType` has been emitted by the transaction with result `result`. A filter function can be passed along to further specify requirements for the event arguments:

@@ -33,3 +33,3 @@ ```javascript

When the filter parameter is omitted or set to null, the assertion checks just for event type:
When the `filter` parameter is omitted or set to null, the assertion checks just for event type:

@@ -53,6 +53,6 @@ ```javascript

```
Depending on the reason for the assertion failure.
Depending on the reason for the assertion failure. The default message also includes a list of events that were emitted in the passed transaction.
### truffleAssert.eventNotEmitted(result, eventType, filter, message)
The `eventNotEmitted` assertion checks that an event with type eventType has not been emitted by the transaction with result result. A filter function can be passed along to further specify requirements for the event arguments:
The `eventNotEmitted` assertion checks that an event with type `eventType` has not been emitted by the transaction with result `result`. A filter function can be passed along to further specify requirements for the event arguments:

@@ -65,3 +65,3 @@ ```javascript

When the filter parameter is omitted or set to null, the assertion checks just for event type:
When the `filter` parameter is omitted or set to null, the assertion checks just for event type:

@@ -83,2 +83,16 @@ ```javascript

```
Depending on the reason for the assertion failure.
Depending on the reason for the assertion failure. The default message also includes a list of events that were emitted in the passed transaction.
### truffleAssert.prettyPrintEmittedEvents(result)
Pretty prints the full list of events with their parameters, that were emitted in transaction with result `result`
```
truffleAssert.prettyPrintEmittedEvents(result);
```
```
Events emitted in tx 0x7da28cf2bd52016ee91f10ec711edd8aa2716aac3ed453b0def0af59991d5120:
----------------------------------------------------------------------------------------
TestEvent(testAddress = 0xe04893f0a1bdb132d66b4e7279492fcfe602f0eb, testInt: 10)
----------------------------------------------------------------------------------------
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc