Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fix “No events were emitted” #12

Open
kennblvnp opened this issue Oct 17, 2018 · 6 comments
Open

How to fix “No events were emitted” #12

kennblvnp opened this issue Oct 17, 2018 · 6 comments

Comments

@kennblvnp
Copy link

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: "*"
    }
  }
};
@loclaidinh
Copy link

I think you need to add 'emit' keyword to fire an event, like this:

emit Transfer(msg.sender, _to, _value);

@kennblvnp
Copy link
Author

@loclaidinh thats already in my code

@lawrencelokinhang
Copy link

@kennblvnp have you solved your problem? I have same problem.

@kennblvnp
Copy link
Author

kennblvnp commented Nov 14, 2019

Hi @lawrencelokinhang I solved it by studying unit testing in solidity or javascript.
You might wanna familiarise Javascript Unit Test they are alike (maybe 5 video tutorials).

because this truffle test --network development is just testing your code locally before going live

@dastageer-eth
Copy link

@kennblvnp Can you put the fixed code if possiable?

@ghost
Copy link

ghost commented May 20, 2022

Hi can you provide the fixed code @kennblvnp ? having the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants