1

I have been following the instructions in the Dapp university tutorial. But I am using Windows 10, Dapp University is Mac.

I downloaded this truffle with smart contract ERC20 from Dapp university.
Reference: https://github.com/dappuniversity/token_sale

This is the reference of the solidity (I only rename the file to bruce.sol) https://github.com/dappuniversity/token_sale/blob/master/contracts/DappToken.sol

Where I run truffle test --network development this displays:

Using network 'local'.



  Contract: BruceToken
    √ initializes the contract with the correct values
    √ allocates the initial supply upon deployment
    1) transfers token ownership
    > No events were emitted
    2) approves tokens for delegated transfer
    > No events were emitted
    3) handles delegated token transfers
    > No events were emitted

  Contract: BruceTokenSale
    √ initializes the contract with the correct values
    4) facilitates token buying

    Events emitted during test:
    ---------------------------

    Transfer(_from: <indexed>, _to: <indexed>, _value: 750000)

    ---------------------------
    5) ends token sale
    > No events were emitted


  3 passing (32s)
  5 failing

  1) Contract: BruceToken
       transfers token ownership:
     AssertionError: error message must contain revert
      at test\BruceToken.js:39:7
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

  2) Contract: BruceToken
       approves tokens for delegated transfer:
     TypeError: Cannot read property 'call' of undefined
      at test\BruceToken.js:62:36
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

  3) Contract: BruceToken
       handles delegated token transfers:
     AssertionError: cannot transfer value larger than approved amount
      at test\BruceToken.js:97:7
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

  4) Contract: BruceTokenSale
       facilitates token buying:
     AssertionError: cannot purchase more tokens than available
      at test\BruceTokenSale.js:61:7
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

  5) Contract: BruceTokenSale
       ends token sale:

      returns all unsold bruce tokens to admin
      + expected - actual

      -250000
      +999990

      at test\BruceTokenSale.js:82:14
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)



PS D:\Blvnp\DappUniversity\brucev2token_sale-master>
PS D:\Blvnp\DappUniversity\brucev2token_sale-master>
PS D:\Blvnp\DappUniversity\brucev2token_sale-master>
PS D:\Blvnp\DappUniversity\brucev2token_sale-master>
PS D:\Blvnp\DappUniversity\brucev2token_sale-master> ^C
PS D:\Blvnp\DappUniversity\brucev2token_sale-master> truffle test --network development
Could not connect to your Ethereum client. Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle.js)

PS D:\Blvnp\DappUniversity\brucev2token_sale-master> truffle test --network development
Using network 'development'.



  Contract: BruceToken
    √ initializes the contract with the correct values (165ms)
    √ allocates the initial supply upon deployment (44ms)
    √ transfers token ownership (214ms)
    1) approves tokens for delegated transfer
    > No events were emitted
    2) handles delegated token transfers

    Events emitted during test:
    ---------------------------

    Transfer(_from: <indexed>, _to: <indexed>, _value: 100)

    ---------------------------

  Contract: BruceTokenSale
    √ initializes the contract with the correct values (41ms)
    √ facilitates token buying (401ms)
    √ ends token sale (501ms)


  6 passing (2s)
  2 failing

  1) Contract: BruceToken
       approves tokens for delegated transfer:
     TypeError: Cannot read property 'call' of undefined
      at test\BruceToken.js:62:36
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

  2) Contract: BruceToken
       handles delegated token transfers:
     AssertionError: cannot transfer value larger than approved amount
      at test\BruceToken.js:97:7
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)


Now this is my truffle.js:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    },
    local: {
      host: "192.168.*.***",
      port: 1201,
      gas: 2000000,
      gasPrice: 10000000000,
      network_id: "*"
    }
  }
};


1

No events emitted is not a bug. So you can't fix it.

When a test fails, Truffle shows you which events emitted during the test so you can debug easily.

  • 1
    Oh I see. Now I know. So.. can you tell why its not emitting events if using private network? using 127.0.0.1:7545 ganache, everything works perfectly. – ichimaru Oct 17 '18 at 11:52
  • When comparing different runs, check your Truffle, Ganache and Solidity compiler versions. That may cause the difference. – ferit Oct 17 '18 at 13:28
  • when using private network, i am not using ganache anymore. and i am using the same truffle folder. the solidity is the problem, i dont know where to check it. – ichimaru Oct 17 '18 at 13:46
  • Have you read solidity.readthedocs.io/en/latest ? If you make an initial investment of reading it now trust me it will save a lot of time as you progress. – ferit Oct 17 '18 at 14:00
1

If you arrived here looking for a way to print the events emitted during your tests, you can do this with the --show-events flag:

truffle test --show-events

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.