Skip to content

Instantly share code, notes, and snippets.

@cds-amal
Created July 20, 2022 14:20
Show Gist options
  • Save cds-amal/7143ffa4c114d220e37e7680390c519d to your computer and use it in GitHub Desktop.
Save cds-amal/7143ffa4c114d220e37e7680390c519d to your computer and use it in GitHub Desktop.

I set up test project based on the metacoin-box (truffle unbox metacoin mc) with two test folders

  • test - has js tests
  • test-solidity - has solidity tests
Test layout

╭─amal@falafel  ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0›  ‹›
╰─$ tree
.
├── contracts
│   ├── ConvertLib.sol
│   ├── MetaCoin.sol
│   └── Migrations.sol
├── LICENSE
├── migrations
│   ├── 1_initial_migration.js
│   └── 2_deploy_contracts.js
├── test
│   └── metacoin.js
├── test-solidity
│   └── TestMetaCoin.sol
└── truffle-config.js

4 directories, 9 files

truffle test

╭─amal@falafel  ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0›  ‹›
╰─$ truffle test
results as expected

Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--1743274-Y2q2VdU15dGG
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang


  Contract: MetaCoin
    ✔ should put 10000 MetaCoin in the first account
    ✔ should call a function that depends on a linked library
    ✔ should send coin correctly (1077ms)


  3 passing (1s)

truffle test path/to/file

╭─amal@falafel  ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0›  ‹›
╰─$ truffle test test/metacoin.js
results as expected

Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--1743388-0nsXaTr7XjbR
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang


  Contract: MetaCoin
    ✔ should put 10000 MetaCoin in the first account
    ✔ should call a function that depends on a linked library
    ✔ should send coin correctly (1063ms)


  3 passing (1s)

truffle test /path/to/folder

╭─amal@falafel  ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0›  ‹›
╰─$ truffle test test-solidity
results as expected

Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Compiling ./test-solidity/TestMetaCoin.sol
> Artifacts written to /tmp/test--1743534-BBNscOqTSZk2
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang


  TestMetaCoin
    ✔ testInitialBalanceUsingDeployedContract (1056ms)
    ✔ testInitialBalanceWithNewMetaCoin (1040ms)


  2 passing (20s)

truffle test /path/to/empty/directory

╭─amal@falafel  ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0›  ‹›
╰─$ mkdir test-empty
╭─amal@falafel  ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0›  ‹›
╰─$ truffle test test-empty
Whoa, runs unspecified tests

Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--1744145-aVxVEeMoq6AW
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang


  Contract: MetaCoin
    ✔ should put 10000 MetaCoin in the first account
    ✔ should call a function that depends on a linked library
    ✔ should send coin correctly (1073ms)


  3 passing (1s)

Unclear API: truffle test /path/to/file /path/to/dir/with/tests

What does it mean when truffle test is invoked with a file and a folder?

╭─amal@falafel  ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0› ‹ruby-3.0.0› ‹›
╰─$ truffle test test/metacoin.js test-solidity
???

Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Compiling ./test-solidity/TestMetaCoin.sol
> Artifacts written to /tmp/test--1749328-NBlMKvd6ADTu
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang


  TestMetaCoin
    ✔ testInitialBalanceUsingDeployedContract (1058ms)
    ✔ testInitialBalanceWithNewMetaCoin (1045ms)


  2 passing (20s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment