[Ethereum] How to fix “No events were emitted”

dapp-developmentsoliditytokenstruffle-migration

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: "*"
    }
  }
};

Best Answer

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.

Related Topic