truffle-token-test-utils

1.0.0 • Public • Published

truffle-token-test-utils

npm npm bundle size

Visualize ERC20 token transfers in Truffle Tests

Install

$ npm install truffle-token-test-utils

Usage

With Truffle:

const tokenTransfers = require("truffle-token-test-utils");
contract("ContractName", (accounts) => {
  tokenTransfers.setWeb3(web3);  // web3 auto injected by truffle in tests
  ...
  const tx = await someContract.someFunction();
  await tokenTransfers.print(tx);
}

With OpenZeppelin:

const { web3 } = require("@openzeppelin/test-environment");
const tokenTransfers = require("truffle-token-test-utils");
tokenTransfers.setWeb3(web3);
...
const tx = await someContract.someFunction();
await tokenTransfers.print(tx);

Sample Output

Console Output

Additional Options:

1. Substitute address with custom names

An object for custom addressToName mapping can be passed along with print() to display names instead of ETH addresses. Without it the default 'SENDER' and 'RECEIVER' are displayed for the transaction sender and receiver contract address repectively. They both can also be overwritten with the passed object.

Eg:

await tokenTransfers.print(tx, {
  "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B": "Vitalik"
});

Output:

Custom Address Mapping output

2. Get overall accounts balance change

Pass boolean true as third argument for print() to display overall token balance change as shown

await tokenTransfers.print(tx, {}, true);

Output:

overall accounts balance output


Developed by:

Apoorv Lathey

Twitter Follow

Package Sidebar

Install

npm i truffle-token-test-utils

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

12.9 kB

Total Files

5

Last publish

Collaborators

  • apoorvlathey